@netlify/plugin-nextjs 4.40.1 → 4.40.2

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 (161) hide show
  1. package/lib/helpers/edge.js +1 -0
  2. package/lib/templates/vendor.js +20 -0
  3. package/package.json +7 -4
  4. package/src/templates/edge/next-dev.js +3 -3
  5. package/src/templates/edge/shims.js +6 -6
  6. package/src/templates/edge-shared/next-utils.ts +3 -3
  7. package/src/templates/edge-shared/utils.ts +1 -1
  8. package/src/templates/vendor/deno.land/std@0.134.0/fmt/colors.ts +536 -0
  9. package/src/templates/vendor/deno.land/std@0.134.0/testing/_diff.ts +360 -0
  10. package/src/templates/vendor/deno.land/std@0.134.0/testing/asserts.ts +866 -0
  11. package/src/templates/vendor/deno.land/std@0.175.0/_util/asserts.ts +25 -0
  12. package/src/templates/vendor/deno.land/std@0.175.0/_util/os.ts +23 -0
  13. package/src/templates/vendor/deno.land/std@0.175.0/async/abortable.ts +149 -0
  14. package/src/templates/vendor/deno.land/std@0.175.0/async/deadline.ts +30 -0
  15. package/src/templates/vendor/deno.land/std@0.175.0/async/debounce.ts +79 -0
  16. package/src/templates/vendor/deno.land/std@0.175.0/async/deferred.ts +48 -0
  17. package/src/templates/vendor/deno.land/std@0.175.0/async/delay.ts +67 -0
  18. package/src/templates/vendor/deno.land/std@0.175.0/async/mod.ts +18 -0
  19. package/src/templates/vendor/deno.land/std@0.175.0/async/mux_async_iterator.ts +97 -0
  20. package/src/templates/vendor/deno.land/std@0.175.0/async/pool.ts +95 -0
  21. package/src/templates/vendor/deno.land/std@0.175.0/async/retry.ts +81 -0
  22. package/src/templates/vendor/deno.land/std@0.175.0/async/tee.ts +100 -0
  23. package/src/templates/vendor/deno.land/std@0.175.0/bytes/index_of_needle.ts +49 -0
  24. package/src/templates/vendor/deno.land/std@0.175.0/crypto/timing_safe_equal.ts +29 -0
  25. package/src/templates/vendor/deno.land/std@0.175.0/datetime/to_imf.ts +45 -0
  26. package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64.ts +144 -0
  27. package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64url.ts +70 -0
  28. package/src/templates/vendor/deno.land/std@0.175.0/flags/mod.ts +785 -0
  29. package/src/templates/vendor/deno.land/std@0.175.0/fmt/colors.ts +569 -0
  30. package/src/templates/vendor/deno.land/std@0.175.0/fmt/printf.ts +939 -0
  31. package/src/templates/vendor/deno.land/std@0.175.0/http/cookie.ts +403 -0
  32. package/src/templates/vendor/deno.land/std@0.175.0/node/_core.ts +77 -0
  33. package/src/templates/vendor/deno.land/std@0.175.0/node/_events.d.ts +848 -0
  34. package/src/templates/vendor/deno.land/std@0.175.0/node/_events.mjs +1033 -0
  35. package/src/templates/vendor/deno.land/std@0.175.0/node/_global.d.ts +66 -0
  36. package/src/templates/vendor/deno.land/std@0.175.0/node/_next_tick.ts +173 -0
  37. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/exiting.ts +4 -0
  38. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/process.ts +131 -0
  39. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/stdio.mjs +7 -0
  40. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/streams.mjs +146 -0
  41. package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.d.ts +1488 -0
  42. package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.mjs +746 -0
  43. package/src/templates/vendor/deno.land/std@0.175.0/node/_util/_util_callbackify.ts +129 -0
  44. package/src/templates/vendor/deno.land/std@0.175.0/node/_utils.ts +206 -0
  45. package/src/templates/vendor/deno.land/std@0.175.0/node/assert.ts +940 -0
  46. package/src/templates/vendor/deno.land/std@0.175.0/node/assertion_error.ts +579 -0
  47. package/src/templates/vendor/deno.land/std@0.175.0/node/async_hooks.ts +331 -0
  48. package/src/templates/vendor/deno.land/std@0.175.0/node/buffer.ts +13 -0
  49. package/src/templates/vendor/deno.land/std@0.175.0/node/events.ts +14 -0
  50. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.d.ts +2074 -0
  51. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.mjs +2607 -0
  52. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/_keys.ts +16 -0
  53. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/constants.ts +5 -0
  54. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/error_codes.ts +7 -0
  55. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/errors.ts +2867 -0
  56. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/fixed_queue.ts +123 -0
  57. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/hide_stack_frames.ts +16 -0
  58. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/net.ts +95 -0
  59. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/normalize_encoding.mjs +72 -0
  60. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/options.ts +45 -0
  61. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/primordials.mjs +30 -0
  62. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/process/per_thread.mjs +272 -0
  63. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/callbacks.mjs +137 -0
  64. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/utils.mjs +580 -0
  65. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/destroy.mjs +320 -0
  66. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/end-of-stream.mjs +229 -0
  67. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/utils.mjs +242 -0
  68. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/comparisons.ts +669 -0
  69. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/debuglog.ts +118 -0
  70. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/inspect.mjs +2237 -0
  71. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/types.ts +113 -0
  72. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util.mjs +143 -0
  73. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/validators.mjs +317 -0
  74. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_libuv_winerror.ts +229 -0
  75. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_listen.ts +16 -0
  76. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_node.ts +18 -0
  77. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_timingSafeEqual.ts +12 -0
  78. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_utils.ts +86 -0
  79. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_winerror.ts +16873 -0
  80. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/ares.ts +66 -0
  81. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/async_wrap.ts +152 -0
  82. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/buffer.ts +130 -0
  83. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/cares_wrap.ts +541 -0
  84. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/config.ts +3 -0
  85. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/connection_wrap.ts +80 -0
  86. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/constants.ts +900 -0
  87. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/contextify.ts +3 -0
  88. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/credentials.ts +3 -0
  89. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/crypto.ts +14 -0
  90. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/errors.ts +3 -0
  91. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs.ts +3 -0
  92. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_dir.ts +3 -0
  93. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_event_wrap.ts +3 -0
  94. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/handle_wrap.ts +50 -0
  95. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/heap_utils.ts +3 -0
  96. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/http_parser.ts +3 -0
  97. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/icu.ts +3 -0
  98. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/inspector.ts +3 -0
  99. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/js_stream.ts +3 -0
  100. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/messaging.ts +3 -0
  101. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/mod.ts +108 -0
  102. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/module_wrap.ts +3 -0
  103. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/native_module.ts +3 -0
  104. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/natives.ts +3 -0
  105. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_file.ts +84 -0
  106. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_options.ts +39 -0
  107. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/options.ts +3 -0
  108. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/os.ts +3 -0
  109. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/performance.ts +3 -0
  110. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/pipe_wrap.ts +392 -0
  111. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/process_methods.ts +3 -0
  112. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/report.ts +3 -0
  113. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/serdes.ts +3 -0
  114. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/signal_wrap.ts +3 -0
  115. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/spawn_sync.ts +3 -0
  116. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/stream_wrap.ts +354 -0
  117. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/string_decoder.ts +15 -0
  118. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/symbols.ts +27 -0
  119. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/task_queue.ts +3 -0
  120. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tcp_wrap.ts +488 -0
  121. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/timers.ts +3 -0
  122. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tls_wrap.ts +3 -0
  123. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/trace_events.ts +3 -0
  124. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tty_wrap.ts +3 -0
  125. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/types.ts +186 -0
  126. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/udp_wrap.ts +496 -0
  127. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/url.ts +3 -0
  128. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/util.ts +126 -0
  129. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/uv.ts +437 -0
  130. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/v8.ts +3 -0
  131. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/worker.ts +3 -0
  132. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/zlib.ts +3 -0
  133. package/src/templates/vendor/deno.land/std@0.175.0/node/process.ts +705 -0
  134. package/src/templates/vendor/deno.land/std@0.175.0/node/stream.ts +37 -0
  135. package/src/templates/vendor/deno.land/std@0.175.0/node/string_decoder.ts +337 -0
  136. package/src/templates/vendor/deno.land/std@0.175.0/node/util/types.ts +4 -0
  137. package/src/templates/vendor/deno.land/std@0.175.0/node/util.ts +289 -0
  138. package/src/templates/vendor/deno.land/std@0.175.0/path/_constants.ts +49 -0
  139. package/src/templates/vendor/deno.land/std@0.175.0/path/_interface.ts +30 -0
  140. package/src/templates/vendor/deno.land/std@0.175.0/path/_util.ts +194 -0
  141. package/src/templates/vendor/deno.land/std@0.175.0/path/common.ts +40 -0
  142. package/src/templates/vendor/deno.land/std@0.175.0/path/glob.ts +418 -0
  143. package/src/templates/vendor/deno.land/std@0.175.0/path/mod.ts +53 -0
  144. package/src/templates/vendor/deno.land/std@0.175.0/path/posix.ts +487 -0
  145. package/src/templates/vendor/deno.land/std@0.175.0/path/separator.ts +7 -0
  146. package/src/templates/vendor/deno.land/std@0.175.0/path/win32.ts +962 -0
  147. package/src/templates/vendor/deno.land/std@0.175.0/streams/write_all.ts +64 -0
  148. package/src/templates/vendor/deno.land/std@0.175.0/testing/_diff.ts +440 -0
  149. package/src/templates/vendor/deno.land/std@0.175.0/testing/_format.ts +23 -0
  150. package/src/templates/vendor/deno.land/std@0.175.0/testing/asserts.ts +906 -0
  151. package/src/templates/vendor/deno.land/std@0.175.0/types.d.ts +89 -0
  152. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts +133 -0
  153. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/asyncify.js +112 -0
  154. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.d.ts +88 -0
  155. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.js +974 -0
  156. package/src/templates/vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts +621 -0
  157. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/compiled/cookie.js +13 -0
  158. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js +12 -0
  159. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js +5 -0
  160. package/src/templates/vendor/import_map.json +13 -0
  161. package/src/templates/vendor/raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts +50 -0
@@ -0,0 +1,2237 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright Joyent, Inc. and other Node contributors.
3
+ //
4
+ // Permission is hereby granted, free of charge, to any person obtaining a
5
+ // copy of this software and associated documentation files (the
6
+ // "Software"), to deal in the Software without restriction, including
7
+ // without limitation the rights to use, copy, modify, merge, publish,
8
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
9
+ // persons to whom the Software is furnished to do so, subject to the
10
+ // following conditions:
11
+ //
12
+ // The above copyright notice and this permission notice shall be included
13
+ // in all copies or substantial portions of the Software.
14
+ //
15
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ import * as types from "./types.ts";
24
+ import { validateObject, validateString } from "../validators.mjs";
25
+ import { codes } from "../error_codes.ts";
26
+
27
+ import {
28
+ ALL_PROPERTIES,
29
+ getOwnNonIndexProperties,
30
+ ONLY_ENUMERABLE,
31
+ } from "../../internal_binding/util.ts";
32
+
33
+ const kObjectType = 0;
34
+ const kArrayType = 1;
35
+ const kArrayExtrasType = 2;
36
+
37
+ const kMinLineLength = 16;
38
+
39
+ // Constants to map the iterator state.
40
+ const kWeak = 0;
41
+ const kIterator = 1;
42
+ const kMapEntries = 2;
43
+
44
+ const kPending = 0;
45
+ const kRejected = 2;
46
+
47
+ // Escaped control characters (plus the single quote and the backslash). Use
48
+ // empty strings to fill up unused entries.
49
+ // deno-fmt-ignore
50
+ const meta = [
51
+ '\\x00', '\\x01', '\\x02', '\\x03', '\\x04', '\\x05', '\\x06', '\\x07', // x07
52
+ '\\b', '\\t', '\\n', '\\x0B', '\\f', '\\r', '\\x0E', '\\x0F', // x0F
53
+ '\\x10', '\\x11', '\\x12', '\\x13', '\\x14', '\\x15', '\\x16', '\\x17', // x17
54
+ '\\x18', '\\x19', '\\x1A', '\\x1B', '\\x1C', '\\x1D', '\\x1E', '\\x1F', // x1F
55
+ '', '', '', '', '', '', '', "\\'", '', '', '', '', '', '', '', '', // x2F
56
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x3F
57
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x4F
58
+ '', '', '', '', '', '', '', '', '', '', '', '', '\\\\', '', '', '', // x5F
59
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x6F
60
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '\\x7F', // x7F
61
+ '\\x80', '\\x81', '\\x82', '\\x83', '\\x84', '\\x85', '\\x86', '\\x87', // x87
62
+ '\\x88', '\\x89', '\\x8A', '\\x8B', '\\x8C', '\\x8D', '\\x8E', '\\x8F', // x8F
63
+ '\\x90', '\\x91', '\\x92', '\\x93', '\\x94', '\\x95', '\\x96', '\\x97', // x97
64
+ '\\x98', '\\x99', '\\x9A', '\\x9B', '\\x9C', '\\x9D', '\\x9E', '\\x9F', // x9F
65
+ ];
66
+
67
+ // https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot
68
+ const isUndetectableObject = (v) => typeof v === "undefined" && v !== undefined;
69
+
70
+ // deno-lint-ignore no-control-regex
71
+ const strEscapeSequencesRegExp = /[\x00-\x1f\x27\x5c\x7f-\x9f]/;
72
+ // deno-lint-ignore no-control-regex
73
+ const strEscapeSequencesReplacer = /[\x00-\x1f\x27\x5c\x7f-\x9f]/g;
74
+ // deno-lint-ignore no-control-regex
75
+ const strEscapeSequencesRegExpSingle = /[\x00-\x1f\x5c\x7f-\x9f]/;
76
+ // deno-lint-ignore no-control-regex
77
+ const strEscapeSequencesReplacerSingle = /[\x00-\x1f\x5c\x7f-\x9f]/g;
78
+
79
+ const keyStrRegExp = /^[a-zA-Z_][a-zA-Z_0-9]*$/;
80
+ const numberRegExp = /^(0|[1-9][0-9]*)$/;
81
+ const nodeModulesRegExp = /[/\\]node_modules[/\\](.+?)(?=[/\\])/g;
82
+
83
+ const classRegExp = /^(\s+[^(]*?)\s*{/;
84
+ // eslint-disable-next-line node-core/no-unescaped-regexp-dot
85
+ const stripCommentsRegExp = /(\/\/.*?\n)|(\/\*(.|\n)*?\*\/)/g;
86
+
87
+ const inspectDefaultOptions = {
88
+ showHidden: false,
89
+ depth: 2,
90
+ colors: false,
91
+ customInspect: true,
92
+ showProxy: false,
93
+ maxArrayLength: 100,
94
+ maxStringLength: 10000,
95
+ breakLength: 80,
96
+ compact: 3,
97
+ sorted: false,
98
+ getters: false,
99
+ };
100
+
101
+ function getUserOptions(ctx, isCrossContext) {
102
+ const ret = {
103
+ stylize: ctx.stylize,
104
+ showHidden: ctx.showHidden,
105
+ depth: ctx.depth,
106
+ colors: ctx.colors,
107
+ customInspect: ctx.customInspect,
108
+ showProxy: ctx.showProxy,
109
+ maxArrayLength: ctx.maxArrayLength,
110
+ maxStringLength: ctx.maxStringLength,
111
+ breakLength: ctx.breakLength,
112
+ compact: ctx.compact,
113
+ sorted: ctx.sorted,
114
+ getters: ctx.getters,
115
+ ...ctx.userOptions,
116
+ };
117
+
118
+ // Typically, the target value will be an instance of `Object`. If that is
119
+ // *not* the case, the object may come from another vm.Context, and we want
120
+ // to avoid passing it objects from this Context in that case, so we remove
121
+ // the prototype from the returned object itself + the `stylize()` function,
122
+ // and remove all other non-primitives, including non-primitive user options.
123
+ if (isCrossContext) {
124
+ Object.setPrototypeOf(ret, null);
125
+ for (const key of Object.keys(ret)) {
126
+ if (
127
+ (typeof ret[key] === "object" || typeof ret[key] === "function") &&
128
+ ret[key] !== null
129
+ ) {
130
+ delete ret[key];
131
+ }
132
+ }
133
+ ret.stylize = Object.setPrototypeOf((value, flavour) => {
134
+ let stylized;
135
+ try {
136
+ stylized = `${ctx.stylize(value, flavour)}`;
137
+ } catch {
138
+ // noop
139
+ }
140
+
141
+ if (typeof stylized !== "string") return value;
142
+ // `stylized` is a string as it should be, which is safe to pass along.
143
+ return stylized;
144
+ }, null);
145
+ }
146
+
147
+ return ret;
148
+ }
149
+
150
+ /**
151
+ * Echos the value of any input. Tries to print the value out
152
+ * in the best way possible given the different types.
153
+ */
154
+ /* Legacy: value, showHidden, depth, colors */
155
+ export function inspect(value, opts) {
156
+ // Default options
157
+ const ctx = {
158
+ budget: {},
159
+ indentationLvl: 0,
160
+ seen: [],
161
+ currentDepth: 0,
162
+ stylize: stylizeNoColor,
163
+ showHidden: inspectDefaultOptions.showHidden,
164
+ depth: inspectDefaultOptions.depth,
165
+ colors: inspectDefaultOptions.colors,
166
+ customInspect: inspectDefaultOptions.customInspect,
167
+ showProxy: inspectDefaultOptions.showProxy,
168
+ maxArrayLength: inspectDefaultOptions.maxArrayLength,
169
+ maxStringLength: inspectDefaultOptions.maxStringLength,
170
+ breakLength: inspectDefaultOptions.breakLength,
171
+ compact: inspectDefaultOptions.compact,
172
+ sorted: inspectDefaultOptions.sorted,
173
+ getters: inspectDefaultOptions.getters,
174
+ };
175
+ if (arguments.length > 1) {
176
+ // Legacy...
177
+ if (arguments.length > 2) {
178
+ if (arguments[2] !== undefined) {
179
+ ctx.depth = arguments[2];
180
+ }
181
+ if (arguments.length > 3 && arguments[3] !== undefined) {
182
+ ctx.colors = arguments[3];
183
+ }
184
+ }
185
+ // Set user-specified options
186
+ if (typeof opts === "boolean") {
187
+ ctx.showHidden = opts;
188
+ } else if (opts) {
189
+ const optKeys = Object.keys(opts);
190
+ for (let i = 0; i < optKeys.length; ++i) {
191
+ const key = optKeys[i];
192
+ // TODO(BridgeAR): Find a solution what to do about stylize. Either make
193
+ // this function public or add a new API with a similar or better
194
+ // functionality.
195
+ if (
196
+ // deno-lint-ignore no-prototype-builtins
197
+ inspectDefaultOptions.hasOwnProperty(key) ||
198
+ key === "stylize"
199
+ ) {
200
+ ctx[key] = opts[key];
201
+ } else if (ctx.userOptions === undefined) {
202
+ // This is required to pass through the actual user input.
203
+ ctx.userOptions = opts;
204
+ }
205
+ }
206
+ }
207
+ }
208
+ if (ctx.colors) ctx.stylize = stylizeWithColor;
209
+ if (ctx.maxArrayLength === null) ctx.maxArrayLength = Infinity;
210
+ if (ctx.maxStringLength === null) ctx.maxStringLength = Infinity;
211
+ return formatValue(ctx, value, 0);
212
+ }
213
+ const customInspectSymbol = Symbol.for("nodejs.util.inspect.custom");
214
+ inspect.custom = customInspectSymbol;
215
+
216
+ Object.defineProperty(inspect, "defaultOptions", {
217
+ get() {
218
+ return inspectDefaultOptions;
219
+ },
220
+ set(options) {
221
+ validateObject(options, "options");
222
+ return Object.assign(inspectDefaultOptions, options);
223
+ },
224
+ });
225
+
226
+ // Set Graphics Rendition https://en.wikipedia.org/wiki/ANSI_escape_code#graphics
227
+ // Each color consists of an array with the color code as first entry and the
228
+ // reset code as second entry.
229
+ const defaultFG = 39;
230
+ const defaultBG = 49;
231
+ inspect.colors = Object.assign(Object.create(null), {
232
+ reset: [0, 0],
233
+ bold: [1, 22],
234
+ dim: [2, 22], // Alias: faint
235
+ italic: [3, 23],
236
+ underline: [4, 24],
237
+ blink: [5, 25],
238
+ // Swap foreground and background colors
239
+ inverse: [7, 27], // Alias: swapcolors, swapColors
240
+ hidden: [8, 28], // Alias: conceal
241
+ strikethrough: [9, 29], // Alias: strikeThrough, crossedout, crossedOut
242
+ doubleunderline: [21, 24], // Alias: doubleUnderline
243
+ black: [30, defaultFG],
244
+ red: [31, defaultFG],
245
+ green: [32, defaultFG],
246
+ yellow: [33, defaultFG],
247
+ blue: [34, defaultFG],
248
+ magenta: [35, defaultFG],
249
+ cyan: [36, defaultFG],
250
+ white: [37, defaultFG],
251
+ bgBlack: [40, defaultBG],
252
+ bgRed: [41, defaultBG],
253
+ bgGreen: [42, defaultBG],
254
+ bgYellow: [43, defaultBG],
255
+ bgBlue: [44, defaultBG],
256
+ bgMagenta: [45, defaultBG],
257
+ bgCyan: [46, defaultBG],
258
+ bgWhite: [47, defaultBG],
259
+ framed: [51, 54],
260
+ overlined: [53, 55],
261
+ gray: [90, defaultFG], // Alias: grey, blackBright
262
+ redBright: [91, defaultFG],
263
+ greenBright: [92, defaultFG],
264
+ yellowBright: [93, defaultFG],
265
+ blueBright: [94, defaultFG],
266
+ magentaBright: [95, defaultFG],
267
+ cyanBright: [96, defaultFG],
268
+ whiteBright: [97, defaultFG],
269
+ bgGray: [100, defaultBG], // Alias: bgGrey, bgBlackBright
270
+ bgRedBright: [101, defaultBG],
271
+ bgGreenBright: [102, defaultBG],
272
+ bgYellowBright: [103, defaultBG],
273
+ bgBlueBright: [104, defaultBG],
274
+ bgMagentaBright: [105, defaultBG],
275
+ bgCyanBright: [106, defaultBG],
276
+ bgWhiteBright: [107, defaultBG],
277
+ });
278
+
279
+ function defineColorAlias(target, alias) {
280
+ Object.defineProperty(inspect.colors, alias, {
281
+ get() {
282
+ return this[target];
283
+ },
284
+ set(value) {
285
+ this[target] = value;
286
+ },
287
+ configurable: true,
288
+ enumerable: false,
289
+ });
290
+ }
291
+
292
+ defineColorAlias("gray", "grey");
293
+ defineColorAlias("gray", "blackBright");
294
+ defineColorAlias("bgGray", "bgGrey");
295
+ defineColorAlias("bgGray", "bgBlackBright");
296
+ defineColorAlias("dim", "faint");
297
+ defineColorAlias("strikethrough", "crossedout");
298
+ defineColorAlias("strikethrough", "strikeThrough");
299
+ defineColorAlias("strikethrough", "crossedOut");
300
+ defineColorAlias("hidden", "conceal");
301
+ defineColorAlias("inverse", "swapColors");
302
+ defineColorAlias("inverse", "swapcolors");
303
+ defineColorAlias("doubleunderline", "doubleUnderline");
304
+
305
+ // TODO(BridgeAR): Add function style support for more complex styles.
306
+ // Don't use 'blue' not visible on cmd.exe
307
+ inspect.styles = Object.assign(Object.create(null), {
308
+ special: "cyan",
309
+ number: "yellow",
310
+ bigint: "yellow",
311
+ boolean: "yellow",
312
+ undefined: "grey",
313
+ null: "bold",
314
+ string: "green",
315
+ symbol: "green",
316
+ date: "magenta",
317
+ // "name": intentionally not styling
318
+ // TODO(BridgeAR): Highlight regular expressions properly.
319
+ regexp: "red",
320
+ module: "underline",
321
+ });
322
+
323
+ function addQuotes(str, quotes) {
324
+ if (quotes === -1) {
325
+ return `"${str}"`;
326
+ }
327
+ if (quotes === -2) {
328
+ return `\`${str}\``;
329
+ }
330
+ return `'${str}'`;
331
+ }
332
+
333
+ // TODO(wafuwafu13): Figure out
334
+ const escapeFn = (str) => meta[str.charCodeAt(0)];
335
+
336
+ // Escape control characters, single quotes and the backslash.
337
+ // This is similar to JSON stringify escaping.
338
+ function strEscape(str) {
339
+ let escapeTest = strEscapeSequencesRegExp;
340
+ let escapeReplace = strEscapeSequencesReplacer;
341
+ let singleQuote = 39;
342
+
343
+ // Check for double quotes. If not present, do not escape single quotes and
344
+ // instead wrap the text in double quotes. If double quotes exist, check for
345
+ // backticks. If they do not exist, use those as fallback instead of the
346
+ // double quotes.
347
+ if (str.includes("'")) {
348
+ // This invalidates the charCode and therefore can not be matched for
349
+ // anymore.
350
+ if (!str.includes('"')) {
351
+ singleQuote = -1;
352
+ } else if (
353
+ !str.includes("`") &&
354
+ !str.includes("${")
355
+ ) {
356
+ singleQuote = -2;
357
+ }
358
+ if (singleQuote !== 39) {
359
+ escapeTest = strEscapeSequencesRegExpSingle;
360
+ escapeReplace = strEscapeSequencesReplacerSingle;
361
+ }
362
+ }
363
+
364
+ // Some magic numbers that worked out fine while benchmarking with v8 6.0
365
+ if (str.length < 5000 && !escapeTest.test(str)) {
366
+ return addQuotes(str, singleQuote);
367
+ }
368
+ if (str.length > 100) {
369
+ str = str.replace(escapeReplace, escapeFn);
370
+ return addQuotes(str, singleQuote);
371
+ }
372
+
373
+ let result = "";
374
+ let last = 0;
375
+ const lastIndex = str.length;
376
+ for (let i = 0; i < lastIndex; i++) {
377
+ const point = str.charCodeAt(i);
378
+ if (
379
+ point === singleQuote ||
380
+ point === 92 ||
381
+ point < 32 ||
382
+ (point > 126 && point < 160)
383
+ ) {
384
+ if (last === i) {
385
+ result += meta[point];
386
+ } else {
387
+ result += `${str.slice(last, i)}${meta[point]}`;
388
+ }
389
+ last = i + 1;
390
+ }
391
+ }
392
+
393
+ if (last !== lastIndex) {
394
+ result += str.slice(last);
395
+ }
396
+ return addQuotes(result, singleQuote);
397
+ }
398
+
399
+ function stylizeWithColor(str, styleType) {
400
+ const style = inspect.styles[styleType];
401
+ if (style !== undefined) {
402
+ const color = inspect.colors[style];
403
+ if (color !== undefined) {
404
+ return `\u001b[${color[0]}m${str}\u001b[${color[1]}m`;
405
+ }
406
+ }
407
+ return str;
408
+ }
409
+
410
+ function stylizeNoColor(str) {
411
+ return str;
412
+ }
413
+
414
+ // Note: using `formatValue` directly requires the indentation level to be
415
+ // corrected by setting `ctx.indentationLvL += diff` and then to decrease the
416
+ // value afterwards again.
417
+ function formatValue(
418
+ ctx,
419
+ value,
420
+ recurseTimes,
421
+ typedArray,
422
+ ) {
423
+ // Primitive types cannot have properties.
424
+ if (
425
+ typeof value !== "object" &&
426
+ typeof value !== "function" &&
427
+ !isUndetectableObject(value)
428
+ ) {
429
+ return formatPrimitive(ctx.stylize, value, ctx);
430
+ }
431
+ if (value === null) {
432
+ return ctx.stylize("null", "null");
433
+ }
434
+
435
+ // Memorize the context for custom inspection on proxies.
436
+ const context = value;
437
+ // Always check for proxies to prevent side effects and to prevent triggering
438
+ // any proxy handlers.
439
+ // TODO(wafuwafu13): Set Proxy
440
+ const proxy = undefined;
441
+ // const proxy = getProxyDetails(value, !!ctx.showProxy);
442
+ // if (proxy !== undefined) {
443
+ // if (ctx.showProxy) {
444
+ // return formatProxy(ctx, proxy, recurseTimes);
445
+ // }
446
+ // value = proxy;
447
+ // }
448
+
449
+ // Provide a hook for user-specified inspect functions.
450
+ // Check that value is an object with an inspect function on it.
451
+ if (ctx.customInspect) {
452
+ const maybeCustom = value[customInspectSymbol];
453
+ if (
454
+ typeof maybeCustom === "function" &&
455
+ // Filter out the util module, its inspect function is special.
456
+ maybeCustom !== inspect &&
457
+ // Also filter out any prototype objects using the circular check.
458
+ !(value.constructor && value.constructor.prototype === value)
459
+ ) {
460
+ // This makes sure the recurseTimes are reported as before while using
461
+ // a counter internally.
462
+ const depth = ctx.depth === null ? null : ctx.depth - recurseTimes;
463
+ const isCrossContext = proxy !== undefined ||
464
+ !(context instanceof Object);
465
+ const ret = maybeCustom.call(
466
+ context,
467
+ depth,
468
+ getUserOptions(ctx, isCrossContext),
469
+ );
470
+ // If the custom inspection method returned `this`, don't go into
471
+ // infinite recursion.
472
+ if (ret !== context) {
473
+ if (typeof ret !== "string") {
474
+ return formatValue(ctx, ret, recurseTimes);
475
+ }
476
+ return ret.replace(/\n/g, `\n${" ".repeat(ctx.indentationLvl)}`);
477
+ }
478
+ }
479
+ }
480
+
481
+ // Using an array here is actually better for the average case than using
482
+ // a Set. `seen` will only check for the depth and will never grow too large.
483
+ if (ctx.seen.includes(value)) {
484
+ let index = 1;
485
+ if (ctx.circular === undefined) {
486
+ ctx.circular = new Map();
487
+ ctx.circular.set(value, index);
488
+ } else {
489
+ index = ctx.circular.get(value);
490
+ if (index === undefined) {
491
+ index = ctx.circular.size + 1;
492
+ ctx.circular.set(value, index);
493
+ }
494
+ }
495
+ return ctx.stylize(`[Circular *${index}]`, "special");
496
+ }
497
+
498
+ return formatRaw(ctx, value, recurseTimes, typedArray);
499
+ }
500
+
501
+ function formatRaw(ctx, value, recurseTimes, typedArray) {
502
+ let keys;
503
+ let protoProps;
504
+ if (ctx.showHidden && (recurseTimes <= ctx.depth || ctx.depth === null)) {
505
+ protoProps = [];
506
+ }
507
+
508
+ const constructor = getConstructorName(value, ctx, recurseTimes, protoProps);
509
+ // Reset the variable to check for this later on.
510
+ if (protoProps !== undefined && protoProps.length === 0) {
511
+ protoProps = undefined;
512
+ }
513
+
514
+ let tag = value[Symbol.toStringTag];
515
+ // Only list the tag in case it's non-enumerable / not an own property.
516
+ // Otherwise we'd print this twice.
517
+ if (
518
+ typeof tag !== "string"
519
+ // TODO(wafuwafu13): Implement
520
+ // (tag !== "" &&
521
+ // (ctx.showHidden
522
+ // ? Object.prototype.hasOwnProperty
523
+ // : Object.prototype.propertyIsEnumerable)(
524
+ // value,
525
+ // Symbol.toStringTag,
526
+ // ))
527
+ ) {
528
+ tag = "";
529
+ }
530
+ let base = "";
531
+ let formatter = getEmptyFormatArray;
532
+ let braces;
533
+ let noIterator = true;
534
+ let i = 0;
535
+ const filter = ctx.showHidden ? ALL_PROPERTIES : ONLY_ENUMERABLE;
536
+
537
+ let extrasType = kObjectType;
538
+
539
+ // Iterators and the rest are split to reduce checks.
540
+ // We have to check all values in case the constructor is set to null.
541
+ // Otherwise it would not possible to identify all types properly.
542
+ if (value[Symbol.iterator] || constructor === null) {
543
+ noIterator = false;
544
+ if (Array.isArray(value)) {
545
+ // Only set the constructor for non ordinary ("Array [...]") arrays.
546
+ const prefix = (constructor !== "Array" || tag !== "")
547
+ ? getPrefix(constructor, tag, "Array", `(${value.length})`)
548
+ : "";
549
+ keys = getOwnNonIndexProperties(value, filter);
550
+ braces = [`${prefix}[`, "]"];
551
+ if (value.length === 0 && keys.length === 0 && protoProps === undefined) {
552
+ return `${braces[0]}]`;
553
+ }
554
+ extrasType = kArrayExtrasType;
555
+ formatter = formatArray;
556
+ } else if (types.isSet(value)) {
557
+ const size = value.size;
558
+ const prefix = getPrefix(constructor, tag, "Set", `(${size})`);
559
+ keys = getKeys(value, ctx.showHidden);
560
+ formatter = constructor !== null
561
+ ? formatSet.bind(null, value)
562
+ : formatSet.bind(null, value.values());
563
+ if (size === 0 && keys.length === 0 && protoProps === undefined) {
564
+ return `${prefix}{}`;
565
+ }
566
+ braces = [`${prefix}{`, "}"];
567
+ } else if (types.isMap(value)) {
568
+ const size = value.size;
569
+ const prefix = getPrefix(constructor, tag, "Map", `(${size})`);
570
+ keys = getKeys(value, ctx.showHidden);
571
+ formatter = constructor !== null
572
+ ? formatMap.bind(null, value)
573
+ : formatMap.bind(null, value.entries());
574
+ if (size === 0 && keys.length === 0 && protoProps === undefined) {
575
+ return `${prefix}{}`;
576
+ }
577
+ braces = [`${prefix}{`, "}"];
578
+ } else if (types.isTypedArray(value)) {
579
+ keys = getOwnNonIndexProperties(value, filter);
580
+ const bound = value;
581
+ const fallback = "";
582
+ if (constructor === null) {
583
+ // TODO(wafuwafu13): Implement
584
+ // fallback = TypedArrayPrototypeGetSymbolToStringTag(value);
585
+ // // Reconstruct the array information.
586
+ // bound = new primordials[fallback](value);
587
+ }
588
+ const size = value.length;
589
+ const prefix = getPrefix(constructor, tag, fallback, `(${size})`);
590
+ braces = [`${prefix}[`, "]"];
591
+ if (value.length === 0 && keys.length === 0 && !ctx.showHidden) {
592
+ return `${braces[0]}]`;
593
+ }
594
+ // Special handle the value. The original value is required below. The
595
+ // bound function is required to reconstruct missing information.
596
+ (formatter) = formatTypedArray.bind(null, bound, size);
597
+ extrasType = kArrayExtrasType;
598
+ } else if (types.isMapIterator(value)) {
599
+ keys = getKeys(value, ctx.showHidden);
600
+ braces = getIteratorBraces("Map", tag);
601
+ // Add braces to the formatter parameters.
602
+ (formatter) = formatIterator.bind(null, braces);
603
+ } else if (types.isSetIterator(value)) {
604
+ keys = getKeys(value, ctx.showHidden);
605
+ braces = getIteratorBraces("Set", tag);
606
+ // Add braces to the formatter parameters.
607
+ (formatter) = formatIterator.bind(null, braces);
608
+ } else {
609
+ noIterator = true;
610
+ }
611
+ }
612
+ if (noIterator) {
613
+ keys = getKeys(value, ctx.showHidden);
614
+ braces = ["{", "}"];
615
+ if (constructor === "Object") {
616
+ if (types.isArgumentsObject(value)) {
617
+ braces[0] = "[Arguments] {";
618
+ } else if (tag !== "") {
619
+ braces[0] = `${getPrefix(constructor, tag, "Object")}{`;
620
+ }
621
+ if (keys.length === 0 && protoProps === undefined) {
622
+ return `${braces[0]}}`;
623
+ }
624
+ } else if (typeof value === "function") {
625
+ base = getFunctionBase(value, constructor, tag);
626
+ if (keys.length === 0 && protoProps === undefined) {
627
+ return ctx.stylize(base, "special");
628
+ }
629
+ } else if (types.isRegExp(value)) {
630
+ // Make RegExps say that they are RegExps
631
+ base = RegExp(constructor !== null ? value : new RegExp(value))
632
+ .toString();
633
+ const prefix = getPrefix(constructor, tag, "RegExp");
634
+ if (prefix !== "RegExp ") {
635
+ base = `${prefix}${base}`;
636
+ }
637
+ if (
638
+ (keys.length === 0 && protoProps === undefined) ||
639
+ (recurseTimes > ctx.depth && ctx.depth !== null)
640
+ ) {
641
+ return ctx.stylize(base, "regexp");
642
+ }
643
+ } else if (types.isDate(value)) {
644
+ // Make dates with properties first say the date
645
+ base = Number.isNaN(value.getTime())
646
+ ? value.toString()
647
+ : value.toISOString();
648
+ const prefix = getPrefix(constructor, tag, "Date");
649
+ if (prefix !== "Date ") {
650
+ base = `${prefix}${base}`;
651
+ }
652
+ if (keys.length === 0 && protoProps === undefined) {
653
+ return ctx.stylize(base, "date");
654
+ }
655
+ } else if (value instanceof Error) {
656
+ base = formatError(value, constructor, tag, ctx, keys);
657
+ if (keys.length === 0 && protoProps === undefined) {
658
+ return base;
659
+ }
660
+ } else if (types.isAnyArrayBuffer(value)) {
661
+ // Fast path for ArrayBuffer and SharedArrayBuffer.
662
+ // Can't do the same for DataView because it has a non-primitive
663
+ // .buffer property that we need to recurse for.
664
+ const arrayType = types.isArrayBuffer(value)
665
+ ? "ArrayBuffer"
666
+ : "SharedArrayBuffer";
667
+ const prefix = getPrefix(constructor, tag, arrayType);
668
+ if (typedArray === undefined) {
669
+ (formatter) = formatArrayBuffer;
670
+ } else if (keys.length === 0 && protoProps === undefined) {
671
+ return prefix +
672
+ `{ byteLength: ${formatNumber(ctx.stylize, value.byteLength)} }`;
673
+ }
674
+ braces[0] = `${prefix}{`;
675
+ Array.prototype.unshift.call(keys, "byteLength");
676
+ } else if (types.isDataView(value)) {
677
+ braces[0] = `${getPrefix(constructor, tag, "DataView")}{`;
678
+ // .buffer goes last, it's not a primitive like the others.
679
+ Array.prototype.unshift.call(keys, "byteLength", "byteOffset", "buffer");
680
+ } else if (types.isPromise(value)) {
681
+ braces[0] = `${getPrefix(constructor, tag, "Promise")}{`;
682
+ (formatter) = formatPromise;
683
+ } else if (types.isWeakSet(value)) {
684
+ braces[0] = `${getPrefix(constructor, tag, "WeakSet")}{`;
685
+ (formatter) = ctx.showHidden ? formatWeakSet : formatWeakCollection;
686
+ } else if (types.isWeakMap(value)) {
687
+ braces[0] = `${getPrefix(constructor, tag, "WeakMap")}{`;
688
+ (formatter) = ctx.showHidden ? formatWeakMap : formatWeakCollection;
689
+ } else if (types.isModuleNamespaceObject(value)) {
690
+ braces[0] = `${getPrefix(constructor, tag, "Module")}{`;
691
+ // Special handle keys for namespace objects.
692
+ (formatter) = formatNamespaceObject.bind(null, keys);
693
+ } else if (types.isBoxedPrimitive(value)) {
694
+ base = getBoxedBase(value, ctx, keys, constructor, tag);
695
+ if (keys.length === 0 && protoProps === undefined) {
696
+ return base;
697
+ }
698
+ } else {
699
+ if (keys.length === 0 && protoProps === undefined) {
700
+ // TODO(wafuwafu13): Implement
701
+ // if (types.isExternal(value)) {
702
+ // const address = getExternalValue(value).toString(16);
703
+ // return ctx.stylize(`[External: ${address}]`, 'special');
704
+ // }
705
+ return `${getCtxStyle(value, constructor, tag)}{}`;
706
+ }
707
+ braces[0] = `${getCtxStyle(value, constructor, tag)}{`;
708
+ }
709
+ }
710
+
711
+ if (recurseTimes > ctx.depth && ctx.depth !== null) {
712
+ let constructorName = getCtxStyle(value, constructor, tag).slice(0, -1);
713
+ if (constructor !== null) {
714
+ constructorName = `[${constructorName}]`;
715
+ }
716
+ return ctx.stylize(constructorName, "special");
717
+ }
718
+ recurseTimes += 1;
719
+
720
+ ctx.seen.push(value);
721
+ ctx.currentDepth = recurseTimes;
722
+ let output;
723
+ const indentationLvl = ctx.indentationLvl;
724
+ try {
725
+ output = formatter(ctx, value, recurseTimes);
726
+ for (i = 0; i < keys.length; i++) {
727
+ output.push(
728
+ formatProperty(ctx, value, recurseTimes, keys[i], extrasType),
729
+ );
730
+ }
731
+ if (protoProps !== undefined) {
732
+ output.push(...protoProps);
733
+ }
734
+ } catch (err) {
735
+ const constructorName = getCtxStyle(value, constructor, tag).slice(0, -1);
736
+ return handleMaxCallStackSize(ctx, err, constructorName, indentationLvl);
737
+ }
738
+ if (ctx.circular !== undefined) {
739
+ const index = ctx.circular.get(value);
740
+ if (index !== undefined) {
741
+ const reference = ctx.stylize(`<ref *${index}>`, "special");
742
+ // Add reference always to the very beginning of the output.
743
+ if (ctx.compact !== true) {
744
+ base = base === "" ? reference : `${reference} ${base}`;
745
+ } else {
746
+ braces[0] = `${reference} ${braces[0]}`;
747
+ }
748
+ }
749
+ }
750
+ ctx.seen.pop();
751
+
752
+ if (ctx.sorted) {
753
+ const comparator = ctx.sorted === true ? undefined : ctx.sorted;
754
+ if (extrasType === kObjectType) {
755
+ output = output.sort(comparator);
756
+ } else if (keys.length > 1) {
757
+ const sorted = output.slice(output.length - keys.length).sort(comparator);
758
+ output.splice(output.length - keys.length, keys.length, ...sorted);
759
+ }
760
+ }
761
+
762
+ const res = reduceToSingleString(
763
+ ctx,
764
+ output,
765
+ base,
766
+ braces,
767
+ extrasType,
768
+ recurseTimes,
769
+ value,
770
+ );
771
+ const budget = ctx.budget[ctx.indentationLvl] || 0;
772
+ const newLength = budget + res.length;
773
+ ctx.budget[ctx.indentationLvl] = newLength;
774
+ // If any indentationLvl exceeds this limit, limit further inspecting to the
775
+ // minimum. Otherwise the recursive algorithm might continue inspecting the
776
+ // object even though the maximum string size (~2 ** 28 on 32 bit systems and
777
+ // ~2 ** 30 on 64 bit systems) exceeded. The actual output is not limited at
778
+ // exactly 2 ** 27 but a bit higher. This depends on the object shape.
779
+ // This limit also makes sure that huge objects don't block the event loop
780
+ // significantly.
781
+ if (newLength > 2 ** 27) {
782
+ ctx.depth = -1;
783
+ }
784
+ return res;
785
+ }
786
+
787
+ const builtInObjects = new Set(
788
+ Object.getOwnPropertyNames(globalThis).filter((e) =>
789
+ /^[A-Z][a-zA-Z0-9]+$/.test(e)
790
+ ),
791
+ );
792
+
793
+ function addPrototypeProperties(
794
+ ctx,
795
+ main,
796
+ obj,
797
+ recurseTimes,
798
+ output,
799
+ ) {
800
+ let depth = 0;
801
+ let keys;
802
+ let keySet;
803
+ do {
804
+ if (depth !== 0 || main === obj) {
805
+ obj = Object.getPrototypeOf(obj);
806
+ // Stop as soon as a null prototype is encountered.
807
+ if (obj === null) {
808
+ return;
809
+ }
810
+ // Stop as soon as a built-in object type is detected.
811
+ const descriptor = Object.getOwnPropertyDescriptor(obj, "constructor");
812
+ if (
813
+ descriptor !== undefined &&
814
+ typeof descriptor.value === "function" &&
815
+ builtInObjects.has(descriptor.value.name)
816
+ ) {
817
+ return;
818
+ }
819
+ }
820
+
821
+ if (depth === 0) {
822
+ keySet = new Set();
823
+ } else {
824
+ Array.prototype.forEach.call(keys, (key) => keySet.add(key));
825
+ }
826
+ // Get all own property names and symbols.
827
+ keys = Reflect.ownKeys(obj);
828
+ Array.prototype.push.call(ctx.seen, main);
829
+ for (const key of keys) {
830
+ // Ignore the `constructor` property and keys that exist on layers above.
831
+ if (
832
+ key === "constructor" ||
833
+ // deno-lint-ignore no-prototype-builtins
834
+ main.hasOwnProperty(key) ||
835
+ (depth !== 0 && keySet.has(key))
836
+ ) {
837
+ continue;
838
+ }
839
+ const desc = Object.getOwnPropertyDescriptor(obj, key);
840
+ if (typeof desc.value === "function") {
841
+ continue;
842
+ }
843
+ const value = formatProperty(
844
+ ctx,
845
+ obj,
846
+ recurseTimes,
847
+ key,
848
+ kObjectType,
849
+ desc,
850
+ main,
851
+ );
852
+ if (ctx.colors) {
853
+ // Faint!
854
+ Array.prototype.push.call(output, `\u001b[2m${value}\u001b[22m`);
855
+ } else {
856
+ Array.prototype.push.call(output, value);
857
+ }
858
+ }
859
+ Array.prototype.pop.call(ctx.seen);
860
+ // Limit the inspection to up to three prototype layers. Using `recurseTimes`
861
+ // is not a good choice here, because it's as if the properties are declared
862
+ // on the current object from the users perspective.
863
+ } while (++depth !== 3);
864
+ }
865
+
866
+ function getConstructorName(
867
+ obj,
868
+ ctx,
869
+ recurseTimes,
870
+ protoProps,
871
+ ) {
872
+ let firstProto;
873
+ const tmp = obj;
874
+ while (obj || isUndetectableObject(obj)) {
875
+ const descriptor = Object.getOwnPropertyDescriptor(obj, "constructor");
876
+ if (
877
+ descriptor !== undefined &&
878
+ typeof descriptor.value === "function" &&
879
+ descriptor.value.name !== "" &&
880
+ isInstanceof(tmp, descriptor.value)
881
+ ) {
882
+ if (
883
+ protoProps !== undefined &&
884
+ (firstProto !== obj ||
885
+ !builtInObjects.has(descriptor.value.name))
886
+ ) {
887
+ addPrototypeProperties(
888
+ ctx,
889
+ tmp,
890
+ firstProto || tmp,
891
+ recurseTimes,
892
+ protoProps,
893
+ );
894
+ }
895
+ return descriptor.value.name;
896
+ }
897
+
898
+ obj = Object.getPrototypeOf(obj);
899
+ if (firstProto === undefined) {
900
+ firstProto = obj;
901
+ }
902
+ }
903
+
904
+ if (firstProto === null) {
905
+ return null;
906
+ }
907
+
908
+ // TODO(wafuwafu13): Implement
909
+ // const res = internalGetConstructorName(tmp);
910
+ const res = undefined;
911
+
912
+ if (recurseTimes > ctx.depth && ctx.depth !== null) {
913
+ return `${res} <Complex prototype>`;
914
+ }
915
+
916
+ const protoConstr = getConstructorName(
917
+ firstProto,
918
+ ctx,
919
+ recurseTimes + 1,
920
+ protoProps,
921
+ );
922
+
923
+ if (protoConstr === null) {
924
+ return `${res} <${
925
+ inspect(firstProto, {
926
+ ...ctx,
927
+ customInspect: false,
928
+ depth: -1,
929
+ })
930
+ }>`;
931
+ }
932
+
933
+ return `${res} <${protoConstr}>`;
934
+ }
935
+
936
+ function formatPrimitive(fn, value, ctx) {
937
+ if (typeof value === "string") {
938
+ let trailer = "";
939
+ if (value.length > ctx.maxStringLength) {
940
+ const remaining = value.length - ctx.maxStringLength;
941
+ value = value.slice(0, ctx.maxStringLength);
942
+ trailer = `... ${remaining} more character${remaining > 1 ? "s" : ""}`;
943
+ }
944
+ if (
945
+ ctx.compact !== true &&
946
+ // TODO(BridgeAR): Add unicode support. Use the readline getStringWidth
947
+ // function.
948
+ value.length > kMinLineLength &&
949
+ value.length > ctx.breakLength - ctx.indentationLvl - 4
950
+ ) {
951
+ return value
952
+ .split(/(?<=\n)/)
953
+ .map((line) => fn(strEscape(line), "string"))
954
+ .join(` +\n${" ".repeat(ctx.indentationLvl + 2)}`) + trailer;
955
+ }
956
+ return fn(strEscape(value), "string") + trailer;
957
+ }
958
+ if (typeof value === "number") {
959
+ return formatNumber(fn, value);
960
+ }
961
+ if (typeof value === "bigint") {
962
+ return formatBigInt(fn, value);
963
+ }
964
+ if (typeof value === "boolean") {
965
+ return fn(`${value}`, "boolean");
966
+ }
967
+ if (typeof value === "undefined") {
968
+ return fn("undefined", "undefined");
969
+ }
970
+ // es6 symbol primitive
971
+ return fn(value.toString(), "symbol");
972
+ }
973
+
974
+ // Return a new empty array to push in the results of the default formatter.
975
+ function getEmptyFormatArray() {
976
+ return [];
977
+ }
978
+
979
+ function isInstanceof(object, proto) {
980
+ try {
981
+ return object instanceof proto;
982
+ } catch {
983
+ return false;
984
+ }
985
+ }
986
+
987
+ function getPrefix(constructor, tag, fallback, size = "") {
988
+ if (constructor === null) {
989
+ if (tag !== "" && fallback !== tag) {
990
+ return `[${fallback}${size}: null prototype] [${tag}] `;
991
+ }
992
+ return `[${fallback}${size}: null prototype] `;
993
+ }
994
+
995
+ if (tag !== "" && constructor !== tag) {
996
+ return `${constructor}${size} [${tag}] `;
997
+ }
998
+ return `${constructor}${size} `;
999
+ }
1000
+
1001
+ function formatArray(ctx, value, recurseTimes) {
1002
+ const valLen = value.length;
1003
+ const len = Math.min(Math.max(0, ctx.maxArrayLength), valLen);
1004
+
1005
+ const remaining = valLen - len;
1006
+ const output = [];
1007
+ for (let i = 0; i < len; i++) {
1008
+ // Special handle sparse arrays.
1009
+ // deno-lint-ignore no-prototype-builtins
1010
+ if (!value.hasOwnProperty(i)) {
1011
+ return formatSpecialArray(ctx, value, recurseTimes, len, output, i);
1012
+ }
1013
+ output.push(formatProperty(ctx, value, recurseTimes, i, kArrayType));
1014
+ }
1015
+ if (remaining > 0) {
1016
+ output.push(`... ${remaining} more item${remaining > 1 ? "s" : ""}`);
1017
+ }
1018
+ return output;
1019
+ }
1020
+
1021
+ function getCtxStyle(_value, constructor, tag) {
1022
+ let fallback = "";
1023
+ if (constructor === null) {
1024
+ // TODO(wafuwafu13): Implement
1025
+ // fallback = internalGetConstructorName(value);
1026
+ if (fallback === tag) {
1027
+ fallback = "Object";
1028
+ }
1029
+ }
1030
+ return getPrefix(constructor, tag, fallback);
1031
+ }
1032
+
1033
+ // Look up the keys of the object.
1034
+ function getKeys(value, showHidden) {
1035
+ let keys;
1036
+ const symbols = Object.getOwnPropertySymbols(value);
1037
+ if (showHidden) {
1038
+ keys = Object.getOwnPropertyNames(value);
1039
+ if (symbols.length !== 0) {
1040
+ Array.prototype.push.apply(keys, symbols);
1041
+ }
1042
+ } else {
1043
+ // This might throw if `value` is a Module Namespace Object from an
1044
+ // unevaluated module, but we don't want to perform the actual type
1045
+ // check because it's expensive.
1046
+ // TODO(devsnek): track https://github.com/tc39/ecma262/issues/1209
1047
+ // and modify this logic as needed.
1048
+ try {
1049
+ keys = Object.keys(value);
1050
+ } catch (_err) {
1051
+ // TODO(wafuwafu13): Implement
1052
+ // assert(isNativeError(err) && err.name === 'ReferenceError' &&
1053
+ // isModuleNamespaceObject(value));
1054
+ keys = Object.getOwnPropertyNames(value);
1055
+ }
1056
+ if (symbols.length !== 0) {
1057
+ // TODO(wafuwafu13): Implement
1058
+ // const filter = (key: any) =>
1059
+ //
1060
+ // Object.prototype.propertyIsEnumerable(value, key);
1061
+ // Array.prototype.push.apply(
1062
+ // keys,
1063
+ // symbols.filter(filter),
1064
+ // );
1065
+ }
1066
+ }
1067
+ return keys;
1068
+ }
1069
+
1070
+ function formatSet(value, ctx, _ignored, recurseTimes) {
1071
+ const output = [];
1072
+ ctx.indentationLvl += 2;
1073
+ for (const v of value) {
1074
+ Array.prototype.push.call(output, formatValue(ctx, v, recurseTimes));
1075
+ }
1076
+ ctx.indentationLvl -= 2;
1077
+ return output;
1078
+ }
1079
+
1080
+ function formatMap(value, ctx, _gnored, recurseTimes) {
1081
+ const output = [];
1082
+ ctx.indentationLvl += 2;
1083
+ for (const { 0: k, 1: v } of value) {
1084
+ output.push(
1085
+ `${formatValue(ctx, k, recurseTimes)} => ${
1086
+ formatValue(ctx, v, recurseTimes)
1087
+ }`,
1088
+ );
1089
+ }
1090
+ ctx.indentationLvl -= 2;
1091
+ return output;
1092
+ }
1093
+
1094
+ function formatTypedArray(
1095
+ value,
1096
+ length,
1097
+ ctx,
1098
+ _ignored,
1099
+ recurseTimes,
1100
+ ) {
1101
+ const maxLength = Math.min(Math.max(0, ctx.maxArrayLength), length);
1102
+ const remaining = value.length - maxLength;
1103
+ const output = new Array(maxLength);
1104
+ const elementFormatter = value.length > 0 && typeof value[0] === "number"
1105
+ ? formatNumber
1106
+ : formatBigInt;
1107
+ for (let i = 0; i < maxLength; ++i) {
1108
+ output[i] = elementFormatter(ctx.stylize, value[i]);
1109
+ }
1110
+ if (remaining > 0) {
1111
+ output[maxLength] = `... ${remaining} more item${remaining > 1 ? "s" : ""}`;
1112
+ }
1113
+ if (ctx.showHidden) {
1114
+ // .buffer goes last, it's not a primitive like the others.
1115
+ // All besides `BYTES_PER_ELEMENT` are actually getters.
1116
+ ctx.indentationLvl += 2;
1117
+ for (
1118
+ const key of [
1119
+ "BYTES_PER_ELEMENT",
1120
+ "length",
1121
+ "byteLength",
1122
+ "byteOffset",
1123
+ "buffer",
1124
+ ]
1125
+ ) {
1126
+ const str = formatValue(ctx, value[key], recurseTimes, true);
1127
+ Array.prototype.push.call(output, `[${key}]: ${str}`);
1128
+ }
1129
+ ctx.indentationLvl -= 2;
1130
+ }
1131
+ return output;
1132
+ }
1133
+
1134
+ function getIteratorBraces(type, tag) {
1135
+ if (tag !== `${type} Iterator`) {
1136
+ if (tag !== "") {
1137
+ tag += "] [";
1138
+ }
1139
+ tag += `${type} Iterator`;
1140
+ }
1141
+ return [`[${tag}] {`, "}"];
1142
+ }
1143
+
1144
+ function formatIterator(braces, ctx, value, recurseTimes) {
1145
+ // TODO(wafuwafu13): Implement
1146
+ // const { 0: entries, 1: isKeyValue } = previewEntries(value, true);
1147
+ const { 0: entries, 1: isKeyValue } = value;
1148
+ if (isKeyValue) {
1149
+ // Mark entry iterators as such.
1150
+ braces[0] = braces[0].replace(/ Iterator] {$/, " Entries] {");
1151
+ return formatMapIterInner(ctx, recurseTimes, entries, kMapEntries);
1152
+ }
1153
+
1154
+ return formatSetIterInner(ctx, recurseTimes, entries, kIterator);
1155
+ }
1156
+
1157
+ function getFunctionBase(value, constructor, tag) {
1158
+ const stringified = Function.prototype.toString.call(value);
1159
+ if (stringified.slice(0, 5) === "class" && stringified.endsWith("}")) {
1160
+ const slice = stringified.slice(5, -1);
1161
+ const bracketIndex = slice.indexOf("{");
1162
+ if (
1163
+ bracketIndex !== -1 &&
1164
+ (!slice.slice(0, bracketIndex).includes("(") ||
1165
+ // Slow path to guarantee that it's indeed a class.
1166
+ classRegExp.test(slice.replace(stripCommentsRegExp)))
1167
+ ) {
1168
+ return getClassBase(value, constructor, tag);
1169
+ }
1170
+ }
1171
+ let type = "Function";
1172
+ if (types.isGeneratorFunction(value)) {
1173
+ type = `Generator${type}`;
1174
+ }
1175
+ if (types.isAsyncFunction(value)) {
1176
+ type = `Async${type}`;
1177
+ }
1178
+ let base = `[${type}`;
1179
+ if (constructor === null) {
1180
+ base += " (null prototype)";
1181
+ }
1182
+ if (value.name === "") {
1183
+ base += " (anonymous)";
1184
+ } else {
1185
+ base += `: ${value.name}`;
1186
+ }
1187
+ base += "]";
1188
+ if (constructor !== type && constructor !== null) {
1189
+ base += ` ${constructor}`;
1190
+ }
1191
+ if (tag !== "" && constructor !== tag) {
1192
+ base += ` [${tag}]`;
1193
+ }
1194
+ return base;
1195
+ }
1196
+
1197
+ function formatError(
1198
+ err,
1199
+ constructor,
1200
+ tag,
1201
+ ctx,
1202
+ keys,
1203
+ ) {
1204
+ const name = err.name != null ? String(err.name) : "Error";
1205
+ let len = name.length;
1206
+ let stack = err.stack ? String(err.stack) : err.toString();
1207
+
1208
+ // Do not "duplicate" error properties that are already included in the output
1209
+ // otherwise.
1210
+ if (!ctx.showHidden && keys.length !== 0) {
1211
+ for (const name of ["name", "message", "stack"]) {
1212
+ const index = keys.indexOf(name);
1213
+ // Only hide the property in case it's part of the original stack
1214
+ if (index !== -1 && stack.includes(err[name])) {
1215
+ keys.splice(index, 1);
1216
+ }
1217
+ }
1218
+ }
1219
+
1220
+ // A stack trace may contain arbitrary data. Only manipulate the output
1221
+ // for "regular errors" (errors that "look normal") for now.
1222
+ if (
1223
+ constructor === null ||
1224
+ (name.endsWith("Error") &&
1225
+ stack.startsWith(name) &&
1226
+ (stack.length === len || stack[len] === ":" || stack[len] === "\n"))
1227
+ ) {
1228
+ let fallback = "Error";
1229
+ if (constructor === null) {
1230
+ const start = stack.match(/^([A-Z][a-z_ A-Z0-9[\]()-]+)(?::|\n {4}at)/) ||
1231
+ stack.match(/^([a-z_A-Z0-9-]*Error)$/);
1232
+ fallback = (start && start[1]) || "";
1233
+ len = fallback.length;
1234
+ fallback = fallback || "Error";
1235
+ }
1236
+ const prefix = getPrefix(constructor, tag, fallback).slice(0, -1);
1237
+ if (name !== prefix) {
1238
+ if (prefix.includes(name)) {
1239
+ if (len === 0) {
1240
+ stack = `${prefix}: ${stack}`;
1241
+ } else {
1242
+ stack = `${prefix}${stack.slice(len)}`;
1243
+ }
1244
+ } else {
1245
+ stack = `${prefix} [${name}]${stack.slice(len)}`;
1246
+ }
1247
+ }
1248
+ }
1249
+ // Ignore the error message if it's contained in the stack.
1250
+ let pos = (err.message && stack.indexOf(err.message)) || -1;
1251
+ if (pos !== -1) {
1252
+ pos += err.message.length;
1253
+ }
1254
+ // Wrap the error in brackets in case it has no stack trace.
1255
+ const stackStart = stack.indexOf("\n at", pos);
1256
+ if (stackStart === -1) {
1257
+ stack = `[${stack}]`;
1258
+ } else if (ctx.colors) {
1259
+ // Highlight userland code and node modules.
1260
+ let newStack = stack.slice(0, stackStart);
1261
+ const lines = stack.slice(stackStart + 1).split("\n");
1262
+ for (const line of lines) {
1263
+ // const core = line.match(coreModuleRegExp);
1264
+ // TODO(wafuwafu13): Implement
1265
+ // if (core !== null && NativeModule.exists(core[1])) {
1266
+ // newStack += `\n${ctx.stylize(line, 'undefined')}`;
1267
+ // } else {
1268
+ // This adds underscores to all node_modules to quickly identify them.
1269
+ let nodeModule;
1270
+ newStack += "\n";
1271
+ let pos = 0;
1272
+ // deno-lint-ignore no-cond-assign
1273
+ while (nodeModule = nodeModulesRegExp.exec(line)) {
1274
+ // '/node_modules/'.length === 14
1275
+ newStack += line.slice(pos, nodeModule.index + 14);
1276
+ newStack += ctx.stylize(nodeModule[1], "module");
1277
+ pos = nodeModule.index + nodeModule[0].length;
1278
+ }
1279
+ newStack += pos === 0 ? line : line.slice(pos);
1280
+ // }
1281
+ }
1282
+ stack = newStack;
1283
+ }
1284
+ // The message and the stack have to be indented as well!
1285
+ if (ctx.indentationLvl !== 0) {
1286
+ const indentation = " ".repeat(ctx.indentationLvl);
1287
+ stack = stack.replace(/\n/g, `\n${indentation}`);
1288
+ }
1289
+ return stack;
1290
+ }
1291
+
1292
+ let hexSlice;
1293
+
1294
+ function formatArrayBuffer(ctx, value) {
1295
+ let buffer;
1296
+ try {
1297
+ buffer = new Uint8Array(value);
1298
+ } catch {
1299
+ return [ctx.stylize("(detached)", "special")];
1300
+ }
1301
+ // TODO(wafuwafu13): Implement
1302
+ // if (hexSlice === undefined)
1303
+ // hexSlice = uncurryThis(require('buffer').Buffer.prototype.hexSlice);
1304
+ let str = hexSlice(buffer, 0, Math.min(ctx.maxArrayLength, buffer.length))
1305
+ .replace(/(.{2})/g, "$1 ").trim();
1306
+
1307
+ const remaining = buffer.length - ctx.maxArrayLength;
1308
+ if (remaining > 0) {
1309
+ str += ` ... ${remaining} more byte${remaining > 1 ? "s" : ""}`;
1310
+ }
1311
+ return [`${ctx.stylize("[Uint8Contents]", "special")}: <${str}>`];
1312
+ }
1313
+
1314
+ function formatNumber(fn, value) {
1315
+ // Format -0 as '-0'. Checking `value === -0` won't distinguish 0 from -0.
1316
+ return fn(Object.is(value, -0) ? "-0" : `${value}`, "number");
1317
+ }
1318
+
1319
+ function formatPromise(ctx, value, recurseTimes) {
1320
+ let output;
1321
+ // TODO(wafuwafu13): Implement
1322
+ // const { 0: state, 1: result } = getPromiseDetails(value);
1323
+ const { 0: state, 1: result } = value;
1324
+ if (state === kPending) {
1325
+ output = [ctx.stylize("<pending>", "special")];
1326
+ } else {
1327
+ ctx.indentationLvl += 2;
1328
+ const str = formatValue(ctx, result, recurseTimes);
1329
+ ctx.indentationLvl -= 2;
1330
+ output = [
1331
+ state === kRejected
1332
+ ? `${ctx.stylize("<rejected>", "special")} ${str}`
1333
+ : str,
1334
+ ];
1335
+ }
1336
+ return output;
1337
+ }
1338
+
1339
+ function formatWeakCollection(ctx) {
1340
+ return [ctx.stylize("<items unknown>", "special")];
1341
+ }
1342
+
1343
+ function formatWeakSet(ctx, value, recurseTimes) {
1344
+ // TODO(wafuwafu13): Implement
1345
+ // const entries = previewEntries(value);
1346
+ const entries = value;
1347
+ return formatSetIterInner(ctx, recurseTimes, entries, kWeak);
1348
+ }
1349
+
1350
+ function formatWeakMap(ctx, value, recurseTimes) {
1351
+ // TODO(wafuwafu13): Implement
1352
+ // const entries = previewEntries(value);
1353
+ const entries = value;
1354
+ return formatMapIterInner(ctx, recurseTimes, entries, kWeak);
1355
+ }
1356
+
1357
+ function formatProperty(
1358
+ ctx,
1359
+ value,
1360
+ recurseTimes,
1361
+ key,
1362
+ type,
1363
+ desc,
1364
+ original = value,
1365
+ ) {
1366
+ let name, str;
1367
+ let extra = " ";
1368
+ desc = desc || Object.getOwnPropertyDescriptor(value, key) ||
1369
+ { value: value[key], enumerable: true };
1370
+ if (desc.value !== undefined) {
1371
+ const diff = (ctx.compact !== true || type !== kObjectType) ? 2 : 3;
1372
+ ctx.indentationLvl += diff;
1373
+ str = formatValue(ctx, desc.value, recurseTimes);
1374
+ if (diff === 3 && ctx.breakLength < getStringWidth(str, ctx.colors)) {
1375
+ extra = `\n${" ".repeat(ctx.indentationLvl)}`;
1376
+ }
1377
+ ctx.indentationLvl -= diff;
1378
+ } else if (desc.get !== undefined) {
1379
+ const label = desc.set !== undefined ? "Getter/Setter" : "Getter";
1380
+ const s = ctx.stylize;
1381
+ const sp = "special";
1382
+ if (
1383
+ ctx.getters && (ctx.getters === true ||
1384
+ (ctx.getters === "get" && desc.set === undefined) ||
1385
+ (ctx.getters === "set" && desc.set !== undefined))
1386
+ ) {
1387
+ try {
1388
+ const tmp = desc.get.call(original);
1389
+ ctx.indentationLvl += 2;
1390
+ if (tmp === null) {
1391
+ str = `${s(`[${label}:`, sp)} ${s("null", "null")}${s("]", sp)}`;
1392
+ } else if (typeof tmp === "object") {
1393
+ str = `${s(`[${label}]`, sp)} ${formatValue(ctx, tmp, recurseTimes)}`;
1394
+ } else {
1395
+ const primitive = formatPrimitive(s, tmp, ctx);
1396
+ str = `${s(`[${label}:`, sp)} ${primitive}${s("]", sp)}`;
1397
+ }
1398
+ ctx.indentationLvl -= 2;
1399
+ } catch (err) {
1400
+ const message = `<Inspection threw (${err.message})>`;
1401
+ str = `${s(`[${label}:`, sp)} ${message}${s("]", sp)}`;
1402
+ }
1403
+ } else {
1404
+ str = ctx.stylize(`[${label}]`, sp);
1405
+ }
1406
+ } else if (desc.set !== undefined) {
1407
+ str = ctx.stylize("[Setter]", "special");
1408
+ } else {
1409
+ str = ctx.stylize("undefined", "undefined");
1410
+ }
1411
+ if (type === kArrayType) {
1412
+ return str;
1413
+ }
1414
+ if (typeof key === "symbol") {
1415
+ const tmp = key.toString().replace(strEscapeSequencesReplacer, escapeFn);
1416
+
1417
+ name = `[${ctx.stylize(tmp, "symbol")}]`;
1418
+ } else if (key === "__proto__") {
1419
+ name = "['__proto__']";
1420
+ } else if (desc.enumerable === false) {
1421
+ const tmp = key.replace(strEscapeSequencesReplacer, escapeFn);
1422
+
1423
+ name = `[${tmp}]`;
1424
+ } else if (keyStrRegExp.test(key)) {
1425
+ name = ctx.stylize(key, "name");
1426
+ } else {
1427
+ name = ctx.stylize(strEscape(key), "string");
1428
+ }
1429
+ return `${name}:${extra}${str}`;
1430
+ }
1431
+
1432
+ function handleMaxCallStackSize(
1433
+ _ctx,
1434
+ _err,
1435
+ _constructorName,
1436
+ _indentationLvl,
1437
+ ) {
1438
+ // TODO(wafuwafu13): Implement
1439
+ // if (types.isStackOverflowError(err)) {
1440
+ // ctx.seen.pop();
1441
+ // ctx.indentationLvl = indentationLvl;
1442
+ // return ctx.stylize(
1443
+ // `[${constructorName}: Inspection interrupted ` +
1444
+ // 'prematurely. Maximum call stack size exceeded.]',
1445
+ // 'special'
1446
+ // );
1447
+ // }
1448
+ // /* c8 ignore next */
1449
+ // assert.fail(err.stack);
1450
+ }
1451
+
1452
+ // deno-lint-ignore no-control-regex
1453
+ const colorRegExp = /\u001b\[\d\d?m/g;
1454
+ function removeColors(str) {
1455
+ return str.replace(colorRegExp, "");
1456
+ }
1457
+
1458
+ function isBelowBreakLength(ctx, output, start, base) {
1459
+ // Each entry is separated by at least a comma. Thus, we start with a total
1460
+ // length of at least `output.length`. In addition, some cases have a
1461
+ // whitespace in-between each other that is added to the total as well.
1462
+ // TODO(BridgeAR): Add unicode support. Use the readline getStringWidth
1463
+ // function. Check the performance overhead and make it an opt-in in case it's
1464
+ // significant.
1465
+ let totalLength = output.length + start;
1466
+ if (totalLength + output.length > ctx.breakLength) {
1467
+ return false;
1468
+ }
1469
+ for (let i = 0; i < output.length; i++) {
1470
+ if (ctx.colors) {
1471
+ totalLength += removeColors(output[i]).length;
1472
+ } else {
1473
+ totalLength += output[i].length;
1474
+ }
1475
+ if (totalLength > ctx.breakLength) {
1476
+ return false;
1477
+ }
1478
+ }
1479
+ // Do not line up properties on the same line if `base` contains line breaks.
1480
+ return base === "" || !base.includes("\n");
1481
+ }
1482
+
1483
+ function formatBigInt(fn, value) {
1484
+ return fn(`${value}n`, "bigint");
1485
+ }
1486
+
1487
+ function formatNamespaceObject(
1488
+ keys,
1489
+ ctx,
1490
+ value,
1491
+ recurseTimes,
1492
+ ) {
1493
+ const output = new Array(keys.length);
1494
+ for (let i = 0; i < keys.length; i++) {
1495
+ try {
1496
+ output[i] = formatProperty(
1497
+ ctx,
1498
+ value,
1499
+ recurseTimes,
1500
+ keys[i],
1501
+ kObjectType,
1502
+ );
1503
+ } catch (_err) {
1504
+ // TODO(wafuwfu13): Implement
1505
+ // assert(isNativeError(err) && err.name === 'ReferenceError');
1506
+ // Use the existing functionality. This makes sure the indentation and
1507
+ // line breaks are always correct. Otherwise it is very difficult to keep
1508
+ // this aligned, even though this is a hacky way of dealing with this.
1509
+ const tmp = { [keys[i]]: "" };
1510
+ output[i] = formatProperty(ctx, tmp, recurseTimes, keys[i], kObjectType);
1511
+ const pos = output[i].lastIndexOf(" ");
1512
+ // We have to find the last whitespace and have to replace that value as
1513
+ // it will be visualized as a regular string.
1514
+ output[i] = output[i].slice(0, pos + 1) +
1515
+ ctx.stylize("<uninitialized>", "special");
1516
+ }
1517
+ }
1518
+ // Reset the keys to an empty array. This prevents duplicated inspection.
1519
+ keys.length = 0;
1520
+ return output;
1521
+ }
1522
+
1523
+ // The array is sparse and/or has extra keys
1524
+ function formatSpecialArray(
1525
+ ctx,
1526
+ value,
1527
+ recurseTimes,
1528
+ maxLength,
1529
+ output,
1530
+ i,
1531
+ ) {
1532
+ const keys = Object.keys(value);
1533
+ let index = i;
1534
+ for (; i < keys.length && output.length < maxLength; i++) {
1535
+ const key = keys[i];
1536
+ const tmp = +key;
1537
+ // Arrays can only have up to 2^32 - 1 entries
1538
+ if (tmp > 2 ** 32 - 2) {
1539
+ break;
1540
+ }
1541
+ if (`${index}` !== key) {
1542
+ if (!numberRegExp.test(key)) {
1543
+ break;
1544
+ }
1545
+ const emptyItems = tmp - index;
1546
+ const ending = emptyItems > 1 ? "s" : "";
1547
+ const message = `<${emptyItems} empty item${ending}>`;
1548
+ output.push(ctx.stylize(message, "undefined"));
1549
+ index = tmp;
1550
+ if (output.length === maxLength) {
1551
+ break;
1552
+ }
1553
+ }
1554
+ output.push(formatProperty(ctx, value, recurseTimes, key, kArrayType));
1555
+ index++;
1556
+ }
1557
+ const remaining = value.length - index;
1558
+ if (output.length !== maxLength) {
1559
+ if (remaining > 0) {
1560
+ const ending = remaining > 1 ? "s" : "";
1561
+ const message = `<${remaining} empty item${ending}>`;
1562
+ output.push(ctx.stylize(message, "undefined"));
1563
+ }
1564
+ } else if (remaining > 0) {
1565
+ output.push(`... ${remaining} more item${remaining > 1 ? "s" : ""}`);
1566
+ }
1567
+ return output;
1568
+ }
1569
+
1570
+ function getBoxedBase(
1571
+ value,
1572
+ ctx,
1573
+ keys,
1574
+ constructor,
1575
+ tag,
1576
+ ) {
1577
+ let type;
1578
+ if (types.isNumberObject(value)) {
1579
+ type = "Number";
1580
+ } else if (types.isStringObject(value)) {
1581
+ type = "String";
1582
+ // For boxed Strings, we have to remove the 0-n indexed entries,
1583
+ // since they just noisy up the output and are redundant
1584
+ // Make boxed primitive Strings look like such
1585
+ keys.splice(0, value.length);
1586
+ } else if (types.isBooleanObject(value)) {
1587
+ type = "Boolean";
1588
+ } else if (types.isBigIntObject(value)) {
1589
+ type = "BigInt";
1590
+ } else {
1591
+ type = "Symbol";
1592
+ }
1593
+ let base = `[${type}`;
1594
+ if (type !== constructor) {
1595
+ if (constructor === null) {
1596
+ base += " (null prototype)";
1597
+ } else {
1598
+ base += ` (${constructor})`;
1599
+ }
1600
+ }
1601
+
1602
+ base += `: ${formatPrimitive(stylizeNoColor, value.valueOf(), ctx)}]`;
1603
+ if (tag !== "" && tag !== constructor) {
1604
+ base += ` [${tag}]`;
1605
+ }
1606
+ if (keys.length !== 0 || ctx.stylize === stylizeNoColor) {
1607
+ return base;
1608
+ }
1609
+ return ctx.stylize(base, type.toLowerCase());
1610
+ }
1611
+
1612
+ function getClassBase(value, constructor, tag) {
1613
+ // deno-lint-ignore no-prototype-builtins
1614
+ const hasName = value.hasOwnProperty("name");
1615
+ const name = (hasName && value.name) || "(anonymous)";
1616
+ let base = `class ${name}`;
1617
+ if (constructor !== "Function" && constructor !== null) {
1618
+ base += ` [${constructor}]`;
1619
+ }
1620
+ if (tag !== "" && constructor !== tag) {
1621
+ base += ` [${tag}]`;
1622
+ }
1623
+ if (constructor !== null) {
1624
+ const superName = Object.getPrototypeOf(value).name;
1625
+ if (superName) {
1626
+ base += ` extends ${superName}`;
1627
+ }
1628
+ } else {
1629
+ base += " extends [null prototype]";
1630
+ }
1631
+ return `[${base}]`;
1632
+ }
1633
+
1634
+ function reduceToSingleString(
1635
+ ctx,
1636
+ output,
1637
+ base,
1638
+ braces,
1639
+ extrasType,
1640
+ recurseTimes,
1641
+ value,
1642
+ ) {
1643
+ if (ctx.compact !== true) {
1644
+ if (typeof ctx.compact === "number" && ctx.compact >= 1) {
1645
+ // Memorize the original output length. In case the output is grouped,
1646
+ // prevent lining up the entries on a single line.
1647
+ const entries = output.length;
1648
+ // Group array elements together if the array contains at least six
1649
+ // separate entries.
1650
+ if (extrasType === kArrayExtrasType && entries > 6) {
1651
+ output = groupArrayElements(ctx, output, value);
1652
+ }
1653
+ // `ctx.currentDepth` is set to the most inner depth of the currently
1654
+ // inspected object part while `recurseTimes` is the actual current depth
1655
+ // that is inspected.
1656
+ //
1657
+ // Example:
1658
+ //
1659
+ // const a = { first: [ 1, 2, 3 ], second: { inner: [ 1, 2, 3 ] } }
1660
+ //
1661
+ // The deepest depth of `a` is 2 (a.second.inner) and `a.first` has a max
1662
+ // depth of 1.
1663
+ //
1664
+ // Consolidate all entries of the local most inner depth up to
1665
+ // `ctx.compact`, as long as the properties are smaller than
1666
+ // `ctx.breakLength`.
1667
+ if (
1668
+ ctx.currentDepth - recurseTimes < ctx.compact &&
1669
+ entries === output.length
1670
+ ) {
1671
+ // Line up all entries on a single line in case the entries do not
1672
+ // exceed `breakLength`. Add 10 as constant to start next to all other
1673
+ // factors that may reduce `breakLength`.
1674
+ const start = output.length + ctx.indentationLvl +
1675
+ braces[0].length + base.length + 10;
1676
+ if (isBelowBreakLength(ctx, output, start, base)) {
1677
+ return `${base ? `${base} ` : ""}${braces[0]} ${join(output, ", ")}` +
1678
+ ` ${braces[1]}`;
1679
+ }
1680
+ }
1681
+ }
1682
+ // Line up each entry on an individual line.
1683
+ const indentation = `\n${" ".repeat(ctx.indentationLvl)}`;
1684
+ return `${base ? `${base} ` : ""}${braces[0]}${indentation} ` +
1685
+ `${join(output, `,${indentation} `)}${indentation}${braces[1]}`;
1686
+ }
1687
+ // Line up all entries on a single line in case the entries do not exceed
1688
+ // `breakLength`.
1689
+ if (isBelowBreakLength(ctx, output, 0, base)) {
1690
+ return `${braces[0]}${base ? ` ${base}` : ""} ${join(output, ", ")} ` +
1691
+ braces[1];
1692
+ }
1693
+ const indentation = " ".repeat(ctx.indentationLvl);
1694
+ // If the opening "brace" is too large, like in the case of "Set {",
1695
+ // we need to force the first item to be on the next line or the
1696
+ // items will not line up correctly.
1697
+ const ln = base === "" && braces[0].length === 1
1698
+ ? " "
1699
+ : `${base ? ` ${base}` : ""}\n${indentation} `;
1700
+ // Line up each entry on an individual line.
1701
+ return `${braces[0]}${ln}${join(output, `,\n${indentation} `)} ${braces[1]}`;
1702
+ }
1703
+
1704
+ // The built-in Array#join is slower in v8 6.0
1705
+ function join(output, separator) {
1706
+ let str = "";
1707
+ if (output.length !== 0) {
1708
+ const lastIndex = output.length - 1;
1709
+ for (let i = 0; i < lastIndex; i++) {
1710
+ // It is faster not to use a template string here
1711
+ str += output[i];
1712
+ str += separator;
1713
+ }
1714
+ str += output[lastIndex];
1715
+ }
1716
+ return str;
1717
+ }
1718
+
1719
+ function groupArrayElements(ctx, output, value) {
1720
+ let totalLength = 0;
1721
+ let maxLength = 0;
1722
+ let i = 0;
1723
+ let outputLength = output.length;
1724
+ if (ctx.maxArrayLength < output.length) {
1725
+ // This makes sure the "... n more items" part is not taken into account.
1726
+ outputLength--;
1727
+ }
1728
+ const separatorSpace = 2; // Add 1 for the space and 1 for the separator.
1729
+ const dataLen = new Array(outputLength);
1730
+ // Calculate the total length of all output entries and the individual max
1731
+ // entries length of all output entries. We have to remove colors first,
1732
+ // otherwise the length would not be calculated properly.
1733
+ for (; i < outputLength; i++) {
1734
+ const len = getStringWidth(output[i], ctx.colors);
1735
+ dataLen[i] = len;
1736
+ totalLength += len + separatorSpace;
1737
+ if (maxLength < len) {
1738
+ maxLength = len;
1739
+ }
1740
+ }
1741
+ // Add two to `maxLength` as we add a single whitespace character plus a comma
1742
+ // in-between two entries.
1743
+ const actualMax = maxLength + separatorSpace;
1744
+ // Check if at least three entries fit next to each other and prevent grouping
1745
+ // of arrays that contains entries of very different length (i.e., if a single
1746
+ // entry is longer than 1/5 of all other entries combined). Otherwise the
1747
+ // space in-between small entries would be enormous.
1748
+ if (
1749
+ actualMax * 3 + ctx.indentationLvl < ctx.breakLength &&
1750
+ (totalLength / actualMax > 5 || maxLength <= 6)
1751
+ ) {
1752
+ const approxCharHeights = 2.5;
1753
+ const averageBias = Math.sqrt(actualMax - totalLength / output.length);
1754
+ const biasedMax = Math.max(actualMax - 3 - averageBias, 1);
1755
+ // Dynamically check how many columns seem possible.
1756
+ const columns = Math.min(
1757
+ // Ideally a square should be drawn. We expect a character to be about 2.5
1758
+ // times as high as wide. This is the area formula to calculate a square
1759
+ // which contains n rectangles of size `actualMax * approxCharHeights`.
1760
+ // Divide that by `actualMax` to receive the correct number of columns.
1761
+ // The added bias increases the columns for short entries.
1762
+ Math.round(
1763
+ Math.sqrt(
1764
+ approxCharHeights * biasedMax * outputLength,
1765
+ ) / biasedMax,
1766
+ ),
1767
+ // Do not exceed the breakLength.
1768
+ Math.floor((ctx.breakLength - ctx.indentationLvl) / actualMax),
1769
+ // Limit array grouping for small `compact` modes as the user requested
1770
+ // minimal grouping.
1771
+ ctx.compact * 4,
1772
+ // Limit the columns to a maximum of fifteen.
1773
+ 15,
1774
+ );
1775
+ // Return with the original output if no grouping should happen.
1776
+ if (columns <= 1) {
1777
+ return output;
1778
+ }
1779
+ const tmp = [];
1780
+ const maxLineLength = [];
1781
+ for (let i = 0; i < columns; i++) {
1782
+ let lineMaxLength = 0;
1783
+ for (let j = i; j < output.length; j += columns) {
1784
+ if (dataLen[j] > lineMaxLength) {
1785
+ lineMaxLength = dataLen[j];
1786
+ }
1787
+ }
1788
+ lineMaxLength += separatorSpace;
1789
+ maxLineLength[i] = lineMaxLength;
1790
+ }
1791
+ let order = String.prototype.padStart;
1792
+ if (value !== undefined) {
1793
+ for (let i = 0; i < output.length; i++) {
1794
+ if (typeof value[i] !== "number" && typeof value[i] !== "bigint") {
1795
+ order = String.prototype.padEnd;
1796
+ break;
1797
+ }
1798
+ }
1799
+ }
1800
+ // Each iteration creates a single line of grouped entries.
1801
+ for (let i = 0; i < outputLength; i += columns) {
1802
+ // The last lines may contain less entries than columns.
1803
+ const max = Math.min(i + columns, outputLength);
1804
+ let str = "";
1805
+ let j = i;
1806
+ for (; j < max - 1; j++) {
1807
+ // Calculate extra color padding in case it's active. This has to be
1808
+ // done line by line as some lines might contain more colors than
1809
+ // others.
1810
+ const padding = maxLineLength[j - i] + output[j].length - dataLen[j];
1811
+ str += `${output[j]}, `.padStart(padding, " ");
1812
+ }
1813
+ if (order === String.prototype.padStart) {
1814
+ const padding = maxLineLength[j - i] +
1815
+ output[j].length -
1816
+ dataLen[j] -
1817
+ separatorSpace;
1818
+ str += output[j].padStart(padding, " ");
1819
+ } else {
1820
+ str += output[j];
1821
+ }
1822
+ Array.prototype.push.call(tmp, str);
1823
+ }
1824
+ if (ctx.maxArrayLength < output.length) {
1825
+ Array.prototype.push.call(tmp, output[outputLength]);
1826
+ }
1827
+ output = tmp;
1828
+ }
1829
+ return output;
1830
+ }
1831
+
1832
+ function formatMapIterInner(
1833
+ ctx,
1834
+ recurseTimes,
1835
+ entries,
1836
+ state,
1837
+ ) {
1838
+ const maxArrayLength = Math.max(ctx.maxArrayLength, 0);
1839
+ // Entries exist as [key1, val1, key2, val2, ...]
1840
+ const len = entries.length / 2;
1841
+ const remaining = len - maxArrayLength;
1842
+ const maxLength = Math.min(maxArrayLength, len);
1843
+ let output = new Array(maxLength);
1844
+ let i = 0;
1845
+ ctx.indentationLvl += 2;
1846
+ if (state === kWeak) {
1847
+ for (; i < maxLength; i++) {
1848
+ const pos = i * 2;
1849
+ output[i] = `${formatValue(ctx, entries[pos], recurseTimes)} => ${
1850
+ formatValue(ctx, entries[pos + 1], recurseTimes)
1851
+ }`;
1852
+ }
1853
+ // Sort all entries to have a halfway reliable output (if more entries than
1854
+ // retrieved ones exist, we can not reliably return the same output) if the
1855
+ // output is not sorted anyway.
1856
+ if (!ctx.sorted) {
1857
+ output = output.sort();
1858
+ }
1859
+ } else {
1860
+ for (; i < maxLength; i++) {
1861
+ const pos = i * 2;
1862
+ const res = [
1863
+ formatValue(ctx, entries[pos], recurseTimes),
1864
+ formatValue(ctx, entries[pos + 1], recurseTimes),
1865
+ ];
1866
+ output[i] = reduceToSingleString(
1867
+ ctx,
1868
+ res,
1869
+ "",
1870
+ ["[", "]"],
1871
+ kArrayExtrasType,
1872
+ recurseTimes,
1873
+ );
1874
+ }
1875
+ }
1876
+ ctx.indentationLvl -= 2;
1877
+ if (remaining > 0) {
1878
+ output.push(`... ${remaining} more item${remaining > 1 ? "s" : ""}`);
1879
+ }
1880
+ return output;
1881
+ }
1882
+
1883
+ function formatSetIterInner(
1884
+ ctx,
1885
+ recurseTimes,
1886
+ entries,
1887
+ state,
1888
+ ) {
1889
+ const maxArrayLength = Math.max(ctx.maxArrayLength, 0);
1890
+ const maxLength = Math.min(maxArrayLength, entries.length);
1891
+ const output = new Array(maxLength);
1892
+ ctx.indentationLvl += 2;
1893
+ for (let i = 0; i < maxLength; i++) {
1894
+ output[i] = formatValue(ctx, entries[i], recurseTimes);
1895
+ }
1896
+ ctx.indentationLvl -= 2;
1897
+ if (state === kWeak && !ctx.sorted) {
1898
+ // Sort all entries to have a halfway reliable output (if more entries than
1899
+ // retrieved ones exist, we can not reliably return the same output) if the
1900
+ // output is not sorted anyway.
1901
+ output.sort();
1902
+ }
1903
+ const remaining = entries.length - maxLength;
1904
+ if (remaining > 0) {
1905
+ Array.prototype.push.call(
1906
+ output,
1907
+ `... ${remaining} more item${remaining > 1 ? "s" : ""}`,
1908
+ );
1909
+ }
1910
+ return output;
1911
+ }
1912
+
1913
+ // Regex used for ansi escape code splitting
1914
+ // Adopted from https://github.com/chalk/ansi-regex/blob/HEAD/index.js
1915
+ // License: MIT, authors: @sindresorhus, Qix-, arjunmehta and LitoMore
1916
+ // Matches all ansi escape code sequences in a string
1917
+ const ansiPattern = "[\\u001B\\u009B][[\\]()#;?]*" +
1918
+ "(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*" +
1919
+ "|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)" +
1920
+ "|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))";
1921
+ const ansi = new RegExp(ansiPattern, "g");
1922
+
1923
+ /**
1924
+ * Returns the number of columns required to display the given string.
1925
+ */
1926
+ export function getStringWidth(str, removeControlChars = true) {
1927
+ let width = 0;
1928
+
1929
+ if (removeControlChars) {
1930
+ str = stripVTControlCharacters(str);
1931
+ }
1932
+ str = str.normalize("NFC");
1933
+ for (const char of str[Symbol.iterator]()) {
1934
+ const code = char.codePointAt(0);
1935
+ if (isFullWidthCodePoint(code)) {
1936
+ width += 2;
1937
+ } else if (!isZeroWidthCodePoint(code)) {
1938
+ width++;
1939
+ }
1940
+ }
1941
+
1942
+ return width;
1943
+ }
1944
+
1945
+ /**
1946
+ * Returns true if the character represented by a given
1947
+ * Unicode code point is full-width. Otherwise returns false.
1948
+ */
1949
+ const isFullWidthCodePoint = (code) => {
1950
+ // Code points are partially derived from:
1951
+ // https://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt
1952
+ return code >= 0x1100 && (
1953
+ code <= 0x115f || // Hangul Jamo
1954
+ code === 0x2329 || // LEFT-POINTING ANGLE BRACKET
1955
+ code === 0x232a || // RIGHT-POINTING ANGLE BRACKET
1956
+ // CJK Radicals Supplement .. Enclosed CJK Letters and Months
1957
+ (code >= 0x2e80 && code <= 0x3247 && code !== 0x303f) ||
1958
+ // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
1959
+ (code >= 0x3250 && code <= 0x4dbf) ||
1960
+ // CJK Unified Ideographs .. Yi Radicals
1961
+ (code >= 0x4e00 && code <= 0xa4c6) ||
1962
+ // Hangul Jamo Extended-A
1963
+ (code >= 0xa960 && code <= 0xa97c) ||
1964
+ // Hangul Syllables
1965
+ (code >= 0xac00 && code <= 0xd7a3) ||
1966
+ // CJK Compatibility Ideographs
1967
+ (code >= 0xf900 && code <= 0xfaff) ||
1968
+ // Vertical Forms
1969
+ (code >= 0xfe10 && code <= 0xfe19) ||
1970
+ // CJK Compatibility Forms .. Small Form Variants
1971
+ (code >= 0xfe30 && code <= 0xfe6b) ||
1972
+ // Halfwidth and Fullwidth Forms
1973
+ (code >= 0xff01 && code <= 0xff60) ||
1974
+ (code >= 0xffe0 && code <= 0xffe6) ||
1975
+ // Kana Supplement
1976
+ (code >= 0x1b000 && code <= 0x1b001) ||
1977
+ // Enclosed Ideographic Supplement
1978
+ (code >= 0x1f200 && code <= 0x1f251) ||
1979
+ // Miscellaneous Symbols and Pictographs 0x1f300 - 0x1f5ff
1980
+ // Emoticons 0x1f600 - 0x1f64f
1981
+ (code >= 0x1f300 && code <= 0x1f64f) ||
1982
+ // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
1983
+ (code >= 0x20000 && code <= 0x3fffd)
1984
+ );
1985
+ };
1986
+
1987
+ const isZeroWidthCodePoint = (code) => {
1988
+ return code <= 0x1F || // C0 control codes
1989
+ (code >= 0x7F && code <= 0x9F) || // C1 control codes
1990
+ (code >= 0x300 && code <= 0x36F) || // Combining Diacritical Marks
1991
+ (code >= 0x200B && code <= 0x200F) || // Modifying Invisible Characters
1992
+ // Combining Diacritical Marks for Symbols
1993
+ (code >= 0x20D0 && code <= 0x20FF) ||
1994
+ (code >= 0xFE00 && code <= 0xFE0F) || // Variation Selectors
1995
+ (code >= 0xFE20 && code <= 0xFE2F) || // Combining Half Marks
1996
+ (code >= 0xE0100 && code <= 0xE01EF); // Variation Selectors
1997
+ };
1998
+
1999
+ function hasBuiltInToString(value) {
2000
+ // TODO(wafuwafu13): Implement
2001
+ // // Prevent triggering proxy traps.
2002
+ // const getFullProxy = false;
2003
+ // const proxyTarget = getProxyDetails(value, getFullProxy);
2004
+ const proxyTarget = undefined;
2005
+ if (proxyTarget !== undefined) {
2006
+ value = proxyTarget;
2007
+ }
2008
+
2009
+ // Count objects that have no `toString` function as built-in.
2010
+ if (typeof value.toString !== "function") {
2011
+ return true;
2012
+ }
2013
+
2014
+ // The object has a own `toString` property. Thus it's not not a built-in one.
2015
+ if (Object.prototype.hasOwnProperty.call(value, "toString")) {
2016
+ return false;
2017
+ }
2018
+
2019
+ // Find the object that has the `toString` property as own property in the
2020
+ // prototype chain.
2021
+ let pointer = value;
2022
+ do {
2023
+ pointer = Object.getPrototypeOf(pointer);
2024
+ } while (!Object.prototype.hasOwnProperty.call(pointer, "toString"));
2025
+
2026
+ // Check closer if the object is a built-in.
2027
+ const descriptor = Object.getOwnPropertyDescriptor(pointer, "constructor");
2028
+ return descriptor !== undefined &&
2029
+ typeof descriptor.value === "function" &&
2030
+ builtInObjects.has(descriptor.value.name);
2031
+ }
2032
+
2033
+ const firstErrorLine = (error) => error.message.split("\n", 1)[0];
2034
+ let CIRCULAR_ERROR_MESSAGE;
2035
+ function tryStringify(arg) {
2036
+ try {
2037
+ return JSON.stringify(arg);
2038
+ } catch (err) {
2039
+ // Populate the circular error message lazily
2040
+ if (!CIRCULAR_ERROR_MESSAGE) {
2041
+ try {
2042
+ const a = {};
2043
+ a.a = a;
2044
+ JSON.stringify(a);
2045
+ } catch (circularError) {
2046
+ CIRCULAR_ERROR_MESSAGE = firstErrorLine(circularError);
2047
+ }
2048
+ }
2049
+ if (
2050
+ err.name === "TypeError" &&
2051
+ firstErrorLine(err) === CIRCULAR_ERROR_MESSAGE
2052
+ ) {
2053
+ return "[Circular]";
2054
+ }
2055
+ throw err;
2056
+ }
2057
+ }
2058
+
2059
+ export function format(...args) {
2060
+ return formatWithOptionsInternal(undefined, args);
2061
+ }
2062
+
2063
+ export function formatWithOptions(inspectOptions, ...args) {
2064
+ if (typeof inspectOptions !== "object" || inspectOptions === null) {
2065
+ throw new codes.ERR_INVALID_ARG_TYPE(
2066
+ "inspectOptions",
2067
+ "object",
2068
+ inspectOptions,
2069
+ );
2070
+ }
2071
+ return formatWithOptionsInternal(inspectOptions, args);
2072
+ }
2073
+
2074
+ function formatNumberNoColor(number, options) {
2075
+ return formatNumber(
2076
+ stylizeNoColor,
2077
+ number,
2078
+ options?.numericSeparator ?? inspectDefaultOptions.numericSeparator,
2079
+ );
2080
+ }
2081
+
2082
+ function formatBigIntNoColor(bigint, options) {
2083
+ return formatBigInt(
2084
+ stylizeNoColor,
2085
+ bigint,
2086
+ options?.numericSeparator ?? inspectDefaultOptions.numericSeparator,
2087
+ );
2088
+ }
2089
+
2090
+ function formatWithOptionsInternal(inspectOptions, args) {
2091
+ const first = args[0];
2092
+ let a = 0;
2093
+ let str = "";
2094
+ let join = "";
2095
+
2096
+ if (typeof first === "string") {
2097
+ if (args.length === 1) {
2098
+ return first;
2099
+ }
2100
+ let tempStr;
2101
+ let lastPos = 0;
2102
+
2103
+ for (let i = 0; i < first.length - 1; i++) {
2104
+ if (first.charCodeAt(i) === 37) { // '%'
2105
+ const nextChar = first.charCodeAt(++i);
2106
+ if (a + 1 !== args.length) {
2107
+ switch (nextChar) {
2108
+ // deno-lint-ignore no-case-declarations
2109
+ case 115: // 's'
2110
+ const tempArg = args[++a];
2111
+ if (typeof tempArg === "number") {
2112
+ tempStr = formatNumberNoColor(tempArg, inspectOptions);
2113
+ } else if (typeof tempArg === "bigint") {
2114
+ tempStr = formatBigIntNoColor(tempArg, inspectOptions);
2115
+ } else if (
2116
+ typeof tempArg !== "object" ||
2117
+ tempArg === null ||
2118
+ !hasBuiltInToString(tempArg)
2119
+ ) {
2120
+ tempStr = String(tempArg);
2121
+ } else {
2122
+ tempStr = inspect(tempArg, {
2123
+ ...inspectOptions,
2124
+ compact: 3,
2125
+ colors: false,
2126
+ depth: 0,
2127
+ });
2128
+ }
2129
+ break;
2130
+ case 106: // 'j'
2131
+ tempStr = tryStringify(args[++a]);
2132
+ break;
2133
+ // deno-lint-ignore no-case-declarations
2134
+ case 100: // 'd'
2135
+ const tempNum = args[++a];
2136
+ if (typeof tempNum === "bigint") {
2137
+ tempStr = formatBigIntNoColor(tempNum, inspectOptions);
2138
+ } else if (typeof tempNum === "symbol") {
2139
+ tempStr = "NaN";
2140
+ } else {
2141
+ tempStr = formatNumberNoColor(Number(tempNum), inspectOptions);
2142
+ }
2143
+ break;
2144
+ case 79: // 'O'
2145
+ tempStr = inspect(args[++a], inspectOptions);
2146
+ break;
2147
+ case 111: // 'o'
2148
+ tempStr = inspect(args[++a], {
2149
+ ...inspectOptions,
2150
+ showHidden: true,
2151
+ showProxy: true,
2152
+ depth: 4,
2153
+ });
2154
+ break;
2155
+ // deno-lint-ignore no-case-declarations
2156
+ case 105: // 'i'
2157
+ const tempInteger = args[++a];
2158
+ if (typeof tempInteger === "bigint") {
2159
+ tempStr = formatBigIntNoColor(tempInteger, inspectOptions);
2160
+ } else if (typeof tempInteger === "symbol") {
2161
+ tempStr = "NaN";
2162
+ } else {
2163
+ tempStr = formatNumberNoColor(
2164
+ Number.parseInt(tempInteger),
2165
+ inspectOptions,
2166
+ );
2167
+ }
2168
+ break;
2169
+ // deno-lint-ignore no-case-declarations
2170
+ case 102: // 'f'
2171
+ const tempFloat = args[++a];
2172
+ if (typeof tempFloat === "symbol") {
2173
+ tempStr = "NaN";
2174
+ } else {
2175
+ tempStr = formatNumberNoColor(
2176
+ Number.parseFloat(tempFloat),
2177
+ inspectOptions,
2178
+ );
2179
+ }
2180
+ break;
2181
+ case 99: // 'c'
2182
+ a += 1;
2183
+ tempStr = "";
2184
+ break;
2185
+ case 37: // '%'
2186
+ str += first.slice(lastPos, i);
2187
+ lastPos = i + 1;
2188
+ continue;
2189
+ default: // Any other character is not a correct placeholder
2190
+ continue;
2191
+ }
2192
+ if (lastPos !== i - 1) {
2193
+ str += first.slice(lastPos, i - 1);
2194
+ }
2195
+ str += tempStr;
2196
+ lastPos = i + 1;
2197
+ } else if (nextChar === 37) {
2198
+ str += first.slice(lastPos, i);
2199
+ lastPos = i + 1;
2200
+ }
2201
+ }
2202
+ }
2203
+ if (lastPos !== 0) {
2204
+ a++;
2205
+ join = " ";
2206
+ if (lastPos < first.length) {
2207
+ str += first.slice(lastPos);
2208
+ }
2209
+ }
2210
+ }
2211
+
2212
+ while (a < args.length) {
2213
+ const value = args[a];
2214
+ str += join;
2215
+ str += typeof value !== "string" ? inspect(value, inspectOptions) : value;
2216
+ join = " ";
2217
+ a++;
2218
+ }
2219
+ return str;
2220
+ }
2221
+
2222
+ /**
2223
+ * Remove all VT control characters. Use to estimate displayed string width.
2224
+ */
2225
+ export function stripVTControlCharacters(str) {
2226
+ validateString(str, "str");
2227
+
2228
+ return str.replace(ansi, "");
2229
+ }
2230
+
2231
+ export default {
2232
+ format,
2233
+ getStringWidth,
2234
+ inspect,
2235
+ stripVTControlCharacters,
2236
+ formatWithOptions,
2237
+ };