Skip to content

Commit 1a63b7c

Browse files
committed
Replaced asString with JSON.stringify
1 parent 0e81122 commit 1a63b7c

File tree

1 file changed

+1
-31
lines changed

1 file changed

+1
-31
lines changed

index.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ function build (schema, options) {
1515
`
1616
code += `
1717
${$asString.toString()}
18-
${$asStringSmall.toString()}
1918
${$asNumber.toString()}
2019
${$asNull.toString()}
2120
${$asBoolean.toString()}
@@ -85,36 +84,7 @@ function $asString (str) {
8584
str = str.toString()
8685
}
8786

88-
if (str.length < 42) {
89-
return $asStringSmall(str)
90-
} else {
91-
return JSON.stringify(str)
92-
}
93-
}
94-
95-
// magically escape strings for json
96-
// relying on their charCodeAt
97-
// everything below 32 needs JSON.stringify()
98-
// 34 and 92 happens all the time, so we
99-
// have a fast case for them
100-
function $asStringSmall (str) {
101-
var result = ''
102-
var last = 0
103-
var l = str.length
104-
var point = 255
105-
for (var i = 0; i < l && point >= 32; i++) {
106-
point = str.charCodeAt(i)
107-
if (point === 34 || point === 92) {
108-
result += str.slice(last, i) + '\\' + str[i]
109-
last = i + 1
110-
}
111-
}
112-
if (last === 0) {
113-
result = str
114-
} else {
115-
result += str.slice(last)
116-
}
117-
return point < 32 ? JSON.stringify(str) : '"' + result + '"'
87+
return JSON.stringify(str)
11888
}
11989

12090
function $asRegExp (reg) {

0 commit comments

Comments
 (0)