Skip to content

Commit

Permalink
per #64, more fixes to address significant performance concerns
Browse files Browse the repository at this point in the history
  • Loading branch information
getify committed Dec 22, 2021
1 parent a5ea0ba commit 17ce6f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions json.minify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! JSON.minify()
v0.2.0 (c) Kyle Simpson
v3.0.0 (c) Kyle Simpson
MIT License
*/

Expand All @@ -21,7 +21,7 @@ module.exports = function JSON_minify(json) {
if (!in_multiline_comment && !in_singleline_comment) {
tmp2 = lc.substring(from);
if (!in_string) {
tmp2 = tmp2.replace(/(\n|\r|\s)*/g,"");
tmp2 = tmp2.replace(/(\n|\r|\s)+/g,"");
}
new_str[ns++] = tmp2;
}
Expand All @@ -32,14 +32,12 @@ module.exports = function JSON_minify(json) {
// a comment? check for previous `\` escaping immediately
// leftward adjacent to this match
if (tmp[0] == "\"" && !in_multiline_comment && !in_singleline_comment) {
// perform look-behind escaping match, but
// limit left-context matching to only go back
// to the position of the last token match
//
// see: https://github.com/getify/JSON.minify/issues/64
lc.lastIndex = prevFrom;

// perform leftward adjacent escaping match
tmp2 = lc.match(/(\\)*$/);
tmp2 = lc.substring(prevFrom).match(/\\+$/);

// start of string with ", or unescaped " character found to end string?
if (!in_string || !tmp2 || (tmp2[0].length % 2) == 0) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-json-minify",
"version": "2.0.0",
"version": "3.0.0",
"description": "minifies blocks of JSON-like content into valid JSON by removing all whitespace *and* comments",
"main": "json.minify.js",
"scripts": {
Expand Down

0 comments on commit 17ce6f8

Please sign in to comment.