fast-json-stringify
Advanced tools
Comparing version 2.7.3 to 2.7.4
18
index.js
@@ -295,3 +295,3 @@ 'use strict' | ||
} else { | ||
return $asString(date) | ||
return $asString(date, skipQuotes) | ||
} | ||
@@ -310,3 +310,3 @@ } | ||
} else { | ||
return $asString(date) | ||
return $asString(date, skipQuotes) | ||
} | ||
@@ -325,11 +325,12 @@ } | ||
} else { | ||
return $asString(date) | ||
return $asString(date, skipQuotes) | ||
} | ||
} | ||
function $asString (str) { | ||
function $asString (str, skipQuotes) { | ||
const quotes = skipQuotes === true ? '' : '"' | ||
if (str instanceof Date) { | ||
return '"' + str.toISOString() + '"' | ||
return quotes + str.toISOString() + quotes | ||
} else if (str === null) { | ||
return '""' | ||
return quotes + quotes | ||
} else if (str instanceof RegExp) { | ||
@@ -340,2 +341,7 @@ str = str.source | ||
} | ||
// If we skipQuotes it means that we are using it as test | ||
// no need to test the string length for the render | ||
if (skipQuotes) { | ||
return str | ||
} | ||
@@ -342,0 +348,0 @@ if (str.length < 42) { |
{ | ||
"name": "fast-json-stringify", | ||
"version": "2.7.3", | ||
"version": "2.7.4", | ||
"description": "Stringify your JSON at max speed", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -142,2 +142,4 @@ # fast-json-stringify | ||
**Note**: In the case of string formatted Date and not Date Object, there will be no manipulation on it. It should be properly formatted. | ||
Example with a MomentJS object: | ||
@@ -144,0 +146,0 @@ |
@@ -451,3 +451,3 @@ 'use strict' | ||
test('anyOf object with field of type string with format or null', (t) => { | ||
test('anyOf object with field date-time of type string with format or null', (t) => { | ||
t.plan(1) | ||
@@ -475,1 +475,47 @@ const toStringify = new Date() | ||
}) | ||
test('anyOf object with field date of type string with format or null', (t) => { | ||
t.plan(1) | ||
const toStringify = '2011-01-01' | ||
const withOneOfSchema = { | ||
type: 'object', | ||
properties: { | ||
prop: { | ||
anyOf: [{ | ||
type: 'string', | ||
format: 'date' | ||
}, { | ||
type: 'null' | ||
}] | ||
} | ||
} | ||
} | ||
const withOneOfStringify = build(withOneOfSchema) | ||
t.equal(withOneOfStringify({ | ||
prop: toStringify | ||
}), '{"prop":"2011-01-01"}') | ||
}) | ||
test('anyOf object with invalid field date of type string with format or null', (t) => { | ||
t.plan(1) | ||
const toStringify = 'foo bar' | ||
const withOneOfSchema = { | ||
type: 'object', | ||
properties: { | ||
prop: { | ||
anyOf: [{ | ||
type: 'string', | ||
format: 'date' | ||
}, { | ||
type: 'null' | ||
}] | ||
} | ||
} | ||
} | ||
const withOneOfStringify = build(withOneOfSchema) | ||
t.equal(withOneOfStringify({ | ||
prop: toStringify | ||
}), '{"prop":null}') | ||
}) |
Sorry, the diff of this file is not supported yet
333008
10057
654