@@ -15,8 +15,6 @@ function build (schema, options) {
15
15
`
16
16
code += `
17
17
${ $asString . toString ( ) }
18
- ${ $asStringSmall . toString ( ) }
19
- ${ $asStringLong . toString ( ) }
20
18
${ $asNumber . toString ( ) }
21
19
${ $asNull . toString ( ) }
22
20
${ $asBoolean . toString ( ) }
@@ -86,47 +84,7 @@ function $asString (str) {
86
84
str = str . toString ( )
87
85
}
88
86
89
- if ( str . length < 42 ) {
90
- return $asStringSmall ( str )
91
- } else {
92
- return $asStringLong ( str )
93
- }
94
- }
95
-
96
- function $asStringLong ( str ) {
97
- var result = ''
98
- var l = str . length
99
- var i
100
-
101
- for ( ; ( i = str . indexOf ( '"' ) ) >= 0 && i < l ; ) {
102
- result += str . slice ( 0 , i ) + '\\"'
103
- str = str . slice ( i + 1 )
104
- l = str . length
105
- }
106
-
107
- if ( l > 0 ) {
108
- result += str
109
- }
110
-
111
- return '"' + result + '"'
112
- }
113
-
114
- function $asStringSmall ( str ) {
115
- var result = ''
116
- var last = 0
117
- var l = str . length
118
- for ( var i = 0 ; i < l ; i ++ ) {
119
- if ( str [ i ] === '"' ) {
120
- result += str . slice ( last , i ) + '\\"'
121
- last = i + 1
122
- }
123
- }
124
- if ( last === 0 ) {
125
- result = str
126
- } else {
127
- result += str . slice ( last )
128
- }
129
- return '"' + result + '"'
87
+ return JSON . stringify ( str )
130
88
}
131
89
132
90
function $asRegExp ( reg ) {
@@ -306,12 +264,13 @@ function buildObject (schema, code, name, externalSchema) {
306
264
307
265
code += result . code
308
266
laterCode = result . laterCode
309
-
267
+ /* eslint-disable no-useless-escape */
310
268
if ( i < a . length - 1 ) {
311
269
code += `
312
270
json += \',\'
313
271
`
314
272
}
273
+ /* eslint-enable no-useless-escape */
315
274
316
275
if ( schema . required && schema . required . indexOf ( key ) !== - 1 ) {
317
276
code += `
@@ -398,14 +357,14 @@ function nested (laterCode, name, key, schema, externalSchema) {
398
357
`
399
358
break
400
359
case 'object' :
401
- funcName = ( name + key ) . replace ( / [ - . \[ \] ] / g, '' )
360
+ funcName = ( name + key ) . replace ( / [ - . \[ \] ] / g, '' ) // eslint-disable-line
402
361
laterCode = buildObject ( schema , laterCode , funcName , externalSchema )
403
362
code += `
404
363
json += ${ funcName } (obj${ key } )
405
364
`
406
365
break
407
366
case 'array' :
408
- funcName = ( name + key ) . replace ( / [ - . \[ \] ] / g, '' )
367
+ funcName = ( name + key ) . replace ( / [ - . \[ \] ] / g, '' ) // eslint-disable-line
409
368
laterCode = buildArray ( schema , laterCode , funcName , externalSchema )
410
369
code += `
411
370
json += ${ funcName } (obj${ key } )
0 commit comments