@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,37 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // compose, destroy and isDisturbed are experimental APIs without
3
+ // typings. They can be exposed once they are released as stable in Node
4
+
5
+ // @deno-types="./_stream.d.ts"
6
+ import {
7
+ _isUint8Array,
8
+ _uint8ArrayToBuffer,
9
+ addAbortSignal,
10
+ // compose,
11
+ // destroy,
12
+ Duplex,
13
+ finished,
14
+ // isDisturbed,
15
+ PassThrough,
16
+ pipeline,
17
+ Readable,
18
+ Stream,
19
+ Transform,
20
+ Writable,
21
+ } from "./_stream.mjs";
22
+
23
+ export {
24
+ _isUint8Array,
25
+ _uint8ArrayToBuffer,
26
+ addAbortSignal,
27
+ Duplex,
28
+ finished,
29
+ PassThrough,
30
+ pipeline,
31
+ Readable,
32
+ Stream,
33
+ Transform,
34
+ Writable,
35
+ };
36
+
37
+ export default Stream;
@@ -0,0 +1,337 @@
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 { Buffer } from "./buffer.ts";
24
+ import { normalizeEncoding as castEncoding, notImplemented } from "./_utils.ts";
25
+
26
+ enum NotImplemented {
27
+ "ascii",
28
+ "latin1",
29
+ "utf16le",
30
+ }
31
+
32
+ function normalizeEncoding(enc?: string): string {
33
+ const encoding = castEncoding(enc ?? null);
34
+ if (encoding && encoding in NotImplemented) notImplemented(encoding);
35
+ if (!encoding && typeof enc === "string" && enc.toLowerCase() !== "raw") {
36
+ throw new Error(`Unknown encoding: ${enc}`);
37
+ }
38
+ return String(encoding);
39
+ }
40
+
41
+ /**
42
+ * Check is `ArrayBuffer` and not `TypedArray`. Typescript allowed `TypedArray` to be passed as `ArrayBuffer` and does not do a deep check
43
+ */
44
+
45
+ function isBufferType(buf: Buffer) {
46
+ return buf instanceof ArrayBuffer && buf.BYTES_PER_ELEMENT;
47
+ }
48
+
49
+ /*
50
+ * Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
51
+ * continuation byte. If an invalid byte is detected, -2 is returned.
52
+ */
53
+ function utf8CheckByte(byte: number): number {
54
+ if (byte <= 0x7f) return 0;
55
+ else if (byte >> 5 === 0x06) return 2;
56
+ else if (byte >> 4 === 0x0e) return 3;
57
+ else if (byte >> 3 === 0x1e) return 4;
58
+ return byte >> 6 === 0x02 ? -1 : -2;
59
+ }
60
+
61
+ /*
62
+ * Checks at most 3 bytes at the end of a Buffer in order to detect an
63
+ * incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
64
+ * needed to complete the UTF-8 character (if applicable) are returned.
65
+ */
66
+ function utf8CheckIncomplete(
67
+ self: StringDecoderBase,
68
+ buf: Buffer,
69
+ i: number,
70
+ ): number {
71
+ let j = buf.length - 1;
72
+ if (j < i) return 0;
73
+ let nb = utf8CheckByte(buf[j]);
74
+ if (nb >= 0) {
75
+ if (nb > 0) self.lastNeed = nb - 1;
76
+ return nb;
77
+ }
78
+ if (--j < i || nb === -2) return 0;
79
+ nb = utf8CheckByte(buf[j]);
80
+ if (nb >= 0) {
81
+ if (nb > 0) self.lastNeed = nb - 2;
82
+ return nb;
83
+ }
84
+ if (--j < i || nb === -2) return 0;
85
+ nb = utf8CheckByte(buf[j]);
86
+ if (nb >= 0) {
87
+ if (nb > 0) {
88
+ if (nb === 2) nb = 0;
89
+ else self.lastNeed = nb - 3;
90
+ }
91
+ return nb;
92
+ }
93
+ return 0;
94
+ }
95
+
96
+ /*
97
+ * Validates as many continuation bytes for a multi-byte UTF-8 character as
98
+ * needed or are available. If we see a non-continuation byte where we expect
99
+ * one, we "replace" the validated continuation bytes we've seen so far with
100
+ * a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
101
+ * behavior. The continuation byte check is included three times in the case
102
+ * where all of the continuation bytes for a character exist in the same buffer.
103
+ * It is also done this way as a slight performance increase instead of using a
104
+ * loop.
105
+ */
106
+ function utf8CheckExtraBytes(
107
+ self: StringDecoderBase,
108
+ buf: Buffer,
109
+ ): string | undefined {
110
+ if ((buf[0] & 0xc0) !== 0x80) {
111
+ self.lastNeed = 0;
112
+ return "\ufffd";
113
+ }
114
+ if (self.lastNeed > 1 && buf.length > 1) {
115
+ if ((buf[1] & 0xc0) !== 0x80) {
116
+ self.lastNeed = 1;
117
+ return "\ufffd";
118
+ }
119
+ if (self.lastNeed > 2 && buf.length > 2) {
120
+ if ((buf[2] & 0xc0) !== 0x80) {
121
+ self.lastNeed = 2;
122
+ return "\ufffd";
123
+ }
124
+ }
125
+ }
126
+ }
127
+
128
+ /*
129
+ * Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
130
+ */
131
+ function utf8FillLastComplete(
132
+ this: StringDecoderBase,
133
+ buf: Buffer,
134
+ ): string | undefined {
135
+ const p = this.lastTotal - this.lastNeed;
136
+ const r = utf8CheckExtraBytes(this, buf);
137
+ if (r !== undefined) return r;
138
+ if (this.lastNeed <= buf.length) {
139
+ buf.copy(this.lastChar, p, 0, this.lastNeed);
140
+ return this.lastChar.toString(this.encoding, 0, this.lastTotal);
141
+ }
142
+ buf.copy(this.lastChar, p, 0, buf.length);
143
+ this.lastNeed -= buf.length;
144
+ }
145
+
146
+ /*
147
+ * Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
148
+ */
149
+ function utf8FillLastIncomplete(
150
+ this: StringDecoderBase,
151
+ buf: Buffer,
152
+ ): string | undefined {
153
+ if (this.lastNeed <= buf.length) {
154
+ buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
155
+ return this.lastChar.toString(this.encoding, 0, this.lastTotal);
156
+ }
157
+ buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
158
+ this.lastNeed -= buf.length;
159
+ }
160
+
161
+ /*
162
+ * Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
163
+ * partial character, the character's bytes are buffered until the required
164
+ * number of bytes are available.
165
+ */
166
+ function utf8Text(this: StringDecoderBase, buf: Buffer, i: number): string {
167
+ const total = utf8CheckIncomplete(this, buf, i);
168
+ if (!this.lastNeed) return buf.toString("utf8", i);
169
+ this.lastTotal = total;
170
+ const end = buf.length - (total - this.lastNeed);
171
+ buf.copy(this.lastChar, 0, end);
172
+ return buf.toString("utf8", i, end);
173
+ }
174
+
175
+ /*
176
+ * For UTF-8, a replacement character is added when ending on a partial
177
+ * character.
178
+ */
179
+ function utf8End(this: Utf8Decoder, buf?: Buffer): string {
180
+ const r = buf && buf.length ? this.write(buf) : "";
181
+ if (this.lastNeed) return r + "\ufffd";
182
+ return r;
183
+ }
184
+
185
+ function utf8Write(
186
+ this: Utf8Decoder | Base64Decoder,
187
+ buf: Buffer | string,
188
+ ): string {
189
+ if (typeof buf === "string") {
190
+ return buf;
191
+ }
192
+ if (buf.length === 0) return "";
193
+ let r;
194
+ let i;
195
+ // Because `TypedArray` is recognized as `ArrayBuffer` but in the reality, there are some fundamental difference. We would need to cast it properly
196
+ const normalizedBuffer: Buffer = isBufferType(buf) ? buf : Buffer.from(buf);
197
+ if (this.lastNeed) {
198
+ r = this.fillLast(normalizedBuffer);
199
+ if (r === undefined) return "";
200
+ i = this.lastNeed;
201
+ this.lastNeed = 0;
202
+ } else {
203
+ i = 0;
204
+ }
205
+ if (i < buf.length) {
206
+ return r
207
+ ? r + this.text(normalizedBuffer, i)
208
+ : this.text(normalizedBuffer, i);
209
+ }
210
+ return r || "";
211
+ }
212
+
213
+ function base64Text(this: StringDecoderBase, buf: Buffer, i: number): string {
214
+ const n = (buf.length - i) % 3;
215
+ if (n === 0) return buf.toString("base64", i);
216
+ this.lastNeed = 3 - n;
217
+ this.lastTotal = 3;
218
+ if (n === 1) {
219
+ this.lastChar[0] = buf[buf.length - 1];
220
+ } else {
221
+ this.lastChar[0] = buf[buf.length - 2];
222
+ this.lastChar[1] = buf[buf.length - 1];
223
+ }
224
+ return buf.toString("base64", i, buf.length - n);
225
+ }
226
+
227
+ function base64End(this: Base64Decoder, buf?: Buffer): string {
228
+ const r = buf && buf.length ? this.write(buf) : "";
229
+ if (this.lastNeed) {
230
+ return r + this.lastChar.toString("base64", 0, 3 - this.lastNeed);
231
+ }
232
+ return r;
233
+ }
234
+
235
+ function simpleWrite(
236
+ this: StringDecoderBase,
237
+ buf: Buffer | string,
238
+ ): string {
239
+ if (typeof buf === "string") {
240
+ return buf;
241
+ }
242
+ return buf.toString(this.encoding);
243
+ }
244
+
245
+ function simpleEnd(this: GenericDecoder, buf?: Buffer): string {
246
+ return buf && buf.length ? this.write(buf) : "";
247
+ }
248
+
249
+ class StringDecoderBase {
250
+ public lastChar: Buffer;
251
+ public lastNeed = 0;
252
+ public lastTotal = 0;
253
+ constructor(public encoding: string, nb: number) {
254
+ this.lastChar = Buffer.allocUnsafe(nb);
255
+ }
256
+ }
257
+
258
+ class Base64Decoder extends StringDecoderBase {
259
+ public end = base64End;
260
+ public fillLast = utf8FillLastIncomplete;
261
+ public text = base64Text;
262
+ public write = utf8Write;
263
+
264
+ constructor(encoding?: string) {
265
+ super(normalizeEncoding(encoding), 3);
266
+ }
267
+ }
268
+
269
+ class GenericDecoder extends StringDecoderBase {
270
+ public end = simpleEnd;
271
+ public fillLast = undefined;
272
+ public text = utf8Text;
273
+ public write = simpleWrite;
274
+
275
+ constructor(encoding?: string) {
276
+ super(normalizeEncoding(encoding), 4);
277
+ }
278
+ }
279
+
280
+ class Utf8Decoder extends StringDecoderBase {
281
+ public end = utf8End;
282
+ public fillLast = utf8FillLastComplete;
283
+ public text = utf8Text;
284
+ public write = utf8Write;
285
+
286
+ constructor(encoding?: string) {
287
+ super(normalizeEncoding(encoding), 4);
288
+ }
289
+ }
290
+
291
+ /*
292
+ * StringDecoder provides an interface for efficiently splitting a series of
293
+ * buffers into a series of JS strings without breaking apart multi-byte
294
+ * characters.
295
+ */
296
+ export class StringDecoder {
297
+ public encoding: string;
298
+ public end: (buf?: Buffer) => string;
299
+ public fillLast: ((buf: Buffer) => string | undefined) | undefined;
300
+ public lastChar: Buffer;
301
+ public lastNeed: number;
302
+ public lastTotal: number;
303
+ public text: (buf: Buffer, n: number) => string;
304
+ public write: (buf: Buffer) => string;
305
+
306
+ constructor(encoding?: string) {
307
+ const normalizedEncoding = normalizeEncoding(encoding);
308
+ let decoder: Utf8Decoder | Base64Decoder | GenericDecoder;
309
+ switch (normalizedEncoding) {
310
+ case "utf8":
311
+ decoder = new Utf8Decoder(encoding);
312
+ break;
313
+ case "base64":
314
+ decoder = new Base64Decoder(encoding);
315
+ break;
316
+ default:
317
+ decoder = new GenericDecoder(encoding);
318
+ }
319
+ this.encoding = decoder.encoding;
320
+ this.end = decoder.end;
321
+ this.fillLast = decoder.fillLast;
322
+ this.lastChar = decoder.lastChar;
323
+ this.lastNeed = decoder.lastNeed;
324
+ this.lastTotal = decoder.lastTotal;
325
+ this.text = decoder.text;
326
+ this.write = decoder.write;
327
+ }
328
+ }
329
+ // Allow calling StringDecoder() without new
330
+ const PStringDecoder = new Proxy(StringDecoder, {
331
+ apply(_target, thisArg, args) {
332
+ // @ts-ignore tedious to replicate types ...
333
+ return Object.assign(thisArg, new StringDecoder(...args));
334
+ },
335
+ });
336
+
337
+ export default { StringDecoder: PStringDecoder };
@@ -0,0 +1,4 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import * as types from "../internal/util/types.ts";
3
+ export * from "../internal/util/types.ts";
4
+ export default { ...types };
@@ -0,0 +1,289 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { promisify } from "./internal/util.mjs";
3
+ import { callbackify } from "./_util/_util_callbackify.ts";
4
+ import { debuglog } from "./internal/util/debuglog.ts";
5
+ import {
6
+ format,
7
+ formatWithOptions,
8
+ inspect,
9
+ stripVTControlCharacters,
10
+ } from "./internal/util/inspect.mjs";
11
+ import { codes } from "./internal/error_codes.ts";
12
+ import types from "./util/types.ts";
13
+ import { Buffer } from "./buffer.ts";
14
+ import { isDeepStrictEqual } from "./internal/util/comparisons.ts";
15
+ import process from "./process.ts";
16
+ import { validateString } from "./internal/validators.mjs";
17
+
18
+ export {
19
+ callbackify,
20
+ debuglog,
21
+ format,
22
+ formatWithOptions,
23
+ inspect,
24
+ promisify,
25
+ stripVTControlCharacters,
26
+ types,
27
+ };
28
+
29
+ /** @deprecated - use `Array.isArray()` instead. */
30
+ export function isArray(value: unknown): boolean {
31
+ return Array.isArray(value);
32
+ }
33
+
34
+ /** @deprecated - use `typeof value === "boolean" || value instanceof Boolean` instead. */
35
+ export function isBoolean(value: unknown): boolean {
36
+ return typeof value === "boolean" || value instanceof Boolean;
37
+ }
38
+
39
+ /** @deprecated - use `value === null` instead. */
40
+ export function isNull(value: unknown): boolean {
41
+ return value === null;
42
+ }
43
+
44
+ /** @deprecated - use `value === null || value === undefined` instead. */
45
+ export function isNullOrUndefined(value: unknown): boolean {
46
+ return value === null || value === undefined;
47
+ }
48
+
49
+ /** @deprecated - use `typeof value === "number" || value instanceof Number` instead. */
50
+ export function isNumber(value: unknown): boolean {
51
+ return typeof value === "number" || value instanceof Number;
52
+ }
53
+
54
+ /** @deprecated - use `typeof value === "string" || value instanceof String` instead. */
55
+ export function isString(value: unknown): boolean {
56
+ return typeof value === "string" || value instanceof String;
57
+ }
58
+
59
+ /** @deprecated - use `typeof value === "symbol"` instead. */
60
+ export function isSymbol(value: unknown): boolean {
61
+ return typeof value === "symbol";
62
+ }
63
+
64
+ /** @deprecated - use `value === undefined` instead. */
65
+ export function isUndefined(value: unknown): boolean {
66
+ return value === undefined;
67
+ }
68
+
69
+ /** @deprecated - use `value !== null && typeof value === "object"` instead. */
70
+ export function isObject(value: unknown): boolean {
71
+ return value !== null && typeof value === "object";
72
+ }
73
+
74
+ /** @deprecated - use `e instanceof Error` instead. */
75
+ export function isError(e: unknown): boolean {
76
+ return e instanceof Error;
77
+ }
78
+
79
+ /** @deprecated - use `typeof value === "function"` instead. */
80
+ export function isFunction(value: unknown): boolean {
81
+ return typeof value === "function";
82
+ }
83
+
84
+ /** @deprecated Use util.types.RegExp() instead. */
85
+ export function isRegExp(value: unknown): boolean {
86
+ return types.isRegExp(value);
87
+ }
88
+
89
+ /** @deprecated Use util.types.isDate() instead. */
90
+ export function isDate(value: unknown): boolean {
91
+ return types.isDate(value);
92
+ }
93
+
94
+ /** @deprecated - use `value === null || (typeof value !== "object" && typeof value !== "function")` instead. */
95
+ export function isPrimitive(value: unknown): boolean {
96
+ return (
97
+ value === null || (typeof value !== "object" && typeof value !== "function")
98
+ );
99
+ }
100
+
101
+ /** @deprecated Use Buffer.isBuffer() instead. */
102
+ export function isBuffer(value: unknown): boolean {
103
+ return Buffer.isBuffer(value);
104
+ }
105
+
106
+ /** @deprecated Use Object.assign() instead. */
107
+ export function _extend(
108
+ target: Record<string, unknown>,
109
+ source: unknown,
110
+ ): Record<string, unknown> {
111
+ // Don't do anything if source isn't an object
112
+ if (source === null || typeof source !== "object") return target;
113
+
114
+ const keys = Object.keys(source!);
115
+ let i = keys.length;
116
+ while (i--) {
117
+ target[keys[i]] = (source as Record<string, unknown>)[keys[i]];
118
+ }
119
+ return target;
120
+ }
121
+
122
+ /**
123
+ * https://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor
124
+ * @param ctor Constructor function which needs to inherit the prototype.
125
+ * @param superCtor Constructor function to inherit prototype from.
126
+ */
127
+ export function inherits<T, U>(
128
+ ctor: new (...args: unknown[]) => T,
129
+ superCtor: new (...args: unknown[]) => U,
130
+ ) {
131
+ if (ctor === undefined || ctor === null) {
132
+ throw new codes.ERR_INVALID_ARG_TYPE("ctor", "Function", ctor);
133
+ }
134
+
135
+ if (superCtor === undefined || superCtor === null) {
136
+ throw new codes.ERR_INVALID_ARG_TYPE("superCtor", "Function", superCtor);
137
+ }
138
+
139
+ if (superCtor.prototype === undefined) {
140
+ throw new codes.ERR_INVALID_ARG_TYPE(
141
+ "superCtor.prototype",
142
+ "Object",
143
+ superCtor.prototype,
144
+ );
145
+ }
146
+ Object.defineProperty(ctor, "super_", {
147
+ value: superCtor,
148
+ writable: true,
149
+ configurable: true,
150
+ });
151
+ Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
152
+ }
153
+
154
+ import { _TextDecoder, _TextEncoder, getSystemErrorName } from "./_utils.ts";
155
+
156
+ /** The global TextDecoder */
157
+ export type TextDecoder = import("./_utils.ts")._TextDecoder;
158
+ export const TextDecoder = _TextDecoder;
159
+
160
+ /** The global TextEncoder */
161
+ export type TextEncoder = import("./_utils.ts")._TextEncoder;
162
+ export const TextEncoder = _TextEncoder;
163
+
164
+ function pad(n: number) {
165
+ return n.toString().padStart(2, "0");
166
+ }
167
+
168
+ const months = [
169
+ "Jan",
170
+ "Feb",
171
+ "Mar",
172
+ "Apr",
173
+ "May",
174
+ "Jun",
175
+ "Jul",
176
+ "Aug",
177
+ "Sep",
178
+ "Oct",
179
+ "Nov",
180
+ "Dec",
181
+ ];
182
+
183
+ /**
184
+ * @returns 26 Feb 16:19:34
185
+ */
186
+ function timestamp(): string {
187
+ const d = new Date();
188
+ const t = [
189
+ pad(d.getHours()),
190
+ pad(d.getMinutes()),
191
+ pad(d.getSeconds()),
192
+ ].join(":");
193
+ return `${(d.getDate())} ${months[(d).getMonth()]} ${t}`;
194
+ }
195
+
196
+ /**
197
+ * Log is just a thin wrapper to console.log that prepends a timestamp
198
+ * @deprecated
199
+ */
200
+ // deno-lint-ignore no-explicit-any
201
+ export function log(...args: any[]) {
202
+ console.log("%s - %s", timestamp(), format(...args));
203
+ }
204
+
205
+ // Keep a list of deprecation codes that have been warned on so we only warn on
206
+ // each one once.
207
+ const codesWarned = new Set();
208
+
209
+ // Mark that a method should not be used.
210
+ // Returns a modified function which warns once by default.
211
+ // If --no-deprecation is set, then it is a no-op.
212
+ // deno-lint-ignore no-explicit-any
213
+ export function deprecate(fn: any, msg: string, code?: any) {
214
+ if (process.noDeprecation === true) {
215
+ return fn;
216
+ }
217
+
218
+ if (code !== undefined) {
219
+ validateString(code, "code");
220
+ }
221
+
222
+ let warned = false;
223
+ // deno-lint-ignore no-explicit-any
224
+ function deprecated(this: any, ...args: any[]) {
225
+ if (!warned) {
226
+ warned = true;
227
+ if (code !== undefined) {
228
+ if (!codesWarned.has(code)) {
229
+ process.emitWarning(msg, "DeprecationWarning", code, deprecated);
230
+ codesWarned.add(code);
231
+ }
232
+ } else {
233
+ // deno-lint-ignore no-explicit-any
234
+ process.emitWarning(msg, "DeprecationWarning", deprecated as any);
235
+ }
236
+ }
237
+ if (new.target) {
238
+ return Reflect.construct(fn, args, new.target);
239
+ }
240
+ return Reflect.apply(fn, this, args);
241
+ }
242
+
243
+ // The wrapper will keep the same prototype as fn to maintain prototype chain
244
+ Object.setPrototypeOf(deprecated, fn);
245
+ if (fn.prototype) {
246
+ // Setting this (rather than using Object.setPrototype, as above) ensures
247
+ // that calling the unwrapped constructor gives an instanceof the wrapped
248
+ // constructor.
249
+ deprecated.prototype = fn.prototype;
250
+ }
251
+
252
+ return deprecated;
253
+ }
254
+
255
+ export { getSystemErrorName, isDeepStrictEqual };
256
+
257
+ export default {
258
+ format,
259
+ formatWithOptions,
260
+ inspect,
261
+ isArray,
262
+ isBoolean,
263
+ isNull,
264
+ isNullOrUndefined,
265
+ isNumber,
266
+ isString,
267
+ isSymbol,
268
+ isUndefined,
269
+ isObject,
270
+ isError,
271
+ isFunction,
272
+ isRegExp,
273
+ isDate,
274
+ isPrimitive,
275
+ isBuffer,
276
+ _extend,
277
+ getSystemErrorName,
278
+ deprecate,
279
+ callbackify,
280
+ promisify,
281
+ inherits,
282
+ types,
283
+ stripVTControlCharacters,
284
+ TextDecoder,
285
+ TextEncoder,
286
+ log,
287
+ debuglog,
288
+ isDeepStrictEqual,
289
+ };