Initial commit - Dutchie dispensary scraper

This commit is contained in:
Kelly
2025-11-28 19:45:44 -07:00
commit 5757a8e9bd
23375 changed files with 3788799 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
import { Stream } from "./Stream";
/** @interface */
export interface Decoder {
/**
* @param {Stream} stream The stream of bytes being decoded.
* @param {number} bite The next byte read from the stream.
* @return {?(number|!Array.<number>)} The next code point(s)
* decoded, or null if not enough data exists in the input
* stream to decode a complete code point, or |finished|.
*/
handler(stream: Stream, bite: number): number | number[];
}

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=Decoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Decoder.js","sourceRoot":"","sources":["../../../src/common/Decoder.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,10 @@
import { Stream } from "./Stream";
/** @interface */
export interface Encoder {
/**
* @param {Stream} stream The stream of code points being encoded.
* @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.<number>)} Byte(s) to emit, or |finished|.
*/
handler(stream: Stream, code_point: number): number | number[];
}

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=Encoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Encoder.js","sourceRoot":"","sources":["../../../src/common/Encoder.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,44 @@
/**
* A stream represents an ordered sequence of tokens.
*/
export declare class Stream {
tokens: number[];
/**
*
* @constructor
* @param {!(Array.<number>|Uint8Array)} tokens Array of tokens that provide
* the stream.
*/
constructor(tokens: number[] | Uint8Array);
/**
* @return {boolean} True if end-of-stream has been hit.
*/
endOfStream(): boolean;
/**
* When a token is read from a stream, the first token in the
* stream must be returned and subsequently removed, and
* end-of-stream must be returned otherwise.
*
* @return {number} Get the next token from the stream, or
* end_of_stream.
*/
read(): number;
/**
* When one or more tokens are prepended to a stream, those tokens
* must be inserted, in given order, before the first token in the
* stream.
*
* @param {(number|!Array.<number>)} token The token(s) to prepend to the
* stream.
*/
prepend(token: (number | Array<number>)): void;
/**
* When one or more tokens are pushed to a stream, those tokens
* must be inserted, in given order, after the last token in the
* stream.
*
* @param {(number|!Array.<number>)} token The tokens(s) to push to the
* stream.
*/
push(token: (number | Array<number>)): void;
}

View File

@@ -0,0 +1,78 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var terminology_1 = require("../encoding/terminology");
/**
* A stream represents an ordered sequence of tokens.
*/
var Stream = /** @class */ (function () {
/**
*
* @constructor
* @param {!(Array.<number>|Uint8Array)} tokens Array of tokens that provide
* the stream.
*/
function Stream(tokens) {
/** @type {!Array.<number>} */
this.tokens = Array.from(tokens);
// Reversed as push/pop is more efficient than shift/unshift.
this.tokens.reverse();
}
/**
* @return {boolean} True if end-of-stream has been hit.
*/
Stream.prototype.endOfStream = function () {
return !this.tokens.length;
};
/**
* When a token is read from a stream, the first token in the
* stream must be returned and subsequently removed, and
* end-of-stream must be returned otherwise.
*
* @return {number} Get the next token from the stream, or
* end_of_stream.
*/
Stream.prototype.read = function () {
if (!this.tokens.length)
return terminology_1.end_of_stream;
return this.tokens.pop();
};
/**
* When one or more tokens are prepended to a stream, those tokens
* must be inserted, in given order, before the first token in the
* stream.
*
* @param {(number|!Array.<number>)} token The token(s) to prepend to the
* stream.
*/
Stream.prototype.prepend = function (token) {
if (Array.isArray(token)) {
var tokens = (token);
while (tokens.length)
this.tokens.push(tokens.pop());
}
else {
this.tokens.push(token);
}
};
/**
* When one or more tokens are pushed to a stream, those tokens
* must be inserted, in given order, after the last token in the
* stream.
*
* @param {(number|!Array.<number>)} token The tokens(s) to push to the
* stream.
*/
Stream.prototype.push = function (token) {
if (Array.isArray(token)) {
var tokens = (token);
while (tokens.length)
this.tokens.unshift(tokens.shift());
}
else {
this.tokens.unshift(token);
}
};
return Stream;
}());
exports.Stream = Stream;
//# sourceMappingURL=Stream.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"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AAC,CAAC;SAC5B;IACH,CAAC;IACH,aAAC;AAAD,CAAC,AA3ED,IA2EC;AA3EY,wBAAM"}

View File

@@ -0,0 +1,38 @@
declare type TextDecoderOptions = {
fatal?: boolean;
ignoreBOM?: boolean;
};
declare type DecodeOptions = {
stream?: boolean;
};
/**
* @constructor
* @param {string=} label The label of the encoding;
* defaults to 'utf-8'.
* @param {Object=} options
*/
export declare class TextDecoder {
private _encoding;
private _decoder;
private _ignoreBOM;
private _BOMseen;
private _error_mode;
private _do_not_flush;
constructor(label?: string, options?: TextDecoderOptions);
get encoding(): string;
get fatal(): boolean;
get ignoreBOM(): boolean;
/**
* @param {BufferSource=} input The buffer of bytes to decode.
* @param {Object=} options
* @return {string} The decoded string.
*/
decode(input?: ArrayBuffer | ArrayLike<number> | Uint8Array, options?: DecodeOptions): string;
/**
* @param {!Array.<number>} stream
* @return {string}
* @this {TextDecoder}
*/
private serializeStream;
}
export {};

View File

@@ -0,0 +1,235 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var defaultEncoding_1 = require("../encoding/defaultEncoding");
var encoding_factory_1 = require("../encoding/encoding-factory");
var encodings_1 = require("../encoding/encodings");
var finished_1 = require("../encoding/finished");
var terminology_1 = require("../encoding/terminology");
var utilities_1 = require("../encoding/utilities");
var Stream_1 = require("./Stream");
/**
* @constructor
* @param {string=} label The label of the encoding;
* defaults to 'utf-8'.
* @param {Object=} options
*/
var TextDecoder = /** @class */ (function () {
function TextDecoder(label, options) {
label = label !== undefined ? String(label) : defaultEncoding_1.DEFAULT_ENCODING;
var optionsMap = utilities_1.ToDictionary(options);
// A TextDecoder object has an associated encoding, decoder,
// stream, ignore BOM flag (initially unset), BOM seen flag
// (initially unset), error mode (initially replacement), and do
// not flush flag (initially unset).
/** @private */
this._encoding = null;
/** @private @type {?Decoder} */
this._decoder = null;
/** @private @type {boolean} */
this._ignoreBOM = false;
/** @private @type {boolean} */
this._BOMseen = false;
/** @private @type {string} */
this._error_mode = 'replacement';
/** @private @type {boolean} */
this._do_not_flush = false;
// 1. Let encoding be the result of getting an encoding from
// label.
var encoding = encodings_1.getEncoding(label);
// 2. If encoding is failure or replacement, throw a RangeError.
if (encoding === null || encoding.name === 'replacement')
throw RangeError('Unknown encoding: ' + label);
if (!encoding_factory_1.decoders[encoding.name]) {
throw Error('Decoder not present.' +
' Did you forget to include encoding-indexes.js first?');
}
// 3. Let dec be a new TextDecoder object.
// const dec = this;
// no need to do this as this is a proper class
// now and TSC will handle transpilation to older platforms
// 4. Set dec's encoding to encoding.
this._encoding = encoding;
// 5. If options's fatal member is true, set dec's error mode to
// fatal.
if (Boolean(optionsMap['fatal']))
this._error_mode = 'fatal';
// 6. If options's ignoreBOM member is true, set dec's ignore BOM
// flag.
if (Boolean(optionsMap['ignoreBOM']))
this._ignoreBOM = true;
// For pre-ES5 runtimes:
// if (!Object.defineProperty) {
// this.encoding = dec._encoding.name.toLowerCase();
// this.fatal = dec._error_mode === 'fatal';
// this.ignoreBOM = dec._ignoreBOM;
// }
// 7. Return dec.
// return dec;
}
Object.defineProperty(TextDecoder.prototype, "encoding", {
// if (Object.defineProperty) {
// The encoding attribute's getter must return encoding's name.
// Object.defineProperty(TextDecoder.prototype, 'encoding', {
// /** @this {TextDecoder} */
// get: function () { return this._encoding.name.toLowerCase(); }
// });
get: function () {
return this._encoding.name.toLowerCase();
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextDecoder.prototype, "fatal", {
// The fatal attribute's getter must return true if error mode
// is fatal, and false otherwise.
// Object.defineProperty(TextDecoder.prototype, 'fatal', {
// /** @this {TextDecoder} */
// get: function () { return this._error_mode === 'fatal'; }
// });
get: function () {
return this._error_mode === 'fatal';
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextDecoder.prototype, "ignoreBOM", {
// The ignoreBOM attribute's getter must return true if ignore
// BOM flag is set, and false otherwise.
// Object.defineProperty(TextDecoder.prototype, 'ignoreBOM', {
// /** @this {TextDecoder} */
// get: function () { return this._ignoreBOM; }
// });
get: function () {
return this._ignoreBOM;
},
enumerable: true,
configurable: true
});
// }
/**
* @param {BufferSource=} input The buffer of bytes to decode.
* @param {Object=} options
* @return {string} The decoded string.
*/
TextDecoder.prototype.decode = function (input, options) {
var bytes = getBytesFromInput(input);
var optionsMap = utilities_1.ToDictionary(options);
// 1. If the do not flush flag is unset, set decoder to a new
// encoding's decoder, set stream to a new stream, and unset the
// BOM seen flag.
if (!this._do_not_flush) {
this._decoder = encoding_factory_1.decoders[this._encoding.name]({
fatal: this._error_mode === 'fatal'
});
this._BOMseen = false;
}
// 2. If options's stream is true, set the do not flush flag, and
// unset the do not flush flag otherwise.
this._do_not_flush = Boolean(optionsMap['stream']);
// 3. If input is given, push a copy of input to stream.
// TODO: Align with spec algorithm - maintain stream on instance.
var input_stream = new Stream_1.Stream(bytes);
// 4. Let output be a new stream.
var output = [];
/** @type {?(number|!Array.<number>)} */
var result;
// 5. While true:
while (true) {
// 1. Let token be the result of reading from stream.
var token = input_stream.read();
// 2. If token is end-of-stream and the do not flush flag is
// set, return output, serialized.
// TODO: Align with spec algorithm.
if (token === terminology_1.end_of_stream)
break;
// 3. Otherwise, run these subsubsteps:
// 1. Let result be the result of processing token for decoder,
// stream, output, and error mode.
result = this._decoder.handler(input_stream, token);
// 2. If result is finished, return output, serialized.
if (result === finished_1.finished)
break;
if (result !== null) {
if (Array.isArray(result))
output.push.apply(output, /**@type {!Array.<number>}*/ (result));
else
output.push(result);
}
// 3. Otherwise, if result is error, throw a TypeError.
// (Thrown in handler)
// 4. Otherwise, do nothing.
}
// TODO: Align with spec algorithm.
if (!this._do_not_flush) {
do {
result = this._decoder.handler(input_stream, input_stream.read());
if (result === finished_1.finished)
break;
if (!result)
continue;
if (Array.isArray(result))
output.push.apply(output, /**@type {!Array.<number>}*/ (result));
else
output.push(result);
} while (!input_stream.endOfStream());
this._decoder = null;
}
return this.serializeStream(output);
};
// A TextDecoder object also has an associated serialize stream
// algorithm...
/**
* @param {!Array.<number>} stream
* @return {string}
* @this {TextDecoder}
*/
TextDecoder.prototype.serializeStream = function (stream) {
// 1. Let token be the result of reading from stream.
// (Done in-place on array, rather than as a stream)
// 2. If encoding is UTF-8, UTF-16BE, or UTF-16LE, and ignore
// BOM flag and BOM seen flag are unset, run these subsubsteps:
if (utilities_1.includes(['UTF-8', 'UTF-16LE', 'UTF-16BE'], this._encoding.name) &&
!this._ignoreBOM && !this._BOMseen) {
if (stream.length > 0 && stream[0] === 0xFEFF) {
// 1. If token is U+FEFF, set BOM seen flag.
this._BOMseen = true;
stream.shift();
}
else if (stream.length > 0) {
// 2. Otherwise, if token is not end-of-stream, set BOM seen
// flag and append token to stream.
this._BOMseen = true;
}
else {
// 3. Otherwise, if token is not end-of-stream, append token
// to output.
// (no-op)
}
}
// 4. Otherwise, return output.
return utilities_1.codePointsToString(stream);
};
return TextDecoder;
}());
exports.TextDecoder = TextDecoder;
function isBufferInstance(input) {
try {
return input instanceof ArrayBuffer;
}
catch (e) {
console.error(e);
return false;
}
}
function getBytesFromInput(input) {
if (typeof input !== 'object')
return new Uint8Array(0);
if (isBufferInstance(input)) {
return new Uint8Array(input);
}
if ('buffer' in input && isBufferInstance(input.buffer)) {
return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
}
return new Uint8Array(0);
}
//# sourceMappingURL=TextDecoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"TextDecoder.js","sourceRoot":"","sources":["../../../src/common/TextDecoder.ts"],"names":[],"mappings":";;AAAA,+DAA+D;AAC/D,iEAAwD;AACxD,mDAAoD;AACpD,iDAAgD;AAChD,uDAAwD;AACxD,mDAAmF;AAEnF,mCAAkC;AAWlC;;;;;GAKG;AACH;IAYE,qBAAY,KAAc,EAAE,OAA4B;QAEtD,KAAK,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,kCAAgB,CAAC;QAC/D,IAAM,UAAU,GAAG,wBAAY,CAAC,OAAO,CAAC,CAAC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E,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAExD,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE;QAC3B,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;KAC9B;IAED,IAAI,QAAQ,IAAI,KAAK,IAAI,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;QACvD,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;KACzE;IAED,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC"}

View File

@@ -0,0 +1,27 @@
declare type TextEncoderOptions = {
NONSTANDARD_allowLegacyEncoding?: boolean;
fatal?: boolean;
};
declare type EncodeOptions = {
stream?: boolean;
};
/**
* @constructor
* @param {string=} label The label of the encoding. NONSTANDARD.
* @param {Object=} options NONSTANDARD.
*/
export declare class TextEncoder {
private _encoding;
private _encoder;
private _do_not_flush;
private _fatal;
constructor(label?: string, options?: TextEncoderOptions);
get encoding(): string;
/**
* @param {string=} opt_string The string to encode.
* @param {Object=} options
* @return {!Uint8Array} Encoded bytes, as a Uint8Array.
*/
encode(opt_string: string, options?: EncodeOptions): Uint8Array;
}
export {};

View File

@@ -0,0 +1,137 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var defaultEncoding_1 = require("../encoding/defaultEncoding");
var encoding_factory_1 = require("../encoding/encoding-factory");
var encodings_1 = require("../encoding/encodings");
var finished_1 = require("../encoding/finished");
var terminology_1 = require("../encoding/terminology");
var utilities_1 = require("../encoding/utilities");
var getGlobalScope_1 = require("../helper/getGlobalScope");
var Stream_1 = require("./Stream");
/**
* @constructor
* @param {string=} label The label of the encoding. NONSTANDARD.
* @param {Object=} options NONSTANDARD.
*/
var TextEncoder = /** @class */ (function () {
function TextEncoder(label, options) {
var optionsMap = utilities_1.ToDictionary(options);
// A TextEncoder object has an associated encoding and encoder.
/** @private */
this._encoding = null;
/** @private @type {?Encoder} */
this._encoder = null;
// Non-standard
/** @private @type {boolean} */
this._do_not_flush = false;
/** @private @type {string} */
this._fatal = Boolean(optionsMap['fatal']) ? 'fatal' : 'replacement';
// 1. Let enc be a new TextEncoder object.
// const enc = this;
// no need to do this as this is a proper class
// now and TSC will handle transpilation to older platforms
// 2. Set enc's encoding to UTF-8's encoder.
if (Boolean(optionsMap['NONSTANDARD_allowLegacyEncoding'])) {
// NONSTANDARD behavior.
label = !!label ? String(label) : defaultEncoding_1.DEFAULT_ENCODING;
var encoding = encodings_1.getEncoding(label);
if (encoding === null || encoding.name === 'replacement')
throw RangeError('Unknown encoding: ' + label);
if (!encoding_factory_1.encoders[encoding.name]) {
throw Error('Encoder not present.' +
' Did you forget to include encoding-indexes.js first?');
}
this._encoding = encoding;
// EXPERIMENTAL_CODE
// } else if (["iso-8859-1", "ISO-8859-1", "latin-1", "latin1", "LATIN-1", "LATIN1"].indexOf(label) !== -1) {
// this._encoding = getEncoding('iso-8859-1');
}
else {
// Standard behavior.
this._encoding = encodings_1.getEncoding('utf-8');
var glo = getGlobalScope_1.getGlobalScope() || {};
if (label !== undefined && 'console' in glo) {
console.warn('TextEncoder constructor called with encoding label, '
+ 'which is ignored.');
}
}
// For pre-ES5 runtimes:
// if (!Object.defineProperty)
// this.encoding = enc._encoding.name.toLowerCase();
// 3. Return enc.
// return enc;
}
Object.defineProperty(TextEncoder.prototype, "encoding", {
// if(Object.defineProperty) {
// // The encoding attribute's getter must return encoding's name.
// Object.defineProperty(TextEncoder.prototype, 'encoding', {
// /** @this {TextEncoder} */
// get: function () { return this._encoding.name.toLowerCase(); }
// });
// }
get: function () {
return this._encoding.name.toLowerCase();
},
enumerable: true,
configurable: true
});
/**
* @param {string=} opt_string The string to encode.
* @param {Object=} options
* @return {!Uint8Array} Encoded bytes, as a Uint8Array.
*/
TextEncoder.prototype.encode = function (opt_string, options) {
opt_string = opt_string === undefined ? '' : String(opt_string);
var optionsMap = utilities_1.ToDictionary(options);
// NOTE: This option is nonstandard. None of the encodings
// permitted for encoding (i.e. UTF-8, UTF-16) are stateful when
// the input is a USVString so streaming is not necessary.
if (!this._do_not_flush)
this._encoder = encoding_factory_1.encoders[this._encoding.name]({
fatal: this._fatal === 'fatal'
});
this._do_not_flush = Boolean(optionsMap['stream']);
// 1. Convert input to a stream.
var input = new Stream_1.Stream(utilities_1.stringToCodePoints(opt_string));
// 2. Let output be a new stream
var output = [];
/** @type {?(number|!Array.<number>)} */
var result;
// 3. While true, run these substeps:
while (true) {
// 1. Let token be the result of reading from input.
var token = input.read();
if (token === terminology_1.end_of_stream)
break;
// 2. Let result be the result of processing token for encoder,
// input, output.
result = this._encoder.handler(input, token);
if (result === finished_1.finished)
break;
if (Array.isArray(result))
output.push.apply(output, /**@type {!Array.<number>}*/ (result));
else
output.push(result);
}
// TODO: Align with spec algorithm.
if (!this._do_not_flush) {
while (true) {
result = this._encoder.handler(input, input.read());
if (result === finished_1.finished)
break;
if (Array.isArray(result))
output.push.apply(output, /**@type {!Array.<number>}*/ (result));
else
output.push(result);
}
this._encoder = null;
}
// 3. If result is finished, convert output into a byte sequence,
// and then return a Uint8Array object wrapping an ArrayBuffer
// containing output.
return new Uint8Array(output);
};
return TextEncoder;
}());
exports.TextEncoder = TextEncoder;
//# sourceMappingURL=TextEncoder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"TextEncoder.js","sourceRoot":"","sources":["../../../src/common/TextEncoder.ts"],"names":[],"mappings":";;AAAA,+DAA+D;AAC/D,iEAAwD;AACxD,mDAAoD;AACpD,iDAAgD;AAChD,uDAAwD;AACxD,mDAAyE;AACzE,2DAA0D;AAE1D,mCAAkC;AAYlC;;;;GAIG;AACH;IAOE,qBAAY,KAAc,EAAE,OAA4B;QAEtD,IAAM,UAAU,GAAG,wBAAY,CAAC,OAAO,CAAC,CAAC;QAEzC,+DAA+D;QAE/D,eAAe;QACf,IAAI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YACjB,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAC7C,IAAI,MAAM,KAAK,mBAAQ;gBACrB,MAAM;YACR,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;gBACvB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,4BAA4B,CAAA,CAAC,MAAM,CAAC,CAAC,CAAC;;gBAEhE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SACvB;QACD,mCAAmC;QACnC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,OAAO,IAAI,EAAE;gBACX,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;gBACpD,IAAI,MAAM,KAAK,mBAAQ;oBACrB,MAAM;gBACR,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;oBACvB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,4BAA4B,CAAA,CAAC,MAAM,CAAC,CAAC,CAAC;;oBAEhE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;aACvB;YACD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;SACtB;QACD,iEAAiE;QACjE,8DAA8D;QAC9D,qBAAqB;QACrB,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IACH,kBAAC;AAAD,CAAC,AAvID,IAuIC;AAvIY,kCAAW"}

View File

@@ -0,0 +1,5 @@
export * from './Decoder';
export * from './Encoder';
export * from './Stream';
export * from './TextEncoder';
export * from './TextDecoder';

View File

@@ -0,0 +1,9 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./Stream"));
__export(require("./TextEncoder"));
__export(require("./TextDecoder"));
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":";;;;;AAEA,8BAAyB;AACzB,mCAA8B;AAC9B,mCAA8B"}