Git Product home page Git Product logo

Comments (5)

TomFrost avatar TomFrost commented on September 17, 2024 1

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.

TomFrost avatar TomFrost commented on September 17, 2024 1

Very welcome! And trust meβ€” for how much debate this topic has seen, this solution is anything but obvious ;-)

from jexl.

TomFrost avatar TomFrost commented on September 17, 2024

Hi cunneen, sorry for the late response on this. Could you provide an example of what you're looking to do?

from jexl.

cunneen avatar cunneen commented on September 17, 2024

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.

cunneen avatar cunneen commented on September 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.