pi-dent-agent 0.2.3 → 0.2.4

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 (55) hide show
  1. package/index.ts +5 -1
  2. package/lib/config.ts +59 -0
  3. package/lib/engine.ts +4 -1
  4. package/lib/script-render.ts +1 -1
  5. package/lib/script-runner.ts +70 -4
  6. package/lib/script-tool-calls.ts +116 -0
  7. package/lib/script-tool-log.ts +143 -0
  8. package/lib/script-tool-types.ts +258 -0
  9. package/lib/script-tool.ts +103 -9
  10. package/lib/script-worker.ts +92 -1
  11. package/lib/search-tool.ts +1 -1
  12. package/lib/tools.ts +13 -5
  13. package/node_modules/express-rate-limit/dist/index.cjs +6 -4
  14. package/node_modules/express-rate-limit/dist/index.mjs +6 -4
  15. package/node_modules/express-rate-limit/package.json +1 -1
  16. package/node_modules/jose/dist/webapi/jwks/remote.js +2 -2
  17. package/node_modules/jose/dist/webapi/jwt/encrypt.js +5 -8
  18. package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +1 -1
  19. package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +2 -2
  20. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +1 -1
  21. package/node_modules/jose/dist/webapi/lib/key.js +2 -0
  22. package/node_modules/jose/package.json +1 -1
  23. package/node_modules/object-inspect/CHANGELOG.md +31 -0
  24. package/node_modules/object-inspect/index.js +326 -24
  25. package/node_modules/object-inspect/package.json +22 -13
  26. package/node_modules/object-inspect/readme.markdown +4 -1
  27. package/node_modules/object-inspect/stringWidth.js +68 -0
  28. package/node_modules/object-inspect/stringWidthRanges.js +38 -0
  29. package/package.json +1 -1
  30. package/node_modules/object-inspect/.eslintrc +0 -53
  31. package/node_modules/object-inspect/.nycrc +0 -13
  32. package/node_modules/object-inspect/example/all.js +0 -23
  33. package/node_modules/object-inspect/example/circular.js +0 -6
  34. package/node_modules/object-inspect/example/fn.js +0 -5
  35. package/node_modules/object-inspect/example/inspect.js +0 -10
  36. package/node_modules/object-inspect/test/bigint.js +0 -58
  37. package/node_modules/object-inspect/test/browser/dom.js +0 -15
  38. package/node_modules/object-inspect/test/circular.js +0 -16
  39. package/node_modules/object-inspect/test/deep.js +0 -12
  40. package/node_modules/object-inspect/test/element.js +0 -53
  41. package/node_modules/object-inspect/test/err.js +0 -48
  42. package/node_modules/object-inspect/test/fakes.js +0 -29
  43. package/node_modules/object-inspect/test/fn.js +0 -76
  44. package/node_modules/object-inspect/test/global.js +0 -17
  45. package/node_modules/object-inspect/test/has.js +0 -15
  46. package/node_modules/object-inspect/test/holes.js +0 -15
  47. package/node_modules/object-inspect/test/indent-option.js +0 -271
  48. package/node_modules/object-inspect/test/inspect.js +0 -139
  49. package/node_modules/object-inspect/test/lowbyte.js +0 -12
  50. package/node_modules/object-inspect/test/number.js +0 -58
  51. package/node_modules/object-inspect/test/quoteStyle.js +0 -26
  52. package/node_modules/object-inspect/test/toStringTag.js +0 -40
  53. package/node_modules/object-inspect/test/undef.js +0 -12
  54. package/node_modules/object-inspect/test/values.js +0 -261
  55. package/node_modules/object-inspect/test-core-js.js +0 -26
@@ -2,10 +2,12 @@ var hasMap = typeof Map === 'function' && Map.prototype;
2
2
  var mapSizeDescriptor = Object.getOwnPropertyDescriptor && hasMap ? Object.getOwnPropertyDescriptor(Map.prototype, 'size') : null;
3
3
  var mapSize = hasMap && mapSizeDescriptor && typeof mapSizeDescriptor.get === 'function' ? mapSizeDescriptor.get : null;
4
4
  var mapForEach = hasMap && Map.prototype.forEach;
5
+ var mapEntries = hasMap && Map.prototype.entries;
5
6
  var hasSet = typeof Set === 'function' && Set.prototype;
6
7
  var setSizeDescriptor = Object.getOwnPropertyDescriptor && hasSet ? Object.getOwnPropertyDescriptor(Set.prototype, 'size') : null;
7
8
  var setSize = hasSet && setSizeDescriptor && typeof setSizeDescriptor.get === 'function' ? setSizeDescriptor.get : null;
8
9
  var setForEach = hasSet && Set.prototype.forEach;
10
+ var setValues = hasSet && Set.prototype.values;
9
11
  var hasWeakMap = typeof WeakMap === 'function' && WeakMap.prototype;
10
12
  var weakMapHas = hasWeakMap ? WeakMap.prototype.has : null;
11
13
  var hasWeakSet = typeof WeakSet === 'function' && WeakSet.prototype;
@@ -25,12 +27,22 @@ var $concat = Array.prototype.concat;
25
27
  var $join = Array.prototype.join;
26
28
  var $arrSlice = Array.prototype.slice;
27
29
  var $floor = Math.floor;
30
+ var $max = Math.max;
31
+ var $min = Math.min;
32
+ var $round = Math.round;
33
+ var $sqrt = Math.sqrt;
28
34
  var bigIntValueOf = typeof BigInt === 'function' ? BigInt.prototype.valueOf : null;
29
35
  var gOPS = Object.getOwnPropertySymbols;
30
36
  var symToString = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? Symbol.prototype.toString : null;
31
37
  var hasShammedSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'object';
32
38
  // ie, `has-tostringtag/shams
33
- var toStringTag = typeof Symbol === 'function' && Symbol.toStringTag && (typeof Symbol.toStringTag === hasShammedSymbols ? 'object' : 'symbol')
39
+ var toStringTag = typeof Symbol === 'function'
40
+ && Symbol.toStringTag
41
+ && (
42
+ hasShammedSymbols
43
+ ? typeof Symbol.toStringTag === 'object'
44
+ : typeof Symbol.toStringTag === 'symbol'
45
+ )
34
46
  ? Symbol.toStringTag
35
47
  : null;
36
48
  var isEnumerable = Object.prototype.propertyIsEnumerable;
@@ -43,6 +55,37 @@ var gPO = (typeof Reflect === 'function' ? Reflect.getPrototypeOf : Object.getPr
43
55
  : null
44
56
  );
45
57
 
58
+ var mapIteratorNext = mapEntries && gPO ? gPO(mapEntries.call(new Map())).next : null;
59
+ var setIteratorNext = setValues && gPO ? gPO(setValues.call(new Set())).next : null;
60
+
61
+ // TODO: replace with `which-typed-array`, and `call-bound` for `TypedArray.prototype.length`
62
+ /* global Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array */
63
+ var typedArrayProto = typeof Uint8Array === 'function' && gPO ? gPO(Uint8Array.prototype) : null;
64
+ var typedArrayTag = typedArrayProto && toStringTag ? getterOf(typedArrayProto, toStringTag) : null;
65
+ var typedArrayLength = typedArrayProto ? getterOf(typedArrayProto, 'length') : null;
66
+ var typedArrayToString = /^\[object (?:Int8|Uint8|Uint8Clamped|Int16|Uint16|Int32|Uint32|Float16|Float32|Float64|BigInt64|BigUint64)Array\]$/;
67
+ var typedArrayLengths = { __proto__: null };
68
+ if (!typedArrayLength) {
69
+ var TypedArrays = [
70
+ typeof Int8Array === 'function' && Int8Array,
71
+ typeof Uint8Array === 'function' && Uint8Array,
72
+ typeof Uint8ClampedArray === 'function' && Uint8ClampedArray,
73
+ typeof Int16Array === 'function' && Int16Array,
74
+ typeof Uint16Array === 'function' && Uint16Array,
75
+ typeof Int32Array === 'function' && Int32Array,
76
+ typeof Uint32Array === 'function' && Uint32Array,
77
+ typeof Float32Array === 'function' && Float32Array,
78
+ typeof Float64Array === 'function' && Float64Array
79
+ ];
80
+ for (var ta = 0; ta < TypedArrays.length; ta++) {
81
+ var TypedArray = TypedArrays[ta];
82
+ var lengthGetter = TypedArray && getterOf(TypedArray.prototype, 'length');
83
+ if (lengthGetter) {
84
+ typedArrayLengths[toStr(new TypedArray(0))] = lengthGetter;
85
+ }
86
+ }
87
+ }
88
+
46
89
  function addNumericSeparator(num, str) {
47
90
  if (
48
91
  num === Infinity
@@ -66,6 +109,7 @@ function addNumericSeparator(num, str) {
66
109
  }
67
110
 
68
111
  var utilInspect = require('./util.inspect');
112
+ var getStringWidth = require('./stringWidth');
69
113
  var inspectCustom = utilInspect.custom;
70
114
  var inspectSymbol = isSymbol(inspectCustom) ? inspectCustom : null;
71
115
 
@@ -80,7 +124,7 @@ var quoteREs = {
80
124
  single: /(['\\])/g
81
125
  };
82
126
 
83
- module.exports = function inspect_(obj, options, depth, seen) {
127
+ module.exports = function inspect_(obj, options, depth, seen, breakState) { // eslint-disable-line max-params
84
128
  var opts = options || {};
85
129
 
86
130
  if (has(opts, 'quoteStyle') && !has(quotes, opts.quoteStyle)) {
@@ -92,8 +136,21 @@ module.exports = function inspect_(obj, options, depth, seen) {
92
136
  : opts.maxStringLength !== null
93
137
  )
94
138
  ) {
95
- throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');
139
+ throw new TypeError('option "maxStringLength", if provided, must be a non-negative integer, Infinity, or `null`');
96
140
  }
141
+ if (
142
+ has(opts, 'maxCollectionLength')
143
+ && opts.maxCollectionLength !== null
144
+ && opts.maxCollectionLength !== Infinity
145
+ && !(
146
+ typeof opts.maxCollectionLength === 'number'
147
+ && opts.maxCollectionLength >= 0
148
+ && $floor(opts.maxCollectionLength) === opts.maxCollectionLength
149
+ )
150
+ ) {
151
+ throw new TypeError('option "maxCollectionLength", if provided, must be a non-negative integer, Infinity, or `null`');
152
+ }
153
+ var maxCollectionLength = typeof opts.maxCollectionLength === 'number' ? opts.maxCollectionLength : Infinity;
97
154
  var customInspect = has(opts, 'customInspect') ? opts.customInspect : true;
98
155
  if (typeof customInspect !== 'boolean' && customInspect !== 'symbol') {
99
156
  throw new TypeError('option "customInspect", if provided, must be `true`, `false`, or `\'symbol\'`');
@@ -111,6 +168,22 @@ module.exports = function inspect_(obj, options, depth, seen) {
111
168
  throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');
112
169
  }
113
170
  var numericSeparator = opts.numericSeparator;
171
+ if (has(opts, 'multilineStrings') && typeof opts.multilineStrings !== 'boolean') {
172
+ throw new TypeError('option "multilineStrings", if provided, must be `true` or `false`');
173
+ }
174
+
175
+ var hasBreakLength = has(opts, 'breakLength');
176
+ if (
177
+ hasBreakLength
178
+ && opts.breakLength !== Infinity
179
+ && (
180
+ typeof opts.breakLength !== 'number'
181
+ || opts.breakLength < 0
182
+ || parseInt(opts.breakLength, 10) !== opts.breakLength
183
+ )
184
+ ) {
185
+ throw new TypeError('option "breakLength", if provided, must be a non-negative integer or `Infinity`');
186
+ }
114
187
 
115
188
  if (typeof obj === 'undefined') {
116
189
  return 'undefined';
@@ -143,7 +216,14 @@ module.exports = function inspect_(obj, options, depth, seen) {
143
216
  return isArray(obj) ? '[Array]' : '[Object]';
144
217
  }
145
218
 
146
- var indent = getIndent(opts, depth);
219
+ var indent = getIndent(hasBreakLength && (typeof opts.indent === 'undefined' || opts.indent === null) ? { indent: 2 } : opts, depth);
220
+ var layout = hasBreakLength ? {
221
+ breakLength: opts.breakLength,
222
+ depth: depth,
223
+ indent: indent,
224
+ maxCollectionLength: maxCollectionLength,
225
+ state: breakState || { currentDepth: depth }
226
+ } : null;
147
227
 
148
228
  if (typeof seen === 'undefined') {
149
229
  seen = [];
@@ -152,25 +232,49 @@ module.exports = function inspect_(obj, options, depth, seen) {
152
232
  }
153
233
 
154
234
  function inspect(value, from, noIndent) {
235
+ var nextSeen = seen;
155
236
  if (from) {
156
- seen = $arrSlice.call(seen);
157
- seen.push(from);
237
+ nextSeen = $arrSlice.call(seen);
238
+ nextSeen.push(from);
158
239
  }
159
- if (noIndent) {
240
+ if (noIndent && !layout) {
160
241
  var newOpts = {
161
242
  depth: opts.depth
162
243
  };
163
244
  if (has(opts, 'quoteStyle')) {
164
245
  newOpts.quoteStyle = opts.quoteStyle;
165
246
  }
166
- return inspect_(value, newOpts, depth + 1, seen);
247
+ if (has(opts, 'maxCollectionLength')) {
248
+ newOpts.maxCollectionLength = opts.maxCollectionLength;
249
+ }
250
+ return inspect_(value, newOpts, depth + 1, nextSeen);
251
+ }
252
+ return inspect_(value, opts, depth + 1, nextSeen, layout ? layout.state : breakState);
253
+ }
254
+
255
+ // like `util.inspect`, track the depth of the most recently entered non-empty object, so a container only fits on one line when few levels are nested below it
256
+ function enter() {
257
+ if (layout) {
258
+ var previousDepth = layout.state.currentDepth;
259
+ layout.state.currentDepth = depth;
260
+ return previousDepth;
261
+ }
262
+ return null;
263
+ }
264
+ function leaveIfEmpty(entries, previousDepth) {
265
+ if (layout && entries.length === 0) {
266
+ layout.state.currentDepth = previousDepth;
167
267
  }
168
- return inspect_(value, opts, depth + 1, seen);
169
268
  }
170
269
 
171
270
  if (typeof obj === 'function' && !isRegExp(obj)) { // in older engines, regexes are callable
172
271
  var name = nameOf(obj);
272
+ var fnDepth = enter();
173
273
  var keys = arrObjKeys(obj, inspect);
274
+ leaveIfEmpty(keys, fnDepth);
275
+ if (layout && keys.length > 0) {
276
+ return breakLines(keys, bracesOf('{', '}', '[Function' + (name ? ': ' + name : ' (anonymous)') + ']', ' '), layout);
277
+ }
174
278
  return '[Function' + (name ? ': ' + name : ' (anonymous)') + ']' + (keys.length > 0 ? ' { ' + $join.call(keys, ', ') + ' }' : '');
175
279
  }
176
280
  if (isSymbol(obj)) {
@@ -190,18 +294,27 @@ module.exports = function inspect_(obj, options, depth, seen) {
190
294
  }
191
295
  if (isArray(obj)) {
192
296
  if (obj.length === 0) { return '[]'; }
193
- var xs = arrObjKeys(obj, inspect);
297
+ enter();
298
+ var xs = arrObjKeys(obj, inspect, maxCollectionLength);
299
+ if (layout) {
300
+ return breakLines(xs, bracesOf('[', ']', '', ' '), layout, obj);
301
+ }
194
302
  if (indent && !singleLineValues(xs)) {
195
303
  return '[' + indentedJoin(xs, indent) + ']';
196
304
  }
197
305
  return '[ ' + $join.call(xs, ', ') + ' ]';
198
306
  }
199
307
  if (isError(obj)) {
308
+ var errorDepth = enter();
200
309
  var parts = arrObjKeys(obj, inspect);
201
310
  if (!('cause' in Error.prototype) && 'cause' in obj && !isEnumerable.call(obj, 'cause')) {
202
- return '{ [' + String(obj) + '] ' + $join.call($concat.call('[cause]: ' + inspect(obj.cause), parts), ', ') + ' }';
311
+ parts = $concat.call(['[cause]: ' + inspect(obj.cause)], parts);
203
312
  }
313
+ leaveIfEmpty(parts, errorDepth);
204
314
  if (parts.length === 0) { return '[' + String(obj) + ']'; }
315
+ if (layout) {
316
+ return breakLines(parts, bracesOf('{ [' + String(obj) + ']', '}', '', ' '), layout);
317
+ }
205
318
  return '{ [' + String(obj) + '] ' + $join.call(parts, ', ') + ' }';
206
319
  }
207
320
  if (typeof obj === 'object' && customInspect) {
@@ -213,21 +326,55 @@ module.exports = function inspect_(obj, options, depth, seen) {
213
326
  }
214
327
  if (isMap(obj)) {
215
328
  var mapParts = [];
216
- if (mapForEach) {
329
+ var mapDepth = enter();
330
+ if (mapIteratorNext && maxCollectionLength < mapSize.call(obj)) {
331
+ var mapIterator = mapEntries.call(obj);
332
+ var mapStep;
333
+ while (mapParts.length < maxCollectionLength && !(mapStep = mapIteratorNext.call(mapIterator)).done) {
334
+ mapParts.push(inspect(mapStep.value[0], obj, true) + ' => ' + inspect(mapStep.value[1], obj));
335
+ }
336
+ } else if (mapForEach) {
217
337
  mapForEach.call(obj, function (value, key) {
218
- mapParts.push(inspect(key, obj, true) + ' => ' + inspect(value, obj));
338
+ if (mapParts.length < maxCollectionLength) {
339
+ mapParts.push(inspect(key, obj, true) + ' => ' + inspect(value, obj));
340
+ }
219
341
  });
220
342
  }
221
- return collectionOf('Map', mapSize.call(obj), mapParts, indent);
343
+ var mapLength = mapSize.call(obj);
344
+ if (maxCollectionLength !== Infinity && mapLength > mapParts.length) {
345
+ mapParts.push(moreItems(mapLength - mapParts.length));
346
+ }
347
+ leaveIfEmpty(mapParts, mapDepth);
348
+ if (layout) {
349
+ return breakLines(mapParts, bracesOf('Map (' + mapLength + ') {', '}', '', ''), layout);
350
+ }
351
+ return collectionOf('Map', mapLength, mapParts, indent);
222
352
  }
223
353
  if (isSet(obj)) {
224
354
  var setParts = [];
225
- if (setForEach) {
355
+ var setDepth = enter();
356
+ if (setIteratorNext && maxCollectionLength < setSize.call(obj)) {
357
+ var setIterator = setValues.call(obj);
358
+ var setStep;
359
+ while (setParts.length < maxCollectionLength && !(setStep = setIteratorNext.call(setIterator)).done) {
360
+ setParts.push(inspect(setStep.value, obj));
361
+ }
362
+ } else if (setForEach) {
226
363
  setForEach.call(obj, function (value) {
227
- setParts.push(inspect(value, obj));
364
+ if (setParts.length < maxCollectionLength) {
365
+ setParts.push(inspect(value, obj));
366
+ }
228
367
  });
229
368
  }
230
- return collectionOf('Set', setSize.call(obj), setParts, indent);
369
+ var setLength = setSize.call(obj);
370
+ if (maxCollectionLength !== Infinity && setLength > setParts.length) {
371
+ setParts.push(moreItems(setLength - setParts.length));
372
+ }
373
+ leaveIfEmpty(setParts, setDepth);
374
+ if (layout) {
375
+ return breakLines(setParts, bracesOf('Set (' + setLength + ') {', '}', '', ''), layout);
376
+ }
377
+ return collectionOf('Set', setLength, setParts, indent);
231
378
  }
232
379
  if (isWeakMap(obj)) {
233
380
  return weakCollectionOf('WeakMap');
@@ -251,7 +398,7 @@ module.exports = function inspect_(obj, options, depth, seen) {
251
398
  return markBoxed(inspect(String(obj)));
252
399
  }
253
400
  // note: in IE 8, sometimes `global !== window` but both are the prototypes of each other
254
- /* eslint-env browser */
401
+ /* global window */
255
402
  if (typeof window !== 'undefined' && obj === window) {
256
403
  return '{ [object Window] }';
257
404
  }
@@ -262,13 +409,18 @@ module.exports = function inspect_(obj, options, depth, seen) {
262
409
  return '{ [object globalThis] }';
263
410
  }
264
411
  if (!isDate(obj) && !isRegExp(obj)) {
265
- var ys = arrObjKeys(obj, inspect);
412
+ var objectDepth = enter();
413
+ var ys = arrObjKeys(obj, inspect, maxCollectionLength);
414
+ leaveIfEmpty(ys, objectDepth);
266
415
  var isPlainObject = gPO ? gPO(obj) === Object.prototype : obj instanceof Object || obj.constructor === Object;
267
- var protoTag = obj instanceof Object ? '' : 'null prototype';
416
+ var protoTag = (gPO ? gPO(obj) === null : !(obj instanceof Object)) ? 'null prototype' : '';
268
417
  var stringTag = !isPlainObject && toStringTag && Object(obj) === obj && toStringTag in obj ? $slice.call(toStr(obj), 8, -1) : protoTag ? 'Object' : '';
269
418
  var constructorTag = isPlainObject || typeof obj.constructor !== 'function' ? '' : obj.constructor.name ? obj.constructor.name + ' ' : '';
270
419
  var tag = constructorTag + (stringTag || protoTag ? '[' + $join.call($concat.call([], stringTag || [], protoTag || []), ': ') + '] ' : '');
271
420
  if (ys.length === 0) { return tag + '{}'; }
421
+ if (layout) {
422
+ return breakLines(ys, bracesOf(tag + '{', '}', '', ' '), layout);
423
+ }
272
424
  if (indent) {
273
425
  return tag + '{' + indentedJoin(ys, indent) + '}';
274
426
  }
@@ -336,6 +488,30 @@ function toStr(obj) {
336
488
  return objectToString.call(obj);
337
489
  }
338
490
 
491
+ function isTypedArray(obj) {
492
+ if (typedArrayTag) {
493
+ return !!typedArrayTag.call(obj);
494
+ }
495
+ return !toStringTag && $test.call(typedArrayToString, toStr(obj));
496
+ }
497
+
498
+ function getTypedArrayLength(obj) {
499
+ if (typedArrayLength) {
500
+ return typedArrayLength.call(obj);
501
+ }
502
+ var getter = typedArrayLengths[toStr(obj)];
503
+ return getter ? getter.call(obj) : obj.length;
504
+ }
505
+
506
+ function getterOf(obj, key) {
507
+ var descriptor = Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
508
+ return descriptor && typeof descriptor.get === 'function' ? descriptor.get : null;
509
+ }
510
+
511
+ function moreItems(count) {
512
+ return '... ' + count + ' more item' + (count > 1 ? 's' : '');
513
+ }
514
+
339
515
  function nameOf(f) {
340
516
  if (f.name) { return f.name; }
341
517
  var m = $match.call(functionToString.call(f), /^function\s*([\w$]+)/);
@@ -443,7 +619,7 @@ function inspectString(str, opts) {
443
619
  var quoteRE = quoteREs[opts.quoteStyle || 'single'];
444
620
  quoteRE.lastIndex = 0;
445
621
  // eslint-disable-next-line no-control-regex
446
- var s = $replace.call($replace.call(str, quoteRE, '\\$1'), /[\x00-\x1f]/g, lowbyte);
622
+ var s = $replace.call($replace.call(str, quoteRE, '\\$1'), opts.multilineStrings ? /[\x00-\x09\x0b-\x1f]/g : /[\x00-\x1f]/g, lowbyte);
447
623
  return wrapQuotes(s, 'single', opts);
448
624
  }
449
625
 
@@ -473,6 +649,118 @@ function collectionOf(type, size, entries, indent) {
473
649
  return type + ' (' + size + ') {' + joinedEntries + '}';
474
650
  }
475
651
 
652
+ // the following three functions port the line-breaking logic of node's `util.inspect` (with its default `compact: 3`), from `lib/internal/util/inspect.js`
653
+ function isBelowBreakLength(entries, start, breakLength) {
654
+ if (breakLength === Infinity) {
655
+ return singleLineValues(entries);
656
+ }
657
+ var totalLength = entries.length + start;
658
+ if (totalLength + entries.length > breakLength) {
659
+ return false;
660
+ }
661
+ for (var i = 0; i < entries.length; i++) {
662
+ totalLength += entries[i].length;
663
+ if (totalLength > breakLength) {
664
+ return false;
665
+ }
666
+ }
667
+ return true;
668
+ }
669
+
670
+ function padTo(str, width, atStart) {
671
+ var fill = width > str.length ? $join.call(Array(width - str.length + 1), ' ') : '';
672
+ return atStart ? fill + str : str + fill;
673
+ }
674
+
675
+ function groupArrayElements(entries, layout, value) {
676
+ var separatorSpace = 2; // a comma and a space
677
+ var totalLength = 0;
678
+ var maxLength = 0;
679
+ var outputLength = entries.length;
680
+ if (layout.maxCollectionLength < entries.length) {
681
+ outputLength -= 1; // leave the `... N more items` entry out of the grouping
682
+ }
683
+ var dataLen = [];
684
+ for (var i = 0; i < outputLength; i++) {
685
+ dataLen[i] = getStringWidth(entries[i]);
686
+ totalLength += dataLen[i] + separatorSpace;
687
+ if (maxLength < dataLen[i]) {
688
+ maxLength = dataLen[i];
689
+ }
690
+ }
691
+ var actualMax = maxLength + separatorSpace;
692
+ var indentationLvl = layout.indent.prev.length;
693
+ if ((actualMax * 3) + indentationLvl >= layout.breakLength || (totalLength / actualMax <= 5 && maxLength > 6)) {
694
+ return entries;
695
+ }
696
+ var averageBias = $sqrt(actualMax - (totalLength / entries.length));
697
+ var biasedMax = $max(actualMax - 3 - averageBias, 1);
698
+ var columns = $min(
699
+ $round($sqrt(2.5 * biasedMax * outputLength) / biasedMax),
700
+ $floor((layout.breakLength - indentationLvl) / actualMax),
701
+ 12, // `compact` * 4
702
+ 15
703
+ );
704
+ if (columns <= 1) {
705
+ return entries;
706
+ }
707
+ var maxLineLength = [];
708
+ for (var c = 0; c < columns; c++) {
709
+ var lineMaxLength = 0;
710
+ for (var j = c; j < entries.length; j += columns) {
711
+ if (dataLen[j] > lineMaxLength) {
712
+ lineMaxLength = dataLen[j];
713
+ }
714
+ }
715
+ maxLineLength[c] = lineMaxLength + separatorSpace;
716
+ }
717
+ var numeric = true;
718
+ for (var k = 0; k < entries.length && numeric; k++) {
719
+ numeric = typeof value[k] === 'number' || typeof value[k] === 'bigint';
720
+ }
721
+ var grouped = [];
722
+ for (var row = 0; row < outputLength; row += columns) {
723
+ var max = $min(row + columns, outputLength);
724
+ var str = '';
725
+ var col = row;
726
+ for (; col < max - 1; col++) {
727
+ str += padTo(entries[col] + ', ', maxLineLength[col - row] + (entries[col].length - dataLen[col]), numeric);
728
+ }
729
+ var lastPadding = maxLineLength[col - row] + (entries[col].length - dataLen[col]) - separatorSpace;
730
+ str += numeric ? padTo(entries[col], lastPadding, true) : entries[col];
731
+ grouped.push(str);
732
+ }
733
+ if (outputLength < entries.length) {
734
+ grouped.push(entries[outputLength]);
735
+ }
736
+ return grouped;
737
+ }
738
+
739
+ // `padding` goes inside the braces only when the entries fit on one line
740
+ function bracesOf(opening, closing, base, padding) {
741
+ return [
742
+ opening,
743
+ closing,
744
+ base,
745
+ padding
746
+ ];
747
+ }
748
+
749
+ function breakLines(entries, braces, layout, arrayValue) {
750
+ var output = arrayValue && entries.length > 6 ? groupArrayElements(entries, layout, arrayValue) : entries;
751
+ var base = braces[2] ? braces[2] + ' ' : '';
752
+ if (layout.state.currentDepth - layout.depth < 3 && output.length === entries.length) {
753
+ var start = output.length + layout.indent.prev.length + braces[0].length + braces[2].length + 10;
754
+ if (isBelowBreakLength(output, start, layout.breakLength)) {
755
+ var joined = $join.call(output, ', ');
756
+ if (indexOf(joined, '\n') < 0) {
757
+ return base + braces[0] + braces[3] + joined + braces[3] + braces[1];
758
+ }
759
+ }
760
+ }
761
+ return base + braces[0] + indentedJoin(output, layout.indent) + braces[1];
762
+ }
763
+
476
764
  function singleLineValues(xs) {
477
765
  for (var i = 0; i < xs.length; i++) {
478
766
  if (indexOf(xs[i], '\n') >= 0) {
@@ -503,14 +791,27 @@ function indentedJoin(xs, indent) {
503
791
  return lineJoiner + $join.call(xs, ',' + lineJoiner) + '\n' + indent.prev;
504
792
  }
505
793
 
506
- function arrObjKeys(obj, inspect) {
794
+ function arrObjKeys(obj, inspect, maxLength) {
507
795
  var isArr = isArray(obj);
796
+ var limit = typeof maxLength === 'number' ? maxLength : Infinity;
797
+ var typedLength = !isArr && limit !== Infinity && isTypedArray(obj) ? getTypedArrayLength(obj) : null;
798
+ if (typeof typedLength !== 'number' || typedLength <= limit) {
799
+ typedLength = null;
800
+ }
508
801
  var xs = [];
509
802
  if (isArr) {
510
- xs.length = obj.length;
511
- for (var i = 0; i < obj.length; i++) {
803
+ xs.length = obj.length < limit ? obj.length : limit;
804
+ for (var i = 0; i < obj.length && i < limit; i++) {
512
805
  xs[i] = has(obj, i) ? inspect(obj[i], obj) : '';
513
806
  }
807
+ if (obj.length > limit) {
808
+ xs.push(moreItems(obj.length - limit));
809
+ }
810
+ } else if (typedLength !== null) {
811
+ for (var t = 0; t < limit; t++) {
812
+ xs.push(t + ': ' + inspect(obj[t], obj));
813
+ }
814
+ xs.push(moreItems(typedLength - limit));
514
815
  }
515
816
  var syms = typeof gOPS === 'function' ? gOPS(obj) : [];
516
817
  var symMap;
@@ -524,6 +825,7 @@ function arrObjKeys(obj, inspect) {
524
825
  for (var key in obj) { // eslint-disable-line no-restricted-syntax
525
826
  if (!has(obj, key)) { continue; } // eslint-disable-line no-restricted-syntax, no-continue
526
827
  if (isArr && String(Number(key)) === key && key < obj.length) { continue; } // eslint-disable-line no-restricted-syntax, no-continue
828
+ if (typedLength !== null && String(Number(key)) === key && key < typedLength) { continue; } // eslint-disable-line no-restricted-syntax, no-continue
527
829
  if (hasShammedSymbols && symMap['$' + key] instanceof Symbol) {
528
830
  // this is to prevent shammed Symbols, which are stored as strings, from being included in the string key section
529
831
  continue; // eslint-disable-line no-restricted-syntax, no-continue
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "object-inspect",
3
- "version": "1.13.4",
3
+ "version": "1.14.0",
4
4
  "description": "string representations of objects in node and the browser",
5
5
  "main": "index.js",
6
6
  "sideEffects": false,
7
7
  "devDependencies": {
8
- "@ljharb/eslint-config": "^21.1.1",
8
+ "@ljharb/eslint-config": "^22.2.5",
9
9
  "@pkgjs/support": "^0.0.6",
10
- "auto-changelog": "^2.5.0",
10
+ "auto-changelog": "^2.7.0",
11
11
  "core-js": "^2.6.12",
12
- "error-cause": "^1.0.8",
12
+ "error-cause": "^1.0.9",
13
13
  "es-value-fixtures": "^1.7.1",
14
- "eslint": "=8.8.0",
15
- "for-each": "^0.3.4",
14
+ "eslint": "^10.15.0",
15
+ "for-each": "^0.3.5",
16
16
  "functions-have-names": "^1.2.3",
17
17
  "glob": "=10.3.7",
18
18
  "globalthis": "^1.0.4",
@@ -20,27 +20,31 @@
20
20
  "has-tostringtag": "^1.0.2",
21
21
  "in-publish": "^2.0.1",
22
22
  "jackspeak": "=2.1.1",
23
+ "jiti": "^0.0.0",
24
+ "keyv": "^5.6.0",
23
25
  "make-arrow-function": "^1.2.0",
24
- "mock-property": "^1.1.0",
25
- "npmignore": "^0.3.1",
26
+ "mock-property": "^1.1.2",
27
+ "npmignore": "^0.3.6",
26
28
  "nyc": "^10.3.2",
29
+ "require-stash": "^1.0.0",
27
30
  "safe-publish-latest": "^2.0.0",
28
31
  "safer-buffer": "^2.1.2",
29
- "semver": "^6.3.1",
32
+ "semver": "^6.3.2",
30
33
  "string.prototype.repeat": "^1.0.0",
31
- "tape": "^5.9.0"
34
+ "tape": "^5.10.3"
32
35
  },
33
36
  "scripts": {
34
37
  "prepack": "npmignore --auto --commentLines=autogenerated",
35
38
  "prepublish": "not-in-publish || npm run prepublishOnly",
36
39
  "prepublishOnly": "safe-publish-latest",
37
40
  "pretest": "npm run lint",
38
- "lint": "eslint --ext=js,mjs .",
41
+ "lint": "eslint .",
39
42
  "postlint": "npx @pkgjs/support validate",
40
43
  "test": "npm run tests-only && npm run test:corejs",
41
44
  "tests-only": "nyc tape 'test/*.js'",
42
45
  "test:corejs": "nyc tape test-core-js.js 'test/*.js'",
43
46
  "posttest": "npx npm@'>=10.2' audit --production",
47
+ "generate:string-width": "node --expose-internals scripts/generate-string-width-ranges.js",
44
48
  "version": "auto-changelog && git add CHANGELOG.md",
45
49
  "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
46
50
  },
@@ -62,7 +66,7 @@
62
66
  },
63
67
  "repository": {
64
68
  "type": "git",
65
- "url": "git://github.com/inspect-js/object-inspect.git"
69
+ "url": "ssh://github.com/inspect-js/object-inspect.git"
66
70
  },
67
71
  "homepage": "https://github.com/inspect-js/object-inspect",
68
72
  "keywords": [
@@ -95,7 +99,12 @@
95
99
  "publishConfig": {
96
100
  "ignore": [
97
101
  ".github/workflows",
98
- "./test-core-js.js"
102
+ ".nycrc",
103
+ "eslint.config.mjs",
104
+ "example/",
105
+ "/test-core-js.js",
106
+ "scripts/",
107
+ "test/"
99
108
  ]
100
109
  },
101
110
  "support": true,
@@ -51,9 +51,12 @@ Return a string `s` with the string representation of `obj` up to a depth of `op
51
51
  Additional options:
52
52
  - `quoteStyle`: must be "single" or "double", if present. Default `'single'` for strings, `'double'` for HTML elements.
53
53
  - `maxStringLength`: must be `0`, a positive integer, `Infinity`, or `null`, if present. Default `Infinity`.
54
+ - `maxCollectionLength`: must be `0`, a positive integer, `Infinity`, or `null`, if present. Default `Infinity`. The maximum number of elements to include when formatting Arrays, TypedArrays, Maps, and Sets; the remaining elements are summarized as `... N more items`.
54
55
  - `customInspect`: When `true`, a custom inspect method function will be invoked (either undere the `util.inspect.custom` symbol, or the `inspect` property). When the string `'symbol'`, only the symbol method will be invoked. Default `true`.
55
56
  - `indent`: must be "\t", `null`, or a positive integer. Default `null`.
56
57
  - `numericSeparator`: must be a boolean, if present. Default `false`. If `true`, all numbers will be printed with numeric separators (eg, `1234.5678` will be printed as `'1_234.567_8'`)
58
+ - `multilineStrings`: must be a boolean, if present. Default `false`. If `true`, newlines (`\n`) in strings will be printed as actual line breaks, inside the quotes, rather than as `\n`. Other control characters, including `\r`, are still escaped.
59
+ - `breakLength`: must be `0`, a positive integer, or `Infinity`, if present. When present, line breaks are decided the same way as node's `util.inspect` with the same `breakLength`: entries are put on one line when they fit within `breakLength` characters (counting indentation) and fewer than 3 levels of objects are nested below, and arrays with more than 6 entries are grouped into aligned columns. Uses `indent` if provided, otherwise 2 spaces. When absent, output is unchanged.
57
60
 
58
61
  # install
59
62
 
@@ -80,5 +83,5 @@ MIT
80
83
  [downloads-url]: https://npm-stat.com/charts.html?package=object-inspect
81
84
  [codecov-image]: https://codecov.io/gh/inspect-js/object-inspect/branch/main/graphs/badge.svg
82
85
  [codecov-url]: https://app.codecov.io/gh/inspect-js/object-inspect/
83
- [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/object-inspect
86
+ [actions-image]: https://img.shields.io/github/check-runs/inspect-js/object-inspect/main
84
87
  [actions-url]: https://github.com/inspect-js/object-inspect/actions