Skip to content

Feat: provide ability to extends/override builtin functions #103

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
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Blackman99
Copy link

@Blackman99 Blackman99 commented May 20, 2025

This PR provide ability to extends/override builtin functions.

API explanation

jmespath.extendsFunction('functionName', function (supportedTypes) {
	return {
		// the function implemention
		processor: function (resolvedArgs) {
			// do somthing with args and return the expected result
		},
		// the signature for validating function parameters
		signature: [
			{
				types: [
					supportedTypes.TYPE_NUMBER,
					// more types...
				]
			}
		]
	}
})

Example usage

 jmespath.extendsFunction('foo', function (supportedTypes) {
	return {
		processor: function (resolvedArgs) {
			return 99 + resolvedArgs[0];
		},
		signature: [
			{ types: [supportedTypes.TYPE_NUMBER] }
		]
	}
});
jmespath.search({ bar: 1 }, 'foo(bar)')
// The result should be 100

The new added extendsFunction function should has no side effects. It only collect built-in types into a object and provide it for custom function creator.

Tests

Relative test is included in this PR.

This PR should fix #25 #30

Tip

Since it seems the original jmespath is no longer under maintaining. If you want to use this API. Just use @sj1/jmespath instead of jmespath

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

Successfully merging this pull request may close these issues.

Feature request: extend built-in functions
1 participant