Skip to content
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

Adding typeof support #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jottinger
Copy link
Contributor

Adds typeof support for the simple operators.

@jwadhams
Copy link
Owner

This is awesome functionality to have. May I propose some refinements?

A) We keep your proposed syntax as a shortcut, and also if you call it with one argument it returns the type:

jsonLogic.apply({"typeof" : [42, "number"] }) // returns true
jsonLogic.apply({"typeof" : 42}) // returns "number"

B) Because JsonLogic also has parsers in other languages that don't have JavaScript's peculiarities, sometimes we have to/get to make better choices. (e.g., our own truthy table ) So this method can/should call an array an array:

//It's a bad idea to use the unary shortcut with array arguments.
jsonLogic.apply({"typeof" :[ [1,2,3] ]}) // returns "array". 

jsonLogic.apply({"typeof" :[ [1,2,3], "object" ]}) // returns false

On the other hand, I would side with JavaScript (over, say, PHP) and not differentiate between integers and floats:

jsonLogic.apply({"typeof" : 42}) // returns "number" not "integer"
jsonLogic.apply({"typeof" : 3.14159}) // returns "number" not "float" or "double"

Do those make sense?

@jottinger
Copy link
Contributor Author

Yeah, I don't particularly care for the multiple return types myself but it
does make a lot of sense. I'll look into incorporating that api ASAP.

On Oct 26, 2016 12:13 PM, "Jeremy Wadhams" [email protected] wrote:

This is awesome functionality to have. May I propose some refinements?

A) We keep your proposed syntax as a shortcut, and also if you call it
with one argument it returns the type:

jsonLogic.apply({"typeof" : [42, "number"] }) // returns true
jsonLogic.apply({"typeof" : 42}) // returns "number"

B) Because JsonLogic also has parsers in other languages that don't have
JavaScript's peculiarities, sometimes we have to/get to make better
choices. (e.g., our own truthy table http://jsonlogic.com/truthy.html )
So this method can/should call an array an array:

//It's a bad idea to use the unary shortcut with array arguments.
jsonLogic.apply({"typeof" :[ [1,2,3] ]}) // returns "array".

jsonLogic.apply({"typeof" :[ [1,2,3], "object" ]}) // returns false

On the other hand, I would side with JavaScript (over, say, PHP) and not
differentiate between integers and floats:

jsonLogic.apply({"typeof" : 42}) // returns "number" not "integer"
jsonLogic.apply({"typeof" : 3.14159}) // returns "number" not "float" or "double"

Do those make sense?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#10 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAcmmii-w7iB7tPtIfnTmxYui4UNk1U-ks5q33wOgaJpZM4Kd3iC
.

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.

2 participants