Skip to content

feat: add function to extends/override builtin functions #102

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

Closed
wants to merge 7 commits into from

Conversation

Blackman99
Copy link

@Blackman99 Blackman99 commented May 19, 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

@Blackman99 Blackman99 closed this May 20, 2025
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