@nberlette/utf8 0.2.0
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/LICENSE +20 -0
- package/README.md +298 -0
- package/cjs/_dnt.shims.d.ts +1 -0
- package/cjs/_dnt.shims.js +61 -0
- package/cjs/_dnt.shims.js.map +1 -0
- package/cjs/_internal.d.ts +54 -0
- package/cjs/_internal.js +173 -0
- package/cjs/_internal.js.map +1 -0
- package/cjs/index.d.ts +28 -0
- package/cjs/index.js +45 -0
- package/cjs/index.js.map +1 -0
- package/cjs/package.json +3 -0
- package/cjs/text_decoder.d.ts +58 -0
- package/cjs/text_decoder.js +242 -0
- package/cjs/text_decoder.js.map +1 -0
- package/cjs/text_decoder_stream.d.ts +41 -0
- package/cjs/text_decoder_stream.js +120 -0
- package/cjs/text_decoder_stream.js.map +1 -0
- package/cjs/text_encoder.d.ts +39 -0
- package/cjs/text_encoder.js +78 -0
- package/cjs/text_encoder.js.map +1 -0
- package/cjs/text_encoder_stream.d.ts +27 -0
- package/cjs/text_encoder_stream.js +75 -0
- package/cjs/text_encoder_stream.js.map +1 -0
- package/esm/_dnt.shims.d.ts +1 -0
- package/esm/_dnt.shims.js +58 -0
- package/esm/_dnt.shims.js.map +1 -0
- package/esm/_internal.d.ts +54 -0
- package/esm/_internal.js +143 -0
- package/esm/_internal.js.map +1 -0
- package/esm/index.d.ts +28 -0
- package/esm/index.js +29 -0
- package/esm/index.js.map +1 -0
- package/esm/package.json +3 -0
- package/esm/text_decoder.d.ts +58 -0
- package/esm/text_decoder.js +238 -0
- package/esm/text_decoder.js.map +1 -0
- package/esm/text_decoder_stream.d.ts +41 -0
- package/esm/text_decoder_stream.js +116 -0
- package/esm/text_decoder_stream.js.map +1 -0
- package/esm/text_encoder.d.ts +39 -0
- package/esm/text_encoder.js +74 -0
- package/esm/text_encoder.js.map +1 -0
- package/esm/text_encoder_stream.d.ts +27 -0
- package/esm/text_encoder_stream.js +71 -0
- package/esm/text_encoder_stream.js.map +1 -0
- package/package.json +187 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-dependency ponyfill for the native `TextEncoderStream` Web API.
|
|
3
|
+
*
|
|
4
|
+
* Uses the {@linkcode TextEncoder} ponyfill to encode strings into UTF-8
|
|
5
|
+
* bytes in a streaming fashion. Requires the `TransformStream` API to be
|
|
6
|
+
* available in the current environment.
|
|
7
|
+
*
|
|
8
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/TextEncoderStream
|
|
9
|
+
* @category Streams
|
|
10
|
+
* @tags utf-8, encoder
|
|
11
|
+
*/
|
|
12
|
+
export declare class TextEncoderStream {
|
|
13
|
+
#private;
|
|
14
|
+
constructor();
|
|
15
|
+
/** The encoding standard to use. This is always `"utf-8"`. */
|
|
16
|
+
get encoding(): string;
|
|
17
|
+
/**
|
|
18
|
+
* @returns the readable stream side of the `TextEncoderStream`, which can be
|
|
19
|
+
* used to read the encoded bytes as they are produced by the encoder.
|
|
20
|
+
*/
|
|
21
|
+
get readable(): ReadableStream<Uint8Array>;
|
|
22
|
+
/**
|
|
23
|
+
* @returns the writable stream side of the `TextEncoderStream`, which can be
|
|
24
|
+
* used to write strings to be encoded by the underlying `TextEncoder`.
|
|
25
|
+
*/
|
|
26
|
+
get writable(): WritableStream<string>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _TextEncoderStream_encoder, _TextEncoderStream_transform;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TextEncoderStream = void 0;
|
|
16
|
+
/**
|
|
17
|
+
* This module provides a streaming encoder for UTF-8 text, which is based on
|
|
18
|
+
* the `TextEncoder` API.
|
|
19
|
+
*
|
|
20
|
+
* This is a zero-dependency ponyfill for the native `TextEncoderStream` Web
|
|
21
|
+
* API, which can be used in any ES2015+ environment with support for the
|
|
22
|
+
* `TransformStream` API.
|
|
23
|
+
*
|
|
24
|
+
* **Note**: This was directly adapted from the Deno `TextEncoderStream`
|
|
25
|
+
* implementation (MIT License), which is based on the WHATWG Streams standard.
|
|
26
|
+
*
|
|
27
|
+
* @module text-encoder-stream
|
|
28
|
+
*/
|
|
29
|
+
const _internal_js_1 = require("./_internal.js");
|
|
30
|
+
const text_encoder_js_1 = require("./text_encoder.js");
|
|
31
|
+
/**
|
|
32
|
+
* Zero-dependency ponyfill for the native `TextEncoderStream` Web API.
|
|
33
|
+
*
|
|
34
|
+
* Uses the {@linkcode TextEncoder} ponyfill to encode strings into UTF-8
|
|
35
|
+
* bytes in a streaming fashion. Requires the `TransformStream` API to be
|
|
36
|
+
* available in the current environment.
|
|
37
|
+
*
|
|
38
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/TextEncoderStream
|
|
39
|
+
* @category Streams
|
|
40
|
+
* @tags utf-8, encoder
|
|
41
|
+
*/
|
|
42
|
+
class TextEncoderStream {
|
|
43
|
+
constructor() {
|
|
44
|
+
_TextEncoderStream_encoder.set(this, void 0);
|
|
45
|
+
_TextEncoderStream_transform.set(this, void 0);
|
|
46
|
+
__classPrivateFieldSet(this, _TextEncoderStream_encoder, new text_encoder_js_1.TextEncoder(), "f");
|
|
47
|
+
__classPrivateFieldSet(this, _TextEncoderStream_transform, new _internal_js_1.TransformStream({
|
|
48
|
+
transform: (chunk, controller) => {
|
|
49
|
+
const encoded = __classPrivateFieldGet(this, _TextEncoderStream_encoder, "f").encode(chunk);
|
|
50
|
+
controller.enqueue(encoded);
|
|
51
|
+
},
|
|
52
|
+
}), "f");
|
|
53
|
+
}
|
|
54
|
+
/** The encoding standard to use. This is always `"utf-8"`. */
|
|
55
|
+
get encoding() {
|
|
56
|
+
return "utf-8";
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @returns the readable stream side of the `TextEncoderStream`, which can be
|
|
60
|
+
* used to read the encoded bytes as they are produced by the encoder.
|
|
61
|
+
*/
|
|
62
|
+
get readable() {
|
|
63
|
+
return __classPrivateFieldGet(this, _TextEncoderStream_transform, "f").readable;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @returns the writable stream side of the `TextEncoderStream`, which can be
|
|
67
|
+
* used to write strings to be encoded by the underlying `TextEncoder`.
|
|
68
|
+
*/
|
|
69
|
+
get writable() {
|
|
70
|
+
return __classPrivateFieldGet(this, _TextEncoderStream_transform, "f").writable;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.TextEncoderStream = TextEncoderStream;
|
|
74
|
+
_TextEncoderStream_encoder = new WeakMap(), _TextEncoderStream_transform = new WeakMap();
|
|
75
|
+
//# sourceMappingURL=text_encoder_stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text_encoder_stream.js","sourceRoot":"","sources":["../src/text_encoder_stream.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;GAYG;AACH,iDAAiD;AACjD,uDAAgD;AAEhD;;;;;;;;;;GAUG;AACH,MAAa,iBAAiB;IAI5B;QAHA,6CAAsB;QACtB,+CAAgD;QAG9C,uBAAA,IAAI,8BAAY,IAAI,6BAAW,EAAE,MAAA,CAAC;QAClC,uBAAA,IAAI,gCAAc,IAAI,8BAAe,CAAC;YACpC,SAAS,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;gBAC/B,MAAM,OAAO,GAAG,uBAAA,IAAI,kCAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC5C,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC9B,CAAC;SACF,CAAC,MAAA,CAAC;IACL,CAAC;IAED,8DAA8D;IAC9D,IAAI,QAAQ;QACV,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;OAGG;IACH,IAAI,QAAQ;QACV,OAAO,uBAAA,IAAI,oCAAW,CAAC,QAAQ,CAAC;IAClC,CAAC;IAED;;;OAGG;IACH,IAAI,QAAQ;QACV,OAAO,uBAAA,IAAI,oCAAW,CAAC,QAAQ,CAAC;IAClC,CAAC;CACF;AAlCD,8CAkCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const dntGlobalThis: Omit<typeof globalThis, never>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const dntGlobals = {};
|
|
2
|
+
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
3
|
+
function createMergeProxy(baseObj, extObj) {
|
|
4
|
+
return new Proxy(baseObj, {
|
|
5
|
+
get(_target, prop, _receiver) {
|
|
6
|
+
if (prop in extObj) {
|
|
7
|
+
return extObj[prop];
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return baseObj[prop];
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
set(_target, prop, value) {
|
|
14
|
+
if (prop in extObj) {
|
|
15
|
+
delete extObj[prop];
|
|
16
|
+
}
|
|
17
|
+
baseObj[prop] = value;
|
|
18
|
+
return true;
|
|
19
|
+
},
|
|
20
|
+
deleteProperty(_target, prop) {
|
|
21
|
+
let success = false;
|
|
22
|
+
if (prop in extObj) {
|
|
23
|
+
delete extObj[prop];
|
|
24
|
+
success = true;
|
|
25
|
+
}
|
|
26
|
+
if (prop in baseObj) {
|
|
27
|
+
delete baseObj[prop];
|
|
28
|
+
success = true;
|
|
29
|
+
}
|
|
30
|
+
return success;
|
|
31
|
+
},
|
|
32
|
+
ownKeys(_target) {
|
|
33
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
34
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
35
|
+
const extKeysSet = new Set(extKeys);
|
|
36
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
37
|
+
},
|
|
38
|
+
defineProperty(_target, prop, desc) {
|
|
39
|
+
if (prop in extObj) {
|
|
40
|
+
delete extObj[prop];
|
|
41
|
+
}
|
|
42
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
43
|
+
return true;
|
|
44
|
+
},
|
|
45
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
46
|
+
if (prop in extObj) {
|
|
47
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
has(_target, prop) {
|
|
54
|
+
return prop in extObj || prop in baseObj;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=_dnt.shims.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.shims.js","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,EAClB,CAAC;AACF,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AAEtE,SAAS,gBAAgB,CACvB,OA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GAAG,OAAO,CAAC,CAAC;QACrE,CAAC;QACD,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI;YAChC,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACnB,OAAQ,MAAc,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;YACD,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;YAC5C,OAAO,IAAI,CAAC;QACd,CAAC;QACD,wBAAwB,CAAC,OAAO,EAAE,IAAI;YACpC,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACnB,OAAO,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACxD,CAAC;iBAAM,CAAC;gBACN,OAAO,OAAO,CAAC,wBAAwB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QACD,GAAG,CAAC,OAAO,EAAE,IAAI;YACf,OAAO,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,OAAO,CAAC;QAC3C,CAAC;KACF,CAAQ,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export declare var undefined: undefined;
|
|
2
|
+
type Uncurry<T, This = void> = T extends (this: infer ThisArg, ...args: infer A) => infer R ? [This] extends [void] ? (thisArg: ThisArg, ...args: A) => R : (thisArg: This, ...args: A) => R : T extends (...args: infer A) => infer R ? (thisArg: [This] extends [void] ? unknown : This, ...args: A) => R : never;
|
|
3
|
+
export type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float16ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | BigInt64ArrayConstructor | BigUint64ArrayConstructor;
|
|
4
|
+
export type TypedArray = InstanceType<TypedArrayConstructor>;
|
|
5
|
+
type TypedArrayToStringTag = TypedArray[typeof Symbol.toStringTag];
|
|
6
|
+
type TypedArrayFromTag<T extends TypedArrayToStringTag> = TypedArray extends infer A extends TypedArray ? A extends {
|
|
7
|
+
[Symbol.toStringTag]: T;
|
|
8
|
+
} ? A : never : never;
|
|
9
|
+
export declare function isTypedArray<T extends TypedArrayToStringTag = TypedArrayToStringTag>(it: unknown, type?: T | undefined): it is TypedArrayFromTag<T>;
|
|
10
|
+
export declare const Object: typeof globalThis.Object;
|
|
11
|
+
export declare const ObjectGetPrototypeOf: (o: any) => any;
|
|
12
|
+
export declare const ObjectDefineProperty: <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T;
|
|
13
|
+
export declare const ObjectGetOwnPropertyDescriptor: (o: any, p: PropertyKey) => PropertyDescriptor | undefined;
|
|
14
|
+
export declare const toString: (thisArg: unknown) => string;
|
|
15
|
+
export declare const Error: typeof globalThis.Error;
|
|
16
|
+
export declare const TypeError: typeof globalThis.TypeError;
|
|
17
|
+
export declare const RangeError: typeof globalThis.RangeError;
|
|
18
|
+
export declare const ReferenceError: typeof globalThis.ReferenceError;
|
|
19
|
+
export declare const Array: typeof globalThis.Array;
|
|
20
|
+
export declare const Symbol: typeof globalThis.Symbol;
|
|
21
|
+
export declare const ArrayBuffer: typeof globalThis.ArrayBuffer;
|
|
22
|
+
export declare const ArrayBufferIsView: (arg: any) => arg is ArrayBufferView;
|
|
23
|
+
export declare const ArrayBufferPrototypeGetByteLength: (thisArg: ArrayBuffer) => number;
|
|
24
|
+
export declare const SharedArrayBuffer: typeof globalThis.SharedArrayBuffer;
|
|
25
|
+
export declare const SharedArrayBufferPrototypeGetByteLength: (thisArg: SharedArrayBuffer) => number;
|
|
26
|
+
export declare const Uint8Array: typeof globalThis.Uint8Array;
|
|
27
|
+
export declare const Uint8ArrayPrototypeSlice: Uncurry<typeof Uint8Array.prototype.slice, Uint8Array>;
|
|
28
|
+
export declare const Uint8ArrayPrototypeSubarray: Uncurry<typeof Uint8Array.prototype.subarray, Uint8Array>;
|
|
29
|
+
export declare const TypedArray: TypedArrayConstructor;
|
|
30
|
+
export declare const TypedArrayPrototype: InstanceType<TypedArrayConstructor>;
|
|
31
|
+
export declare const TypedArrayPrototypeGetToStringTag: any;
|
|
32
|
+
export declare const TypedArrayPrototypeSubarray: Uncurry<typeof TypedArrayPrototype.subarray, typeof TypedArrayPrototype>;
|
|
33
|
+
export declare const String: typeof globalThis.String;
|
|
34
|
+
export declare const StringFromCharCode: typeof String.fromCharCode;
|
|
35
|
+
export declare const StringPrototype: typeof String.prototype;
|
|
36
|
+
export declare const StringPrototypeCharCodeAt: Uncurry<typeof String.prototype.charCodeAt, string>;
|
|
37
|
+
export declare const StringPrototypeReplace: Uncurry<typeof String.prototype.replace, string>;
|
|
38
|
+
export declare const StringPrototypeSlice: Uncurry<typeof String.prototype.slice, string>;
|
|
39
|
+
export declare const StringPrototypeCodePointAt: Uncurry<typeof String.prototype.codePointAt, string>;
|
|
40
|
+
export declare const StringPrototypeToLowerCase: Uncurry<typeof String.prototype.toLowerCase, string>;
|
|
41
|
+
export declare const StringPrototypeTrim: Uncurry<typeof String.prototype.trim, string>;
|
|
42
|
+
export declare const Promise: typeof globalThis.Promise;
|
|
43
|
+
export declare const PromiseResolve: {
|
|
44
|
+
(): Promise<void>;
|
|
45
|
+
<T>(value: T): Promise<Awaited<T>>;
|
|
46
|
+
<T>(value: T | PromiseLike<T>): Promise<Awaited<T>>;
|
|
47
|
+
};
|
|
48
|
+
export declare const PromiseReject: <T = never>(reason?: any) => Promise<T>;
|
|
49
|
+
export declare const TransformStream: typeof globalThis.TransformStream;
|
|
50
|
+
export declare function getCodePoint(input: string, index: number): number;
|
|
51
|
+
export declare function utf8BytesNeeded(codePoint: number): number;
|
|
52
|
+
export declare function normalizeEncoding(label: string): string;
|
|
53
|
+
export declare function toUint8Array(input?: BufferSource | null): Uint8Array;
|
|
54
|
+
export {};
|
package/esm/_internal.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// deno-lint-ignore no-var
|
|
2
|
+
import * as dntShim from "./_dnt.shims.js";
|
|
3
|
+
export var undefined;
|
|
4
|
+
const $global = (() => {
|
|
5
|
+
try {
|
|
6
|
+
if (typeof dntShim.dntGlobalThis === "object")
|
|
7
|
+
return dntShim.dntGlobalThis;
|
|
8
|
+
return (0, eval)("this");
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
if (typeof dntShim.dntGlobalThis === "object")
|
|
12
|
+
return dntShim.dntGlobalThis;
|
|
13
|
+
if (typeof self === "object")
|
|
14
|
+
return self;
|
|
15
|
+
if (typeof global === "object")
|
|
16
|
+
return global;
|
|
17
|
+
if (typeof root === "object")
|
|
18
|
+
return root;
|
|
19
|
+
if (typeof this === "object")
|
|
20
|
+
return this;
|
|
21
|
+
// ewww
|
|
22
|
+
throw "Unable to locate global `this`";
|
|
23
|
+
}
|
|
24
|
+
})();
|
|
25
|
+
export function isTypedArray(it, type) {
|
|
26
|
+
try {
|
|
27
|
+
return TypedArrayPrototypeGetToStringTag(it) === type;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export const Object = $global.Object;
|
|
34
|
+
export const ObjectGetPrototypeOf = Object.getPrototypeOf;
|
|
35
|
+
export const ObjectDefineProperty = Object.defineProperty;
|
|
36
|
+
export const ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
37
|
+
const Function = $global.Function;
|
|
38
|
+
const FunctionPrototype = Function.prototype;
|
|
39
|
+
const { bind, call } = FunctionPrototype;
|
|
40
|
+
const uncurryThis = (fn) => {
|
|
41
|
+
const bound = bind.call(call, fn);
|
|
42
|
+
ObjectDefineProperty(bound, "name", { value: fn.name });
|
|
43
|
+
return bound;
|
|
44
|
+
};
|
|
45
|
+
const FunctionPrototypeBind = uncurryThis(bind);
|
|
46
|
+
function uncurryGetter(o, p) {
|
|
47
|
+
return uncurryThis(lookupGetter(o, p));
|
|
48
|
+
}
|
|
49
|
+
function lookupGetter(o, p, _allowUndefined) {
|
|
50
|
+
return ObjectGetOwnPropertyDescriptor(o, p)?.get ?? (() => undefined);
|
|
51
|
+
}
|
|
52
|
+
// deno-lint-ignore no-explicit-any
|
|
53
|
+
function bindAndRename(fn, thisArg, name = fn.name) {
|
|
54
|
+
const bound = FunctionPrototypeBind(fn, thisArg);
|
|
55
|
+
ObjectDefineProperty(bound, "name", { value: name });
|
|
56
|
+
return bound;
|
|
57
|
+
}
|
|
58
|
+
export const toString = uncurryThis(Object.prototype.toString);
|
|
59
|
+
export const Error = $global.Error;
|
|
60
|
+
export const TypeError = $global.TypeError;
|
|
61
|
+
export const RangeError = $global.RangeError;
|
|
62
|
+
export const ReferenceError = $global.ReferenceError;
|
|
63
|
+
export const Array = $global.Array;
|
|
64
|
+
export const Symbol = $global.Symbol;
|
|
65
|
+
export const ArrayBuffer = $global.ArrayBuffer;
|
|
66
|
+
export const ArrayBufferIsView = ArrayBuffer.isView;
|
|
67
|
+
export const ArrayBufferPrototypeGetByteLength = uncurryGetter(ArrayBuffer.prototype, "byteLength");
|
|
68
|
+
export const SharedArrayBuffer = $global.SharedArrayBuffer;
|
|
69
|
+
export const SharedArrayBufferPrototypeGetByteLength = uncurryGetter(SharedArrayBuffer.prototype, "byteLength");
|
|
70
|
+
export const Uint8Array = $global.Uint8Array;
|
|
71
|
+
export const Uint8ArrayPrototypeSlice = uncurryThis(Uint8Array.prototype.slice);
|
|
72
|
+
export const Uint8ArrayPrototypeSubarray = uncurryThis(Uint8Array.prototype.subarray);
|
|
73
|
+
export const TypedArray = ObjectGetPrototypeOf(Uint8Array);
|
|
74
|
+
export const TypedArrayPrototype = TypedArray?.prototype;
|
|
75
|
+
export const TypedArrayPrototypeGetToStringTag = uncurryGetter(TypedArrayPrototype, Symbol.toStringTag);
|
|
76
|
+
export const TypedArrayPrototypeSubarray // deno-lint-ignore no-explicit-any
|
|
77
|
+
= uncurryThis(TypedArrayPrototype.subarray);
|
|
78
|
+
export const String = $global.String;
|
|
79
|
+
export const StringFromCharCode = String.fromCharCode;
|
|
80
|
+
export const StringPrototype = String.prototype;
|
|
81
|
+
export const StringPrototypeCharCodeAt = uncurryThis(StringPrototype.charCodeAt);
|
|
82
|
+
export const StringPrototypeReplace = uncurryThis(StringPrototype.replace);
|
|
83
|
+
export const StringPrototypeSlice = uncurryThis(StringPrototype.slice);
|
|
84
|
+
export const StringPrototypeCodePointAt = uncurryThis(StringPrototype.codePointAt);
|
|
85
|
+
export const StringPrototypeToLowerCase = uncurryThis(StringPrototype.toLowerCase);
|
|
86
|
+
export const StringPrototypeTrim = uncurryThis(StringPrototype.trim);
|
|
87
|
+
export const Promise = $global.Promise;
|
|
88
|
+
export const PromiseResolve = bindAndRename(Promise.resolve, Promise);
|
|
89
|
+
export const PromiseReject = bindAndRename(Promise.reject, Promise);
|
|
90
|
+
export const TransformStream = $global.TransformStream;
|
|
91
|
+
export function getCodePoint(input, index) {
|
|
92
|
+
const first = StringPrototypeCharCodeAt(input, index);
|
|
93
|
+
if (first >= 0xd800 && first <= 0xdbff) {
|
|
94
|
+
const second = StringPrototypeCharCodeAt(input, index + 1);
|
|
95
|
+
if (second >= 0xdc00 && second <= 0xdfff) {
|
|
96
|
+
return ((first - 0xd800) << 10) + (second - 0xdc00) + 0x10000;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return first;
|
|
100
|
+
}
|
|
101
|
+
export function utf8BytesNeeded(codePoint) {
|
|
102
|
+
if (codePoint <= 0x7f)
|
|
103
|
+
return 1;
|
|
104
|
+
if (codePoint <= 0x7ff)
|
|
105
|
+
return 2;
|
|
106
|
+
if (codePoint <= 0xffff)
|
|
107
|
+
return 3;
|
|
108
|
+
return 4;
|
|
109
|
+
}
|
|
110
|
+
export function normalizeEncoding(label) {
|
|
111
|
+
let encoding = StringPrototypeToLowerCase(label);
|
|
112
|
+
encoding = StringPrototypeTrim(encoding);
|
|
113
|
+
if (encoding === "utf8" || encoding === "utf-8")
|
|
114
|
+
return "utf-8";
|
|
115
|
+
throw new TypeError(`The encoding label provided ('${label}') is invalid.`);
|
|
116
|
+
}
|
|
117
|
+
export function toUint8Array(input) {
|
|
118
|
+
if (input == null) {
|
|
119
|
+
return new Uint8Array();
|
|
120
|
+
}
|
|
121
|
+
else if (isTypedArray(input, "Uint8Array")) {
|
|
122
|
+
return input;
|
|
123
|
+
}
|
|
124
|
+
else if (ArrayBufferIsView(input)) {
|
|
125
|
+
return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
try {
|
|
129
|
+
SharedArrayBufferPrototypeGetByteLength(input);
|
|
130
|
+
return new Uint8Array(input);
|
|
131
|
+
}
|
|
132
|
+
catch (_) {
|
|
133
|
+
try {
|
|
134
|
+
ArrayBufferPrototypeGetByteLength(input);
|
|
135
|
+
return new Uint8Array(input);
|
|
136
|
+
}
|
|
137
|
+
catch (_) {
|
|
138
|
+
throw new TypeError('The "input" argument must be of type BufferSource');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=_internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_internal.js","sourceRoot":"","sources":["../src/_internal.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAE3C,MAAM,CAAC,IAAI,SAAoB,CAAC;AAKhC,MAAM,OAAO,GAAiC,CAAC,GAAG,EAAE;IAClD,IAAI,CAAC;QACH,IAAI,OAAO,OAAO,CAAC,aAAa,KAAK,QAAQ;YAAE,OAAO,OAAO,CAAC,aAAa,CAAC;QAC5E,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,OAAO,OAAO,CAAC,aAAa,KAAK,QAAQ;YAAE,OAAO,OAA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/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* # `@nick/utf8`
|
|
3
|
+
*
|
|
4
|
+
* This package provides blazing-fast, zero-dependency ponyfills for the native
|
|
5
|
+
* `TextEncoder` and `TextDecoder` APIs, as well as the streaming counterparts,
|
|
6
|
+
* `TextEncoderStream` and `TextDecoderStream`.
|
|
7
|
+
*
|
|
8
|
+
* The ponyfills are based on the WHATWG Encoding standard, and are designed to
|
|
9
|
+
* work in any ES2015+ environment, including Deno, Node, Bun, and the browser.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { TextEncoder, TextDecoder } from "@nick/utf8";
|
|
14
|
+
*
|
|
15
|
+
* const encoder = new TextEncoder();
|
|
16
|
+
* const decoder = new TextDecoder();
|
|
17
|
+
*
|
|
18
|
+
* const buffer = encoder.encode("Hello, world!");
|
|
19
|
+
* const text = decoder.decode(buffer);
|
|
20
|
+
*
|
|
21
|
+
* console.log(text); // Outputs: "Hello, world!"
|
|
22
|
+
* ```
|
|
23
|
+
* @module utf8
|
|
24
|
+
*/
|
|
25
|
+
export * from "./text_encoder.js";
|
|
26
|
+
export * from "./text_decoder.js";
|
|
27
|
+
export * from "./text_encoder_stream.js";
|
|
28
|
+
export * from "./text_decoder_stream.js";
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* # `@nick/utf8`
|
|
3
|
+
*
|
|
4
|
+
* This package provides blazing-fast, zero-dependency ponyfills for the native
|
|
5
|
+
* `TextEncoder` and `TextDecoder` APIs, as well as the streaming counterparts,
|
|
6
|
+
* `TextEncoderStream` and `TextDecoderStream`.
|
|
7
|
+
*
|
|
8
|
+
* The ponyfills are based on the WHATWG Encoding standard, and are designed to
|
|
9
|
+
* work in any ES2015+ environment, including Deno, Node, Bun, and the browser.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { TextEncoder, TextDecoder } from "@nick/utf8";
|
|
14
|
+
*
|
|
15
|
+
* const encoder = new TextEncoder();
|
|
16
|
+
* const decoder = new TextDecoder();
|
|
17
|
+
*
|
|
18
|
+
* const buffer = encoder.encode("Hello, world!");
|
|
19
|
+
* const text = decoder.decode(buffer);
|
|
20
|
+
*
|
|
21
|
+
* console.log(text); // Outputs: "Hello, world!"
|
|
22
|
+
* ```
|
|
23
|
+
* @module utf8
|
|
24
|
+
*/
|
|
25
|
+
export * from "./text_encoder.js";
|
|
26
|
+
export * from "./text_decoder.js";
|
|
27
|
+
export * from "./text_encoder_stream.js";
|
|
28
|
+
export * from "./text_decoder_stream.js";
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC"}
|
package/esm/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the {@linkcode TextDecoder} constructor.
|
|
3
|
+
*/
|
|
4
|
+
export interface TextDecoderOptions {
|
|
5
|
+
/**
|
|
6
|
+
* If true, invalid bytes will throw a TypeError. Otherwise, they will be
|
|
7
|
+
* replaced with the Unicode replacement character.
|
|
8
|
+
* @default {false}
|
|
9
|
+
*/
|
|
10
|
+
fatal?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* If true, the BOM (Byte Order Mark) will be ignored.
|
|
13
|
+
* @default {false}
|
|
14
|
+
*/
|
|
15
|
+
ignoreBOM?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** Options for the {@linkcode TextDecoder.decode} method. */
|
|
18
|
+
export interface TextDecodeOptions {
|
|
19
|
+
/**
|
|
20
|
+
* If true, indicates that the data being decoded is part of a larger stream.
|
|
21
|
+
* This allows the decoder to handle incomplete byte sequences appropriately.
|
|
22
|
+
* @default {false}
|
|
23
|
+
*/
|
|
24
|
+
stream?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Decodes an encoded sequence of bytes into a string, using the specified
|
|
28
|
+
* encoding standard. Currently, only UTF-8 encoding is supported.
|
|
29
|
+
*
|
|
30
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder
|
|
31
|
+
* @category Encoding
|
|
32
|
+
* @tags utf-8, decoder
|
|
33
|
+
*/
|
|
34
|
+
export declare class TextDecoder {
|
|
35
|
+
#private;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new TextDecoder instance.
|
|
38
|
+
* @param label The encoding to use. Currently, only "utf-8" is supported.
|
|
39
|
+
* @param options Configuration options.
|
|
40
|
+
*/
|
|
41
|
+
constructor(label?: string, options?: TextDecoderOptions);
|
|
42
|
+
/** The encoding standard to use. */
|
|
43
|
+
get encoding(): string;
|
|
44
|
+
/** If true, invalid bytes will throw a TypeError. */
|
|
45
|
+
get fatal(): boolean;
|
|
46
|
+
/** If true, the BOM (Byte Order Mark) will be ignored. */
|
|
47
|
+
get ignoreBOM(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Decodes a BufferSource into a string using UTF-8 decoding.
|
|
50
|
+
*
|
|
51
|
+
* @param input The bytes to decode. Defaults to an empty Uint8Array.
|
|
52
|
+
* @param [options] Decoding options.
|
|
53
|
+
* @returns The decoded string.
|
|
54
|
+
* @throws if the input is not a BufferSource.
|
|
55
|
+
* @throws if fatal is true and an invalid byte sequence is encountered.
|
|
56
|
+
*/
|
|
57
|
+
decode(input?: BufferSource, options?: TextDecodeOptions): string;
|
|
58
|
+
}
|