Skip to content

Commit

Permalink
Strictly validate that the jsonString argument is a string
Browse files Browse the repository at this point in the history
Fixes #43
  • Loading branch information
sindresorhus committed Apr 6, 2020
1 parent e60ad00 commit 681f8b8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const isEscaped = (jsonString, quotePosition) => {
};

module.exports = (jsonString, options = {}) => {
if (typeof jsonString !== 'string') {
throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof jsonString}\``);
}

const strip = options.whitespace === false ? stripWithoutWhitespace : stripWithWhitespace;

let insideString = false;
Expand Down

0 comments on commit 681f8b8

Please sign in to comment.