1
1
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$' ;
2
- const unsafeChars = / [ < > \b \f \n \r \t \0 \u2028 \u2029 ] / g;
2
+ const unsafe_chars = / [ < > \b \f \n \r \t \0 \u2028 \u2029 ] / g;
3
3
const reserved =
4
4
/ ^ (?: d o | i f | i n | f o r | i n t | l e t | n e w | t r y | v a r | b y t e | c a s e | c h a r | e l s e | e n u m | g o t o | l o n g | t h i s | v o i d | w i t h | a w a i t | b r e a k | c a t c h | c l a s s | c o n s t | f i n a l | f l o a t | s h o r t | s u p e r | t h r o w | w h i l e | y i e l d | d e l e t e | d o u b l e | e x p o r t | i m p o r t | n a t i v e | r e t u r n | s w i t c h | t h r o w s | t y p e o f | b o o l e a n | d e f a u l t | e x t e n d s | f i n a l l y | p a c k a g e | p r i v a t e | a b s t r a c t | c o n t i n u e | d e b u g g e r | f u n c t i o n | v o l a t i l e | i n t e r f a c e | p r o t e c t e d | t r a n s i e n t | i m p l e m e n t s | i n s t a n c e o f | s y n c h r o n i z e d ) $ / ;
5
5
@@ -18,7 +18,7 @@ const escaped = {
18
18
'\u2028' : '\\u2028' ,
19
19
'\u2029' : '\\u2029'
20
20
} ;
21
- const objectProtoOwnPropertyNames = Object . getOwnPropertyNames ( Object . prototype )
21
+ const object_proto_names = Object . getOwnPropertyNames ( Object . prototype )
22
22
. sort ( )
23
23
. join ( '\0' ) ;
24
24
@@ -42,8 +42,8 @@ export function devalue(value) {
42
42
43
43
counts . set ( thing , 1 ) ;
44
44
45
- if ( ! isPrimitive ( thing ) ) {
46
- const type = getType ( thing ) ;
45
+ if ( ! is_primitive ( thing ) ) {
46
+ const type = get_type ( thing ) ;
47
47
48
48
switch ( type ) {
49
49
case 'Number' :
@@ -70,7 +70,7 @@ export function devalue(value) {
70
70
proto !== Object . prototype &&
71
71
proto !== null &&
72
72
Object . getOwnPropertyNames ( proto ) . sort ( ) . join ( '\0' ) !==
73
- objectProtoOwnPropertyNames
73
+ object_proto_names
74
74
) {
75
75
throw new Error ( `Cannot stringify arbitrary non-POJOs` ) ;
76
76
}
@@ -92,7 +92,7 @@ export function devalue(value) {
92
92
. filter ( ( entry ) => entry [ 1 ] > 1 )
93
93
. sort ( ( a , b ) => b [ 1 ] - a [ 1 ] )
94
94
. forEach ( ( entry , i ) => {
95
- names . set ( entry [ 0 ] , getName ( i ) ) ;
95
+ names . set ( entry [ 0 ] , get_name ( i ) ) ;
96
96
} ) ;
97
97
98
98
/**
@@ -104,11 +104,11 @@ export function devalue(value) {
104
104
return names . get ( thing ) ;
105
105
}
106
106
107
- if ( isPrimitive ( thing ) ) {
108
- return stringifyPrimitive ( thing ) ;
107
+ if ( is_primitive ( thing ) ) {
108
+ return stringify_primitive ( thing ) ;
109
109
}
110
110
111
- const type = getType ( thing ) ;
111
+ const type = get_type ( thing ) ;
112
112
113
113
switch ( type ) {
114
114
case 'Number' :
@@ -117,7 +117,9 @@ export function devalue(value) {
117
117
return `Object(${ stringify ( thing . valueOf ( ) ) } )` ;
118
118
119
119
case 'RegExp' :
120
- return `new RegExp(${ stringifyString ( thing . source ) } , "${ thing . flags } ")` ;
120
+ return `new RegExp(${ stringify_string ( thing . source ) } , "${
121
+ thing . flags
122
+ } ")`;
121
123
122
124
case 'Date' :
123
125
return `new Date(${ thing . getTime ( ) } )` ;
@@ -135,7 +137,7 @@ export function devalue(value) {
135
137
136
138
default :
137
139
const obj = `{${ Object . keys ( thing )
138
- . map ( ( key ) => `${ safeKey ( key ) } :${ stringify ( thing [ key ] ) } ` )
140
+ . map ( ( key ) => `${ safe_key ( key ) } :${ stringify ( thing [ key ] ) } ` )
139
141
. join ( ',' ) } }`;
140
142
const proto = Object . getPrototypeOf ( thing ) ;
141
143
if ( proto === null ) {
@@ -163,12 +165,12 @@ export function devalue(value) {
163
165
names . forEach ( ( name , thing ) => {
164
166
params . push ( name ) ;
165
167
166
- if ( isPrimitive ( thing ) ) {
167
- values . push ( stringifyPrimitive ( thing ) ) ;
168
+ if ( is_primitive ( thing ) ) {
169
+ values . push ( stringify_primitive ( thing ) ) ;
168
170
return ;
169
171
}
170
172
171
- const type = getType ( thing ) ;
173
+ const type = get_type ( thing ) ;
172
174
173
175
switch ( type ) {
174
176
case 'Number' :
@@ -215,7 +217,9 @@ export function devalue(value) {
215
217
Object . getPrototypeOf ( thing ) === null ? 'Object.create(null)' : '{}'
216
218
) ;
217
219
Object . keys ( thing ) . forEach ( ( key ) => {
218
- statements . push ( `${ name } ${ safeProp ( key ) } =${ stringify ( thing [ key ] ) } ` ) ;
220
+ statements . push (
221
+ `${ name } ${ safe_prop ( key ) } =${ stringify ( thing [ key ] ) } `
222
+ ) ;
219
223
} ) ;
220
224
}
221
225
} ) ;
@@ -231,7 +235,7 @@ export function devalue(value) {
231
235
}
232
236
233
237
/** @param {number } num */
234
- function getName ( num ) {
238
+ function get_name ( num ) {
235
239
let name = '' ;
236
240
237
241
do {
@@ -243,13 +247,13 @@ function getName(num) {
243
247
}
244
248
245
249
/** @param {any } thing */
246
- function isPrimitive ( thing ) {
250
+ function is_primitive ( thing ) {
247
251
return Object ( thing ) !== thing ;
248
252
}
249
253
250
254
/** @param {any } thing */
251
- function stringifyPrimitive ( thing ) {
252
- if ( typeof thing === 'string' ) return stringifyString ( thing ) ;
255
+ function stringify_primitive ( thing ) {
256
+ if ( typeof thing === 'string' ) return stringify_string ( thing ) ;
253
257
if ( thing === void 0 ) return 'void 0' ;
254
258
if ( thing === 0 && 1 / thing < 0 ) return '-0' ;
255
259
const str = String ( thing ) ;
@@ -259,36 +263,36 @@ function stringifyPrimitive(thing) {
259
263
}
260
264
261
265
/** @param {any } thing */
262
- function getType ( thing ) {
266
+ function get_type ( thing ) {
263
267
return Object . prototype . toString . call ( thing ) . slice ( 8 , - 1 ) ;
264
268
}
265
269
266
270
/** @param {string } c */
267
- function escapeUnsafeChar ( c ) {
271
+ function escape_unsafe_char ( c ) {
268
272
return escaped [ c ] || c ;
269
273
}
270
274
271
275
/** @param {string } str */
272
- function escapeUnsafeChars ( str ) {
273
- return str . replace ( unsafeChars , escapeUnsafeChar ) ;
276
+ function escape_unsafe_chars ( str ) {
277
+ return str . replace ( unsafe_chars , escape_unsafe_char ) ;
274
278
}
275
279
276
280
/** @param {string } key */
277
- function safeKey ( key ) {
281
+ function safe_key ( key ) {
278
282
return / ^ [ _ $ a - z A - Z ] [ _ $ a - z A - Z 0 - 9 ] * $ / . test ( key )
279
283
? key
280
- : escapeUnsafeChars ( JSON . stringify ( key ) ) ;
284
+ : escape_unsafe_chars ( JSON . stringify ( key ) ) ;
281
285
}
282
286
283
287
/** @param {string } key */
284
- function safeProp ( key ) {
288
+ function safe_prop ( key ) {
285
289
return / ^ [ _ $ a - z A - Z ] [ _ $ a - z A - Z 0 - 9 ] * $ / . test ( key )
286
290
? `.${ key } `
287
- : `[${ escapeUnsafeChars ( JSON . stringify ( key ) ) } ]` ;
291
+ : `[${ escape_unsafe_chars ( JSON . stringify ( key ) ) } ]` ;
288
292
}
289
293
290
294
/** @param {string } str */
291
- function stringifyString ( str ) {
295
+ function stringify_string ( str ) {
292
296
let result = '"' ;
293
297
294
298
for ( let i = 0 ; i < str . length ; i += 1 ) {
0 commit comments