-
Notifications
You must be signed in to change notification settings - Fork 3
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
Support urlencoded for all methods #77 #83
Conversation
* @returns {Object} | ||
*/ | ||
function parseJson(value, type) { | ||
return typeof value === 'string' && ['array', 'object'].indexOf(type) !== -1 ? |
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.
parseJson
is never called with other types, why do you need this check here?
Seems that type
parameter is not needed at all.
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.
Not all folks pass arrays and objects in string representation.
JSON.parse([1,2]); // Uncaught SyntaxError: Unexpected token ,
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 mean, typeof value === 'string' ?
is enough
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.
Oups. You're right)
50cb618
to
5174af6
Compare
I don't like the idea of treating |
*/ | ||
function parseJson(value) { | ||
return typeof value === 'string' ? | ||
JSON.parse(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.
Let's add try-catch here and throw some human-friendly error instead of SyntaxError)
🤘 |
🆗 |
👍 |
Support urlencoded for all methods #77
No description provided.