fast-json-stringify 5.13.0 → 5.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/serializer.js +10 -10
- package/package.json +3 -3
package/lib/serializer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
// eslint-disable-next-line
|
|
4
|
-
const STR_ESCAPE = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]
|
|
4
|
+
const STR_ESCAPE = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]/
|
|
5
5
|
|
|
6
6
|
module.exports = class Serializer {
|
|
7
7
|
constructor (options) {
|
|
@@ -25,13 +25,12 @@ module.exports = class Serializer {
|
|
|
25
25
|
|
|
26
26
|
asInteger (i) {
|
|
27
27
|
if (typeof i === 'number') {
|
|
28
|
-
if (i === Infinity || i === -Infinity) {
|
|
29
|
-
throw new Error(`The value "${i}" cannot be converted to an integer.`)
|
|
30
|
-
}
|
|
31
28
|
if (Number.isInteger(i)) {
|
|
32
29
|
return '' + i
|
|
33
30
|
}
|
|
34
|
-
if
|
|
31
|
+
// check if number is Infinity or NaN
|
|
32
|
+
// eslint-disable-next-line no-self-compare
|
|
33
|
+
if (i === Infinity || i === -Infinity || i !== i) {
|
|
35
34
|
throw new Error(`The value "${i}" cannot be converted to an integer.`)
|
|
36
35
|
}
|
|
37
36
|
return this.parseInteger(i)
|
|
@@ -52,7 +51,9 @@ module.exports = class Serializer {
|
|
|
52
51
|
|
|
53
52
|
asNumber (i) {
|
|
54
53
|
const num = Number(i)
|
|
55
|
-
if
|
|
54
|
+
// check if number is NaN
|
|
55
|
+
// eslint-disable-next-line no-self-compare
|
|
56
|
+
if (num !== num) {
|
|
56
57
|
throw new Error(`The value "${i}" cannot be converted to a number.`)
|
|
57
58
|
} else if (!Number.isFinite(num)) {
|
|
58
59
|
return 'null'
|
|
@@ -128,10 +129,6 @@ module.exports = class Serializer {
|
|
|
128
129
|
// eslint-disable-next-line
|
|
129
130
|
for (var i = 0; i < len; i++) {
|
|
130
131
|
point = str.charCodeAt(i)
|
|
131
|
-
if (point < 32 || (point >= 0xD800 && point <= 0xDFFF)) {
|
|
132
|
-
// The current character is non-printable characters or a surrogate.
|
|
133
|
-
return JSON.stringify(str)
|
|
134
|
-
}
|
|
135
132
|
if (
|
|
136
133
|
point === 0x22 || // '"'
|
|
137
134
|
point === 0x5c // '\'
|
|
@@ -139,6 +136,9 @@ module.exports = class Serializer {
|
|
|
139
136
|
last === -1 && (last = 0)
|
|
140
137
|
result += str.slice(last, i) + '\\'
|
|
141
138
|
last = i
|
|
139
|
+
} else if (point < 32 || (point >= 0xD800 && point <= 0xDFFF)) {
|
|
140
|
+
// The current character is non-printable characters or a surrogate.
|
|
141
|
+
return JSON.stringify(str)
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fast-json-stringify",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.14.0",
|
|
4
4
|
"description": "Stringify your JSON at max speed",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"simple-git": "^3.7.1",
|
|
47
47
|
"standard": "^17.0.0",
|
|
48
48
|
"tap": "^16.0.1",
|
|
49
|
-
"tsd": "^0.
|
|
49
|
+
"tsd": "^0.31.0",
|
|
50
50
|
"webpack": "^5.40.0",
|
|
51
51
|
"fast-json-stringify": "."
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"ajv": "^8.10.0",
|
|
55
|
-
"ajv-formats": "^
|
|
55
|
+
"ajv-formats": "^3.0.1",
|
|
56
56
|
"fast-deep-equal": "^3.1.3",
|
|
57
57
|
"fast-uri": "^2.1.0",
|
|
58
58
|
"rfdc": "^1.2.0",
|