golden-fleece
Advanced tools
Comparing version 1.0.5 to 1.0.6
# golden-fleece changelog | ||
## 1.0.6 | ||
* Fix stringification of strings with characters that need to be escaped ([#10](https://github.com/Rich-Harris/golden-fleece/pull/10)) | ||
* Correctly patch objects with no properties in common ([#9](https://github.com/Rich-Harris/golden-fleece/pull/9)) | ||
* Remove `locate-character` from dependencies (it is bundled) ([#11](https://github.com/Rich-Harris/golden-fleece/pull/11)) | ||
## 1.0.5 | ||
@@ -4,0 +10,0 @@ |
@@ -385,4 +385,20 @@ function __extends(d, b) { | ||
} | ||
// https://mathiasbynens.be/notes/javascript-escapes | ||
var escapeable$1 = { | ||
"'": "'", | ||
'"': '"', | ||
'\b': 'b', | ||
'\n': 'n', | ||
'\f': 'f', | ||
'\r': 'r', | ||
'\t': 't', | ||
'\v': 'v', | ||
'\0': '0' | ||
}; | ||
var escapeableRegex = new RegExp("[" + Object.keys(escapeable$1).join('') + "]", 'g'); | ||
function stringifyString(str, quote) { | ||
return quote + str.replace(quote === "'" ? /'/g : /"/g, '\\' + quote) + quote; | ||
var otherQuote = quote === '"' ? "'" : '"'; | ||
return quote + str.replace(escapeableRegex, function (char) { | ||
return char === otherQuote ? char : '\\' + escapeable$1[char]; | ||
}) + quote; | ||
} | ||
@@ -572,12 +588,6 @@ function stringifyProperty(key, value, quote, indentation, indentString, newlines) { | ||
var propertyValue = value[key]; | ||
if (newlinesInsideValue) { | ||
patched += | ||
"," + indentation + | ||
stringifyProperty(key, propertyValue, quote, indentation, indentString, true); | ||
} | ||
else { | ||
patched += | ||
", " + | ||
stringifyProperty(key, propertyValue, quote, indentation, indentString, false); | ||
} | ||
patched += | ||
(started ? ',' + (newlinesInsideValue ? indentation : ' ') : intro) + | ||
stringifyProperty(key, propertyValue, quote, indentation, indentString, newlinesInsideValue); | ||
started = true; | ||
}); | ||
@@ -584,0 +594,0 @@ patched += str.slice(c, node.end); |
@@ -391,4 +391,20 @@ (function (global, factory) { | ||
} | ||
// https://mathiasbynens.be/notes/javascript-escapes | ||
var escapeable$1 = { | ||
"'": "'", | ||
'"': '"', | ||
'\b': 'b', | ||
'\n': 'n', | ||
'\f': 'f', | ||
'\r': 'r', | ||
'\t': 't', | ||
'\v': 'v', | ||
'\0': '0' | ||
}; | ||
var escapeableRegex = new RegExp("[" + Object.keys(escapeable$1).join('') + "]", 'g'); | ||
function stringifyString(str, quote) { | ||
return quote + str.replace(quote === "'" ? /'/g : /"/g, '\\' + quote) + quote; | ||
var otherQuote = quote === '"' ? "'" : '"'; | ||
return quote + str.replace(escapeableRegex, function (char) { | ||
return char === otherQuote ? char : '\\' + escapeable$1[char]; | ||
}) + quote; | ||
} | ||
@@ -578,12 +594,6 @@ function stringifyProperty(key, value, quote, indentation, indentString, newlines) { | ||
var propertyValue = value[key]; | ||
if (newlinesInsideValue) { | ||
patched += | ||
"," + indentation + | ||
stringifyProperty(key, propertyValue, quote, indentation, indentString, true); | ||
} | ||
else { | ||
patched += | ||
", " + | ||
stringifyProperty(key, propertyValue, quote, indentation, indentString, false); | ||
} | ||
patched += | ||
(started ? ',' + (newlinesInsideValue ? indentation : ' ') : intro) + | ||
stringifyProperty(key, propertyValue, quote, indentation, indentString, newlinesInsideValue); | ||
started = true; | ||
}); | ||
@@ -590,0 +600,0 @@ patched += str.slice(c, node.end); |
{ | ||
"name": "golden-fleece", | ||
"description": "Parse and manipulate JSON5 strings", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"main": "golden-fleece.umd.js", | ||
@@ -23,2 +23,3 @@ "module": "golden-fleece.es.js", | ||
"json5": "^0.5.1", | ||
"locate-character": "^2.0.3", | ||
"mocha": "^3.5.0", | ||
@@ -40,6 +41,3 @@ "right-pad": "^1.0.1", | ||
"prepublishOnly": "npm test && npm run build" | ||
}, | ||
"dependencies": { | ||
"locate-character": "^2.0.3" | ||
} | ||
} |
@@ -256,25 +256,13 @@ import { parse } from './parse'; | ||
if (newlinesInsideValue) { | ||
patched += | ||
`,${indentation}` + | ||
stringifyProperty( | ||
key, | ||
propertyValue, | ||
quote, | ||
indentation, | ||
indentString, | ||
true | ||
); | ||
} else { | ||
patched += | ||
`, ` + | ||
stringifyProperty( | ||
key, | ||
propertyValue, | ||
quote, | ||
indentation, | ||
indentString, | ||
false | ||
); | ||
} | ||
patched += | ||
(started ? ',' + (newlinesInsideValue ? indentation : ' ') : intro) + | ||
stringifyProperty( | ||
key, | ||
propertyValue, | ||
quote, | ||
indentation, | ||
indentString, | ||
newlinesInsideValue | ||
); | ||
started = true; | ||
}); | ||
@@ -281,0 +269,0 @@ |
@@ -11,4 +11,21 @@ import { spaces, entirelyValidIdentifier } from './shared'; | ||
// https://mathiasbynens.be/notes/javascript-escapes | ||
const escapeable: Record<string, string> = { | ||
"'": "'", | ||
'"': '"', | ||
'\b': 'b', | ||
'\n': 'n', | ||
'\f': 'f', | ||
'\r': 'r', | ||
'\t': 't', | ||
'\v': 'v', | ||
'\0': '0' | ||
}; | ||
const escapeableRegex = new RegExp(`[${Object.keys(escapeable).join('')}]`, 'g'); | ||
export function stringifyString(str: string, quote: string) { | ||
return quote + str.replace(quote === "'" ? /'/g : /"/g, '\\' + quote) + quote; | ||
const otherQuote = quote === '"' ? "'" : '"'; | ||
return quote + str.replace(escapeableRegex, char => | ||
char === otherQuote ? char : '\\' + escapeable[char] | ||
) + quote; | ||
} | ||
@@ -15,0 +32,0 @@ |
70760
0
2111
18
- Removedlocate-character@^2.0.3
- Removedlocate-character@2.0.5(transitive)