Skip to content

Proposal: URL/URI Helper 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

Closed
jhorbulyk opened this issue Dec 7, 2017 · 8 comments
Closed

Proposal: URL/URI Helper Functions #103

jhorbulyk opened this issue Dec 7, 2017 · 8 comments

Comments

@jhorbulyk
Copy link
Contributor

jhorbulyk commented Dec 7, 2017

It would be useful if the following JavaScript string operators were exposed to JSONata:

This functionality would be useful in order to write transformations which produce or consume URLs/URIs. Would adding such functionality be in the spirit of the library's intended purposes?

@xogeny
Copy link
Contributor

xogeny commented Jan 10, 2018

Can't you simply add these via assign/bindings/registerFunction?

@jhorbulyk
Copy link
Contributor Author

@xogeny You could register these functions however they encompase pretty standard functionality that one would want in most places which is why adding them to the set of built-in functions would be pretty desireable IMO.

@xogeny
Copy link
Contributor

xogeny commented Jan 10, 2018

Do you think this could be addressed by having a plugin system for registering functions in bulk? That way, people could pick and choose what "libraries" of functions they wanted to have pre-defined in their application and it could even provide a mechanism to provide such libraries as packages in npm for easy use.

@jhorbulyk
Copy link
Contributor Author

A plugin system could be a useful JSONata feature. My thoughts:

  • It isn't necessary for this particular request
  • These exist as native functions in the underlying language (JavaScript). It seems sensible that they could also exist as native functions in JSONata.
  • The cost of overhead of a plugin system may not be worth it given the relative symplicity of JSONata.
  • JSONata appears useful as transformation language. I'm less certain about JSONata's utility as a framework for transformations.
  • I can't think of use cases in which a user wouldn't want functions such as encodeURIComponent() to be available.

@xogeny
Copy link
Contributor

xogeny commented Jan 10, 2018

All good comments. Regarding your last point, the issue is really just making sure the global namespace doesn't get too polluted. One could say "I can't think of a use cases in which a user wouldn't want ... mongodb/fetch/node/DOM/whatever ...functions to be available". But you make a good point that these are native to Javascript and don't introduce dependencies.

@andrew-coleman
Copy link
Member

@xogeny - I think the idea of a plugin system is a good one. Please could you raise a separate issue outlining your proposal (especially the external API)? Many thanks.

@jhorbulyk - I'm always open to adding more functions that are of genuine use to (at least) more than one user, and these might qualify on that. However, just because they are in the underlying Javascript language won't help the groups that are currently implementing JSONata in Java and Golang (plus any potential future implementors in other host languages). That is one of the reasons why this implementation has no dependencies on other packages.

@xogeny
Copy link
Contributor

xogeny commented Jan 11, 2018

Thinking about this more, I think there are two ways a "plugin" system could operate. It could either be used to add functions, in bulk, to an existing expression (essentially just invoking registerFunction on it many times). Or, it could modify the jsonata module itself (at runtime) to augment the default set of functions that get associated with every expression. Of course, one might choose to support both types. But I'd be curious if anybody has any feedback on what use case is more pressing...?

@andrew-coleman
Copy link
Member

Resolved by #357

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

No branches or pull requests

3 participants