@nodetool-ai/sandbox-runtime 0.0.0-stage → 0.8.9-beta.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.
- package/README.md +24 -2
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/host-access-gate.d.ts +24 -0
- package/dist/host-access-gate.d.ts.map +1 -0
- package/dist/host-access-gate.js +31 -0
- package/dist/host-access-gate.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +318 -0
- package/dist/index.js.map +1 -0
- package/dist/js-sandbox-worker/engine.d.ts +4 -0
- package/dist/js-sandbox-worker/engine.d.ts.map +1 -0
- package/dist/js-sandbox-worker/engine.js +82 -0
- package/dist/js-sandbox-worker/engine.js.map +1 -0
- package/dist/js-sandbox-worker/host.d.ts +136 -0
- package/dist/js-sandbox-worker/host.d.ts.map +1 -0
- package/dist/js-sandbox-worker/host.js +482 -0
- package/dist/js-sandbox-worker/host.js.map +1 -0
- package/dist/js-sandbox-worker/interpreter.d.ts +276 -0
- package/dist/js-sandbox-worker/interpreter.d.ts.map +1 -0
- package/dist/js-sandbox-worker/interpreter.js +1318 -0
- package/dist/js-sandbox-worker/interpreter.js.map +1 -0
- package/dist/js-sandbox-worker/protocol.d.ts +168 -0
- package/dist/js-sandbox-worker/protocol.d.ts.map +1 -0
- package/dist/js-sandbox-worker/protocol.js +217 -0
- package/dist/js-sandbox-worker/protocol.js.map +1 -0
- package/dist/js-sandbox-worker/worker-entry.d.ts +26 -0
- package/dist/js-sandbox-worker/worker-entry.d.ts.map +1 -0
- package/dist/js-sandbox-worker/worker-entry.js +308 -0
- package/dist/js-sandbox-worker/worker-entry.js.map +1 -0
- package/dist/limits.d.ts +77 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/limits.js +56 -0
- package/dist/limits.js.map +1 -0
- package/dist/sandbox-bootstrap-modules.d.ts +54 -0
- package/dist/sandbox-bootstrap-modules.d.ts.map +1 -0
- package/dist/sandbox-bootstrap-modules.js +104 -0
- package/dist/sandbox-bootstrap-modules.js.map +1 -0
- package/dist/sandbox-bytes.d.ts +43 -0
- package/dist/sandbox-bytes.d.ts.map +1 -0
- package/dist/sandbox-bytes.js +61 -0
- package/dist/sandbox-bytes.js.map +1 -0
- package/dist/sandbox-canvas-api.d.ts +30 -0
- package/dist/sandbox-canvas-api.d.ts.map +1 -0
- package/dist/sandbox-canvas-api.js +81 -0
- package/dist/sandbox-canvas-api.js.map +1 -0
- package/dist/sandbox-constants.d.ts +5 -0
- package/dist/sandbox-constants.d.ts.map +1 -0
- package/dist/sandbox-constants.js +13 -0
- package/dist/sandbox-constants.js.map +1 -0
- package/dist/sandbox-json-transport.d.ts +107 -0
- package/dist/sandbox-json-transport.d.ts.map +1 -0
- package/dist/sandbox-json-transport.js +324 -0
- package/dist/sandbox-json-transport.js.map +1 -0
- package/dist/timeline-capture.d.ts +21 -0
- package/dist/timeline-capture.d.ts.map +1 -0
- package/dist/timeline-capture.js +564 -0
- package/dist/timeline-capture.js.map +1 -0
- package/dist/utils/type-guards.d.ts +26 -0
- package/dist/utils/type-guards.d.ts.map +1 -0
- package/dist/utils/type-guards.js +44 -0
- package/dist/utils/type-guards.js.map +1 -0
- package/package.json +138 -4
- package/vendor/README.md +17 -0
- package/vendor/quickjs/LICENSE +21 -0
- package/vendor/quickjs/PROVENANCE.json +8 -0
- package/vendor/quickjs/adapter/fetch.d.ts +56 -0
- package/vendor/quickjs/adapter/fetch.js +140 -0
- package/vendor/quickjs/createTimeInterval.d.ts +9 -0
- package/vendor/quickjs/createTimeInterval.js +22 -0
- package/vendor/quickjs/createVirtualFileSystem.d.ts +13 -0
- package/vendor/quickjs/createVirtualFileSystem.js +191 -0
- package/vendor/quickjs/index.d.ts +77 -0
- package/vendor/quickjs/index.js +77 -0
- package/vendor/quickjs/loadAsyncQuickJs.d.ts +12 -0
- package/vendor/quickjs/loadAsyncQuickJs.js +66 -0
- package/vendor/quickjs/loadQuickJs.d.ts +12 -0
- package/vendor/quickjs/loadQuickJs.js +73 -0
- package/vendor/quickjs/modules/assert.d.ts +2 -0
- package/vendor/quickjs/modules/assert.js +47 -0
- package/vendor/quickjs/modules/buffer.d.ts +2 -0
- package/vendor/quickjs/modules/buffer.js +106 -0
- package/vendor/quickjs/modules/build/test-lib.js +2 -0
- package/vendor/quickjs/modules/events.d.ts +2 -0
- package/vendor/quickjs/modules/events.js +4 -0
- package/vendor/quickjs/modules/fs.d.ts +2 -0
- package/vendor/quickjs/modules/fs.js +76 -0
- package/vendor/quickjs/modules/fs_promises.d.ts +2 -0
- package/vendor/quickjs/modules/fs_promises.js +328 -0
- package/vendor/quickjs/modules/module.d.ts +2 -0
- package/vendor/quickjs/modules/module.js +33 -0
- package/vendor/quickjs/modules/nodeCompatibility/headers.d.ts +2 -0
- package/vendor/quickjs/modules/nodeCompatibility/headers.js +58 -0
- package/vendor/quickjs/modules/nodeCompatibility/request.d.ts +2 -0
- package/vendor/quickjs/modules/nodeCompatibility/request.js +5 -0
- package/vendor/quickjs/modules/nodeCompatibility/response.d.ts +2 -0
- package/vendor/quickjs/modules/nodeCompatibility/response.js +5 -0
- package/vendor/quickjs/modules/path.d.ts +2 -0
- package/vendor/quickjs/modules/path.js +504 -0
- package/vendor/quickjs/modules/process.d.ts +2 -0
- package/vendor/quickjs/modules/process.js +309 -0
- package/vendor/quickjs/modules/punycode.d.ts +2 -0
- package/vendor/quickjs/modules/punycode.js +443 -0
- package/vendor/quickjs/modules/querystring.d.ts +2 -0
- package/vendor/quickjs/modules/querystring.js +15 -0
- package/vendor/quickjs/modules/string_decoder.d.ts +2 -0
- package/vendor/quickjs/modules/string_decoder.js +223 -0
- package/vendor/quickjs/modules/timers.d.ts +2 -0
- package/vendor/quickjs/modules/timers.js +10 -0
- package/vendor/quickjs/modules/timers_promises.d.ts +2 -0
- package/vendor/quickjs/modules/timers_promises.js +40 -0
- package/vendor/quickjs/modules/url.d.ts +2 -0
- package/vendor/quickjs/modules/url.js +104 -0
- package/vendor/quickjs/modules/util.d.ts +2 -0
- package/vendor/quickjs/modules/util.js +233 -0
- package/vendor/quickjs/package.json +3 -0
- package/vendor/quickjs/sandbox/asyncVersion/createAsyncEvalCodeFunction.d.ts +4 -0
- package/vendor/quickjs/sandbox/asyncVersion/createAsyncEvalCodeFunction.js +76 -0
- package/vendor/quickjs/sandbox/asyncVersion/createAsyncValidateCodeFunction.d.ts +3 -0
- package/vendor/quickjs/sandbox/asyncVersion/createAsyncValidateCodeFunction.js +22 -0
- package/vendor/quickjs/sandbox/asyncVersion/executeAsyncSandboxFunction.d.ts +12 -0
- package/vendor/quickjs/sandbox/asyncVersion/executeAsyncSandboxFunction.js +9 -0
- package/vendor/quickjs/sandbox/asyncVersion/getAsyncModuleLoader.d.ts +4 -0
- package/vendor/quickjs/sandbox/asyncVersion/getAsyncModuleLoader.js +30 -0
- package/vendor/quickjs/sandbox/asyncVersion/modulePathNormalizerAsync.d.ts +2 -0
- package/vendor/quickjs/sandbox/asyncVersion/modulePathNormalizerAsync.js +12 -0
- package/vendor/quickjs/sandbox/asyncVersion/prepareAsyncNodeCompatibility.d.ts +3 -0
- package/vendor/quickjs/sandbox/asyncVersion/prepareAsyncNodeCompatibility.js +11 -0
- package/vendor/quickjs/sandbox/asyncVersion/prepareAsyncSandbox.d.ts +4 -0
- package/vendor/quickjs/sandbox/asyncVersion/prepareAsyncSandbox.js +10 -0
- package/vendor/quickjs/sandbox/expose/expose.d.ts +3 -0
- package/vendor/quickjs/sandbox/expose/expose.js +155 -0
- package/vendor/quickjs/sandbox/expose/isES2015Class.d.ts +1 -0
- package/vendor/quickjs/sandbox/expose/isES2015Class.js +4 -0
- package/vendor/quickjs/sandbox/expose/isObject.d.ts +1 -0
- package/vendor/quickjs/sandbox/expose/isObject.js +4 -0
- package/vendor/quickjs/sandbox/expose/pendingHostPromises.d.ts +6 -0
- package/vendor/quickjs/sandbox/expose/pendingHostPromises.js +40 -0
- package/vendor/quickjs/sandbox/getMaxIntervalAmount.d.ts +8 -0
- package/vendor/quickjs/sandbox/getMaxIntervalAmount.js +12 -0
- package/vendor/quickjs/sandbox/getMaxTimeoutAmount.d.ts +8 -0
- package/vendor/quickjs/sandbox/getMaxTimeoutAmount.js +12 -0
- package/vendor/quickjs/sandbox/handleEvalError.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleEvalError.js +21 -0
- package/vendor/quickjs/sandbox/handleToNative/handleToNative.d.ts +9 -0
- package/vendor/quickjs/sandbox/handleToNative/handleToNative.js +153 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/index.d.ts +10 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/index.js +36 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeArrayBuffer.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeArrayBuffer.js +4 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeBuffer.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeBuffer.js +16 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeDate.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeDate.js +16 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeError.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeError.js +18 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeHeaders.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeHeaders.js +17 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeMap.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeMap.js +18 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeSet.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeSet.js +16 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeURLSearchParams.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeURLSearchParams.js +17 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeUrl.d.ts +2 -0
- package/vendor/quickjs/sandbox/handleToNative/serializer/serializeUrl.js +17 -0
- package/vendor/quickjs/sandbox/helper.d.ts +2 -0
- package/vendor/quickjs/sandbox/helper.js +14 -0
- package/vendor/quickjs/sandbox/provide/provideConsole.d.ts +6 -0
- package/vendor/quickjs/sandbox/provide/provideConsole.js +53 -0
- package/vendor/quickjs/sandbox/provide/provideEnv.d.ts +3 -0
- package/vendor/quickjs/sandbox/provide/provideEnv.js +10 -0
- package/vendor/quickjs/sandbox/provide/provideFs.d.ts +4 -0
- package/vendor/quickjs/sandbox/provide/provideFs.js +159 -0
- package/vendor/quickjs/sandbox/provide/provideHttp.d.ts +9 -0
- package/vendor/quickjs/sandbox/provide/provideHttp.js +42 -0
- package/vendor/quickjs/sandbox/provide/provideTimingFunctions.d.ts +7 -0
- package/vendor/quickjs/sandbox/provide/provideTimingFunctions.js +119 -0
- package/vendor/quickjs/sandbox/setupFileSystem.d.ts +3 -0
- package/vendor/quickjs/sandbox/setupFileSystem.js +13 -0
- package/vendor/quickjs/sandbox/syncVersion/createEvalCodeFunction.d.ts +4 -0
- package/vendor/quickjs/sandbox/syncVersion/createEvalCodeFunction.js +76 -0
- package/vendor/quickjs/sandbox/syncVersion/createValidateCodeFunction.d.ts +3 -0
- package/vendor/quickjs/sandbox/syncVersion/createValidateCodeFunction.js +22 -0
- package/vendor/quickjs/sandbox/syncVersion/executeSandboxFunction.d.ts +12 -0
- package/vendor/quickjs/sandbox/syncVersion/executeSandboxFunction.js +9 -0
- package/vendor/quickjs/sandbox/syncVersion/getModuleLoader.d.ts +4 -0
- package/vendor/quickjs/sandbox/syncVersion/getModuleLoader.js +30 -0
- package/vendor/quickjs/sandbox/syncVersion/modulePathNormalizer.d.ts +2 -0
- package/vendor/quickjs/sandbox/syncVersion/modulePathNormalizer.js +12 -0
- package/vendor/quickjs/sandbox/syncVersion/prepareNodeCompatibility.d.ts +3 -0
- package/vendor/quickjs/sandbox/syncVersion/prepareNodeCompatibility.js +11 -0
- package/vendor/quickjs/sandbox/syncVersion/prepareSandbox.d.ts +4 -0
- package/vendor/quickjs/sandbox/syncVersion/prepareSandbox.js +10 -0
- package/vendor/quickjs/types/CodeFunctionInput.d.ts +12 -0
- package/vendor/quickjs/types/CodeFunctionInput.js +1 -0
- package/vendor/quickjs/types/ErrorResponse.d.ts +9 -0
- package/vendor/quickjs/types/ErrorResponse.js +1 -0
- package/vendor/quickjs/types/LoadQuickJsOptions.d.ts +3 -0
- package/vendor/quickjs/types/LoadQuickJsOptions.js +1 -0
- package/vendor/quickjs/types/OkResponse.d.ts +4 -0
- package/vendor/quickjs/types/OkResponse.js +1 -0
- package/vendor/quickjs/types/OkResponseCheck.d.ts +3 -0
- package/vendor/quickjs/types/OkResponseCheck.js +1 -0
- package/vendor/quickjs/types/Prettify.d.ts +3 -0
- package/vendor/quickjs/types/Prettify.js +1 -0
- package/vendor/quickjs/types/RuntimeOptions.d.ts +87 -0
- package/vendor/quickjs/types/RuntimeOptions.js +1 -0
- package/vendor/quickjs/types/SandboxEvalCode.d.ts +5 -0
- package/vendor/quickjs/types/SandboxEvalCode.js +1 -0
- package/vendor/quickjs/types/SandboxFunction.d.ts +16 -0
- package/vendor/quickjs/types/SandboxFunction.js +1 -0
- package/vendor/quickjs/types/SandboxOptions.d.ts +152 -0
- package/vendor/quickjs/types/SandboxOptions.js +1 -0
- package/vendor/quickjs/types/SandboxValidateCode.d.ts +9 -0
- package/vendor/quickjs/types/SandboxValidateCode.js +1 -0
- package/vendor/quickjs/types/Serializer.d.ts +2 -0
- package/vendor/quickjs/types/Serializer.js +1 -0
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
export default `
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/** Highest positive signed 32-bit float value */
|
|
5
|
+
const maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
|
|
6
|
+
|
|
7
|
+
/** Bootstring parameters */
|
|
8
|
+
const base = 36;
|
|
9
|
+
const tMin = 1;
|
|
10
|
+
const tMax = 26;
|
|
11
|
+
const skew = 38;
|
|
12
|
+
const damp = 700;
|
|
13
|
+
const initialBias = 72;
|
|
14
|
+
const initialN = 128; // 0x80
|
|
15
|
+
const delimiter = '-'; // '\x2D'
|
|
16
|
+
|
|
17
|
+
/** Regular expressions */
|
|
18
|
+
const regexPunycode = /^xn--/;
|
|
19
|
+
const regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
|
|
20
|
+
const regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
|
|
21
|
+
|
|
22
|
+
/** Error messages */
|
|
23
|
+
const errors = {
|
|
24
|
+
'overflow': 'Overflow: input needs wider integers to process',
|
|
25
|
+
'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
|
|
26
|
+
'invalid-input': 'Invalid input'
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** Convenience shortcuts */
|
|
30
|
+
const baseMinusTMin = base - tMin;
|
|
31
|
+
const floor = Math.floor;
|
|
32
|
+
const stringFromCharCode = String.fromCharCode;
|
|
33
|
+
|
|
34
|
+
/*--------------------------------------------------------------------------*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A generic error utility function.
|
|
38
|
+
* @private
|
|
39
|
+
* @param {String} type The error type.
|
|
40
|
+
* @returns {Error} Throws a \`RangeError\` with the applicable error message.
|
|
41
|
+
*/
|
|
42
|
+
function error(type) {
|
|
43
|
+
throw new RangeError(errors[type]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A generic \`Array#map\` utility function.
|
|
48
|
+
* @private
|
|
49
|
+
* @param {Array} array The array to iterate over.
|
|
50
|
+
* @param {Function} callback The function that gets called for every array
|
|
51
|
+
* item.
|
|
52
|
+
* @returns {Array} A new array of values returned by the callback function.
|
|
53
|
+
*/
|
|
54
|
+
function map(array, fn) {
|
|
55
|
+
const result = [];
|
|
56
|
+
let length = array.length;
|
|
57
|
+
while (length--) {
|
|
58
|
+
result[length] = fn(array[length]);
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A simple \`Array#map\`-like wrapper to work with domain name strings or email
|
|
65
|
+
* addresses.
|
|
66
|
+
* @private
|
|
67
|
+
* @param {String} domain The domain name or email address.
|
|
68
|
+
* @param {Function} callback The function that gets called for every
|
|
69
|
+
* character.
|
|
70
|
+
* @returns {Array} A new string of characters returned by the callback
|
|
71
|
+
* function.
|
|
72
|
+
*/
|
|
73
|
+
function mapDomain(string, fn) {
|
|
74
|
+
const parts = string.split('@');
|
|
75
|
+
let result = '';
|
|
76
|
+
if (parts.length > 1) {
|
|
77
|
+
// In email addresses, only the domain name should be punycoded. Leave
|
|
78
|
+
// the local part (i.e. everything up to \`@\`) intact.
|
|
79
|
+
result = parts[0] + '@';
|
|
80
|
+
string = parts[1];
|
|
81
|
+
}
|
|
82
|
+
// Avoid \`split(regex)\` for IE8 compatibility. See #17.
|
|
83
|
+
string = string.replace(regexSeparators, '\x2E');
|
|
84
|
+
const labels = string.split('.');
|
|
85
|
+
const encoded = map(labels, fn).join('.');
|
|
86
|
+
return result + encoded;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Creates an array containing the numeric code points of each Unicode
|
|
91
|
+
* character in the string. While JavaScript uses UCS-2 internally,
|
|
92
|
+
* this function will convert a pair of surrogate halves (each of which
|
|
93
|
+
* UCS-2 exposes as separate characters) into a single code point,
|
|
94
|
+
* matching UTF-16.
|
|
95
|
+
* @see \`punycode.ucs2.encode\`
|
|
96
|
+
* @see <https://mathiasbynens.be/notes/javascript-encoding>
|
|
97
|
+
* @memberOf punycode.ucs2
|
|
98
|
+
* @name decode
|
|
99
|
+
* @param {String} string The Unicode input string (UCS-2).
|
|
100
|
+
* @returns {Array} The new array of code points.
|
|
101
|
+
*/
|
|
102
|
+
function ucs2decode(string) {
|
|
103
|
+
const output = [];
|
|
104
|
+
let counter = 0;
|
|
105
|
+
const length = string.length;
|
|
106
|
+
while (counter < length) {
|
|
107
|
+
const value = string.charCodeAt(counter++);
|
|
108
|
+
if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
|
|
109
|
+
// It's a high surrogate, and there is a next character.
|
|
110
|
+
const extra = string.charCodeAt(counter++);
|
|
111
|
+
if ((extra & 0xFC00) == 0xDC00) { // Low surrogate.
|
|
112
|
+
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
|
|
113
|
+
} else {
|
|
114
|
+
// It's an unmatched surrogate; only append this code unit, in case the
|
|
115
|
+
// next code unit is the high surrogate of a surrogate pair.
|
|
116
|
+
output.push(value);
|
|
117
|
+
counter--;
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
output.push(value);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return output;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Creates a string based on an array of numeric code points.
|
|
128
|
+
* @see \`punycode.ucs2.decode\`
|
|
129
|
+
* @memberOf punycode.ucs2
|
|
130
|
+
* @name encode
|
|
131
|
+
* @param {Array} codePoints The array of numeric code points.
|
|
132
|
+
* @returns {String} The new Unicode string (UCS-2).
|
|
133
|
+
*/
|
|
134
|
+
const ucs2encode = array => String.fromCodePoint(...array);
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Converts a basic code point into a digit/integer.
|
|
138
|
+
* @see \`digitToBasic()\`
|
|
139
|
+
* @private
|
|
140
|
+
* @param {Number} codePoint The basic numeric code point value.
|
|
141
|
+
* @returns {Number} The numeric value of a basic code point (for use in
|
|
142
|
+
* representing integers) in the range \`0\` to \`base - 1\`, or \`base\` if
|
|
143
|
+
* the code point does not represent a value.
|
|
144
|
+
*/
|
|
145
|
+
const basicToDigit = function(codePoint) {
|
|
146
|
+
if (codePoint - 0x30 < 0x0A) {
|
|
147
|
+
return codePoint - 0x16;
|
|
148
|
+
}
|
|
149
|
+
if (codePoint - 0x41 < 0x1A) {
|
|
150
|
+
return codePoint - 0x41;
|
|
151
|
+
}
|
|
152
|
+
if (codePoint - 0x61 < 0x1A) {
|
|
153
|
+
return codePoint - 0x61;
|
|
154
|
+
}
|
|
155
|
+
return base;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Converts a digit/integer into a basic code point.
|
|
160
|
+
* @see \`basicToDigit()\`
|
|
161
|
+
* @private
|
|
162
|
+
* @param {Number} digit The numeric value of a basic code point.
|
|
163
|
+
* @returns {Number} The basic code point whose value (when used for
|
|
164
|
+
* representing integers) is \`digit\`, which needs to be in the range
|
|
165
|
+
* \`0\` to \`base - 1\`. If \`flag\` is non-zero, the uppercase form is
|
|
166
|
+
* used; else, the lowercase form is used. The behavior is undefined
|
|
167
|
+
* if \`flag\` is non-zero and \`digit\` has no uppercase form.
|
|
168
|
+
*/
|
|
169
|
+
const digitToBasic = function(digit, flag) {
|
|
170
|
+
// 0..25 map to ASCII a..z or A..Z
|
|
171
|
+
// 26..35 map to ASCII 0..9
|
|
172
|
+
return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Bias adaptation function as per section 3.4 of RFC 3492.
|
|
177
|
+
* https://tools.ietf.org/html/rfc3492#section-3.4
|
|
178
|
+
* @private
|
|
179
|
+
*/
|
|
180
|
+
const adapt = function(delta, numPoints, firstTime) {
|
|
181
|
+
let k = 0;
|
|
182
|
+
delta = firstTime ? floor(delta / damp) : delta >> 1;
|
|
183
|
+
delta += floor(delta / numPoints);
|
|
184
|
+
for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
|
|
185
|
+
delta = floor(delta / baseMinusTMin);
|
|
186
|
+
}
|
|
187
|
+
return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Converts a Punycode string of ASCII-only symbols to a string of Unicode
|
|
192
|
+
* symbols.
|
|
193
|
+
* @memberOf punycode
|
|
194
|
+
* @param {String} input The Punycode string of ASCII-only symbols.
|
|
195
|
+
* @returns {String} The resulting string of Unicode symbols.
|
|
196
|
+
*/
|
|
197
|
+
const decode = function(input) {
|
|
198
|
+
// Don't use UCS-2.
|
|
199
|
+
const output = [];
|
|
200
|
+
const inputLength = input.length;
|
|
201
|
+
let i = 0;
|
|
202
|
+
let n = initialN;
|
|
203
|
+
let bias = initialBias;
|
|
204
|
+
|
|
205
|
+
// Handle the basic code points: let \`basic\` be the number of input code
|
|
206
|
+
// points before the last delimiter, or \`0\` if there is none, then copy
|
|
207
|
+
// the first basic code points to the output.
|
|
208
|
+
|
|
209
|
+
let basic = input.lastIndexOf(delimiter);
|
|
210
|
+
if (basic < 0) {
|
|
211
|
+
basic = 0;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
for (let j = 0; j < basic; ++j) {
|
|
215
|
+
// if it's not a basic code point
|
|
216
|
+
if (input.charCodeAt(j) >= 0x80) {
|
|
217
|
+
error('not-basic');
|
|
218
|
+
}
|
|
219
|
+
output.push(input.charCodeAt(j));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Main decoding loop: start just after the last delimiter if any basic code
|
|
223
|
+
// points were copied; start at the beginning otherwise.
|
|
224
|
+
|
|
225
|
+
for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
|
|
226
|
+
|
|
227
|
+
// \`index\` is the index of the next character to be consumed.
|
|
228
|
+
// Decode a generalized variable-length integer into \`delta\`,
|
|
229
|
+
// which gets added to \`i\`. The overflow checking is easier
|
|
230
|
+
// if we increase \`i\` as we go, then subtract off its starting
|
|
231
|
+
// value at the end to obtain \`delta\`.
|
|
232
|
+
let oldi = i;
|
|
233
|
+
for (let w = 1, k = base; /* no condition */; k += base) {
|
|
234
|
+
|
|
235
|
+
if (index >= inputLength) {
|
|
236
|
+
error('invalid-input');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const digit = basicToDigit(input.charCodeAt(index++));
|
|
240
|
+
|
|
241
|
+
if (digit >= base || digit > floor((maxInt - i) / w)) {
|
|
242
|
+
error('overflow');
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
i += digit * w;
|
|
246
|
+
const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
|
247
|
+
|
|
248
|
+
if (digit < t) {
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const baseMinusT = base - t;
|
|
253
|
+
if (w > floor(maxInt / baseMinusT)) {
|
|
254
|
+
error('overflow');
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
w *= baseMinusT;
|
|
258
|
+
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const out = output.length + 1;
|
|
262
|
+
bias = adapt(i - oldi, out, oldi == 0);
|
|
263
|
+
|
|
264
|
+
// \`i\` was supposed to wrap around from \`out\` to \`0\`,
|
|
265
|
+
// incrementing \`n\` each time, so we'll fix that now:
|
|
266
|
+
if (floor(i / out) > maxInt - n) {
|
|
267
|
+
error('overflow');
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
n += floor(i / out);
|
|
271
|
+
i %= out;
|
|
272
|
+
|
|
273
|
+
// Insert \`n\` at position \`i\` of the output.
|
|
274
|
+
output.splice(i++, 0, n);
|
|
275
|
+
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return String.fromCodePoint(...output);
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Converts a string of Unicode symbols (e.g. a domain name label) to a
|
|
283
|
+
* Punycode string of ASCII-only symbols.
|
|
284
|
+
* @memberOf punycode
|
|
285
|
+
* @param {String} input The string of Unicode symbols.
|
|
286
|
+
* @returns {String} The resulting Punycode string of ASCII-only symbols.
|
|
287
|
+
*/
|
|
288
|
+
const encode = function(input) {
|
|
289
|
+
const output = [];
|
|
290
|
+
|
|
291
|
+
// Convert the input in UCS-2 to an array of Unicode code points.
|
|
292
|
+
input = ucs2decode(input);
|
|
293
|
+
|
|
294
|
+
// Cache the length.
|
|
295
|
+
let inputLength = input.length;
|
|
296
|
+
|
|
297
|
+
// Initialize the state.
|
|
298
|
+
let n = initialN;
|
|
299
|
+
let delta = 0;
|
|
300
|
+
let bias = initialBias;
|
|
301
|
+
|
|
302
|
+
// Handle the basic code points.
|
|
303
|
+
for (const currentValue of input) {
|
|
304
|
+
if (currentValue < 0x80) {
|
|
305
|
+
output.push(stringFromCharCode(currentValue));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
let basicLength = output.length;
|
|
310
|
+
let handledCPCount = basicLength;
|
|
311
|
+
|
|
312
|
+
// \`handledCPCount\` is the number of code points that have been handled;
|
|
313
|
+
// \`basicLength\` is the number of basic code points.
|
|
314
|
+
|
|
315
|
+
// Finish the basic string with a delimiter unless it's empty.
|
|
316
|
+
if (basicLength) {
|
|
317
|
+
output.push(delimiter);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Main encoding loop:
|
|
321
|
+
while (handledCPCount < inputLength) {
|
|
322
|
+
|
|
323
|
+
// All non-basic code points < n have been handled already. Find the next
|
|
324
|
+
// larger one:
|
|
325
|
+
let m = maxInt;
|
|
326
|
+
for (const currentValue of input) {
|
|
327
|
+
if (currentValue >= n && currentValue < m) {
|
|
328
|
+
m = currentValue;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Increase \`delta\` enough to advance the decoder's <n,i> state to <m,0>,
|
|
333
|
+
// but guard against overflow.
|
|
334
|
+
const handledCPCountPlusOne = handledCPCount + 1;
|
|
335
|
+
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
|
|
336
|
+
error('overflow');
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
delta += (m - n) * handledCPCountPlusOne;
|
|
340
|
+
n = m;
|
|
341
|
+
|
|
342
|
+
for (const currentValue of input) {
|
|
343
|
+
if (currentValue < n && ++delta > maxInt) {
|
|
344
|
+
error('overflow');
|
|
345
|
+
}
|
|
346
|
+
if (currentValue == n) {
|
|
347
|
+
// Represent delta as a generalized variable-length integer.
|
|
348
|
+
let q = delta;
|
|
349
|
+
for (let k = base; /* no condition */; k += base) {
|
|
350
|
+
const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
|
351
|
+
if (q < t) {
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
const qMinusT = q - t;
|
|
355
|
+
const baseMinusT = base - t;
|
|
356
|
+
output.push(
|
|
357
|
+
stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
|
|
358
|
+
);
|
|
359
|
+
q = floor(qMinusT / baseMinusT);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
output.push(stringFromCharCode(digitToBasic(q, 0)));
|
|
363
|
+
bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
|
|
364
|
+
delta = 0;
|
|
365
|
+
++handledCPCount;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
++delta;
|
|
370
|
+
++n;
|
|
371
|
+
|
|
372
|
+
}
|
|
373
|
+
return output.join('');
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Converts a Punycode string representing a domain name or an email address
|
|
378
|
+
* to Unicode. Only the Punycoded parts of the input will be converted, i.e.
|
|
379
|
+
* it doesn't matter if you call it on a string that has already been
|
|
380
|
+
* converted to Unicode.
|
|
381
|
+
* @memberOf punycode
|
|
382
|
+
* @param {String} input The Punycoded domain name or email address to
|
|
383
|
+
* convert to Unicode.
|
|
384
|
+
* @returns {String} The Unicode representation of the given Punycode
|
|
385
|
+
* string.
|
|
386
|
+
*/
|
|
387
|
+
const toUnicode = function(input) {
|
|
388
|
+
return mapDomain(input, function(string) {
|
|
389
|
+
return regexPunycode.test(string)
|
|
390
|
+
? decode(string.slice(4).toLowerCase())
|
|
391
|
+
: string;
|
|
392
|
+
});
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Converts a Unicode string representing a domain name or an email address to
|
|
397
|
+
* Punycode. Only the non-ASCII parts of the domain name will be converted,
|
|
398
|
+
* i.e. it doesn't matter if you call it with a domain that's already in
|
|
399
|
+
* ASCII.
|
|
400
|
+
* @memberOf punycode
|
|
401
|
+
* @param {String} input The domain name or email address to convert, as a
|
|
402
|
+
* Unicode string.
|
|
403
|
+
* @returns {String} The Punycode representation of the given domain name or
|
|
404
|
+
* email address.
|
|
405
|
+
*/
|
|
406
|
+
const toASCII = function(input) {
|
|
407
|
+
return mapDomain(input, function(string) {
|
|
408
|
+
return regexNonASCII.test(string)
|
|
409
|
+
? 'xn--' + encode(string)
|
|
410
|
+
: string;
|
|
411
|
+
});
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
/*--------------------------------------------------------------------------*/
|
|
415
|
+
|
|
416
|
+
/** Define the public API */
|
|
417
|
+
const punycode = {
|
|
418
|
+
/**
|
|
419
|
+
* A string representing the current Punycode.js version number.
|
|
420
|
+
* @memberOf punycode
|
|
421
|
+
* @type String
|
|
422
|
+
*/
|
|
423
|
+
'version': '2.1.0',
|
|
424
|
+
/**
|
|
425
|
+
* An object of methods to convert from JavaScript's internal character
|
|
426
|
+
* representation (UCS-2) to Unicode code points, and back.
|
|
427
|
+
* @see <https://mathiasbynens.be/notes/javascript-encoding>
|
|
428
|
+
* @memberOf punycode
|
|
429
|
+
* @type Object
|
|
430
|
+
*/
|
|
431
|
+
'ucs2': {
|
|
432
|
+
'decode': ucs2decode,
|
|
433
|
+
'encode': ucs2encode
|
|
434
|
+
},
|
|
435
|
+
'decode': decode,
|
|
436
|
+
'encode': encode,
|
|
437
|
+
'toASCII': toASCII,
|
|
438
|
+
'toUnicode': toUnicode
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
export { ucs2decode, ucs2encode, decode, encode, toASCII, toUnicode };
|
|
442
|
+
export default punycode;
|
|
443
|
+
`;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: "\nfunction e(e, n) { return Object.prototype.hasOwnProperty.call(e, n) } var n = function (n, r, t, o) { r = r || \"&\", t = t || \"=\"; var a = {}; if (\"string\" != typeof n || 0 === n.length) { return a; } var u = /[+]/g; n = n.split(r); var c = 1e3; o && \"number\" == typeof o.maxKeys && (c = o.maxKeys); var i = n.length; c > 0 && i > c && (i = c); for (var s = 0; s < i; ++s) { var p, f, d, y, m = n[s].replace(u, \"%20\"), l = m.indexOf(t); l >= 0 ? (p = m.substr(0, l), f = m.substr(l + 1)) : (p = m, f = \"\"), d = decodeURIComponent(p), y = decodeURIComponent(f), e(a, d) ? Array.isArray(a[d]) ? a[d].push(y) : a[d] = [a[d], y] : a[d] = y; } return a }, r = function (e) { switch (typeof e) { case \"string\": return e; case \"boolean\": return e ? \"true\" : \"false\"; case \"number\": return isFinite(e) ? e : \"\"; default: return \"\" } }, t = function (e, n, t, o) { return n = n || \"&\", t = t || \"=\", null === e && (e = void 0), \"object\" == typeof e ? Object.keys(e).map((function (o) { var a = encodeURIComponent(r(o)) + t; return Array.isArray(e[o]) ? e[o].map((function (e) { return a + encodeURIComponent(r(e)) })).join(n) : a + encodeURIComponent(r(e[o])) })).join(n) : o ? encodeURIComponent(r(o)) + t + encodeURIComponent(r(e)) : \"\" }, o = {}; o.decode = o.parse = n, o.encode = o.stringify = t; o.decode; o.encode; o.parse; o.stringify;\n\no.decode;\no.encode;\no.parse;\no.stringify;\n\nvar decode = o.decode;\nvar encode = o.encode;\nvar parse = o.parse;\nvar stringify = o.stringify;\n\nexport { decode, o as default, encode, parse, stringify };\n";
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default `
|
|
2
|
+
function e(e, n) { return Object.prototype.hasOwnProperty.call(e, n) } var n = function (n, r, t, o) { r = r || "&", t = t || "="; var a = {}; if ("string" != typeof n || 0 === n.length) { return a; } var u = /[+]/g; n = n.split(r); var c = 1e3; o && "number" == typeof o.maxKeys && (c = o.maxKeys); var i = n.length; c > 0 && i > c && (i = c); for (var s = 0; s < i; ++s) { var p, f, d, y, m = n[s].replace(u, "%20"), l = m.indexOf(t); l >= 0 ? (p = m.substr(0, l), f = m.substr(l + 1)) : (p = m, f = ""), d = decodeURIComponent(p), y = decodeURIComponent(f), e(a, d) ? Array.isArray(a[d]) ? a[d].push(y) : a[d] = [a[d], y] : a[d] = y; } return a }, r = function (e) { switch (typeof e) { case "string": return e; case "boolean": return e ? "true" : "false"; case "number": return isFinite(e) ? e : ""; default: return "" } }, t = function (e, n, t, o) { return n = n || "&", t = t || "=", null === e && (e = void 0), "object" == typeof e ? Object.keys(e).map((function (o) { var a = encodeURIComponent(r(o)) + t; return Array.isArray(e[o]) ? e[o].map((function (e) { return a + encodeURIComponent(r(e)) })).join(n) : a + encodeURIComponent(r(e[o])) })).join(n) : o ? encodeURIComponent(r(o)) + t + encodeURIComponent(r(e)) : "" }, o = {}; o.decode = o.parse = n, o.encode = o.stringify = t; o.decode; o.encode; o.parse; o.stringify;
|
|
3
|
+
|
|
4
|
+
o.decode;
|
|
5
|
+
o.encode;
|
|
6
|
+
o.parse;
|
|
7
|
+
o.stringify;
|
|
8
|
+
|
|
9
|
+
var decode = o.decode;
|
|
10
|
+
var encode = o.encode;
|
|
11
|
+
var parse = o.parse;
|
|
12
|
+
var stringify = o.stringify;
|
|
13
|
+
|
|
14
|
+
export { decode, o as default, encode, parse, stringify };
|
|
15
|
+
`;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: "\n// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nimport {Buffer} from 'node:buffer';\n\nvar isBufferEncoding = Buffer.isEncoding\n || function(encoding) {\n switch (encoding && encoding.toLowerCase()) {\n case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true;\n default: return false;\n }\n }\n\n\nfunction assertEncoding(encoding) {\n if (encoding && !isBufferEncoding(encoding)) {\n throw new Error('Unknown encoding: ' + encoding);\n }\n}\n\n// StringDecoder provides an interface for efficiently splitting a series of\n// buffers into a series of JS strings without breaking apart multi-byte\n// characters. CESU-8 is handled as part of the UTF-8 encoding.\n//\n// @TODO Handling all encodings inside a single object makes it very difficult\n// to reason about this code, so it should be split up in the future.\n// @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code\n// points as used by CESU-8.\nexport function StringDecoder(encoding) {\n this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');\n assertEncoding(encoding);\n switch (this.encoding) {\n case 'utf8':\n // CESU-8 represents each of Surrogate Pair by 3-bytes\n this.surrogateSize = 3;\n break;\n case 'ucs2':\n case 'utf16le':\n // UTF-16 represents each of Surrogate Pair by 2-bytes\n this.surrogateSize = 2;\n this.detectIncompleteChar = utf16DetectIncompleteChar;\n break;\n case 'base64':\n // Base-64 stores 3 bytes in 4 chars, and pads the remainder.\n this.surrogateSize = 3;\n this.detectIncompleteChar = base64DetectIncompleteChar;\n break;\n default:\n this.write = passThroughWrite;\n return;\n }\n\n // Enough space to store all bytes of a single character. UTF-8 needs 4\n // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).\n this.charBuffer = new Buffer(6);\n // Number of bytes received for the current incomplete multi-byte character.\n this.charReceived = 0;\n // Number of bytes expected for the current incomplete multi-byte character.\n this.charLength = 0;\n};\n\n\n// write decodes the given buffer and returns it as JS string that is\n// guaranteed to not contain any partial multi-byte characters. Any partial\n// character found at the end of the buffer is buffered up, and will be\n// returned when calling write again with the remaining bytes.\n//\n// Note: Converting a Buffer containing an orphan surrogate to a String\n// currently works, but converting a String to a Buffer (via `new Buffer`, or\n// Buffer#write) will replace incomplete surrogates with the unicode\n// replacement character. See https://codereview.chromium.org/121173009/ .\nStringDecoder.prototype.write = function(buffer) {\n var charStr = '';\n // if our last write ended with an incomplete multibyte character\n while (this.charLength) {\n // determine how many remaining bytes this buffer has to offer for this char\n var available = (buffer.length >= this.charLength - this.charReceived) ?\n this.charLength - this.charReceived :\n buffer.length;\n\n // add the new bytes to the char buffer\n buffer.copy(this.charBuffer, this.charReceived, 0, available);\n this.charReceived += available;\n\n if (this.charReceived < this.charLength) {\n // still not enough chars in this buffer? wait for more ...\n return '';\n }\n\n // remove bytes belonging to the current character from the buffer\n buffer = buffer.slice(available, buffer.length);\n\n // get the character that was split\n charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);\n\n // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character\n var charCode = charStr.charCodeAt(charStr.length - 1);\n if (charCode >= 0xD800 && charCode <= 0xDBFF) {\n this.charLength += this.surrogateSize;\n charStr = '';\n continue;\n }\n this.charReceived = this.charLength = 0;\n\n // if there are no more bytes in this buffer, just emit our char\n if (buffer.length === 0) {\n return charStr;\n }\n break;\n }\n\n // determine and set charLength / charReceived\n this.detectIncompleteChar(buffer);\n\n var end = buffer.length;\n if (this.charLength) {\n // buffer the incomplete character bytes we got\n buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);\n end -= this.charReceived;\n }\n\n charStr += buffer.toString(this.encoding, 0, end);\n\n var end = charStr.length - 1;\n var charCode = charStr.charCodeAt(end);\n // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character\n if (charCode >= 0xD800 && charCode <= 0xDBFF) {\n var size = this.surrogateSize;\n this.charLength += size;\n this.charReceived += size;\n this.charBuffer.copy(this.charBuffer, size, 0, size);\n buffer.copy(this.charBuffer, 0, 0, size);\n return charStr.substring(0, end);\n }\n\n // or just emit the charStr\n return charStr;\n};\n\n// detectIncompleteChar determines if there is an incomplete UTF-8 character at\n// the end of the given buffer. If so, it sets this.charLength to the byte\n// length that character, and sets this.charReceived to the number of bytes\n// that are available for this character.\nStringDecoder.prototype.detectIncompleteChar = function(buffer) {\n // determine how many bytes we have to check at the end of this buffer\n var i = (buffer.length >= 3) ? 3 : buffer.length;\n\n // Figure out if one of the last i bytes of our buffer announces an\n // incomplete char.\n for (; i > 0; i--) {\n var c = buffer[buffer.length - i];\n\n // See http://en.wikipedia.org/wiki/UTF-8#Description\n\n // 110XXXXX\n if (i == 1 && c >> 5 == 0x06) {\n this.charLength = 2;\n break;\n }\n\n // 1110XXXX\n if (i <= 2 && c >> 4 == 0x0E) {\n this.charLength = 3;\n break;\n }\n\n // 11110XXX\n if (i <= 3 && c >> 3 == 0x1E) {\n this.charLength = 4;\n break;\n }\n }\n this.charReceived = i;\n};\n\nStringDecoder.prototype.end = function(buffer) {\n var res = '';\n if (buffer && buffer.length)\n res = this.write(buffer);\n\n if (this.charReceived) {\n var cr = this.charReceived;\n var buf = this.charBuffer;\n var enc = this.encoding;\n res += buf.slice(0, cr).toString(enc);\n }\n\n return res;\n};\n\nfunction passThroughWrite(buffer) {\n return buffer.toString(this.encoding);\n}\n\nfunction utf16DetectIncompleteChar(buffer) {\n this.charReceived = buffer.length % 2;\n this.charLength = this.charReceived ? 2 : 0;\n}\n\nfunction base64DetectIncompleteChar(buffer) {\n this.charReceived = buffer.length % 3;\n this.charLength = this.charReceived ? 3 : 0;\n}\n";
|
|
2
|
+
export default _default;
|