-
Notifications
You must be signed in to change notification settings - Fork 259
Add typeOf() function. #381
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
Add typeOf() function. #381
Conversation
andrew-coleman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Jacob, many thanks for implementing this. Just a couple of review points... ;)
src/functions.js
Outdated
| if(['string', 'boolean'].includes(typeof value)) { | ||
| return typeof value; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array.includes() is an ES6 function, which means that the transpiled jsonata-es5.js will not work in ES5 environments such as IE unless we explicitly put the polyfill into polyfill.js.
However, in this case, I think it would be easier to remove this block and replace it with two if statements for the string and boolean cases.
docs/object-functions.md
Outdated
| ## `$typeOf()` | ||
| __Signature:__`$typeOf(value)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I prefer the name $type as you proposed originally in #208. In general I favour names as single words, provided the word is a meaningful representation of what the function does. I think in this case $type would be ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Most languages (e.g. JavaScript) call the operator typeof so I went with that pattern. If single word function names are preferred, we can use that.
* Rename `typeOf()` to `type()` * Avoid use of Array.includes()
|
excellent - many thanks! |
Proposed in #208