object-lib
Advanced tools
Comparing version 4.1.0 to 4.1.1
@@ -0,1 +1,7 @@ | ||
const subs = { // table of character substitutions | ||
'\n': '\\n', | ||
'\r': '\\r', | ||
'\t': '\\t' | ||
}; | ||
export default (str) => { | ||
@@ -7,3 +13,3 @@ let result = str; | ||
const unescaped = []; | ||
result = result.split(''); | ||
let escaped = false; | ||
@@ -13,4 +19,4 @@ let quoted = false; | ||
const char = result[i]; | ||
if (['\n', '\r', '\t'].includes(char) && quoted) { | ||
unescaped.push(i); | ||
if (quoted && char in subs) { | ||
result[i] = subs[char]; | ||
} | ||
@@ -22,11 +28,5 @@ if (!escaped && char === '"') { | ||
} | ||
result = result.join(''); | ||
result = result.replace(/\n/g, (m, idx) => { | ||
if (unescaped.includes(idx)) { | ||
return JSON.stringify(m).slice(1, -1); | ||
} | ||
return m; | ||
}); | ||
return JSON.parse(result); | ||
}; |
{ | ||
"name": "object-lib", | ||
"type": "module", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13917