yves 1.0.99 → 1.1.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/LICENSE +1 -1
- package/README.md +142 -48
- package/dist/yves.js +2722 -14483
- package/lib/yves.mjs +385 -905
- package/package.json +14 -17
- package/.eslintignore +0 -3
- package/.eslintrc.cjs +0 -48
- package/.tm_properties +0 -2
- package/Makefile +0 -4
- package/test/yves-test.js +0 -217
package/lib/yves.mjs
CHANGED
|
@@ -1,88 +1,323 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import sortobject from 'deep-sort-object'
|
|
2
|
+
import debug from 'debug'
|
|
3
|
+
|
|
4
|
+
const ANSI_CODES = {
|
|
5
|
+
bold: [1, 22],
|
|
6
|
+
underline: [4, 24],
|
|
7
|
+
inverse: [7, 27],
|
|
8
|
+
cyan: [36, 39],
|
|
9
|
+
magenta: [35, 39],
|
|
10
|
+
blue: [34, 39],
|
|
11
|
+
yellow: [33, 39],
|
|
12
|
+
green: [32, 39],
|
|
13
|
+
red: [31, 39],
|
|
14
|
+
grey: [90, 39],
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const HTML_STYLE_MAP = {
|
|
18
|
+
bold: 'font-weight:bold',
|
|
19
|
+
underline: 'text-decoration:underline',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const RESERVED_WORDS = new Set([
|
|
23
|
+
'abstract', 'else', 'instanceof', 'switch', 'boolean', 'enum', 'int',
|
|
24
|
+
'synchronized', 'break', 'export', 'interface', 'this', 'byte', 'extends',
|
|
25
|
+
'long', 'throw', 'case', 'false', 'native', 'throws', 'catch', 'final',
|
|
26
|
+
'new', 'transient', 'char', 'finally', 'null', 'true', 'class', 'float',
|
|
27
|
+
'package', 'try', 'const', 'for', 'private', 'typeof', 'continue',
|
|
28
|
+
'function', 'protected', 'var', 'debugger', 'goto', 'public', 'void',
|
|
29
|
+
'default', 'if', 'return', 'volatile', 'delete', 'implements', 'short',
|
|
30
|
+
'while', 'do', 'import', 'static', 'with', 'double', 'in', 'super',
|
|
31
|
+
])
|
|
32
|
+
|
|
33
|
+
// Unicode property escapes (Node 18+) replace massive hand-rolled character class regexes
|
|
34
|
+
const regexIdentifierName = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*$/u
|
|
35
|
+
const regexES3ReservedWord = /^(?:do|if|in|for|int|new|try|var|byte|case|char|else|enum|goto|long|null|this|true|void|with|break|catch|class|const|false|final|float|short|super|throw|while|delete|double|export|import|native|public|return|static|switch|throws|typeof|boolean|default|extends|finally|package|private|abstract|continue|debugger|function|volatile|interface|protected|transient|implements|instanceof|synchronized)$/
|
|
36
|
+
const regexNumber = /^(?![+-])([0-9a-fA-FxX+\-.]+)$/
|
|
37
|
+
const regexOctalLiteral = /^0[0-7]+$/
|
|
38
|
+
const regexZeroWidth = /\u200c|\u200d/
|
|
39
|
+
|
|
40
|
+
function quoteKey(word) {
|
|
41
|
+
const value = word
|
|
42
|
+
let valueAsNumber = Number(value)
|
|
43
|
+
|
|
44
|
+
const valueAsUnescaped = value.replace(
|
|
45
|
+
/\\u([a-fA-F0-9]{4})|\\u\{([0-9a-fA-F]+)\}/g,
|
|
46
|
+
(_, $1, $2) => {
|
|
47
|
+
const cp = parseInt($2 || $1, 16)
|
|
48
|
+
return (cp >= 0xd800 && cp <= 0xdfff) ? '\0' : String.fromCodePoint(cp)
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
const isIdentifier = regexIdentifierName.test(valueAsUnescaped)
|
|
53
|
+
|
|
54
|
+
if (isIdentifier) {
|
|
55
|
+
const needsQuotes = regexES3ReservedWord.test(valueAsUnescaped) || regexZeroWidth.test(valueAsUnescaped)
|
|
56
|
+
if (needsQuotes) return `'${value}'`
|
|
57
|
+
} else if (regexNumber.test(value) && !isNaN(valueAsNumber)) {
|
|
58
|
+
if (regexOctalLiteral.test(value)) valueAsNumber = parseInt(value, 8)
|
|
59
|
+
return word
|
|
60
|
+
} else {
|
|
61
|
+
return `'${value.replace(/['\\]/g, '\\$&')}'`
|
|
19
62
|
}
|
|
63
|
+
|
|
64
|
+
if (RESERVED_WORDS.has(word)) return `'${word}'`
|
|
65
|
+
return word
|
|
20
66
|
}
|
|
21
67
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
68
|
+
function htmlEscape(str) {
|
|
69
|
+
return str
|
|
70
|
+
.replace(/&/g, '&')
|
|
71
|
+
.replace(/</g, '<')
|
|
72
|
+
.replace(/>/g, '>')
|
|
73
|
+
.replace(/"/g, '"')
|
|
74
|
+
.replace(/'/g, ''')
|
|
75
|
+
}
|
|
25
76
|
|
|
26
|
-
|
|
77
|
+
function merge(...objs) {
|
|
78
|
+
const target = {}
|
|
79
|
+
for (const o of objs) {
|
|
80
|
+
for (const k of Object.keys(o)) {
|
|
81
|
+
if (k === 'styles') {
|
|
82
|
+
target.styles = o.styles ? { ...o.styles } : false
|
|
83
|
+
} else {
|
|
84
|
+
target[k] = o[k]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return target
|
|
89
|
+
}
|
|
27
90
|
|
|
28
|
-
|
|
91
|
+
function typeOf(value) {
|
|
92
|
+
let s = typeof value
|
|
93
|
+
if (s === 'object' || s === 'function') {
|
|
94
|
+
if (value === null) return 'null'
|
|
95
|
+
// Order matters: iterate all types, last match wins (most specific types are last)
|
|
96
|
+
const types = [Object, Array, String, RegExp, Number, Function, Boolean, Date, Buffer]
|
|
97
|
+
for (const T of types) {
|
|
98
|
+
try { if (value instanceof T) s = T.name.toLowerCase() } catch { /* ignore */ }
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return s
|
|
102
|
+
}
|
|
29
103
|
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
104
|
+
function getCircularReplacer() {
|
|
105
|
+
const seen = new WeakSet()
|
|
106
|
+
return (key, value) => {
|
|
107
|
+
if (typeof value === 'object' && value !== null) {
|
|
108
|
+
if (seen.has(value)) return
|
|
109
|
+
seen.add(value)
|
|
36
110
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
111
|
+
if (typeof value === 'bigint') return value.toString()
|
|
112
|
+
return value
|
|
113
|
+
}
|
|
40
114
|
}
|
|
41
115
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
116
|
+
// --- Core stringify functions (take ctx to avoid global mutable state) ---
|
|
117
|
+
|
|
118
|
+
function stringify(obj, options, ctx) {
|
|
119
|
+
const stylize = (str, style) => yves.stylize(str, options?.styles?.[style], options)
|
|
120
|
+
|
|
121
|
+
const index = ctx.stack.indexOf(obj)
|
|
122
|
+
if (index !== -1) {
|
|
123
|
+
return stylize('.'.repeat(ctx.stack.length - index), 'special')
|
|
45
124
|
}
|
|
125
|
+
ctx.stack.push(obj)
|
|
46
126
|
|
|
47
|
-
|
|
48
|
-
|
|
127
|
+
const result = (() => {
|
|
128
|
+
switch (typeOf(obj)) {
|
|
129
|
+
case 'string': {
|
|
130
|
+
if (options?.templateStrings && !options?.json && /[\r\n\t\u0001-\u001F]/u.test(obj)) {
|
|
131
|
+
return stylize('`' + obj.replace(/`/g, '\\`') + '`', 'string')
|
|
132
|
+
}
|
|
133
|
+
const quoted = obj.indexOf("'") === -1 && !options?.json
|
|
134
|
+
? `'${obj.replace(/'/g, "\\'")}'`
|
|
135
|
+
: `"${obj.replace(/"/g, '\\"')}"`
|
|
136
|
+
return stylize(stringifyString(quoted, options), 'string')
|
|
137
|
+
}
|
|
138
|
+
case 'buffer':
|
|
139
|
+
return stringifyBuffer(obj, options, ctx)
|
|
140
|
+
case 'regexp':
|
|
141
|
+
return stylize(obj.toString(), 'regexp')
|
|
142
|
+
case 'number':
|
|
143
|
+
return stylize(`${obj}`, 'number')
|
|
144
|
+
case 'bigint':
|
|
145
|
+
return stylize(`${obj}n`, 'number')
|
|
146
|
+
case 'function':
|
|
147
|
+
return options?.stream
|
|
148
|
+
? stylize(options.functions ? obj.toString() : 'Function', 'other')
|
|
149
|
+
: '[Function]'
|
|
150
|
+
case 'null':
|
|
151
|
+
return stylize('null', 'special')
|
|
152
|
+
case 'undefined':
|
|
153
|
+
return stylize('undefined', 'special')
|
|
154
|
+
case 'boolean':
|
|
155
|
+
return stylize(`${obj}`, 'bool')
|
|
156
|
+
case 'date':
|
|
157
|
+
return stylize(`new Date("${obj.toISOString()}")`, 'date')
|
|
158
|
+
case 'array':
|
|
159
|
+
return stringifyArray(obj, options, ctx.stack.length, ctx)
|
|
160
|
+
case 'object':
|
|
161
|
+
return stringifyObject(obj, options, ctx.stack.length, ctx)
|
|
162
|
+
}
|
|
163
|
+
})()
|
|
164
|
+
|
|
165
|
+
ctx.stack.pop()
|
|
166
|
+
return result
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function stringifyBuffer(obj, options, ctx) {
|
|
170
|
+
if (ctx.seen.has(obj)) return stringify('[Circular]', options, ctx)
|
|
171
|
+
ctx.seen.add(obj)
|
|
172
|
+
const hex = [...Buffer.from(obj)].map(b => b.toString(16).padStart(2, '0')).join(' ')
|
|
173
|
+
return yves.stylize(`<Buffer ${hex}>`, options?.styles?.other, options)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function stringifyString(str, options) {
|
|
177
|
+
let result = str
|
|
178
|
+
if (options?.escape) {
|
|
179
|
+
result = result
|
|
180
|
+
.replace(/\r/g, '\\r')
|
|
181
|
+
.replace(/\n/g, '\\n')
|
|
182
|
+
.replace(/\t/g, '\\t')
|
|
183
|
+
.replace(/[\u0001-\u001F]/gu, m => `\\x${m.charCodeAt(0).toString(16).padStart(2, '0')}`)
|
|
184
|
+
if (options?.html) result = htmlEscape(result)
|
|
185
|
+
}
|
|
186
|
+
if (options && Object.hasOwn(options, 'maxStringLength') && options.maxStringLength >= 0) {
|
|
187
|
+
if (result.length > options.maxStringLength) {
|
|
188
|
+
const len = Math.max(0, options.maxStringLength - 3)
|
|
189
|
+
result = result.slice(0, len) + '...'
|
|
190
|
+
}
|
|
49
191
|
}
|
|
192
|
+
return result
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function stringifyArray(ary, options, level, ctx) {
|
|
196
|
+
if (ctx.seen.has(ary)) return stringify('[Circular]', options, ctx)
|
|
197
|
+
ctx.seen.add(ary)
|
|
198
|
+
|
|
199
|
+
const pretty = options?.pretty && (
|
|
200
|
+
ary.length > 4 ||
|
|
201
|
+
ary.some(o => (o !== null && typeof o === 'object' && Object.keys(o).length > 0) || (Array.isArray(o) && o.length > 0))
|
|
202
|
+
)
|
|
203
|
+
const ws = pretty ? '\n' + ' '.repeat(level * (options?.indent ?? 4)) : ' '
|
|
50
204
|
|
|
51
|
-
|
|
52
|
-
|
|
205
|
+
const truncate = options && Object.hasOwn(options, 'maxArrayLength') && options.maxArrayLength >= 0
|
|
206
|
+
const length = truncate ? Math.min(ary.length, options.maxArrayLength) : ary.length
|
|
207
|
+
|
|
208
|
+
const out = []
|
|
209
|
+
for (let i = 0; i < length; i++) {
|
|
210
|
+
out.push(stringify(ary[i], options, ctx))
|
|
53
211
|
}
|
|
212
|
+
if (length < ary.length) out.push('<<truncated>>')
|
|
213
|
+
|
|
214
|
+
if (out.length === 0) return '[]'
|
|
215
|
+
|
|
216
|
+
const trailing = (options?.json || !options?.trailingComma) || !pretty ? '' : ','
|
|
217
|
+
const closing = pretty ? ws.slice(0, -1 * (options?.indent ?? 4)) : ws
|
|
218
|
+
return `[${ws}${out.join(`,${pretty ? ws : ' '}`)}${trailing}${closing}]`
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function yvesInclude(key, includes) {
|
|
222
|
+
if (!includes?.length) return true
|
|
223
|
+
return includes.some(inc =>
|
|
224
|
+
typeof inc === 'string' ? key === inc : (inc instanceof RegExp && inc.test(key))
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function yvesExclude(key, excludes) {
|
|
229
|
+
if (!excludes?.length) return false
|
|
230
|
+
return excludes.some(exc =>
|
|
231
|
+
typeof exc === 'string' ? key === exc : (exc instanceof RegExp && exc.test(key))
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function yvesObfuscate(key, obfuscates) {
|
|
236
|
+
if (!obfuscates?.length) return false
|
|
237
|
+
return obfuscates.some(obf =>
|
|
238
|
+
typeof obf === 'string' ? key === obf : (obf instanceof RegExp && obf.test(key))
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function stringifyObject(obj, options, level, ctx) {
|
|
243
|
+
if (ctx.seen.has(obj)) return stringify('[Circular]', options, ctx)
|
|
244
|
+
ctx.seen.add(obj)
|
|
245
|
+
|
|
246
|
+
const keys = options?.showHidden ? Object.keys(obj) : Object.getOwnPropertyNames(obj)
|
|
247
|
+
if (options?.sortKeys) keys.sort()
|
|
54
248
|
|
|
55
|
-
|
|
56
|
-
|
|
249
|
+
const pretty = options?.pretty && (
|
|
250
|
+
keys.length > (options?.singleLineMax ?? 2) ||
|
|
251
|
+
keys.some(k => typeof obj[k] === 'object')
|
|
252
|
+
)
|
|
253
|
+
const ws = pretty ? '\n' + ' '.repeat(level * (options?.indent ?? 4)) : ' '
|
|
254
|
+
|
|
255
|
+
const truncate = options && Object.hasOwn(options, 'maxObjectKeys') && options.maxObjectKeys >= 0
|
|
256
|
+
const includeKeys = truncate ? keys.slice(0, options.maxObjectKeys) : keys
|
|
257
|
+
|
|
258
|
+
const out = []
|
|
259
|
+
for (const k of includeKeys) {
|
|
260
|
+
if (level === 1 && options?.exclude?.includes(k)) continue
|
|
261
|
+
if (!Object.hasOwn(obj, k)) continue
|
|
262
|
+
if (yvesExclude(k, options?.excludes)) continue
|
|
263
|
+
if (!yvesInclude(k, options?.includes)) continue
|
|
264
|
+
if (obj[k] instanceof Function && options?.hideFunctions) continue
|
|
265
|
+
|
|
266
|
+
const keyStr = options?.json ? `"${k}"` : quoteKey(k)
|
|
267
|
+
const styledKey = yves.stylize(keyStr, options?.styles?.key, options)
|
|
268
|
+
const val = yvesObfuscate(k, options?.obfuscates)
|
|
269
|
+
? stringify('<<obfuscated>>', options, ctx)
|
|
270
|
+
: stringify(obj[k], options, ctx)
|
|
271
|
+
out.push(`${styledKey}: ${val}`)
|
|
57
272
|
}
|
|
58
273
|
|
|
59
|
-
if (
|
|
60
|
-
|
|
274
|
+
if (includeKeys.length < keys.length) {
|
|
275
|
+
out.push(yves.stylize('<<truncated>>', options?.styles?.key, options?.styles))
|
|
61
276
|
}
|
|
62
277
|
|
|
278
|
+
if (out.length === 0) return '{}'
|
|
279
|
+
|
|
280
|
+
const trailing = (options?.json || !options?.trailingComma) || !pretty ? '' : ','
|
|
281
|
+
const closing = pretty ? ws.slice(0, -1 * (options?.indent ?? 4)) : ws
|
|
282
|
+
return `{${ws}${out.join(`,${pretty ? ws : ' '}`)}${trailing}${closing}}`
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// --- Main yves object ---
|
|
286
|
+
|
|
287
|
+
const yves = (...args) => {
|
|
288
|
+
const results = args.map(a => yves.inspector({ stream: null })(a))
|
|
289
|
+
const log = yves._console?.log ?? console.log
|
|
290
|
+
log(results.join(' '))
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
yves.supportsColors = () => {
|
|
294
|
+
if ('YVES_COLORS' in process.env) return true
|
|
295
|
+
if (process.stdout && !process.stdout.isTTY) return false
|
|
296
|
+
if (process.platform === 'win32') return true
|
|
297
|
+
if (process.env.TERM === 'dumb') return false
|
|
298
|
+
if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) return true
|
|
63
299
|
return false
|
|
64
300
|
}
|
|
65
301
|
|
|
66
302
|
yves.defaults = {
|
|
67
303
|
styles: {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
special: 'grey', // null, undefined...
|
|
304
|
+
all: 'cyan',
|
|
305
|
+
label: 'underline',
|
|
306
|
+
other: 'inverted',
|
|
307
|
+
key: 'bold',
|
|
308
|
+
special: 'grey',
|
|
74
309
|
string: 'green',
|
|
75
310
|
number: 'magenta',
|
|
76
|
-
bool: 'blue',
|
|
77
|
-
regexp: 'green',
|
|
311
|
+
bool: 'blue',
|
|
312
|
+
regexp: 'green',
|
|
78
313
|
},
|
|
79
|
-
pretty: true,
|
|
314
|
+
pretty: true,
|
|
80
315
|
indent: 4,
|
|
81
316
|
hideFunctions: false,
|
|
82
317
|
showHidden: false,
|
|
83
318
|
sortKeys: false,
|
|
84
|
-
stream: process
|
|
85
|
-
maxLength: -1,
|
|
319
|
+
stream: process?.stdout,
|
|
320
|
+
maxLength: -1,
|
|
86
321
|
colors: yves.supportsColors(),
|
|
87
322
|
html: false,
|
|
88
323
|
json: false,
|
|
@@ -98,130 +333,86 @@ yves.defaults = {
|
|
|
98
333
|
templateStrings: true,
|
|
99
334
|
}
|
|
100
335
|
|
|
101
|
-
yves.options =
|
|
102
|
-
yves.defaults =
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function getCircularReplacer() {
|
|
106
|
-
const seen = new WeakSet()
|
|
107
|
-
return function ( key, value ) {
|
|
108
|
-
if ( typeof value === 'object' && value !== null ) {
|
|
109
|
-
if ( seen.has( value ) ) {
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
seen.add( value )
|
|
113
|
-
}
|
|
114
|
-
if ( typeof value === 'bigint' && value !== null ) {
|
|
115
|
-
return value.toString()
|
|
116
|
-
}
|
|
117
|
-
return value
|
|
118
|
-
}
|
|
336
|
+
yves.options = (opts) => {
|
|
337
|
+
yves.defaults = { ...yves.defaults, ...opts }
|
|
119
338
|
}
|
|
120
339
|
|
|
121
|
-
|
|
122
|
-
yves.inspector = function ( options ) {
|
|
340
|
+
yves.inspector = function (options) {
|
|
123
341
|
const that = this
|
|
124
|
-
return
|
|
125
|
-
const lmyopts = merge(
|
|
126
|
-
if (
|
|
127
|
-
obj = sortobject(
|
|
342
|
+
return (obj, label, opts) => {
|
|
343
|
+
const lmyopts = merge(yves.defaults ?? {}, options ?? {}, opts ?? {})
|
|
344
|
+
if (lmyopts.sorted && typeOf(obj) === 'object') {
|
|
345
|
+
obj = sortobject(obj)
|
|
128
346
|
}
|
|
129
|
-
if (
|
|
347
|
+
if (lmyopts.decycle) {
|
|
130
348
|
try {
|
|
131
|
-
JSON.stringify(
|
|
132
|
-
|
|
133
|
-
)
|
|
134
|
-
} catch ( e ) {
|
|
135
|
-
if ( e.message === 'Converting circular structure to JSON' ) {
|
|
349
|
+
JSON.stringify(obj, (key, value) => typeof value === 'bigint' ? value.toString() : value)
|
|
350
|
+
} catch (e) {
|
|
351
|
+
if (e.message.startsWith('Converting circular structure to JSON')) {
|
|
136
352
|
try {
|
|
137
|
-
obj = JSON.parse(
|
|
138
|
-
} catch (
|
|
139
|
-
return
|
|
353
|
+
obj = JSON.parse(JSON.stringify(obj, getCircularReplacer()))
|
|
354
|
+
} catch (e2) {
|
|
355
|
+
return `Error: ${e2.message}`
|
|
140
356
|
}
|
|
141
357
|
} else {
|
|
142
|
-
return
|
|
358
|
+
return `Error: ${e.message}`
|
|
143
359
|
}
|
|
144
360
|
}
|
|
145
361
|
}
|
|
146
|
-
const myopts = merge(
|
|
147
|
-
const result = that.inspect.call(
|
|
148
|
-
if (
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
( myopts && myopts.styles && myopts.styles.all
|
|
152
|
-
? 'color:' + myopts.styles.all + ';'
|
|
153
|
-
: '' ) +
|
|
154
|
-
'">' +
|
|
155
|
-
result +
|
|
156
|
-
'</pre>'
|
|
157
|
-
)
|
|
158
|
-
} else {
|
|
159
|
-
return result
|
|
362
|
+
const myopts = merge(options ?? {}, opts ?? {})
|
|
363
|
+
const result = that.inspect.call(that, obj, label, myopts)
|
|
364
|
+
if (myopts.html && !myopts.stream) {
|
|
365
|
+
const colorStyle = myopts?.styles?.all ? `color:${myopts.styles.all};` : ''
|
|
366
|
+
return `<pre class="yves" style="padding:8px;background-color:black;color:white;overflow:auto;border-radius:6px;${colorStyle}">${result}</pre>`
|
|
160
367
|
}
|
|
368
|
+
return result
|
|
161
369
|
}
|
|
162
370
|
}
|
|
163
371
|
|
|
164
|
-
yves.debugger =
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const deb = debug(
|
|
169
|
-
deb.log =
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if ( !window.debug ) window.debug = deb // eslint-disable-line no-undef
|
|
175
|
-
} else {
|
|
176
|
-
if ( typeof process != 'undefined' ) {
|
|
177
|
-
if ( !global.debug ) global.debug = deb
|
|
178
|
-
}
|
|
372
|
+
yves.debugger = (namespace, options) => {
|
|
373
|
+
if (!namespace && !options) return debug
|
|
374
|
+
|
|
375
|
+
if (!options) {
|
|
376
|
+
const deb = debug(namespace)
|
|
377
|
+
deb.log = (yves._console?.log ?? console.log).bind(console)
|
|
378
|
+
if (typeof window !== 'undefined' && window.document) { // eslint-disable-line no-undef
|
|
379
|
+
if (!window.debug) window.debug = deb // eslint-disable-line no-undef
|
|
380
|
+
} else if (typeof process !== 'undefined') {
|
|
381
|
+
if (!global.debug) global.debug = deb
|
|
179
382
|
}
|
|
180
383
|
return deb
|
|
181
|
-
} else {
|
|
182
|
-
debug.formatters[namespace] = function ( y ) {
|
|
183
|
-
return yves.inspector()(
|
|
184
|
-
y,
|
|
185
|
-
null,
|
|
186
|
-
Object.assign( options, { stream: null } )
|
|
187
|
-
)
|
|
188
|
-
}
|
|
189
384
|
}
|
|
385
|
+
|
|
386
|
+
debug.formatters[namespace] = (y) =>
|
|
387
|
+
yves.inspector()(y, null, { ...options, stream: null })
|
|
190
388
|
}
|
|
191
389
|
|
|
192
|
-
if (
|
|
193
|
-
debug.formatters.y =
|
|
194
|
-
|
|
195
|
-
}
|
|
390
|
+
if (!debug.formatters.y) {
|
|
391
|
+
debug.formatters.y = (y) => yves.inspector()(y, null, { stream: null })
|
|
392
|
+
}
|
|
196
393
|
|
|
197
|
-
yves.debugger(
|
|
198
|
-
yves.debugger(
|
|
199
|
-
stream: null,
|
|
200
|
-
sortKeys: true,
|
|
201
|
-
hideFunctions: true,
|
|
202
|
-
singleLineMax: 0,
|
|
203
|
-
} )
|
|
394
|
+
yves.debugger('y', { stream: null })
|
|
395
|
+
yves.debugger('Y', { stream: null, sortKeys: true, hideFunctions: true, singleLineMax: 0 })
|
|
204
396
|
|
|
205
397
|
yves._console = null
|
|
206
398
|
yves._console_namespace = ''
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (
|
|
210
|
-
namespace += ':'
|
|
399
|
+
|
|
400
|
+
yves.console = (namespace = '') => {
|
|
401
|
+
if (namespace.length && !namespace.endsWith(':')) namespace += ':'
|
|
211
402
|
yves._console_namespace = namespace
|
|
212
403
|
|
|
213
|
-
yves.debugLog = yves.debugger(
|
|
214
|
-
yves.debugInfo = yves.debugger(
|
|
215
|
-
yves.debugWarn = yves.debugger(
|
|
216
|
-
yves.debugError = yves.debugger(
|
|
217
|
-
yves.debugDir = yves.debugger(
|
|
404
|
+
yves.debugLog = yves.debugger(`${namespace}console:log`)
|
|
405
|
+
yves.debugInfo = yves.debugger(`${namespace}console:info`)
|
|
406
|
+
yves.debugWarn = yves.debugger(`${namespace}console:warn`)
|
|
407
|
+
yves.debugError = yves.debugger(`${namespace}console:error`)
|
|
408
|
+
yves.debugDir = yves.debugger(`${namespace}console:dir`)
|
|
218
409
|
|
|
219
410
|
yves.console_setup()
|
|
220
411
|
yves.console_set()
|
|
221
412
|
}
|
|
222
413
|
|
|
223
|
-
yves.console_setup =
|
|
224
|
-
if (
|
|
414
|
+
yves.console_setup = () => {
|
|
415
|
+
if (!yves._console) {
|
|
225
416
|
yves._console = {
|
|
226
417
|
log: console.log,
|
|
227
418
|
info: console.info,
|
|
@@ -234,78 +425,24 @@ yves.console_setup = function () {
|
|
|
234
425
|
|
|
235
426
|
yves.debugLog = null
|
|
236
427
|
yves.logLevel = 0
|
|
237
|
-
yves.log =
|
|
238
|
-
const result = Function.prototype.apply.call(
|
|
239
|
-
yves.debugLog
|
|
240
|
-
? yves.debugLog
|
|
241
|
-
: yves._console.log
|
|
242
|
-
? yves._console.log
|
|
243
|
-
: console.log,
|
|
244
|
-
yves,
|
|
245
|
-
arguments
|
|
246
|
-
)
|
|
247
|
-
return result
|
|
248
|
-
}
|
|
428
|
+
yves.log = (...args) => (yves.debugLog ?? yves._console?.log ?? console.log)(...args)
|
|
249
429
|
|
|
250
430
|
yves.debugInfo = null
|
|
251
|
-
yves.info =
|
|
252
|
-
const result = Function.prototype.apply.call(
|
|
253
|
-
yves.debugInfo
|
|
254
|
-
? yves.debugInfo
|
|
255
|
-
: yves._console.info
|
|
256
|
-
? yves._console.info
|
|
257
|
-
: console.info,
|
|
258
|
-
yves,
|
|
259
|
-
arguments
|
|
260
|
-
)
|
|
261
|
-
return result
|
|
262
|
-
}
|
|
431
|
+
yves.info = (...args) => (yves.debugInfo ?? yves._console?.info ?? console.info)(...args)
|
|
263
432
|
|
|
264
433
|
yves.debugWarn = null
|
|
265
|
-
yves.warn =
|
|
266
|
-
const result = Function.prototype.apply.call(
|
|
267
|
-
yves.debugWarn
|
|
268
|
-
? yves.debugWarn
|
|
269
|
-
: yves._console.warn
|
|
270
|
-
? yves._console.warn
|
|
271
|
-
: console.warn,
|
|
272
|
-
yves,
|
|
273
|
-
arguments
|
|
274
|
-
)
|
|
275
|
-
return result
|
|
276
|
-
}
|
|
434
|
+
yves.warn = (...args) => (yves.debugWarn ?? yves._console?.warn ?? console.warn)(...args)
|
|
277
435
|
|
|
278
436
|
yves.debugError = null
|
|
279
|
-
yves.error =
|
|
280
|
-
const result = Function.prototype.apply.call(
|
|
281
|
-
yves.debugError
|
|
282
|
-
? yves.debugError
|
|
283
|
-
: yves._console.error
|
|
284
|
-
? yves._console.error
|
|
285
|
-
: console.error,
|
|
286
|
-
yves,
|
|
287
|
-
arguments
|
|
288
|
-
)
|
|
289
|
-
return result
|
|
290
|
-
}
|
|
437
|
+
yves.error = (...args) => (yves.debugError ?? yves._console?.error ?? console.error)(...args)
|
|
291
438
|
|
|
292
439
|
yves.debugDir = null
|
|
293
|
-
yves.dir =
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
const result = Function.prototype.apply.call(
|
|
297
|
-
yves.debugDir
|
|
298
|
-
? yves.debugDir
|
|
299
|
-
: yves._console.dir
|
|
300
|
-
? yves._console.dir
|
|
301
|
-
: console.dir,
|
|
302
|
-
yves,
|
|
303
|
-
args
|
|
304
|
-
)
|
|
305
|
-
return result
|
|
440
|
+
yves.dir = (...args) => {
|
|
441
|
+
const fn = yves.debugDir ?? yves._console?.dir ?? console.dir
|
|
442
|
+
fn('%y', ...args)
|
|
306
443
|
}
|
|
307
444
|
|
|
308
|
-
yves.console_set =
|
|
445
|
+
yves.console_set = () => {
|
|
309
446
|
console.log = yves.log
|
|
310
447
|
console.info = yves.info
|
|
311
448
|
console.warn = yves.warn
|
|
@@ -313,717 +450,60 @@ yves.console_set = function () {
|
|
|
313
450
|
console.dir = yves.dir
|
|
314
451
|
}
|
|
315
452
|
|
|
316
|
-
yves.console_unset =
|
|
317
|
-
if (
|
|
318
|
-
if (
|
|
319
|
-
if (
|
|
320
|
-
if (
|
|
321
|
-
if (
|
|
322
|
-
if (
|
|
453
|
+
yves.console_unset = () => {
|
|
454
|
+
if (yves._console) {
|
|
455
|
+
if (yves._console.log) console.log = yves._console.log
|
|
456
|
+
if (yves._console.info) console.info = yves._console.info
|
|
457
|
+
if (yves._console.warn) console.warn = yves._console.warn
|
|
458
|
+
if (yves._console.error) console.error = yves._console.error
|
|
459
|
+
if (yves._console.dir) console.dir = yves._console.dir
|
|
323
460
|
}
|
|
324
461
|
}
|
|
325
462
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
const str = jsonc.stringify( obj )
|
|
331
|
-
if ( str ) {
|
|
332
|
-
obj = jsonc.parse( str )
|
|
333
|
-
}
|
|
334
|
-
options = merge( this.defaults, options || {} )
|
|
335
|
-
stack = []
|
|
336
|
-
seenObjects = []
|
|
337
|
-
return this.print( stringify( obj, options ), label, options )
|
|
463
|
+
yves.inspect = function (obj, label, options) {
|
|
464
|
+
options = merge(this.defaults, options ?? {})
|
|
465
|
+
const ctx = { stack: [], seen: new Set() }
|
|
466
|
+
return this.print(stringify(obj, options, ctx), label, options)
|
|
338
467
|
}
|
|
339
468
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
// length manually.
|
|
347
|
-
yves.print = function ( str, label, options ) {
|
|
348
|
-
if ( options && !options.html ) {
|
|
349
|
-
if ( str )
|
|
350
|
-
for ( let c = 0, i = 0; i < str.length; i++ ) {
|
|
351
|
-
if ( str.charAt( i ) === '\x1b' ) {
|
|
352
|
-
i += 4
|
|
353
|
-
} // `4` because '\x1b[25m'.length + 1 == 5
|
|
354
|
-
else if ( c === options.maxLength ) {
|
|
355
|
-
str = str.slice( 0, i - 1 ) + '…'
|
|
356
|
-
break
|
|
357
|
-
} else {
|
|
358
|
-
c++
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
if ( options && options.stream ) {
|
|
363
|
-
return options.stream.write.call(
|
|
364
|
-
options.stream,
|
|
365
|
-
( label
|
|
366
|
-
? this.stylize(
|
|
367
|
-
label,
|
|
368
|
-
options && options.styles && options.styles.label,
|
|
369
|
-
options
|
|
370
|
-
) + ': '
|
|
371
|
-
: '' ) +
|
|
372
|
-
this.stylize(
|
|
373
|
-
str,
|
|
374
|
-
options && options.styles && options.styles.all,
|
|
375
|
-
options
|
|
376
|
-
) +
|
|
377
|
-
( options.html ? '' : options.colors ? '\x1b[0m' : '' ) +
|
|
378
|
-
'\n'
|
|
379
|
-
)
|
|
380
|
-
} else {
|
|
381
|
-
return (
|
|
382
|
-
( label
|
|
383
|
-
? this.stylize(
|
|
384
|
-
label,
|
|
385
|
-
options && options.styles && options.styles.label,
|
|
386
|
-
options
|
|
387
|
-
) + ': '
|
|
388
|
-
: '' ) +
|
|
389
|
-
this.stylize(
|
|
390
|
-
str,
|
|
391
|
-
options && options.styles && options.styles.all,
|
|
392
|
-
options
|
|
393
|
-
) +
|
|
394
|
-
( options && options.html
|
|
395
|
-
? ''
|
|
396
|
-
: options && options.colors
|
|
397
|
-
? '\x1b[0m'
|
|
398
|
-
: '' )
|
|
399
|
-
)
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
// Apply a style to a string, eventually,
|
|
404
|
-
// I'd like this to support passing multiple
|
|
405
|
-
// styles.
|
|
406
|
-
yves.stylize = function ( str, style, options ) {
|
|
407
|
-
if ( options && options.colors ) {
|
|
408
|
-
if ( options.html ) {
|
|
409
|
-
let codes = {
|
|
410
|
-
bold: 'font-weight:bold',
|
|
411
|
-
underline: 'text-decoration: underline',
|
|
412
|
-
}
|
|
413
|
-
if ( style ) {
|
|
414
|
-
if ( codes[style] ) {
|
|
415
|
-
return '<span style="' + style + '">' + str + '</span>'
|
|
416
|
-
} else {
|
|
417
|
-
return '<span style="color:' + style + '">' + str + '</span>'
|
|
418
|
-
}
|
|
419
|
-
} else {
|
|
420
|
-
return str
|
|
421
|
-
}
|
|
422
|
-
} else {
|
|
423
|
-
let codes = {
|
|
424
|
-
bold: [ 1, 22 ],
|
|
425
|
-
underline: [ 4, 24 ],
|
|
426
|
-
inverse: [ 7, 27 ],
|
|
427
|
-
cyan: [ 36, 39 ],
|
|
428
|
-
magenta: [ 35, 39 ],
|
|
429
|
-
blue: [ 34, 39 ],
|
|
430
|
-
yellow: [ 33, 39 ],
|
|
431
|
-
green: [ 32, 39 ],
|
|
432
|
-
red: [ 31, 39 ],
|
|
433
|
-
grey: [ 90, 39 ],
|
|
434
|
-
},
|
|
435
|
-
endCode
|
|
436
|
-
|
|
437
|
-
if ( style && codes[style] ) {
|
|
438
|
-
endCode =
|
|
439
|
-
codes[style][1] === 39 &&
|
|
440
|
-
options &&
|
|
441
|
-
options.styles &&
|
|
442
|
-
options.styles.all
|
|
443
|
-
? codes[options.styles.all][0]
|
|
444
|
-
: codes[style][1]
|
|
445
|
-
return '\x1b[' + codes[style][0] + 'm' + str + '\x1b[' + endCode + 'm'
|
|
446
|
-
} else {
|
|
447
|
-
return str
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
} else {
|
|
451
|
-
return str
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// Convert any object to a string, ready for output.
|
|
456
|
-
// When an 'array' or an 'object' are encountered, they are
|
|
457
|
-
// passed to specialized functions, which can then recursively call
|
|
458
|
-
// stringify().
|
|
459
|
-
function stringify( obj, options ) {
|
|
460
|
-
const that = this
|
|
461
|
-
const stylize = function ( str, style ) {
|
|
462
|
-
return yves.stylize(
|
|
463
|
-
str,
|
|
464
|
-
options && options.styles && options.styles[style],
|
|
465
|
-
options
|
|
466
|
-
)
|
|
467
|
-
}
|
|
468
|
-
let index
|
|
469
|
-
let result
|
|
470
|
-
|
|
471
|
-
if ( ( index = stack.indexOf( obj ) ) !== -1 ) {
|
|
472
|
-
return stylize( new Array( stack.length - index + 1 ).join( '.' ), 'special' )
|
|
473
|
-
}
|
|
474
|
-
stack.push( obj )
|
|
475
|
-
|
|
476
|
-
result = ( function ( obj ) {
|
|
477
|
-
switch ( typeOf( obj ) ) {
|
|
478
|
-
case 'string': {
|
|
479
|
-
if (
|
|
480
|
-
options &&
|
|
481
|
-
options.templateStrings &&
|
|
482
|
-
!options.json &&
|
|
483
|
-
obj.match( /[\r\n\t\u0001-\u001F]/ ) // eslint-disable-line no-control-regex
|
|
484
|
-
) {
|
|
485
|
-
obj = '`' + obj.replace( /`/g, '\\`' ) + '`'
|
|
486
|
-
} else {
|
|
487
|
-
obj = stringifyString(
|
|
488
|
-
obj.indexOf( '\'' ) === -1 && !( options && options.json )
|
|
489
|
-
? '\'' + obj.replace( /'/g, '\\\'' ) + '\''
|
|
490
|
-
: '"' + obj.replace( /"/g, '\\"' ) + '"',
|
|
491
|
-
options
|
|
492
|
-
)
|
|
493
|
-
}
|
|
494
|
-
return stylize( obj, 'string' )
|
|
495
|
-
}
|
|
496
|
-
case 'buffer':
|
|
497
|
-
return stringifyBuffer( obj, options, stack.length )
|
|
498
|
-
case 'regexp':
|
|
499
|
-
return stylize( obj.toString(), 'regexp' )
|
|
500
|
-
case 'number':
|
|
501
|
-
return stylize( obj + '', 'number' )
|
|
502
|
-
case 'bigint':
|
|
503
|
-
return stylize( obj + 'n', 'number' )
|
|
504
|
-
case 'function':
|
|
505
|
-
return options && options.stream
|
|
506
|
-
? stylize( options.functions ? obj.toString() : 'Function', 'other' )
|
|
507
|
-
: '[Function]'
|
|
508
|
-
case 'null':
|
|
509
|
-
return stylize( 'null', 'special' )
|
|
510
|
-
case 'undefined':
|
|
511
|
-
return stylize( 'undefined', 'special' )
|
|
512
|
-
case 'boolean':
|
|
513
|
-
return stylize( obj + '', 'bool' )
|
|
514
|
-
case 'date':
|
|
515
|
-
return stylize( 'new Date("' + obj.toISOString() + '")', 'date' )
|
|
516
|
-
case 'array':
|
|
517
|
-
return stringifyArray( obj, options, stack.length )
|
|
518
|
-
case 'object':
|
|
519
|
-
return stringifyObject( obj, options, stack.length )
|
|
520
|
-
}
|
|
521
|
-
} )( obj )
|
|
522
|
-
|
|
523
|
-
stack.pop()
|
|
524
|
-
|
|
525
|
-
return result
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
function stringifyBuffer( obj, options, length ) {
|
|
529
|
-
if ( seenObjects.indexOf( obj ) !== -1 ) {
|
|
530
|
-
return stringify( '[Circular]' )
|
|
531
|
-
}
|
|
532
|
-
seenObjects.push( obj )
|
|
533
|
-
return obj.inspect()
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
function htmlspecialchars( string, quote_style, charset, double_encode ) {
|
|
537
|
-
let optTemp = 0,
|
|
538
|
-
i = 0,
|
|
539
|
-
noquotes = false
|
|
540
|
-
if ( typeof quote_style === 'undefined' || quote_style === null ) {
|
|
541
|
-
quote_style = 2
|
|
542
|
-
}
|
|
543
|
-
string = string.toString()
|
|
544
|
-
if ( double_encode !== false ) {
|
|
545
|
-
string = string.replace( /&/g, '&' )
|
|
546
|
-
}
|
|
547
|
-
string = string.replace( /</g, '<' ).replace( />/g, '>' )
|
|
548
|
-
const OPTS = {
|
|
549
|
-
ENT_NOQUOTES: 0,
|
|
550
|
-
ENT_HTML_QUOTE_SINGLE: 1,
|
|
551
|
-
ENT_HTML_QUOTE_DOUBLE: 2,
|
|
552
|
-
ENT_COMPAT: 2,
|
|
553
|
-
ENT_QUOTES: 3,
|
|
554
|
-
ENT_IGNORE: 4,
|
|
555
|
-
}
|
|
556
|
-
if ( quote_style === 0 ) {
|
|
557
|
-
noquotes = true
|
|
558
|
-
}
|
|
559
|
-
if ( typeof quote_style !== 'number' ) {
|
|
560
|
-
quote_style = [].concat( quote_style )
|
|
561
|
-
for ( let i = 0; i < quote_style.length; i++ ) {
|
|
562
|
-
if ( OPTS[quote_style[i]] === 0 ) {
|
|
563
|
-
noquotes = true
|
|
564
|
-
} else if ( OPTS[quote_style[i]] ) {
|
|
565
|
-
optTemp = optTemp | OPTS[quote_style[i]]
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
quote_style = optTemp
|
|
569
|
-
}
|
|
570
|
-
if ( quote_style & OPTS.ENT_HTML_QUOTE_SINGLE ) {
|
|
571
|
-
string = string.replace( /'/g, ''' )
|
|
572
|
-
}
|
|
573
|
-
if ( !noquotes ) {
|
|
574
|
-
string = string.replace( /"/g, '"' )
|
|
575
|
-
}
|
|
576
|
-
return string
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
// Escape invisible characters in a string
|
|
580
|
-
function stringifyString( str, options ) {
|
|
581
|
-
let result
|
|
582
|
-
if ( options && options.escape ) {
|
|
583
|
-
result = str
|
|
584
|
-
.replace( /\r/g, '\\r' )
|
|
585
|
-
.replace( /\n/g, '\\n' )
|
|
586
|
-
.replace( /\t/g, '\\t' )
|
|
587
|
-
.replace( /[\u0001-\u001F]/g, function ( match ) { // eslint-disable-line no-control-regex
|
|
588
|
-
return '\\x' + match[0].charCodeAt( 0 ).toString( 16 )
|
|
589
|
-
} )
|
|
590
|
-
if ( options && options.html ) {
|
|
591
|
-
result = htmlspecialchars( result )
|
|
592
|
-
}
|
|
593
|
-
} else {
|
|
594
|
-
result = str
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
// Truncate the string if a maximum length is configured
|
|
598
|
-
|
|
599
|
-
const truncate =
|
|
600
|
-
options &&
|
|
601
|
-
Object.prototype.hasOwnProperty.call( options, 'maxStringLength' ) &&
|
|
602
|
-
options.maxStringLength >= 0
|
|
603
|
-
if ( truncate && options && result.length > options.maxStringLength ) {
|
|
604
|
-
const length = Math.min( result.length, options.maxStringLength - 3 )
|
|
605
|
-
result = result.substr( 0, length ) + '...'
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
return result
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
// Convert an array to a string, such as [1, 2, 3].
|
|
612
|
-
// This function calls stringify() for each of the elements
|
|
613
|
-
// in the array.
|
|
614
|
-
function stringifyArray( ary, options, level ) {
|
|
615
|
-
if ( seenObjects.indexOf( ary ) !== -1 ) {
|
|
616
|
-
return stringify( '[Circular]' )
|
|
617
|
-
}
|
|
618
|
-
seenObjects.push( ary )
|
|
619
|
-
|
|
620
|
-
const out = []
|
|
621
|
-
const pretty =
|
|
622
|
-
options &&
|
|
623
|
-
options.pretty &&
|
|
624
|
-
( ary.length > 4 ||
|
|
625
|
-
ary.some( function ( o ) {
|
|
626
|
-
return (
|
|
627
|
-
( o !== null && typeof o === 'object' && Object.keys( o ).length > 0 ) ||
|
|
628
|
-
( Array.isArray( o ) && o.length > 0 )
|
|
629
|
-
)
|
|
630
|
-
} ) )
|
|
631
|
-
const ws = pretty
|
|
632
|
-
? '\n' + new Array( level * options.indent + 1 ).join( ' ' )
|
|
633
|
-
: ' '
|
|
634
|
-
|
|
635
|
-
const truncate =
|
|
636
|
-
options &&
|
|
637
|
-
Object.prototype.hasOwnProperty.call( options, 'maxArrayLength' ) &&
|
|
638
|
-
options.maxArrayLength >= 0
|
|
639
|
-
|
|
640
|
-
const length = truncate
|
|
641
|
-
? Math.min( ary.length, options && options.maxArrayLength )
|
|
642
|
-
: ary.length
|
|
643
|
-
for ( let i = 0; i < length; i++ ) {
|
|
644
|
-
out.push( stringify( ary[i], options ) )
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
// Add a special String if the array was truncated
|
|
648
|
-
if ( length < ary.length ) {
|
|
649
|
-
out.push( '<<truncated>>' )
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
if ( out.length === 0 ) {
|
|
653
|
-
return '[]'
|
|
654
|
-
} else {
|
|
655
|
-
return (
|
|
656
|
-
'[' +
|
|
657
|
-
ws +
|
|
658
|
-
out.join( ',' + ( pretty ? ws : ' ' ) ) +
|
|
659
|
-
( ( options && ( options.json || !options.trailingComma ) ) || !pretty
|
|
660
|
-
? ''
|
|
661
|
-
: ',' ) +
|
|
662
|
-
( pretty ? ws.slice( 0, -1 * options.indent ) : ws ) +
|
|
663
|
-
']'
|
|
664
|
-
)
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
const quote_reserved_words = ( function ( word ) {
|
|
669
|
-
const reserved_words = [
|
|
670
|
-
'abstract',
|
|
671
|
-
'else',
|
|
672
|
-
'instanceof',
|
|
673
|
-
'switch',
|
|
674
|
-
'boolean',
|
|
675
|
-
'enum',
|
|
676
|
-
'int',
|
|
677
|
-
'synchronized',
|
|
678
|
-
'break',
|
|
679
|
-
'export',
|
|
680
|
-
'interface',
|
|
681
|
-
'this',
|
|
682
|
-
'byte',
|
|
683
|
-
'extends',
|
|
684
|
-
'long',
|
|
685
|
-
'throw',
|
|
686
|
-
'case',
|
|
687
|
-
'false',
|
|
688
|
-
'native',
|
|
689
|
-
'throws',
|
|
690
|
-
'catch',
|
|
691
|
-
'final',
|
|
692
|
-
'new',
|
|
693
|
-
'transient',
|
|
694
|
-
'char',
|
|
695
|
-
'finally',
|
|
696
|
-
'null',
|
|
697
|
-
'true',
|
|
698
|
-
'class',
|
|
699
|
-
'float',
|
|
700
|
-
'package',
|
|
701
|
-
'try',
|
|
702
|
-
'const',
|
|
703
|
-
'for',
|
|
704
|
-
'private',
|
|
705
|
-
'typeof',
|
|
706
|
-
'continue',
|
|
707
|
-
'function',
|
|
708
|
-
'protected',
|
|
709
|
-
'var',
|
|
710
|
-
'debugger',
|
|
711
|
-
'goto',
|
|
712
|
-
'public',
|
|
713
|
-
'void',
|
|
714
|
-
'default',
|
|
715
|
-
'if',
|
|
716
|
-
'return',
|
|
717
|
-
'volatile',
|
|
718
|
-
'delete',
|
|
719
|
-
'implements',
|
|
720
|
-
'short',
|
|
721
|
-
'while',
|
|
722
|
-
'do',
|
|
723
|
-
'import',
|
|
724
|
-
'static',
|
|
725
|
-
'with',
|
|
726
|
-
'double',
|
|
727
|
-
'in',
|
|
728
|
-
'super',
|
|
729
|
-
]
|
|
730
|
-
|
|
731
|
-
// According to ES6 + Unicode 7.0.0
|
|
732
|
-
const regexIdentifierNameES6 =
|
|
733
|
-
/^(?:[$A-Z_a-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B2\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDE00-\uDE11\uDE13-\uDE2B\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDE00-\uDE2F\uDE44\uDE80-\uDEAA]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF98]|\uD809[\uDC00-\uDC6E]|[\uD80C\uD840-\uD868\uD86A-\uD86C][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D]|\uD87E[\uDC00-\uDE1D])(?:[$0-9A-Z_a-z\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B2\u08E4-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D60-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA69D\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2D\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDD0-\uDDDA\uDE00-\uDE11\uDE13-\uDE37\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF01-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF98]|\uD809[\uDC00-\uDC6E]|[\uD80C\uD840-\uD868\uD86A-\uD86C][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF])*$/ // eslint-disable-line no-misleading-character-class
|
|
734
|
-
// According to ES5 + Unicode 7.0.0
|
|
735
|
-
const regexIdentifierNameES5 =
|
|
736
|
-
/^(?:[$A-Z_a-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B2\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC])(?:[$0-9A-Z_a-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B2\u08E4-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D60-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA69D\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2D\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC])*$/ // eslint-disable-line no-misleading-character-class
|
|
737
|
-
const regexES3ReservedWord =
|
|
738
|
-
/^(?:do|if|in|for|int|new|try|var|byte|case|char|else|enum|goto|long|null|this|true|void|with|break|catch|class|const|false|final|float|short|super|throw|while|delete|double|export|import|native|public|return|static|switch|throws|typeof|boolean|default|extends|finally|package|private|abstract|continue|debugger|function|volatile|interface|protected|transient|implements|instanceof|synchronized)$/
|
|
739
|
-
// Zero-width characters that are allowed in IdentifierPart as per ES5, but not in ES3
|
|
740
|
-
const regexZeroWidth = /\u200c|\u200d/
|
|
741
|
-
const regexNumber = /^(?![+-])([0-9a-fA-FxX+-.]+)$/
|
|
742
|
-
const regexSpecialCharacters = /['\\]/g
|
|
743
|
-
const regexOctalLiteral = /^0[0-7]+$/
|
|
744
|
-
// https://mathiasbynens.be/notes/javascript-escapes#unicode
|
|
745
|
-
const regexUnicodeEscape = /\\u([a-fA-F0-9]{4})/g
|
|
746
|
-
// https://mathiasbynens.be/notes/localstorage-pattern
|
|
747
|
-
|
|
748
|
-
function isNumericLiteral( string, number ) {
|
|
749
|
-
// Consider: empty string, `2e2`, `010`, ` 010` (leading space), `1.23`, `.23`, `+1`, `-0`, etc.
|
|
750
|
-
return regexNumber.test( string ) && !isNaN( number )
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
return function ( word ) {
|
|
754
|
-
const value = word
|
|
755
|
-
|
|
756
|
-
let valueAsNumber = Number( value ) // Number('010') returns 10, not 8 :'(
|
|
757
|
-
// Both Unicode escapes and Unicode code point escapes are allowed.
|
|
758
|
-
// Note: the replacement must happen in a single `replace` call.
|
|
759
|
-
const valueAsUnescapedString = value.replace(
|
|
760
|
-
/\\u([a-fA-F0-9]{4})|\\u\{([0-9a-fA-F]{1,})\}/g,
|
|
761
|
-
function ( $0, $1, $2 ) {
|
|
762
|
-
const codePoint = parseInt( $2 || $1, 16 )
|
|
763
|
-
// If it’s a surrogate…
|
|
764
|
-
if ( codePoint >= 0xd800 && codePoint <= 0xdfff ) {
|
|
765
|
-
// Return a character that is never valid in an identifier.
|
|
766
|
-
// This prevents the surrogate from pairing with another.
|
|
767
|
-
return '\0'
|
|
768
|
-
}
|
|
769
|
-
return String.fromCodePoint( codePoint )
|
|
770
|
-
}
|
|
771
|
-
)
|
|
772
|
-
const es5Warning = !regexIdentifierNameES5.test(
|
|
773
|
-
// Only Unicode escapes are allowed in ES5 identifiers.
|
|
774
|
-
value.replace( /\\u([a-fA-F0-9]{4})/g, function ( $0, $1 ) {
|
|
775
|
-
return String.fromCodePoint( parseInt( $1, 16 ) )
|
|
776
|
-
} )
|
|
777
|
-
)
|
|
778
|
-
const isIdentifierNameES6 = regexIdentifierNameES6.test(
|
|
779
|
-
valueAsUnescapedString
|
|
780
|
-
)
|
|
781
|
-
let needsQuotes = true
|
|
782
|
-
let needsBrackets = true
|
|
783
|
-
let es3Warning = false
|
|
784
|
-
let quotedValue
|
|
785
|
-
if ( isIdentifierNameES6 ) {
|
|
786
|
-
es3Warning = needsQuotes =
|
|
787
|
-
es5Warning ||
|
|
788
|
-
regexES3ReservedWord.test( valueAsUnescapedString ) ||
|
|
789
|
-
regexZeroWidth.test( valueAsUnescapedString )
|
|
790
|
-
needsQuotes && ( quotedValue = '\'' + value + '\'' )
|
|
791
|
-
needsBrackets = false
|
|
792
|
-
} else if ( isNumericLiteral( value, valueAsNumber ) ) {
|
|
793
|
-
if ( regexOctalLiteral.test( value ) ) {
|
|
794
|
-
// parse octal literals, e.g. `010`
|
|
795
|
-
valueAsNumber = parseInt( value, 8 )
|
|
796
|
-
}
|
|
797
|
-
needsQuotes = false
|
|
798
|
-
quotedValue = '\'' + valueAsNumber + '\''
|
|
799
|
-
} else {
|
|
800
|
-
quotedValue = '\'' + value.replace( regexSpecialCharacters, '\\$&' ) + '\''
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
if ( needsQuotes ) {
|
|
804
|
-
return quotedValue
|
|
469
|
+
yves.print = (str, label, options) => {
|
|
470
|
+
if (options && !options.html && str) {
|
|
471
|
+
for (let c = 0, i = 0; i < str.length; i++) {
|
|
472
|
+
if (str.charAt(i) === '\x1b') { i += 4 }
|
|
473
|
+
else if (c === options.maxLength) { str = `${str.slice(0, i - 1)}\u2026`; break }
|
|
474
|
+
else { c++ }
|
|
805
475
|
}
|
|
806
|
-
|
|
807
|
-
for ( let i in reserved_words ) {
|
|
808
|
-
if ( word === reserved_words[i] ) {
|
|
809
|
-
return '\'' + word + '\''
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
return word
|
|
813
476
|
}
|
|
814
|
-
} )()
|
|
815
|
-
|
|
816
|
-
function yvesInclude( key, includes ) {
|
|
817
|
-
if ( includes && includes.length ) {
|
|
818
|
-
for ( let i in includes ) {
|
|
819
|
-
if ( typeof includes[i] == 'string' && key === includes[i] ) return true
|
|
820
|
-
if (
|
|
821
|
-
typeof includes[i] == 'object' &&
|
|
822
|
-
isItA( includes[i], RegExp ) &&
|
|
823
|
-
includes[i].test( key )
|
|
824
|
-
)
|
|
825
|
-
return true
|
|
826
|
-
}
|
|
827
|
-
return false
|
|
828
|
-
}
|
|
829
|
-
return true
|
|
830
|
-
}
|
|
831
477
|
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
typeof excludes[i] == 'object' &&
|
|
838
|
-
isItA( excludes[i], RegExp ) &&
|
|
839
|
-
excludes[i].test( key )
|
|
840
|
-
)
|
|
841
|
-
return true
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
return false
|
|
845
|
-
}
|
|
478
|
+
const styledLabel = label
|
|
479
|
+
? `${yves.stylize(label, options?.styles?.label, options)}: `
|
|
480
|
+
: ''
|
|
481
|
+
const styledStr = yves.stylize(str, options?.styles?.all, options)
|
|
482
|
+
const reset = options?.html ? '' : (options?.colors ? '\x1b[0m' : '')
|
|
846
483
|
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
for ( let i in obfuscates ) {
|
|
850
|
-
if ( typeof obfuscates[i] == 'string' && key === obfuscates[i] )
|
|
851
|
-
return true
|
|
852
|
-
if (
|
|
853
|
-
typeof obfuscates[i] == 'object' &&
|
|
854
|
-
isItA( obfuscates[i], RegExp ) &&
|
|
855
|
-
obfuscates[i].test( key )
|
|
856
|
-
)
|
|
857
|
-
return true
|
|
858
|
-
}
|
|
484
|
+
if (options?.stream) {
|
|
485
|
+
return options.stream.write(`${styledLabel}${styledStr}${reset}\n`)
|
|
859
486
|
}
|
|
860
|
-
return
|
|
487
|
+
return `${styledLabel}${styledStr}${reset}`
|
|
861
488
|
}
|
|
862
489
|
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
// and does not output functions or prototype values.
|
|
866
|
-
function stringifyObject( obj, options, level ) {
|
|
867
|
-
if ( seenObjects.indexOf( obj ) !== -1 ) {
|
|
868
|
-
return stringify( '[Circular]' )
|
|
869
|
-
}
|
|
870
|
-
seenObjects.push( obj )
|
|
871
|
-
|
|
872
|
-
const clas = Object.prototype.toString.call( obj ).slice( 8, -1 )
|
|
873
|
-
const out = []
|
|
874
|
-
const pretty =
|
|
875
|
-
options &&
|
|
876
|
-
options.pretty &&
|
|
877
|
-
( Object.keys( obj ).length > options.singleLineMax ||
|
|
878
|
-
Object.keys( obj ).some( function ( k ) {
|
|
879
|
-
return typeof obj[k] === 'object'
|
|
880
|
-
} ) )
|
|
881
|
-
const ws = pretty
|
|
882
|
-
? '\n' + new Array( level * options.indent + 1 ).join( ' ' )
|
|
883
|
-
: ' '
|
|
884
|
-
|
|
885
|
-
const keys =
|
|
886
|
-
options && options.showHidden
|
|
887
|
-
? Object.keys( obj )
|
|
888
|
-
: Object.getOwnPropertyNames( obj )
|
|
889
|
-
if ( options && options.sortKeys ) keys.sort()
|
|
890
|
-
|
|
891
|
-
const truncate =
|
|
892
|
-
options &&
|
|
893
|
-
Object.prototype.hasOwnProperty.call( options, 'maxObjectKeys' ) &&
|
|
894
|
-
options.maxObjectKeys >= 0
|
|
895
|
-
|
|
896
|
-
// Slice the keys to the maximum length if they exceed the maxObjectKeys option
|
|
897
|
-
const includeKeys = truncate
|
|
898
|
-
? keys.slice( 0, options && options.maxObjectKeys )
|
|
899
|
-
: keys
|
|
900
|
-
if ( includeKeys )
|
|
901
|
-
for ( let ki in includeKeys ) {
|
|
902
|
-
const k = includeKeys[ki]
|
|
903
|
-
// includeKeys.forEach(function (k) {
|
|
904
|
-
if (
|
|
905
|
-
!(
|
|
906
|
-
level == 1 &&
|
|
907
|
-
options &&
|
|
908
|
-
options.exclude &&
|
|
909
|
-
~options.exclude.indexOf( k )
|
|
910
|
-
)
|
|
911
|
-
) {
|
|
912
|
-
if (
|
|
913
|
-
Object.prototype.hasOwnProperty.call( obj, k ) &&
|
|
914
|
-
!yvesExclude( k, options && options.excludes ) &&
|
|
915
|
-
yvesInclude( k, options && options.includes ) &&
|
|
916
|
-
// && (!options.obfuscate || !options.obfuscate.length || )
|
|
917
|
-
!( isItA( obj[k], Function ) && options && options.hideFunctions )
|
|
918
|
-
) {
|
|
919
|
-
out.push(
|
|
920
|
-
( options && options.json ? '"' : '' ) +
|
|
921
|
-
yves.stylize(
|
|
922
|
-
options && options.json ? k : quote_reserved_words( k ),
|
|
923
|
-
options && options.styles && options.styles.key,
|
|
924
|
-
options
|
|
925
|
-
) +
|
|
926
|
-
( options && options.json ? '"' : '' ) +
|
|
927
|
-
': ' +
|
|
928
|
-
stringify(
|
|
929
|
-
yvesObfuscate( k, options && options.obfuscates )
|
|
930
|
-
? '<<obfuscated>>'
|
|
931
|
-
: obj[k],
|
|
932
|
-
options
|
|
933
|
-
)
|
|
934
|
-
)
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
}
|
|
490
|
+
yves.stylize = (str, style, options) => {
|
|
491
|
+
if (!options?.colors) return str
|
|
938
492
|
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
options && options.styles
|
|
946
|
-
)
|
|
947
|
-
)
|
|
493
|
+
if (options.html) {
|
|
494
|
+
if (!style) return str
|
|
495
|
+
const cssStyle = HTML_STYLE_MAP[style]
|
|
496
|
+
return cssStyle
|
|
497
|
+
? `<span style="${cssStyle}">${str}</span>`
|
|
498
|
+
: `<span style="color:${style}">${str}</span>`
|
|
948
499
|
}
|
|
949
500
|
|
|
950
|
-
if (
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
out.join( ',' + ( pretty ? ws : ' ' ) ) +
|
|
957
|
-
( ( options && ( options.json || !options.trailingComma ) ) || !pretty
|
|
958
|
-
? ''
|
|
959
|
-
: ',' ) +
|
|
960
|
-
( pretty ? ws.slice( 0, -1 * options.indent ) : ws ) +
|
|
961
|
-
'}'
|
|
962
|
-
)
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
// A better `typeof`
|
|
967
|
-
function typeOf( value ) {
|
|
968
|
-
function isObject( x ) {
|
|
969
|
-
return x != null && ( typeof x == 'object' || typeof x == 'function' )
|
|
970
|
-
}
|
|
971
|
-
let s = typeof value
|
|
972
|
-
const types = [
|
|
973
|
-
Object,
|
|
974
|
-
Array,
|
|
975
|
-
String,
|
|
976
|
-
RegExp,
|
|
977
|
-
Number,
|
|
978
|
-
Function,
|
|
979
|
-
Boolean,
|
|
980
|
-
Date,
|
|
981
|
-
Buffer,
|
|
982
|
-
]
|
|
983
|
-
if ( s === 'object' || s === 'function' ) {
|
|
984
|
-
if ( value ) {
|
|
985
|
-
if ( types )
|
|
986
|
-
for ( let ti in types ) {
|
|
987
|
-
const t = types[ti]
|
|
988
|
-
if ( value && isItA( value, t ) ) {
|
|
989
|
-
s = t.name.toLowerCase()
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
} else {
|
|
993
|
-
s = 'null'
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
return s
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
function merge( /* variable args */ ) {
|
|
1000
|
-
const objs = Array.prototype.slice.call( arguments )
|
|
1001
|
-
const target = {}
|
|
1002
|
-
|
|
1003
|
-
if ( objs )
|
|
1004
|
-
for ( let oi in objs ) {
|
|
1005
|
-
const o = objs[oi]
|
|
1006
|
-
const oks = Object.keys( o )
|
|
1007
|
-
if ( oks )
|
|
1008
|
-
for ( let oki in oks ) {
|
|
1009
|
-
const k = oks[oki]
|
|
1010
|
-
if ( typeof k === 'string' ) {
|
|
1011
|
-
if ( k === 'styles' ) {
|
|
1012
|
-
if ( !o.styles ) {
|
|
1013
|
-
target.styles = false
|
|
1014
|
-
} else {
|
|
1015
|
-
target.styles = {}
|
|
1016
|
-
for ( let s in o.styles ) {
|
|
1017
|
-
target.styles[s] = o.styles[s]
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
} else {
|
|
1021
|
-
target[k] = o[k]
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
return target
|
|
501
|
+
if (!style || !ANSI_CODES[style]) return str
|
|
502
|
+
const [open, close] = ANSI_CODES[style]
|
|
503
|
+
const endCode = close === 39 && options?.styles?.all
|
|
504
|
+
? ANSI_CODES[options.styles.all][0]
|
|
505
|
+
: close
|
|
506
|
+
return `\x1b[${open}m${str}\x1b[${endCode}m`
|
|
1027
507
|
}
|
|
1028
508
|
|
|
1029
509
|
yves.typeOf = typeOf
|