@contrast/agent 4.16.2 → 4.18.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.
Files changed (147) hide show
  1. package/esm.mjs +21 -11
  2. package/lib/assess/policy/propagators.json +4 -0
  3. package/lib/assess/policy/signatures.json +5 -0
  4. package/lib/assess/propagators/fastify-static/allowed-path.js +85 -0
  5. package/lib/assess/sources/index.js +26 -5
  6. package/lib/cli-rewriter/index.js +1 -1
  7. package/lib/contrast.js +1 -1
  8. package/lib/core/config/options.js +14 -1
  9. package/lib/core/config/util.js +39 -11
  10. package/lib/core/rewrite/index.js +2 -2
  11. package/lib/protect/service.js +2 -0
  12. package/lib/util/trace-util.js +5 -4
  13. package/node_modules/@colors/colors/LICENSE +26 -0
  14. package/node_modules/@colors/colors/README.md +219 -0
  15. package/node_modules/@colors/colors/examples/normal-usage.js +83 -0
  16. package/node_modules/@colors/colors/examples/safe-string.js +80 -0
  17. package/node_modules/@colors/colors/index.d.ts +136 -0
  18. package/node_modules/@colors/colors/lib/colors.js +211 -0
  19. package/node_modules/@colors/colors/lib/custom/trap.js +46 -0
  20. package/node_modules/@colors/colors/lib/custom/zalgo.js +110 -0
  21. package/node_modules/@colors/colors/lib/extendStringPrototype.js +110 -0
  22. package/node_modules/@colors/colors/lib/index.js +13 -0
  23. package/node_modules/@colors/colors/lib/maps/america.js +10 -0
  24. package/node_modules/@colors/colors/lib/maps/rainbow.js +12 -0
  25. package/node_modules/@colors/colors/lib/maps/random.js +11 -0
  26. package/node_modules/@colors/colors/lib/maps/zebra.js +5 -0
  27. package/node_modules/@colors/colors/lib/styles.js +95 -0
  28. package/node_modules/@colors/colors/lib/system/has-flag.js +35 -0
  29. package/node_modules/@colors/colors/lib/system/supports-colors.js +151 -0
  30. package/node_modules/@colors/colors/package.json +49 -0
  31. package/node_modules/@colors/colors/safe.d.ts +48 -0
  32. package/node_modules/@colors/colors/safe.js +10 -0
  33. package/node_modules/@colors/colors/themes/generic-logging.js +12 -0
  34. package/node_modules/@dabh/diagnostics/README.md +16 -16
  35. package/node_modules/@dabh/diagnostics/package.json +9 -9
  36. package/node_modules/color/README.md +9 -0
  37. package/node_modules/color/index.js +4 -1
  38. package/node_modules/color/package.json +8 -8
  39. package/node_modules/color-string/README.md +6 -2
  40. package/node_modules/color-string/index.js +21 -13
  41. package/node_modules/color-string/package.json +4 -4
  42. package/node_modules/colorspace/package.json +5 -5
  43. package/node_modules/fecha/dist/fecha.min.js +1 -1
  44. package/node_modules/fecha/dist/fecha.min.js.map +1 -0
  45. package/node_modules/fecha/lib/fecha.d.ts +2 -2
  46. package/node_modules/fecha/lib/fecha.js +35 -18
  47. package/node_modules/fecha/lib/fecha.js.map +1 -0
  48. package/node_modules/fecha/lib/fecha.umd.js +35 -18
  49. package/node_modules/fecha/lib/fecha.umd.js.map +1 -0
  50. package/node_modules/fecha/package.json +9 -10
  51. package/node_modules/fecha/src/fecha.ts +524 -0
  52. package/node_modules/logform/.eslintrc +1 -1
  53. package/node_modules/logform/CHANGELOG.md +24 -0
  54. package/node_modules/logform/README.md +15 -17
  55. package/node_modules/logform/browser.js +3 -1
  56. package/node_modules/logform/cli.js +1 -1
  57. package/node_modules/logform/colorize.js +2 -2
  58. package/node_modules/logform/dist/browser.js +8 -2
  59. package/node_modules/logform/dist/cli.js +2 -2
  60. package/node_modules/logform/dist/colorize.js +5 -5
  61. package/node_modules/logform/dist/errors.js +1 -1
  62. package/node_modules/logform/dist/format.js +9 -5
  63. package/node_modules/logform/dist/index.js +53 -20
  64. package/node_modules/logform/dist/json.js +7 -6
  65. package/node_modules/logform/dist/logstash.js +1 -1
  66. package/node_modules/logform/dist/pad-levels.js +4 -4
  67. package/node_modules/logform/dist/printf.js +1 -1
  68. package/node_modules/logform/dist/simple.js +1 -1
  69. package/node_modules/logform/dist/splat.js +2 -2
  70. package/node_modules/logform/dist/uncolorize.js +1 -1
  71. package/node_modules/logform/errors.js +1 -1
  72. package/node_modules/logform/index.d.ts +36 -0
  73. package/node_modules/logform/index.js +19 -20
  74. package/node_modules/logform/json.js +7 -7
  75. package/node_modules/logform/logstash.js +1 -1
  76. package/node_modules/logform/package.json +10 -9
  77. package/node_modules/logform/simple.js +1 -1
  78. package/node_modules/logform/uncolorize.js +1 -1
  79. package/node_modules/safe-stable-stringify/CHANGELOG.md +75 -0
  80. package/node_modules/safe-stable-stringify/LICENSE +21 -0
  81. package/node_modules/safe-stable-stringify/esm/package.json +4 -0
  82. package/node_modules/safe-stable-stringify/esm/wrapper.js +6 -0
  83. package/node_modules/safe-stable-stringify/index.d.ts +18 -0
  84. package/node_modules/safe-stable-stringify/index.js +618 -0
  85. package/node_modules/safe-stable-stringify/package.json +69 -0
  86. package/node_modules/safe-stable-stringify/readme.md +170 -0
  87. package/node_modules/safe-stable-stringify/tsconfig.json +22 -0
  88. package/node_modules/winston/LICENSE +18 -18
  89. package/node_modules/winston/README.md +1231 -1230
  90. package/node_modules/winston/dist/winston/common.js +10 -10
  91. package/node_modules/winston/dist/winston/config/index.js +17 -17
  92. package/node_modules/winston/dist/winston/container.js +46 -46
  93. package/node_modules/winston/dist/winston/create-logger.js +28 -24
  94. package/node_modules/winston/dist/winston/exception-handler.js +49 -49
  95. package/node_modules/winston/dist/winston/exception-stream.js +27 -27
  96. package/node_modules/winston/dist/winston/logger.js +152 -138
  97. package/node_modules/winston/dist/winston/profiler.js +22 -22
  98. package/node_modules/winston/dist/winston/rejection-handler.js +54 -54
  99. package/node_modules/winston/dist/winston/tail-file.js +14 -14
  100. package/node_modules/winston/dist/winston/transports/console.js +31 -31
  101. package/node_modules/winston/dist/winston/transports/file.js +101 -101
  102. package/node_modules/winston/dist/winston/transports/http.js +119 -41
  103. package/node_modules/winston/dist/winston/transports/index.js +17 -17
  104. package/node_modules/winston/dist/winston/transports/stream.js +24 -24
  105. package/node_modules/winston/dist/winston.js +91 -97
  106. package/node_modules/winston/index.d.ts +213 -193
  107. package/node_modules/winston/lib/winston/common.js +61 -61
  108. package/node_modules/winston/lib/winston/config/index.d.ts +99 -98
  109. package/node_modules/winston/lib/winston/config/index.js +35 -35
  110. package/node_modules/winston/lib/winston/container.js +114 -114
  111. package/node_modules/winston/lib/winston/create-logger.js +104 -104
  112. package/node_modules/winston/lib/winston/exception-handler.js +245 -245
  113. package/node_modules/winston/lib/winston/exception-stream.js +54 -54
  114. package/node_modules/winston/lib/winston/logger.js +676 -667
  115. package/node_modules/winston/lib/winston/profiler.js +51 -51
  116. package/node_modules/winston/lib/winston/rejection-handler.js +251 -251
  117. package/node_modules/winston/lib/winston/tail-file.js +124 -124
  118. package/node_modules/winston/lib/winston/transports/console.js +117 -117
  119. package/node_modules/winston/lib/winston/transports/file.js +695 -695
  120. package/node_modules/winston/lib/winston/transports/http.js +267 -202
  121. package/node_modules/winston/lib/winston/transports/index.d.ts +103 -100
  122. package/node_modules/winston/lib/winston/transports/index.js +56 -56
  123. package/node_modules/winston/lib/winston/transports/stream.js +63 -63
  124. package/node_modules/winston/lib/winston.js +176 -182
  125. package/node_modules/winston/node_modules/winston-transport/.babelrc +3 -0
  126. package/node_modules/winston/node_modules/winston-transport/.eslintrc +7 -0
  127. package/node_modules/winston/node_modules/winston-transport/.gitattributes +1 -0
  128. package/node_modules/winston/node_modules/winston-transport/.nyc_output/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
  129. package/node_modules/winston/node_modules/winston-transport/.nyc_output/processinfo/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
  130. package/node_modules/winston/node_modules/winston-transport/.nyc_output/processinfo/index.json +1 -0
  131. package/node_modules/winston/node_modules/winston-transport/CHANGELOG.md +126 -0
  132. package/node_modules/winston/node_modules/winston-transport/LICENSE +22 -0
  133. package/node_modules/winston/node_modules/winston-transport/README.md +50 -0
  134. package/node_modules/winston/node_modules/winston-transport/dist/index.js +215 -0
  135. package/node_modules/winston/node_modules/winston-transport/dist/legacy.js +116 -0
  136. package/node_modules/winston/node_modules/winston-transport/index.d.ts +39 -0
  137. package/node_modules/winston/node_modules/winston-transport/index.js +215 -0
  138. package/node_modules/winston/node_modules/winston-transport/legacy.js +119 -0
  139. package/node_modules/winston/node_modules/winston-transport/package.json +56 -0
  140. package/node_modules/winston/package.json +76 -75
  141. package/package.json +9 -6
  142. package/node_modules/@dabh/diagnostics/example.png +0 -0
  143. package/node_modules/color-string/CHANGELOG.md +0 -18
  144. package/node_modules/colorspace/test.js +0 -14
  145. package/node_modules/fecha/CHANGELOG.md +0 -67
  146. package/node_modules/logform/.travis.yml +0 -17
  147. package/node_modules/winston/CHANGELOG.md +0 -560
@@ -0,0 +1,618 @@
1
+ 'use strict'
2
+
3
+ const stringify = configure()
4
+
5
+ // @ts-expect-error
6
+ stringify.configure = configure
7
+ // @ts-expect-error
8
+ stringify.stringify = stringify
9
+
10
+ // @ts-expect-error
11
+ stringify.default = stringify
12
+
13
+ // @ts-expect-error used for named export
14
+ exports.stringify = stringify
15
+ // @ts-expect-error used for named export
16
+ exports.configure = configure
17
+
18
+ module.exports = stringify
19
+
20
+ // eslint-disable-next-line
21
+ const strEscapeSequencesRegExp = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/
22
+ // eslint-disable-next-line
23
+ const strEscapeSequencesReplacer = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/g
24
+
25
+ // Escaped special characters. Use empty strings to fill up unused entries.
26
+ const meta = [
27
+ '\\u0000', '\\u0001', '\\u0002', '\\u0003', '\\u0004',
28
+ '\\u0005', '\\u0006', '\\u0007', '\\b', '\\t',
29
+ '\\n', '\\u000b', '\\f', '\\r', '\\u000e',
30
+ '\\u000f', '\\u0010', '\\u0011', '\\u0012', '\\u0013',
31
+ '\\u0014', '\\u0015', '\\u0016', '\\u0017', '\\u0018',
32
+ '\\u0019', '\\u001a', '\\u001b', '\\u001c', '\\u001d',
33
+ '\\u001e', '\\u001f', '', '', '\\"',
34
+ '', '', '', '', '', '', '', '', '', '',
35
+ '', '', '', '', '', '', '', '', '', '',
36
+ '', '', '', '', '', '', '', '', '', '',
37
+ '', '', '', '', '', '', '', '', '', '',
38
+ '', '', '', '', '', '', '', '', '', '',
39
+ '', '', '', '', '', '', '', '\\\\'
40
+ ]
41
+
42
+ function escapeFn (str) {
43
+ if (str.length === 2) {
44
+ const charCode = str.charCodeAt(1)
45
+ return `${str[0]}\\u${charCode.toString(16)}`
46
+ }
47
+ const charCode = str.charCodeAt(0)
48
+ return meta.length > charCode
49
+ ? meta[charCode]
50
+ : `\\u${charCode.toString(16)}`
51
+ }
52
+
53
+ // Escape C0 control characters, double quotes, the backslash and every code
54
+ // unit with a numeric value in the inclusive range 0xD800 to 0xDFFF.
55
+ function strEscape (str) {
56
+ // Some magic numbers that worked out fine while benchmarking with v8 8.0
57
+ if (str.length < 5000 && !strEscapeSequencesRegExp.test(str)) {
58
+ return str
59
+ }
60
+ if (str.length > 100) {
61
+ return str.replace(strEscapeSequencesReplacer, escapeFn)
62
+ }
63
+ let result = ''
64
+ let last = 0
65
+ for (let i = 0; i < str.length; i++) {
66
+ const point = str.charCodeAt(i)
67
+ if (point === 34 || point === 92 || point < 32) {
68
+ result += `${str.slice(last, i)}${meta[point]}`
69
+ last = i + 1
70
+ } else if (point >= 0xd800 && point <= 0xdfff) {
71
+ if (point <= 0xdbff && i + 1 < str.length) {
72
+ const point = str.charCodeAt(i + 1)
73
+ if (point >= 0xdc00 && point <= 0xdfff) {
74
+ i++
75
+ continue
76
+ }
77
+ }
78
+ result += `${str.slice(last, i)}${`\\u${point.toString(16)}`}`
79
+ last = i + 1
80
+ }
81
+ }
82
+ result += str.slice(last)
83
+ return result
84
+ }
85
+
86
+ function insertSort (array) {
87
+ // Insertion sort is very efficient for small input sizes but it has a bad
88
+ // worst case complexity. Thus, use native array sort for bigger values.
89
+ if (array.length > 2e2) {
90
+ return array.sort()
91
+ }
92
+ for (let i = 1; i < array.length; i++) {
93
+ const currentValue = array[i]
94
+ let position = i
95
+ while (position !== 0 && array[position - 1] > currentValue) {
96
+ array[position] = array[position - 1]
97
+ position--
98
+ }
99
+ array[position] = currentValue
100
+ }
101
+ return array
102
+ }
103
+
104
+ const typedArrayPrototypeGetSymbolToStringTag =
105
+ Object.getOwnPropertyDescriptor(
106
+ Object.getPrototypeOf(
107
+ Object.getPrototypeOf(
108
+ new Uint8Array()
109
+ )
110
+ ),
111
+ Symbol.toStringTag
112
+ ).get
113
+
114
+ function isTypedArrayWithEntries (value) {
115
+ return typedArrayPrototypeGetSymbolToStringTag.call(value) !== undefined && value.length !== 0
116
+ }
117
+
118
+ function stringifyTypedArray (array, separator, maximumBreadth) {
119
+ if (array.length < maximumBreadth) {
120
+ maximumBreadth = array.length
121
+ }
122
+ const whitespace = separator === ',' ? '' : ' '
123
+ let res = `"0":${whitespace}${array[0]}`
124
+ for (let i = 1; i < maximumBreadth; i++) {
125
+ res += `${separator}"${i}":${whitespace}${array[i]}`
126
+ }
127
+ return res
128
+ }
129
+
130
+ function getCircularValueOption (options) {
131
+ if (options && Object.prototype.hasOwnProperty.call(options, 'circularValue')) {
132
+ var circularValue = options.circularValue
133
+ if (typeof circularValue === 'string') {
134
+ return `"${circularValue}"`
135
+ }
136
+ if (circularValue == null) {
137
+ return circularValue
138
+ }
139
+ if (circularValue === Error || circularValue === TypeError) {
140
+ return {
141
+ toString () {
142
+ throw new TypeError('Converting circular structure to JSON')
143
+ }
144
+ }
145
+ }
146
+ throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined')
147
+ }
148
+ return '"[Circular]"'
149
+ }
150
+
151
+ function getBooleanOption (options, key) {
152
+ if (options && Object.prototype.hasOwnProperty.call(options, key)) {
153
+ var value = options[key]
154
+ if (typeof value !== 'boolean') {
155
+ throw new TypeError(`The "${key}" argument must be of type boolean`)
156
+ }
157
+ }
158
+ return value === undefined ? true : value
159
+ }
160
+
161
+ function getPositiveIntegerOption (options, key) {
162
+ if (options && Object.prototype.hasOwnProperty.call(options, key)) {
163
+ var value = options[key]
164
+ if (typeof value !== 'number') {
165
+ throw new TypeError(`The "${key}" argument must be of type number`)
166
+ }
167
+ if (!Number.isInteger(value)) {
168
+ throw new TypeError(`The "${key}" argument must be an integer`)
169
+ }
170
+ if (value < 1) {
171
+ throw new RangeError(`The "${key}" argument must be >= 1`)
172
+ }
173
+ }
174
+ return value === undefined ? Infinity : value
175
+ }
176
+
177
+ function getItemCount (number) {
178
+ if (number === 1) {
179
+ return '1 item'
180
+ }
181
+ return `${number} items`
182
+ }
183
+
184
+ function getUniqueReplacerSet (replacerArray) {
185
+ const replacerSet = new Set()
186
+ for (const value of replacerArray) {
187
+ if (typeof value === 'string') {
188
+ replacerSet.add(value)
189
+ } else if (typeof value === 'number') {
190
+ replacerSet.add(String(value))
191
+ }
192
+ }
193
+ return replacerSet
194
+ }
195
+
196
+ function configure (options) {
197
+ const circularValue = getCircularValueOption(options)
198
+ const bigint = getBooleanOption(options, 'bigint')
199
+ const deterministic = getBooleanOption(options, 'deterministic')
200
+ const maximumDepth = getPositiveIntegerOption(options, 'maximumDepth')
201
+ const maximumBreadth = getPositiveIntegerOption(options, 'maximumBreadth')
202
+
203
+ function stringifyFnReplacer (key, parent, stack, replacer, spacer, indentation) {
204
+ let value = parent[key]
205
+
206
+ if (typeof value === 'object' && value !== null && typeof value.toJSON === 'function') {
207
+ value = value.toJSON(key)
208
+ }
209
+ value = replacer.call(parent, key, value)
210
+
211
+ switch (typeof value) {
212
+ case 'string':
213
+ return `"${strEscape(value)}"`
214
+ case 'object': {
215
+ if (value === null) {
216
+ return 'null'
217
+ }
218
+ if (stack.indexOf(value) !== -1) {
219
+ return circularValue
220
+ }
221
+
222
+ let res = ''
223
+ let join = ','
224
+ const originalIndentation = indentation
225
+
226
+ if (Array.isArray(value)) {
227
+ if (value.length === 0) {
228
+ return '[]'
229
+ }
230
+ if (maximumDepth < stack.length + 1) {
231
+ return '"[Array]"'
232
+ }
233
+ stack.push(value)
234
+ if (spacer !== '') {
235
+ indentation += spacer
236
+ res += `\n${indentation}`
237
+ join = `,\n${indentation}`
238
+ }
239
+ const maximumValuesToStringify = Math.min(value.length, maximumBreadth)
240
+ let i = 0
241
+ for (; i < maximumValuesToStringify - 1; i++) {
242
+ const tmp = stringifyFnReplacer(i, value, stack, replacer, spacer, indentation)
243
+ res += tmp !== undefined ? tmp : 'null'
244
+ res += join
245
+ }
246
+ const tmp = stringifyFnReplacer(i, value, stack, replacer, spacer, indentation)
247
+ res += tmp !== undefined ? tmp : 'null'
248
+ if (value.length - 1 > maximumBreadth) {
249
+ const removedKeys = value.length - maximumBreadth - 1
250
+ res += `${join}"... ${getItemCount(removedKeys)} not stringified"`
251
+ }
252
+ if (spacer !== '') {
253
+ res += `\n${originalIndentation}`
254
+ }
255
+ stack.pop()
256
+ return `[${res}]`
257
+ }
258
+
259
+ let keys = Object.keys(value)
260
+ const keyLength = keys.length
261
+ if (keyLength === 0) {
262
+ return '{}'
263
+ }
264
+ if (maximumDepth < stack.length + 1) {
265
+ return '"[Object]"'
266
+ }
267
+ let whitespace = ''
268
+ let separator = ''
269
+ if (spacer !== '') {
270
+ indentation += spacer
271
+ join = `,\n${indentation}`
272
+ whitespace = ' '
273
+ }
274
+ let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth)
275
+ if (isTypedArrayWithEntries(value)) {
276
+ res += stringifyTypedArray(value, join, maximumBreadth)
277
+ keys = keys.slice(value.length)
278
+ maximumPropertiesToStringify -= value.length
279
+ separator = join
280
+ }
281
+ if (deterministic) {
282
+ keys = insertSort(keys)
283
+ }
284
+ stack.push(value)
285
+ for (let i = 0; i < maximumPropertiesToStringify; i++) {
286
+ const key = keys[i]
287
+ const tmp = stringifyFnReplacer(key, value, stack, replacer, spacer, indentation)
288
+ if (tmp !== undefined) {
289
+ res += `${separator}"${strEscape(key)}":${whitespace}${tmp}`
290
+ separator = join
291
+ }
292
+ }
293
+ if (keyLength > maximumBreadth) {
294
+ const removedKeys = keyLength - maximumBreadth
295
+ res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`
296
+ separator = join
297
+ }
298
+ if (spacer !== '' && separator.length > 1) {
299
+ res = `\n${indentation}${res}\n${originalIndentation}`
300
+ }
301
+ stack.pop()
302
+ return `{${res}}`
303
+ }
304
+ case 'number':
305
+ return isFinite(value) ? String(value) : 'null'
306
+ case 'boolean':
307
+ return value === true ? 'true' : 'false'
308
+ case 'bigint':
309
+ return bigint ? String(value) : undefined
310
+ }
311
+ }
312
+
313
+ function stringifyArrayReplacer (key, value, stack, replacer, spacer, indentation) {
314
+ if (typeof value === 'object' && value !== null && typeof value.toJSON === 'function') {
315
+ value = value.toJSON(key)
316
+ }
317
+
318
+ switch (typeof value) {
319
+ case 'string':
320
+ return `"${strEscape(value)}"`
321
+ case 'object': {
322
+ if (value === null) {
323
+ return 'null'
324
+ }
325
+ if (stack.indexOf(value) !== -1) {
326
+ return circularValue
327
+ }
328
+
329
+ const originalIndentation = indentation
330
+ let res = ''
331
+ let join = ','
332
+
333
+ if (Array.isArray(value)) {
334
+ if (value.length === 0) {
335
+ return '[]'
336
+ }
337
+ if (maximumDepth < stack.length + 1) {
338
+ return '"[Array]"'
339
+ }
340
+ stack.push(value)
341
+ if (spacer !== '') {
342
+ indentation += spacer
343
+ res += `\n${indentation}`
344
+ join = `,\n${indentation}`
345
+ }
346
+ const maximumValuesToStringify = Math.min(value.length, maximumBreadth)
347
+ let i = 0
348
+ for (; i < maximumValuesToStringify - 1; i++) {
349
+ const tmp = stringifyArrayReplacer(i, value[i], stack, replacer, spacer, indentation)
350
+ res += tmp !== undefined ? tmp : 'null'
351
+ res += join
352
+ }
353
+ const tmp = stringifyArrayReplacer(i, value[i], stack, replacer, spacer, indentation)
354
+ res += tmp !== undefined ? tmp : 'null'
355
+ if (value.length - 1 > maximumBreadth) {
356
+ const removedKeys = value.length - maximumBreadth - 1
357
+ res += `${join}"... ${getItemCount(removedKeys)} not stringified"`
358
+ }
359
+ if (spacer !== '') {
360
+ res += `\n${originalIndentation}`
361
+ }
362
+ stack.pop()
363
+ return `[${res}]`
364
+ }
365
+ if (replacer.size === 0) {
366
+ return '{}'
367
+ }
368
+ stack.push(value)
369
+ let whitespace = ''
370
+ if (spacer !== '') {
371
+ indentation += spacer
372
+ join = `,\n${indentation}`
373
+ whitespace = ' '
374
+ }
375
+ let separator = ''
376
+ for (const key of replacer) {
377
+ const tmp = stringifyArrayReplacer(key, value[key], stack, replacer, spacer, indentation)
378
+ if (tmp !== undefined) {
379
+ res += `${separator}"${strEscape(key)}":${whitespace}${tmp}`
380
+ separator = join
381
+ }
382
+ }
383
+ if (spacer !== '' && separator.length > 1) {
384
+ res = `\n${indentation}${res}\n${originalIndentation}`
385
+ }
386
+ stack.pop()
387
+ return `{${res}}`
388
+ }
389
+ case 'number':
390
+ return isFinite(value) ? String(value) : 'null'
391
+ case 'boolean':
392
+ return value === true ? 'true' : 'false'
393
+ case 'bigint':
394
+ return bigint ? String(value) : undefined
395
+ }
396
+ }
397
+
398
+ function stringifyIndent (key, value, stack, spacer, indentation) {
399
+ switch (typeof value) {
400
+ case 'string':
401
+ return `"${strEscape(value)}"`
402
+ case 'object': {
403
+ if (value === null) {
404
+ return 'null'
405
+ }
406
+ if (typeof value.toJSON === 'function') {
407
+ value = value.toJSON(key)
408
+ // Prevent calling `toJSON` again.
409
+ if (typeof value !== 'object') {
410
+ return stringifyIndent(key, value, stack, spacer, indentation)
411
+ }
412
+ if (value === null) {
413
+ return 'null'
414
+ }
415
+ }
416
+ if (stack.indexOf(value) !== -1) {
417
+ return circularValue
418
+ }
419
+ const originalIndentation = indentation
420
+
421
+ if (Array.isArray(value)) {
422
+ if (value.length === 0) {
423
+ return '[]'
424
+ }
425
+ if (maximumDepth < stack.length + 1) {
426
+ return '"[Array]"'
427
+ }
428
+ stack.push(value)
429
+ indentation += spacer
430
+ let res = `\n${indentation}`
431
+ const join = `,\n${indentation}`
432
+ const maximumValuesToStringify = Math.min(value.length, maximumBreadth)
433
+ let i = 0
434
+ for (; i < maximumValuesToStringify - 1; i++) {
435
+ const tmp = stringifyIndent(i, value[i], stack, spacer, indentation)
436
+ res += tmp !== undefined ? tmp : 'null'
437
+ res += join
438
+ }
439
+ const tmp = stringifyIndent(i, value[i], stack, spacer, indentation)
440
+ res += tmp !== undefined ? tmp : 'null'
441
+ if (value.length - 1 > maximumBreadth) {
442
+ const removedKeys = value.length - maximumBreadth - 1
443
+ res += `${join}"... ${getItemCount(removedKeys)} not stringified"`
444
+ }
445
+ res += `\n${originalIndentation}`
446
+ stack.pop()
447
+ return `[${res}]`
448
+ }
449
+
450
+ let keys = Object.keys(value)
451
+ const keyLength = keys.length
452
+ if (keyLength === 0) {
453
+ return '{}'
454
+ }
455
+ if (maximumDepth < stack.length + 1) {
456
+ return '"[Object]"'
457
+ }
458
+ indentation += spacer
459
+ const join = `,\n${indentation}`
460
+ let res = ''
461
+ let separator = ''
462
+ let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth)
463
+ if (isTypedArrayWithEntries(value)) {
464
+ res += stringifyTypedArray(value, join, maximumBreadth)
465
+ keys = keys.slice(value.length)
466
+ maximumPropertiesToStringify -= value.length
467
+ separator = join
468
+ }
469
+ if (deterministic) {
470
+ keys = insertSort(keys)
471
+ }
472
+ stack.push(value)
473
+ for (let i = 0; i < maximumPropertiesToStringify; i++) {
474
+ const key = keys[i]
475
+ const tmp = stringifyIndent(key, value[key], stack, spacer, indentation)
476
+ if (tmp !== undefined) {
477
+ res += `${separator}"${strEscape(key)}": ${tmp}`
478
+ separator = join
479
+ }
480
+ }
481
+ if (keyLength > maximumBreadth) {
482
+ const removedKeys = keyLength - maximumBreadth
483
+ res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`
484
+ separator = join
485
+ }
486
+ if (separator !== '') {
487
+ res = `\n${indentation}${res}\n${originalIndentation}`
488
+ }
489
+ stack.pop()
490
+ return `{${res}}`
491
+ }
492
+ case 'number':
493
+ return isFinite(value) ? String(value) : 'null'
494
+ case 'boolean':
495
+ return value === true ? 'true' : 'false'
496
+ case 'bigint':
497
+ return bigint ? String(value) : undefined
498
+ }
499
+ }
500
+
501
+ function stringifySimple (key, value, stack) {
502
+ switch (typeof value) {
503
+ case 'string':
504
+ return `"${strEscape(value)}"`
505
+ case 'object': {
506
+ if (value === null) {
507
+ return 'null'
508
+ }
509
+ if (typeof value.toJSON === 'function') {
510
+ value = value.toJSON(key)
511
+ // Prevent calling `toJSON` again
512
+ if (typeof value !== 'object') {
513
+ return stringifySimple(key, value, stack)
514
+ }
515
+ if (value === null) {
516
+ return 'null'
517
+ }
518
+ }
519
+ if (stack.indexOf(value) !== -1) {
520
+ return circularValue
521
+ }
522
+
523
+ let res = ''
524
+
525
+ if (Array.isArray(value)) {
526
+ if (value.length === 0) {
527
+ return '[]'
528
+ }
529
+ if (maximumDepth < stack.length + 1) {
530
+ return '"[Array]"'
531
+ }
532
+ stack.push(value)
533
+ const maximumValuesToStringify = Math.min(value.length, maximumBreadth)
534
+ let i = 0
535
+ for (; i < maximumValuesToStringify - 1; i++) {
536
+ const tmp = stringifySimple(i, value[i], stack)
537
+ res += tmp !== undefined ? tmp : 'null'
538
+ res += ','
539
+ }
540
+ const tmp = stringifySimple(i, value[i], stack)
541
+ res += tmp !== undefined ? tmp : 'null'
542
+ if (value.length - 1 > maximumBreadth) {
543
+ const removedKeys = value.length - maximumBreadth - 1
544
+ res += `,"... ${getItemCount(removedKeys)} not stringified"`
545
+ }
546
+ stack.pop()
547
+ return `[${res}]`
548
+ }
549
+
550
+ let keys = Object.keys(value)
551
+ const keyLength = keys.length
552
+ if (keyLength === 0) {
553
+ return '{}'
554
+ }
555
+ if (maximumDepth < stack.length + 1) {
556
+ return '"[Object]"'
557
+ }
558
+ let separator = ''
559
+ let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth)
560
+ if (isTypedArrayWithEntries(value)) {
561
+ res += stringifyTypedArray(value, ',', maximumBreadth)
562
+ keys = keys.slice(value.length)
563
+ maximumPropertiesToStringify -= value.length
564
+ separator = ','
565
+ }
566
+ if (deterministic) {
567
+ keys = insertSort(keys)
568
+ }
569
+ stack.push(value)
570
+ for (let i = 0; i < maximumPropertiesToStringify; i++) {
571
+ const key = keys[i]
572
+ const tmp = stringifySimple(key, value[key], stack)
573
+ if (tmp !== undefined) {
574
+ res += `${separator}"${strEscape(key)}":${tmp}`
575
+ separator = ','
576
+ }
577
+ }
578
+ if (keyLength > maximumBreadth) {
579
+ const removedKeys = keyLength - maximumBreadth
580
+ res += `${separator}"...":"${getItemCount(removedKeys)} not stringified"`
581
+ }
582
+ stack.pop()
583
+ return `{${res}}`
584
+ }
585
+ case 'number':
586
+ return isFinite(value) ? String(value) : 'null'
587
+ case 'boolean':
588
+ return value === true ? 'true' : 'false'
589
+ case 'bigint':
590
+ return bigint ? String(value) : undefined
591
+ }
592
+ }
593
+
594
+ function stringify (value, replacer, space) {
595
+ if (arguments.length > 1) {
596
+ let spacer = ''
597
+ if (typeof space === 'number') {
598
+ spacer = ' '.repeat(Math.min(space, 10))
599
+ } else if (typeof space === 'string') {
600
+ spacer = space.slice(0, 10)
601
+ }
602
+ if (replacer != null) {
603
+ if (typeof replacer === 'function') {
604
+ return stringifyFnReplacer('', { '': value }, [], replacer, spacer, '')
605
+ }
606
+ if (Array.isArray(replacer)) {
607
+ return stringifyArrayReplacer('', value, [], getUniqueReplacerSet(replacer), spacer, '')
608
+ }
609
+ }
610
+ if (spacer.length !== 0) {
611
+ return stringifyIndent('', value, [], spacer, '')
612
+ }
613
+ }
614
+ return stringifySimple('', value, [])
615
+ }
616
+
617
+ return stringify
618
+ }
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "safe-stable-stringify",
3
+ "version": "2.3.1",
4
+ "description": "Deterministic and safely JSON.stringify to quickly serialize JavaScript objects",
5
+ "exports": {
6
+ "require": "./index.js",
7
+ "import": "./esm/wrapper.js"
8
+ },
9
+ "keywords": [
10
+ "stable",
11
+ "stringify",
12
+ "JSON",
13
+ "JSON.stringify",
14
+ "safe",
15
+ "serialize",
16
+ "deterministic",
17
+ "circular",
18
+ "object",
19
+ "predicable",
20
+ "repeatable",
21
+ "fast",
22
+ "bigint"
23
+ ],
24
+ "main": "index.js",
25
+ "scripts": {
26
+ "test": "standard && tap test.js",
27
+ "tap": "tap test.js",
28
+ "tap:only": "tap test.js --watch --only",
29
+ "benchmark": "node benchmark.js",
30
+ "compare": "node compare.js",
31
+ "lint": "standard --fix",
32
+ "tsc": "tsc --project tsconfig.json"
33
+ },
34
+ "engines": {
35
+ "node": ">=10"
36
+ },
37
+ "author": "Ruben Bridgewater",
38
+ "license": "MIT",
39
+ "typings": "index.d.ts",
40
+ "devDependencies": {
41
+ "@types/json-stable-stringify": "^1.0.32",
42
+ "@types/node": "^16.11.1",
43
+ "benchmark": "^2.1.4",
44
+ "clone": "^2.1.2",
45
+ "fast-json-stable-stringify": "^2.1.0",
46
+ "fast-safe-stringify": "^2.0.7",
47
+ "fast-stable-stringify": "^1.0.0",
48
+ "faster-stable-stringify": "^1.0.0",
49
+ "fastest-stable-stringify": "^2.0.2",
50
+ "json-stable-stringify": "^1.0.1",
51
+ "json-stringify-deterministic": "^1.0.1",
52
+ "json-stringify-safe": "^5.0.1",
53
+ "standard": "^15.0.0",
54
+ "tap": "^15.0.9",
55
+ "typescript": "^4.4.3"
56
+ },
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git+https://github.com/BridgeAR/safe-stable-stringify.git"
60
+ },
61
+ "bugs": {
62
+ "url": "https://github.com/BridgeAR/safe-stable-stringify/issues"
63
+ },
64
+ "homepage": "https://github.com/BridgeAR/safe-stable-stringify#readme"
65
+
66
+ ,"_resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.3.1.tgz"
67
+ ,"_integrity": "sha512-kYBSfT+troD9cDA85VDnHZ1rpHC50O0g1e6WlGHVCz/g+JS+9WKLj+XwFYyR8UbrZN8ll9HUpDAAddY58MGisg=="
68
+ ,"_from": "safe-stable-stringify@2.3.1"
69
+ }