Comments (5)
Ah, understood! This has been discussed before, with various solutions being considered. The two that made it the furthest are in your list -- .
and a dedicated keyword to access the root level.
Ultimately, both solutions have pitfalls that negatively outweigh the simple solution: just wrap that context in another variable. So rather than Jexl specifying that ROOT
refers to the top-level context, the engineer can just pass { ROOT: originalContext }
as the context and keep all that control.
Let me know if you have a use case that's not solved by this pattern!
from jexl.
Very welcome! And trust meβ for how much debate this topic has seen, this solution is anything but obvious ;-)
from jexl.
Hi cunneen, sorry for the late response on this. Could you provide an example of what you're looking to do?
from jexl.
Thanks @TomFrost. So to specify and perform a transform, the syntax seems to require I specify a data property name as a parameter to perform the transform on.
For example, name
in the following example is the input data property:
var jexl = require("jexl");
const context = {
name: { first: 'Sterling', last: 'Archer' },
assoc: [
{ first: 'Lana', last: 'Kane' },
{ first: 'Cyril', last: 'Figgis' },
{ first: 'Pam', last: 'Poovey' }
],
age: 36
}
// Transform
jexl.addTransform('upper', val => val.toUpperCase())
await jexl.eval('"duchess"|upper + " " + name.last|upper', context); // note the property 'name' here
So how can I specify and perform if my input data looks like this? :
const context = [
{ first: 'Lana', last: 'Kane' },
{ first: 'Cyril', last: 'Figgis' },
{ first: 'Pam', last: 'Poovey' }
]
I need a syntax token that allows me to specify that the transform applies to the entire context document rather than a property of the document e.g. .
or *
or JEXL_ROOT
from jexl.
Thanks @TomFrost . So simple, I'm embarrassed not to have thought of it. Thanks for the detailed answer to my question.
from jexl.
Related Issues (20)
- Match operator not recognized HOT 2
- Opinions on functions vs transforms? HOT 3
- '&&' and '||' priority HOT 1
- -a(2,3) HOT 1
- Scientific number notation: 1e2, 2.1e-3 etc HOT 3
- Cannot index into static array or object HOT 4
- Is this project maintained? Do you want a hand? HOT 8
- Errors for bad identifiers HOT 1
- Object's prototype methods return undefined for token type
- Security? does it use actual JS eval function? HOT 1
- Problem with inline if HOT 1
- How to convert AST to an expression string? HOT 5
- Object keys with a space HOT 2
- Run in browser?
- Cannot read properties of undefined (reading '0')
- Backslashes are wrongly unescaped
- Keys with hyphens evaluate to null HOT 1
- Inconsistency between null and undefined operations HOT 1
- Transform Confusion HOT 1
- Minus token is confused for binaryOp in function arguments HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jexl.