Skip to content

Feature request: extend built-in functions #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vasile-baluta opened this issue Mar 1, 2017 · 2 comments · May be fixed by #103
Open

Feature request: extend built-in functions #25

vasile-baluta opened this issue Mar 1, 2017 · 2 comments · May be fixed by #103

Comments

@vasile-baluta
Copy link

Hello.
We need to add some more built-in functions.

One would be the diff between two numbers. Another function would make a number negative. We can contribute with the code ourselves if it is ok.

@kesor
Copy link

kesor commented Dec 30, 2019

I am missing a function that will parse inline JSON, like the from_string function in here - https://github.com/Kintyre/jmespath/blob/7e185c/bin/jpath.py#L15

@glenveegee
Copy link

We've implemented this in a new typescript version if you're interested to check it out. The implementation maintains validation and interpreter scoping within the function. It also helps to add any number of custom functions as a series of plugins to jmespath. See https://github.com/nanoporetech/jmespath-ts

Here's a snippet from the unit test:

  it('register a customFunction', () =>  {
      expect(() => search({
        foo: 60,
        bar: 10
      }, 'divide(foo, bar)')
      ).toThrow('Unknown function: divide()');


      jmespath.registerFunction('divide', function(resolvedArgs) {
          const [dividend, divisor] = resolvedArgs;
          return dividend / divisor;
        },
        [{ types: [jmespath.TYPE_NUMBER] }, { types: [jmespath.TYPE_NUMBER] }]
      )

      expect(search({
        foo: 60,
        bar: 10
      }, 'divide(foo, bar)')
      ).toEqual(6)
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants