golden-fleece
Advanced tools
Comparing version 1.0.3 to 1.0.4
# golden-fleece changelog | ||
## 1.0.4 | ||
* Ensure keys are properly quoted ([#3](https://github.com/Rich-Harris/golden-fleece/pull/3)) | ||
* Make options... optional ([#4](https://github.com/Rich-Harris/golden-fleece/pull/4)) | ||
## 1.0.3 | ||
@@ -4,0 +9,0 @@ |
@@ -8,3 +8,4 @@ function __extends(d, b) { | ||
var whitespace = /\s/; | ||
var validIdentifier = /[a-zA-Z_$][a-zA-Z0-9_$]*/; | ||
var validIdentifierCharacters = /[a-zA-Z_$][a-zA-Z0-9_$]*/; | ||
var entirelyValidIdentifier = new RegExp('^' + validIdentifierCharacters.source + '$'); | ||
var number = /^NaN|(?:[-+]?(?:(?:Infinity)|(?:0[xX][a-fA-F0-9]+)|(?:0[bB][01]+)|(?:(?:(?:[1-9]\d*|0)?\.\d+|(?:[1-9]\d*|0)\.\d*|(?:[1-9]\d*|0))(?:[E|e][+|-]?\d+)?)))/; | ||
@@ -272,3 +273,3 @@ var SINGLE_QUOTE = "'"; | ||
var start = this.index; | ||
var name = this.read(validIdentifier); | ||
var name = this.read(validIdentifierCharacters); | ||
if (name) { | ||
@@ -367,4 +368,4 @@ return { | ||
function stringify(value, options) { | ||
var quote = options.singleQuotes ? "'" : '"'; | ||
var indentString = options.spaces ? spaces(options.spaces) : '\t'; | ||
var quote = (options && options.singleQuotes) ? "'" : '"'; | ||
var indentString = (options && options.spaces) ? spaces(options.spaces) : '\t'; | ||
return stringifyValue(value, quote, '\n', indentString, true); | ||
@@ -376,3 +377,3 @@ } | ||
function stringifyProperty(key, value, quote, indentation, indentString, newlines) { | ||
return ((validIdentifier.test(key) ? key : stringifyString(key, quote)) + | ||
return ((entirelyValidIdentifier.test(key) ? key : stringifyString(key, quote)) + | ||
': ' + | ||
@@ -379,0 +380,0 @@ stringifyValue(value, quote, indentation, indentString, newlines)); |
@@ -14,3 +14,4 @@ (function (global, factory) { | ||
var whitespace = /\s/; | ||
var validIdentifier = /[a-zA-Z_$][a-zA-Z0-9_$]*/; | ||
var validIdentifierCharacters = /[a-zA-Z_$][a-zA-Z0-9_$]*/; | ||
var entirelyValidIdentifier = new RegExp('^' + validIdentifierCharacters.source + '$'); | ||
var number = /^NaN|(?:[-+]?(?:(?:Infinity)|(?:0[xX][a-fA-F0-9]+)|(?:0[bB][01]+)|(?:(?:(?:[1-9]\d*|0)?\.\d+|(?:[1-9]\d*|0)\.\d*|(?:[1-9]\d*|0))(?:[E|e][+|-]?\d+)?)))/; | ||
@@ -278,3 +279,3 @@ var SINGLE_QUOTE = "'"; | ||
var start = this.index; | ||
var name = this.read(validIdentifier); | ||
var name = this.read(validIdentifierCharacters); | ||
if (name) { | ||
@@ -373,4 +374,4 @@ return { | ||
function stringify(value, options) { | ||
var quote = options.singleQuotes ? "'" : '"'; | ||
var indentString = options.spaces ? spaces(options.spaces) : '\t'; | ||
var quote = (options && options.singleQuotes) ? "'" : '"'; | ||
var indentString = (options && options.spaces) ? spaces(options.spaces) : '\t'; | ||
return stringifyValue(value, quote, '\n', indentString, true); | ||
@@ -382,3 +383,3 @@ } | ||
function stringifyProperty(key, value, quote, indentation, indentString, newlines) { | ||
return ((validIdentifier.test(key) ? key : stringifyString(key, quote)) + | ||
return ((entirelyValidIdentifier.test(key) ? key : stringifyString(key, quote)) + | ||
': ' + | ||
@@ -385,0 +386,0 @@ stringifyValue(value, quote, indentation, indentString, newlines)); |
{ | ||
"name": "golden-fleece", | ||
"description": "Parse and manipulate JSON5 strings", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"main": "golden-fleece.umd.js", | ||
@@ -6,0 +6,0 @@ "module": "golden-fleece.es.js", |
@@ -7,3 +7,3 @@ # golden-fleece | ||
For the [Svelte REPL](https://svlte.technology/repl), where we want to allow arbitrary data in the bottom right-hand panel, but we also want to update the object without reformatting it as JSON. | ||
For the [Svelte REPL](https://svelte.technology/repl), where we want to allow arbitrary data in the bottom right-hand panel, but we also want to update the object without reformatting it as JSON. | ||
@@ -130,2 +130,2 @@ | ||
[LIL](LICENSE) | ||
[LIL](LICENSE) |
import { | ||
number, | ||
whitespace, | ||
validIdentifier, | ||
validIdentifierCharacters, | ||
SINGLE_QUOTE, | ||
@@ -297,3 +297,3 @@ DOUBLE_QUOTE | ||
const name = this.read(validIdentifier); | ||
const name = this.read(validIdentifierCharacters); | ||
@@ -300,0 +300,0 @@ if (name) { |
export const whitespace = /\s/; | ||
export const validIdentifier = /[a-zA-Z_$][a-zA-Z0-9_$]*/; | ||
export const validIdentifierCharacters = /[a-zA-Z_$][a-zA-Z0-9_$]*/; | ||
export const entirelyValidIdentifier = new RegExp('^' + validIdentifierCharacters.source + '$'); | ||
export const number = /^NaN|(?:[-+]?(?:(?:Infinity)|(?:0[xX][a-fA-F0-9]+)|(?:0[bB][01]+)|(?:(?:(?:[1-9]\d*|0)?\.\d+|(?:[1-9]\d*|0)\.\d*|(?:[1-9]\d*|0))(?:[E|e][+|-]?\d+)?)))/ | ||
@@ -4,0 +5,0 @@ |
@@ -1,7 +0,7 @@ | ||
import { spaces, validIdentifier } from './shared'; | ||
import { spaces, entirelyValidIdentifier } from './shared'; | ||
import { StringifierOptions } from './interfaces'; | ||
export function stringify(value: any, options: StringifierOptions) { | ||
const quote = options.singleQuotes ? "'" : '"'; | ||
const indentString = options.spaces ? spaces(options.spaces) : '\t'; | ||
export function stringify(value: any, options?: StringifierOptions) { | ||
const quote = (options && options.singleQuotes) ? "'" : '"'; | ||
const indentString = (options && options.spaces) ? spaces(options.spaces) : '\t'; | ||
@@ -24,3 +24,3 @@ return stringifyValue(value, quote, '\n', indentString, true); | ||
return ( | ||
(validIdentifier.test(key) ? key : stringifyString(key, quote)) + | ||
(entirelyValidIdentifier.test(key) ? key : stringifyString(key, quote)) + | ||
': ' + | ||
@@ -27,0 +27,0 @@ stringifyValue(value, quote, indentation, indentString, newlines) |
export declare const whitespace: RegExp; | ||
export declare const validIdentifier: RegExp; | ||
export declare const validIdentifierCharacters: RegExp; | ||
export declare const entirelyValidIdentifier: RegExp; | ||
export declare const number: RegExp; | ||
@@ -4,0 +5,0 @@ export declare const SINGLE_QUOTE = "'"; |
import { StringifierOptions } from './interfaces'; | ||
export declare function stringify(value: any, options: StringifierOptions): string; | ||
export declare function stringify(value: any, options?: StringifierOptions): string; | ||
export declare function stringifyString(str: string, quote: string): string; | ||
export declare function stringifyProperty(key: string, value: any, quote: string, indentation: string, indentString: string, newlines: boolean): string; | ||
export declare function stringifyValue(value: any, quote: string, indentation: string, indentString: string, newlines: boolean): string; |
68538
2043
130