@atproto/lex-data 0.0.14 → 0.1.0-next.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/CHANGELOG.md +28 -0
- package/dist/blob.d.ts +118 -39
- package/dist/blob.d.ts.map +1 -1
- package/dist/blob.js +68 -22
- package/dist/blob.js.map +1 -1
- package/dist/cid.d.ts.map +1 -1
- package/dist/cid.js +75 -79
- package/dist/cid.js.map +1 -1
- package/dist/index.js +8 -11
- package/dist/index.js.map +1 -1
- package/dist/lex-equals.js +9 -12
- package/dist/lex-equals.js.map +1 -1
- package/dist/lex-error.js +2 -7
- package/dist/lex-error.js.map +1 -1
- package/dist/lex.js +10 -17
- package/dist/lex.js.map +1 -1
- package/dist/lib/nodejs-buffer.d.ts +4 -0
- package/dist/lib/nodejs-buffer.d.ts.map +1 -1
- package/dist/lib/nodejs-buffer.js +1 -4
- package/dist/lib/nodejs-buffer.js.map +1 -1
- package/dist/lib/util.js +2 -6
- package/dist/lib/util.js.map +1 -1
- package/dist/object.js +3 -8
- package/dist/object.js.map +1 -1
- package/dist/uint8array-base64.js +1 -2
- package/dist/uint8array-concat.d.ts +2 -2
- package/dist/uint8array-concat.d.ts.map +1 -1
- package/dist/uint8array-concat.js +4 -8
- package/dist/uint8array-concat.js.map +1 -1
- package/dist/uint8array-from-base64.js +7 -11
- package/dist/uint8array-from-base64.js.map +1 -1
- package/dist/uint8array-to-base64.js +7 -11
- package/dist/uint8array-to-base64.js.map +1 -1
- package/dist/uint8array.d.ts +1 -1
- package/dist/uint8array.d.ts.map +1 -1
- package/dist/uint8array.js +17 -23
- package/dist/uint8array.js.map +1 -1
- package/dist/utf8-from-base64.js +6 -10
- package/dist/utf8-from-base64.js.map +1 -1
- package/dist/utf8-from-bytes.d.ts +3 -0
- package/dist/utf8-from-bytes.d.ts.map +1 -0
- package/dist/utf8-from-bytes.js +15 -0
- package/dist/utf8-from-bytes.js.map +1 -0
- package/dist/utf8-grapheme-len.js +4 -8
- package/dist/utf8-grapheme-len.js.map +1 -1
- package/dist/utf8-len.js +4 -8
- package/dist/utf8-len.js.map +1 -1
- package/dist/utf8-to-base64.js +8 -12
- package/dist/utf8-to-base64.js.map +1 -1
- package/dist/utf8.d.ts +18 -0
- package/dist/utf8.d.ts.map +1 -1
- package/dist/utf8.js +32 -16
- package/dist/utf8.js.map +1 -1
- package/package.json +7 -8
- package/src/blob.test.ts +38 -25
- package/src/blob.ts +190 -52
- package/src/cid-implementation.test.ts +3 -3
- package/src/cid.ts +1 -0
- package/src/core-js.d.ts +2 -0
- package/src/lib/nodejs-buffer.ts +10 -0
- package/src/uint8array-concat.ts +7 -3
- package/src/uint8array-from-base64.test.ts +2 -2
- package/src/uint8array-to-base64.test.ts +2 -2
- package/src/uint8array.test.ts +2 -2
- package/src/utf8-from-bytes.test.ts +43 -0
- package/src/utf8-from-bytes.ts +21 -0
- package/src/utf8.ts +20 -0
- package/tsconfig.tests.json +1 -1
package/dist/lex.js
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.isLexMap = isLexMap;
|
|
4
|
-
exports.isLexArray = isLexArray;
|
|
5
|
-
exports.isLexScalar = isLexScalar;
|
|
6
|
-
exports.isLexValue = isLexValue;
|
|
7
|
-
exports.isTypedLexMap = isTypedLexMap;
|
|
8
|
-
const cid_js_1 = require("./cid.js");
|
|
9
|
-
const object_js_1 = require("./object.js");
|
|
1
|
+
import { isCid } from './cid.js';
|
|
2
|
+
import { isPlainObject } from './object.js';
|
|
10
3
|
/**
|
|
11
4
|
* Type guard to check if a value is a valid {@link LexMap}.
|
|
12
5
|
*
|
|
@@ -26,8 +19,8 @@ const object_js_1 = require("./object.js");
|
|
|
26
19
|
* }
|
|
27
20
|
* ```
|
|
28
21
|
*/
|
|
29
|
-
function isLexMap(value) {
|
|
30
|
-
return
|
|
22
|
+
export function isLexMap(value) {
|
|
23
|
+
return isPlainObject(value) && Object.values(value).every(isLexValue);
|
|
31
24
|
}
|
|
32
25
|
/**
|
|
33
26
|
* Type guard to check if a value is a valid {@link LexArray}.
|
|
@@ -48,7 +41,7 @@ function isLexMap(value) {
|
|
|
48
41
|
* }
|
|
49
42
|
* ```
|
|
50
43
|
*/
|
|
51
|
-
function isLexArray(value) {
|
|
44
|
+
export function isLexArray(value) {
|
|
52
45
|
return Array.isArray(value) && value.every(isLexValue);
|
|
53
46
|
}
|
|
54
47
|
/**
|
|
@@ -70,10 +63,10 @@ function isLexArray(value) {
|
|
|
70
63
|
* isLexScalar([1, 2]) // false (arrays are not scalars)
|
|
71
64
|
* ```
|
|
72
65
|
*/
|
|
73
|
-
function isLexScalar(value) {
|
|
66
|
+
export function isLexScalar(value) {
|
|
74
67
|
switch (typeof value) {
|
|
75
68
|
case 'object':
|
|
76
|
-
return value === null || value instanceof Uint8Array ||
|
|
69
|
+
return value === null || value instanceof Uint8Array || isCid(value);
|
|
77
70
|
case 'string':
|
|
78
71
|
case 'boolean':
|
|
79
72
|
return true;
|
|
@@ -107,7 +100,7 @@ function isLexScalar(value) {
|
|
|
107
100
|
* isLexValue({ fn: () => {} }) // false (functions not allowed)
|
|
108
101
|
* ```
|
|
109
102
|
*/
|
|
110
|
-
function isLexValue(value) {
|
|
103
|
+
export function isLexValue(value) {
|
|
111
104
|
// Using a stack to avoid recursion depth issues.
|
|
112
105
|
const stack = [value];
|
|
113
106
|
// Cyclic structures are not valid LexValues as they cannot be serialized to
|
|
@@ -116,7 +109,7 @@ function isLexValue(value) {
|
|
|
116
109
|
const visited = new Set();
|
|
117
110
|
do {
|
|
118
111
|
const value = stack.pop();
|
|
119
|
-
if (
|
|
112
|
+
if (isPlainObject(value)) {
|
|
120
113
|
if (visited.has(value))
|
|
121
114
|
return false;
|
|
122
115
|
visited.add(value);
|
|
@@ -157,7 +150,7 @@ function isLexValue(value) {
|
|
|
157
150
|
* }
|
|
158
151
|
* ```
|
|
159
152
|
*/
|
|
160
|
-
function isTypedLexMap(value) {
|
|
153
|
+
export function isTypedLexMap(value) {
|
|
161
154
|
return (isLexMap(value) && typeof value.$type === 'string' && value.$type.length > 0);
|
|
162
155
|
}
|
|
163
156
|
//# sourceMappingURL=lex.js.map
|
package/dist/lex.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lex.js","sourceRoot":"","sources":["../src/lex.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lex.js","sourceRoot":"","sources":["../src/lex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAyE3C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,aAAa,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;AACvE,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;AACxD,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,YAAY,UAAU,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;QACtE,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS;YACZ,OAAO,IAAI,CAAA;QACb,KAAK,QAAQ;YACX,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAA;QAC1C,cAAc;QACd;YACE,OAAO,KAAK,CAAA;IAChB,CAAC;AACH,CAAC;AAED;;;;;;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AG,CAAC,CAC7E,CAAA;AACH,CAAC","sourcesContent":["import { Cid, isCid } from './cid.js'\nimport { isPlainObject } from './object.js'\n\n/**\n * Primitive values in the Lexicon data model.\n *\n * Represents the basic scalar types that can appear in AT Protocol data:\n * - `number` - Integer values only (no floats)\n * - `string` - UTF-8 text\n * - `boolean` - true or false\n * - `null` - Explicit null value\n * - `Cid` - Content Identifier (link by hash)\n * - `Uint8Array` - Binary data (bytes)\n *\n * @see {@link LexValue} for the complete recursive value type\n */\nexport type LexScalar = number | string | boolean | null | Cid | Uint8Array\n\n/**\n * Any valid Lexicon value (recursive type).\n *\n * This is the union of all types that can appear in AT Protocol Lexicon data:\n * - {@link LexScalar} - Primitive values (number, string, boolean, null, Cid, Uint8Array)\n * - `LexValue[]` - Arrays of LexValues\n * - `{ [key: string]?: LexValue }` - Objects with string keys and LexValue values\n *\n * @example\n * ```typescript\n * import type { LexValue } from '@atproto/lex'\n *\n * const scalar: LexValue = 'hello'\n * const array: LexValue = [1, 2, 3]\n * const object: LexValue = { name: 'Alice', age: 30 }\n * ```\n *\n * @see {@link LexScalar} for primitive value types\n * @see {@link LexMap} for object types\n * @see {@link LexArray} for array types\n */\nexport type LexValue = LexScalar | LexValue[] | { [_ in string]?: LexValue }\n\n/**\n * Object with string keys and LexValue values.\n *\n * Represents a plain object in the Lexicon data model where all values\n * must be valid {@link LexValue} types.\n *\n * @example\n * ```typescript\n * import type { LexMap } from '@atproto/lex'\n *\n * const user: LexMap = {\n * name: 'Alice',\n * age: 30,\n * tags: ['admin', 'user']\n * }\n * ```\n *\n * @see {@link TypedLexMap} for objects with a required `$type` property\n */\nexport type LexMap = { [_ in string]?: LexValue }\n\n/**\n * Array of {@link LexValue} elements.\n *\n * @example\n * ```typescript\n * import type { LexArray } from '@atproto/lex'\n *\n * const items: LexArray = [1, 'two', { three: 3 }]\n * ```\n */\nexport type LexArray = LexValue[]\n\n/**\n * Type guard to check if a value is a valid {@link LexMap}.\n *\n * Returns true if the value is a plain object where all values are valid\n * {@link LexValue} types.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid LexMap\n *\n * @example\n * ```typescript\n * import { isLexMap } from '@atproto/lex'\n *\n * if (isLexMap(data)) {\n * // data is narrowed to LexMap\n * console.log(Object.keys(data))\n * }\n * ```\n */\nexport function isLexMap(value: unknown): value is LexMap {\n return isPlainObject(value) && Object.values(value).every(isLexValue)\n}\n\n/**\n * Type guard to check if a value is a valid {@link LexArray}.\n *\n * Returns true if the value is an array where all elements are valid\n * {@link LexValue} types.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid LexArray\n *\n * @example\n * ```typescript\n * import { isLexArray } from '@atproto/lex'\n *\n * if (isLexArray(data)) {\n * // data is narrowed to LexArray\n * data.forEach(item => console.log(item))\n * }\n * ```\n */\nexport function isLexArray(value: unknown): value is LexArray {\n return Array.isArray(value) && value.every(isLexValue)\n}\n\n/**\n * Type guard to check if a value is a valid {@link LexScalar}.\n *\n * Returns true if the value is one of the primitive Lexicon types:\n * number (integer only), string, boolean, null, Cid, or Uint8Array.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid LexScalar\n *\n * @example\n * ```typescript\n * import { isLexScalar } from '@atproto/lex'\n *\n * isLexScalar('hello') // true\n * isLexScalar(42) // true\n * isLexScalar(3.14) // false (floats not allowed)\n * isLexScalar([1, 2]) // false (arrays are not scalars)\n * ```\n */\nexport function isLexScalar(value: unknown): value is LexScalar {\n switch (typeof value) {\n case 'object':\n return value === null || value instanceof Uint8Array || isCid(value)\n case 'string':\n case 'boolean':\n return true\n case 'number':\n if (Number.isInteger(value)) return true\n // fallthrough\n default:\n return false\n }\n}\n\n/**\n * Type guard to check if a value is a valid {@link LexValue}.\n *\n * Performs a deep check to validate that the value (and all nested values)\n * conform to the Lexicon data model. This includes checking for:\n * - Valid scalar types (number, string, boolean, null, Cid, Uint8Array)\n * - Arrays containing only valid LexValues\n * - Plain objects with string keys and valid LexValue values\n * - No cyclic references (which cannot be serialized to JSON or CBOR)\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid LexValue\n *\n * @example\n * ```typescript\n * import { isLexValue } from '@atproto/lex'\n *\n * isLexValue({ name: 'Alice', tags: ['admin'] }) // true\n * isLexValue(new Date()) // false (not a plain object)\n * isLexValue({ fn: () => {} }) // false (functions not allowed)\n * ```\n */\nexport function isLexValue(value: unknown): value is LexValue {\n // Using a stack to avoid recursion depth issues.\n const stack: unknown[] = [value]\n // Cyclic structures are not valid LexValues as they cannot be serialized to\n // JSON or CBOR. This also allows us to avoid infinite loops when traversing\n // the structure.\n const visited = new Set<object>()\n\n do {\n const value = stack.pop()!\n\n if (isPlainObject(value)) {\n if (visited.has(value)) return false\n visited.add(value)\n stack.push(...Object.values(value))\n } else if (Array.isArray(value)) {\n if (visited.has(value)) return false\n visited.add(value)\n stack.push(...value)\n } else {\n if (!isLexScalar(value)) return false\n }\n } while (stack.length > 0)\n\n // Optimization: ease GC's work\n visited.clear()\n\n return true\n}\n\n/**\n * A {@link LexMap} with a required `$type` property.\n *\n * Used to represent typed objects in the Lexicon data model, where the\n * `$type` property identifies the Lexicon schema that defines the object's\n * structure.\n *\n * @example\n * ```typescript\n * import type { TypedLexMap } from '@atproto/lex'\n *\n * const post: TypedLexMap = {\n * $type: 'app.bsky.feed.post',\n * text: 'Hello world!',\n * createdAt: '2024-01-01T00:00:00Z'\n * }\n * ```\n *\n * @see {@link isTypedLexMap} to check if a value is a TypedLexMap\n */\nexport type TypedLexMap<T extends string = string> = LexMap & { $type: T }\n\n/**\n * Type guard to check if a value is a {@link TypedLexMap}.\n *\n * Returns true if the value is a valid {@link LexMap} with a non-empty\n * `$type` string property.\n *\n * @param value - The LexValue to check\n * @returns `true` if the value is a TypedLexMap\n *\n * @example\n * ```typescript\n * import { isTypedLexMap } from '@atproto/lex'\n *\n * const data = { $type: 'app.bsky.feed.post', text: 'Hello' }\n *\n * if (isTypedLexMap(data)) {\n * console.log(data.$type) // 'app.bsky.feed.post'\n * }\n * ```\n */\nexport function isTypedLexMap(value: LexValue): value is TypedLexMap {\n return (\n isLexMap(value) && typeof value.$type === 'string' && value.$type.length > 0\n )\n}\n"]}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
type Encoding = 'utf8' | 'base64' | 'base64url';
|
|
2
|
+
type WithImplicitCoercion<T> = T | {
|
|
3
|
+
valueOf(): T;
|
|
4
|
+
};
|
|
2
5
|
interface NodeJSBuffer<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> extends Uint8Array<TArrayBuffer> {
|
|
3
6
|
byteLength: number;
|
|
4
7
|
toString(encoding?: Encoding): string;
|
|
@@ -7,6 +10,7 @@ interface NodeJSBufferConstructor {
|
|
|
7
10
|
new (input: string, encoding?: Encoding): NodeJSBuffer;
|
|
8
11
|
from(input: Uint8Array | ArrayBuffer | ArrayBufferView): NodeJSBuffer<ArrayBuffer>;
|
|
9
12
|
from(input: string, encoding?: Encoding): NodeJSBuffer<ArrayBuffer>;
|
|
13
|
+
from<TArrayBuffer extends ArrayBufferLike>(arrayBuffer: WithImplicitCoercion<TArrayBuffer>, byteOffset?: number, length?: number): Buffer<TArrayBuffer>;
|
|
10
14
|
concat(list: readonly Uint8Array[], totalLength?: number): NodeJSBuffer;
|
|
11
15
|
byteLength(input: string, encoding?: Encoding): number;
|
|
12
16
|
prototype: NodeJSBuffer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodejs-buffer.d.ts","sourceRoot":"","sources":["../../src/lib/nodejs-buffer.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"nodejs-buffer.d.ts","sourceRoot":"","sources":["../../src/lib/nodejs-buffer.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,CAAA;AAK/C,KAAK,oBAAoB,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,OAAO,IAAI,CAAC,CAAA;CAAE,CAAA;AAEnD,UAAU,YAAY,CAAC,YAAY,SAAS,eAAe,GAAG,eAAe,CAC3E,SAAQ,UAAU,CAAC,YAAY,CAAC;IAChC,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAA;CACtC;AAED,UAAU,uBAAuB;IAC/B,KAAK,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,YAAY,CAAA;IACtD,IAAI,CACF,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,eAAe,GAChD,YAAY,CAAC,WAAW,CAAC,CAAA;IAC5B,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,YAAY,CAAC,WAAW,CAAC,CAAA;IACnE,IAAI,CAAC,YAAY,SAAS,eAAe,EACvC,WAAW,EAAE,oBAAoB,CAAC,YAAY,CAAC,EAC/C,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAAC,YAAY,CAAC,CAAA;IACvB,MAAM,CAAC,IAAI,EAAE,SAAS,UAAU,EAAE,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,YAAY,CAAA;IACvE,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAA;IACtD,SAAS,EAAE,YAAY,CAAA;CACxB;AAMD,eAAO,MAAM,YAAY,EAAE,uBAAuB,GAAG,IAIT,CAAA"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NodeJSBuffer = void 0;
|
|
4
1
|
// Avoids a direct reference to Node.js Buffer, which might not exist in some
|
|
5
2
|
// environments (e.g. browsers, Deno, Bun) to prevent bundlers from trying to
|
|
6
3
|
// include polyfills.
|
|
7
4
|
const BUFFER = /*#__PURE__*/ (() => 'Bu' + 'f'.repeat(2) + 'er')();
|
|
8
|
-
|
|
5
|
+
export const NodeJSBuffer = globalThis?.[BUFFER]?.prototype instanceof Uint8Array &&
|
|
9
6
|
'byteLength' in globalThis[BUFFER]
|
|
10
7
|
? globalThis[BUFFER]
|
|
11
8
|
: /* v8 ignore next -- @preserve */ null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodejs-buffer.js","sourceRoot":"","sources":["../../src/lib/nodejs-buffer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nodejs-buffer.js","sourceRoot":"","sources":["../../src/lib/nodejs-buffer.ts"],"names":[],"mappings":"AA6BA,6EAA6E;AAC7E,6EAA6E;AAC7E,qBAAqB;AACrB,MAAM,MAAM,GAAG,aAAa,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAc,CAAA;AAC9E,MAAM,CAAC,MAAM,YAAY,GACtB,UAAkB,EAAE,CAAC,MAAM,CAAC,EAAE,SAAS,YAAY,UAAU;IAC9D,YAAY,IAAK,UAAkB,CAAC,MAAM,CAAC;IACzC,CAAC,CAAG,UAAkB,CAAC,MAAM,CAA6B;IAC1D,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA","sourcesContent":["type Encoding = 'utf8' | 'base64' | 'base64url'\n\n// Node's buffer module declares this type internally, but referencing it here\n// would couple this file to @types/node. Local copy keeps this module\n// standalone so it compiles in any environment (see tsconfig/isomorphic.json).\ntype WithImplicitCoercion<T> = T | { valueOf(): T }\n\ninterface NodeJSBuffer<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>\n extends Uint8Array<TArrayBuffer> {\n byteLength: number\n toString(encoding?: Encoding): string\n}\n\ninterface NodeJSBufferConstructor {\n new (input: string, encoding?: Encoding): NodeJSBuffer\n from(\n input: Uint8Array | ArrayBuffer | ArrayBufferView,\n ): NodeJSBuffer<ArrayBuffer>\n from(input: string, encoding?: Encoding): NodeJSBuffer<ArrayBuffer>\n from<TArrayBuffer extends ArrayBufferLike>(\n arrayBuffer: WithImplicitCoercion<TArrayBuffer>,\n byteOffset?: number,\n length?: number,\n ): Buffer<TArrayBuffer>\n concat(list: readonly Uint8Array[], totalLength?: number): NodeJSBuffer\n byteLength(input: string, encoding?: Encoding): number\n prototype: NodeJSBuffer\n}\n\n// Avoids a direct reference to Node.js Buffer, which might not exist in some\n// environments (e.g. browsers, Deno, Bun) to prevent bundlers from trying to\n// include polyfills.\nconst BUFFER = /*#__PURE__*/ (() => 'Bu' + 'f'.repeat(2) + 'er')() as 'Buffer'\nexport const NodeJSBuffer: NodeJSBufferConstructor | null =\n (globalThis as any)?.[BUFFER]?.prototype instanceof Uint8Array &&\n 'byteLength' in (globalThis as any)[BUFFER]\n ? ((globalThis as any)[BUFFER] as NodeJSBufferConstructor)\n : /* v8 ignore next -- @preserve */ null\n"]}
|
package/dist/lib/util.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toHexString = toHexString;
|
|
4
|
-
exports.isUint8 = isUint8;
|
|
5
|
-
function toHexString(number) {
|
|
1
|
+
export function toHexString(number) {
|
|
6
2
|
return `0x${number.toString(16).padStart(2, '0')}`;
|
|
7
3
|
}
|
|
8
|
-
function isUint8(val) {
|
|
4
|
+
export function isUint8(val) {
|
|
9
5
|
return Number.isInteger(val) && val >= 0 && val < 256;
|
|
10
6
|
}
|
|
11
7
|
//# sourceMappingURL=util.js.map
|
package/dist/lib/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/lib/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/lib/util.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,OAAO,KAAK,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAA;AACpD,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,GAAY;IAClC,OAAO,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAK,GAAc,IAAI,CAAC,IAAK,GAAc,GAAG,GAAG,CAAA;AAC/E,CAAC","sourcesContent":["export function toHexString(number: number): string {\n return `0x${number.toString(16).padStart(2, '0')}`\n}\n\nexport function isUint8(val: unknown): val is number {\n return Number.isInteger(val) && (val as number) >= 0 && (val as number) < 256\n}\n"]}
|
package/dist/object.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isObject = isObject;
|
|
4
|
-
exports.isPlainObject = isPlainObject;
|
|
5
|
-
exports.isPlainProto = isPlainProto;
|
|
6
1
|
/**
|
|
7
2
|
* Checks whether the input is an object (not null).
|
|
8
3
|
*
|
|
@@ -23,7 +18,7 @@ exports.isPlainProto = isPlainProto;
|
|
|
23
18
|
* isObject('string') // false
|
|
24
19
|
* ```
|
|
25
20
|
*/
|
|
26
|
-
function isObject(input) {
|
|
21
|
+
export function isObject(input) {
|
|
27
22
|
return input != null && typeof input === 'object';
|
|
28
23
|
}
|
|
29
24
|
const ObjectProto = Object.prototype;
|
|
@@ -50,7 +45,7 @@ const ObjectToString = Object.prototype.toString;
|
|
|
50
45
|
* isPlainObject(null) // false
|
|
51
46
|
* ```
|
|
52
47
|
*/
|
|
53
|
-
function isPlainObject(input) {
|
|
48
|
+
export function isPlainObject(input) {
|
|
54
49
|
return isObject(input) && isPlainProto(input);
|
|
55
50
|
}
|
|
56
51
|
/**
|
|
@@ -72,7 +67,7 @@ function isPlainObject(input) {
|
|
|
72
67
|
* isPlainProto(new Date()) // false (Date.prototype)
|
|
73
68
|
* ```
|
|
74
69
|
*/
|
|
75
|
-
function isPlainProto(input) {
|
|
70
|
+
export function isPlainProto(input) {
|
|
76
71
|
const proto = Object.getPrototypeOf(input);
|
|
77
72
|
if (proto === null)
|
|
78
73
|
return true;
|
package/dist/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAA;AACnD,CAAC;AAED,MAAM,WAAW,GAAG,MAAM,CAAC,SAAS,CAAA;AACpC,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAA;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,CAAA;AAC/C,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IAC1C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAC/B,OAAO,CACL,CAAC,KAAK,KAAK,WAAW;QACpB,sEAAsE;QACtE,6BAA6B;QAC7B,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;QACxC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CACjD,CAAA;AACH,CAAC","sourcesContent":["/**\n * Checks whether the input is an object (not null).\n *\n * Returns true for any non-null value with typeof 'object', including\n * arrays, plain objects, class instances, etc.\n *\n * @param input - The value to check\n * @returns `true` if the input is an object (not null)\n *\n * @example\n * ```typescript\n * import { isObject } from '@atproto/lex-data'\n *\n * isObject({}) // true\n * isObject([1, 2, 3]) // true\n * isObject(new Date()) // true\n * isObject(null) // false\n * isObject('string') // false\n * ```\n */\nexport function isObject(input: unknown): input is object {\n return input != null && typeof input === 'object'\n}\n\nconst ObjectProto = Object.prototype\nconst ObjectToString = Object.prototype.toString\n\n/**\n * Checks whether the input is a plain object.\n *\n * A plain object is an object (not null) whose prototype is either null\n * or `Object.prototype`. This excludes arrays, class instances, and other\n * special objects.\n *\n * @param input - The value to check\n * @returns `true` if the input is a plain object\n *\n * @example\n * ```typescript\n * import { isPlainObject } from '@atproto/lex-data'\n *\n * isPlainObject({}) // true\n * isPlainObject({ a: 1 }) // true\n * isPlainObject(Object.create(null)) // true\n * isPlainObject([1, 2, 3]) // false\n * isPlainObject(new Date()) // false\n * isPlainObject(null) // false\n * ```\n */\nexport function isPlainObject(input: unknown) {\n return isObject(input) && isPlainProto(input)\n}\n\n/**\n * Checks whether the prototype of an object is plain (null or Object.prototype).\n *\n * This is useful for checking if an object is a plain object without\n * checking that it's non-null first (the null check is already done).\n *\n * @param input - The object to check (must be non-null)\n * @returns `true` if the object's prototype is plain\n *\n * @example\n * ```typescript\n * import { isPlainProto } from '@atproto/lex-data'\n *\n * isPlainProto({}) // true\n * isPlainProto(Object.create(null)) // true\n * isPlainProto([1, 2, 3]) // false (Array.prototype)\n * isPlainProto(new Date()) // false (Date.prototype)\n * ```\n */\nexport function isPlainProto(input: object): input is Record<string, unknown> {\n const proto = Object.getPrototypeOf(input)\n if (proto === null) return true\n return (\n (proto === ObjectProto ||\n // Needed to support NodeJS's `runInNewContext` which produces objects\n // with a different prototype\n Object.getPrototypeOf(proto) === null) &&\n ObjectToString.call(input) === '[object Object]'\n )\n}\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const ui8ConcatNode: ((array: readonly Uint8Array[]) => Uint8Array) | null;
|
|
2
|
-
export declare function ui8ConcatPonyfill(array: readonly Uint8Array[]): Uint8Array
|
|
1
|
+
export declare const ui8ConcatNode: ((array: readonly Uint8Array[]) => Uint8Array<ArrayBuffer>) | null;
|
|
2
|
+
export declare function ui8ConcatPonyfill(array: readonly Uint8Array[]): Uint8Array<ArrayBuffer>;
|
|
3
3
|
//# sourceMappingURL=uint8array-concat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8array-concat.d.ts","sourceRoot":"","sources":["../src/uint8array-concat.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"uint8array-concat.d.ts","sourceRoot":"","sources":["../src/uint8array-concat.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,WAEb,SAAS,UAAU,EAAE,KAC3B,UAAU,CAAC,WAAW,CAAC,QAGY,CAAA;AAE1C,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,SAAS,UAAU,EAAE,GAC3B,UAAU,CAAC,WAAW,CAAC,CAUzB"}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.ui8ConcatPonyfill = ui8ConcatPonyfill;
|
|
5
|
-
const nodejs_buffer_js_1 = require("./lib/nodejs-buffer.js");
|
|
6
|
-
const Buffer = nodejs_buffer_js_1.NodeJSBuffer;
|
|
7
|
-
exports.ui8ConcatNode = Buffer
|
|
1
|
+
import { NodeJSBuffer } from './lib/nodejs-buffer.js';
|
|
2
|
+
const Buffer = NodeJSBuffer;
|
|
3
|
+
export const ui8ConcatNode = Buffer
|
|
8
4
|
? function ui8ConcatNode(array) {
|
|
9
5
|
return Buffer.concat(array);
|
|
10
6
|
}
|
|
11
7
|
: /* v8 ignore next -- @preserve */ null;
|
|
12
|
-
function ui8ConcatPonyfill(array) {
|
|
8
|
+
export function ui8ConcatPonyfill(array) {
|
|
13
9
|
let totalLength = 0;
|
|
14
10
|
for (const arr of array)
|
|
15
11
|
totalLength += arr.length;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8array-concat.js","sourceRoot":"","sources":["../src/uint8array-concat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uint8array-concat.js","sourceRoot":"","sources":["../src/uint8array-concat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAErD,MAAM,MAAM,GAAG,YAAY,CAAA;AAE3B,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM;IACjC,CAAC,CAAC,SAAS,aAAa,CACpB,KAA4B;QAE5B,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAA4B,CAAA;IACxD,CAAC;IACH,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE1C,MAAM,UAAU,iBAAiB,CAC/B,KAA4B;IAE5B,IAAI,WAAW,GAAG,CAAC,CAAA;IACnB,KAAK,MAAM,GAAG,IAAI,KAAK;QAAE,WAAW,IAAI,GAAG,CAAC,MAAM,CAAA;IAClD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAA;IAC1C,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACvB,MAAM,IAAI,GAAG,CAAC,MAAM,CAAA;IACtB,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { NodeJSBuffer } from './lib/nodejs-buffer.js'\n\nconst Buffer = NodeJSBuffer\n\nexport const ui8ConcatNode = Buffer\n ? function ui8ConcatNode(\n array: readonly Uint8Array[],\n ): Uint8Array<ArrayBuffer> {\n return Buffer.concat(array) as Uint8Array<ArrayBuffer>\n }\n : /* v8 ignore next -- @preserve */ null\n\nexport function ui8ConcatPonyfill(\n array: readonly Uint8Array[],\n): Uint8Array<ArrayBuffer> {\n let totalLength = 0\n for (const arr of array) totalLength += arr.length\n const result = new Uint8Array(totalLength)\n let offset = 0\n for (const arr of array) {\n result.set(arr, offset)\n offset += arr.length\n }\n return result\n}\n"]}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const from_string_1 = require("uint8arrays/from-string");
|
|
6
|
-
const nodejs_buffer_js_1 = require("./lib/nodejs-buffer.js");
|
|
7
|
-
const Buffer = nodejs_buffer_js_1.NodeJSBuffer;
|
|
8
|
-
exports.fromBase64Native = typeof Uint8Array.fromBase64 === 'function'
|
|
1
|
+
import { fromString } from 'uint8arrays/from-string';
|
|
2
|
+
import { NodeJSBuffer } from './lib/nodejs-buffer.js';
|
|
3
|
+
const Buffer = NodeJSBuffer;
|
|
4
|
+
export const fromBase64Native = typeof Uint8Array.fromBase64 === 'function'
|
|
9
5
|
? function fromBase64Native(b64, alphabet = 'base64') {
|
|
10
6
|
return Uint8Array.fromBase64(b64, {
|
|
11
7
|
alphabet,
|
|
@@ -13,7 +9,7 @@ exports.fromBase64Native = typeof Uint8Array.fromBase64 === 'function'
|
|
|
13
9
|
});
|
|
14
10
|
}
|
|
15
11
|
: /* v8 ignore next -- @preserve */ null;
|
|
16
|
-
|
|
12
|
+
export const fromBase64Node = Buffer
|
|
17
13
|
? function fromBase64Node(b64, alphabet = 'base64') {
|
|
18
14
|
const bytes = Buffer.from(b64, alphabet);
|
|
19
15
|
verifyBase64ForBytes(b64, bytes);
|
|
@@ -23,8 +19,8 @@ exports.fromBase64Node = Buffer
|
|
|
23
19
|
return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
24
20
|
}
|
|
25
21
|
: /* v8 ignore next -- @preserve */ null;
|
|
26
|
-
function fromBase64Ponyfill(b64, alphabet = 'base64') {
|
|
27
|
-
const bytes =
|
|
22
|
+
export function fromBase64Ponyfill(b64, alphabet = 'base64') {
|
|
23
|
+
const bytes = fromString(b64, b64.endsWith('=') ? `${alphabet}pad` : alphabet);
|
|
28
24
|
verifyBase64ForBytes(b64, bytes);
|
|
29
25
|
return bytes;
|
|
30
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8array-from-base64.js","sourceRoot":"","sources":["../src/uint8array-from-base64.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uint8array-from-base64.js","sourceRoot":"","sources":["../src/uint8array-from-base64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAGrD,MAAM,MAAM,GAAG,YAAY,CAAA;AAkB3B,MAAM,CAAC,MAAM,gBAAgB,GAC3B,OAAO,UAAU,CAAC,UAAU,KAAK,UAAU;IACzC,CAAC,CAAC,SAAS,gBAAgB,CACvB,GAAW,EACX,WAA2B,QAAQ;QAEnC,OAAO,UAAU,CAAC,UAAW,CAAC,GAAG,EAAE;YACjC,QAAQ;YACR,iBAAiB,EAAE,OAAO;SAC3B,CAAC,CAAA;IACJ,CAAC;IACH,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE5C,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM;IAClC,CAAC,CAAC,SAAS,cAAc,CACrB,GAAW,EACX,WAA2B,QAAQ;QAEnC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;QACxC,oBAAoB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QAChC,qEAAqE;QACrE,yEAAyE;QACzE,4DAA4D;QAC5D,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;IACzE,CAAC;IACH,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE1C,MAAM,UAAU,kBAAkB,CAChC,GAA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AAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;IAC1C,CAAC;IAED,qEAAqE;IACrE,qBAAqB;IACrB,KACE,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,EACpC,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,YAAY,EAC7B,CAAC,EAAE,EACH,CAAC;QACD,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QAC9B,IACE,CAAC,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC,IAAI,MAAM;YACrC,CAAC,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,IAAI,GAAG,CAAC,IAAI,MAAM;YACtC,CAAC,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC,IAAI,MAAM;YACrC,IAAI,KAAK,EAAE,IAAI,IAAI;YACnB,IAAI,KAAK,EAAE,CAAC,IAAI;UAChB,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;QAC1C,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { fromString } from 'uint8arrays/from-string'\nimport { NodeJSBuffer } from './lib/nodejs-buffer.js'\nimport { Base64Alphabet } from './uint8array-base64.js'\n\nconst Buffer = NodeJSBuffer\n\ndeclare global {\n interface Uint8ArrayConstructor {\n /**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64 Uint8Array.fromBase64()}\n */\n fromBase64?: (\n b64: string,\n options?: {\n /** @default 'base64' */\n alphabet?: 'base64' | 'base64url'\n lastChunkHandling?: 'loose' | 'strict' | 'stop-before-partial'\n },\n ) => Uint8Array\n }\n}\n\nexport const fromBase64Native =\n typeof Uint8Array.fromBase64 === 'function'\n ? function fromBase64Native(\n b64: string,\n alphabet: Base64Alphabet = 'base64',\n ): Uint8Array {\n return Uint8Array.fromBase64!(b64, {\n alphabet,\n lastChunkHandling: 'loose',\n })\n }\n : /* v8 ignore next -- @preserve */ null\n\nexport const fromBase64Node = Buffer\n ? function fromBase64Node(\n b64: string,\n alphabet: Base64Alphabet = 'base64',\n ): Uint8Array {\n const bytes = Buffer.from(b64, alphabet)\n verifyBase64ForBytes(b64, bytes)\n // Convert to Uint8Array because even though Buffer is a sub class of\n // Uint8Array, it serializes differently to Uint8Array (e.g. in JSON) and\n // results in unexpected behavior downstream (e.g. in tests)\n return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength)\n }\n : /* v8 ignore next -- @preserve */ null\n\nexport function fromBase64Ponyfill(\n b64: string,\n alphabet: Base64Alphabet = 'base64',\n): Uint8Array {\n const bytes = fromString(b64, b64.endsWith('=') ? `${alphabet}pad` : alphabet)\n verifyBase64ForBytes(b64, bytes)\n return bytes\n}\n\n// @NOTE NodeJS will silently stop decoding at the first invalid character,\n// while \"uint8arrays/from-string\" will not validate that the padding is\n// correct. The following function performs basic validation to ensure that the\n// input was a valid base64 string. The availability of the \"bytes\" allows\n// to perform checks with O[1] complexity.\nfunction verifyBase64ForBytes(b64: string, bytes: Uint8Array): void {\n const paddingCount = b64.endsWith('==') ? 2 : b64.endsWith('=') ? 1 : 0\n const trimmedLength = b64.length - paddingCount\n const expectedByteLength = Math.floor((trimmedLength * 3) / 4)\n if (bytes.length !== expectedByteLength) {\n throw new Error('Invalid base64 string')\n }\n\n const expectedB64Length = (bytes.length / 3) * 4\n const expectedPaddingCount =\n expectedB64Length % 4 === 0 ? 0 : 4 - (expectedB64Length % 4)\n const expectedFullB64Length = expectedB64Length + expectedPaddingCount\n if (b64.length > expectedFullB64Length) {\n throw new Error('Invalid base64 string')\n }\n\n // The previous might still allow false positive if only the last few\n // chars are invalid.\n for (\n let i = Math.ceil(expectedB64Length);\n i < b64.length - paddingCount;\n i++\n ) {\n const code = b64.charCodeAt(i)\n if (\n !(code >= 65 && code <= 90) && // A-Z\n !(code >= 97 && code <= 122) && // a-z\n !(code >= 48 && code <= 57) && // 0-9\n code !== 43 && // +\n code !== 47 // /\n ) {\n throw new Error('Invalid base64 string')\n }\n }\n}\n"]}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const to_string_1 = require("uint8arrays/to-string");
|
|
6
|
-
const nodejs_buffer_js_1 = require("./lib/nodejs-buffer.js");
|
|
7
|
-
const Buffer = nodejs_buffer_js_1.NodeJSBuffer;
|
|
8
|
-
exports.toBase64Native = typeof Uint8Array.prototype.toBase64 === 'function'
|
|
1
|
+
import { toString } from 'uint8arrays/to-string';
|
|
2
|
+
import { NodeJSBuffer } from './lib/nodejs-buffer.js';
|
|
3
|
+
const Buffer = NodeJSBuffer;
|
|
4
|
+
export const toBase64Native = typeof Uint8Array.prototype.toBase64 === 'function'
|
|
9
5
|
? function toBase64Native(bytes, alphabet = 'base64') {
|
|
10
6
|
return bytes.toBase64({ alphabet, omitPadding: true });
|
|
11
7
|
}
|
|
12
8
|
: /* v8 ignore next -- @preserve */ null;
|
|
13
|
-
|
|
9
|
+
export const toBase64Node = Buffer
|
|
14
10
|
? function toBase64Node(bytes, alphabet = 'base64') {
|
|
15
11
|
const buffer = bytes instanceof Buffer ? bytes : Buffer.from(bytes);
|
|
16
12
|
const b64 = buffer.toString(alphabet);
|
|
@@ -25,7 +21,7 @@ exports.toBase64Node = Buffer
|
|
|
25
21
|
: b64;
|
|
26
22
|
}
|
|
27
23
|
: /* v8 ignore next -- @preserve */ null;
|
|
28
|
-
function toBase64Ponyfill(bytes, alphabet = 'base64') {
|
|
29
|
-
return
|
|
24
|
+
export function toBase64Ponyfill(bytes, alphabet = 'base64') {
|
|
25
|
+
return toString(bytes, alphabet);
|
|
30
26
|
}
|
|
31
27
|
//# sourceMappingURL=uint8array-to-base64.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8array-to-base64.js","sourceRoot":"","sources":["../src/uint8array-to-base64.ts"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,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM;YAC3B,CAAC,CAAC,GAAG,CAAA;IACT,CAAC;IACH,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE1C,MAAM,UAAU,gBAAgB,CAC9B,KAAiB,EACjB,WAA2B,QAAQ;IAEnC,OAAO,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;AAClC,CAAC","sourcesContent":["import { toString } from 'uint8arrays/to-string'\nimport { NodeJSBuffer } from './lib/nodejs-buffer.js'\nimport { Base64Alphabet } from './uint8array-base64.js'\n\nconst Buffer = NodeJSBuffer\n\ndeclare global {\n interface Uint8Array {\n /**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64 Uint8Array.prototype.toBase64()}\n */\n toBase64?: (options?: {\n /** @default 'base64' */\n alphabet?: 'base64' | 'base64url'\n omitPadding?: boolean\n }) => string\n }\n}\n\nexport const toBase64Native =\n typeof Uint8Array.prototype.toBase64 === 'function'\n ? function toBase64Native(\n bytes: Uint8Array,\n alphabet: Base64Alphabet = 'base64',\n ): string {\n return bytes.toBase64!({ alphabet, omitPadding: true })\n }\n : /* v8 ignore next -- @preserve */ null\n\nexport const toBase64Node = Buffer\n ? function toBase64Node(\n bytes: Uint8Array,\n alphabet: Base64Alphabet = 'base64',\n ): string {\n const buffer = bytes instanceof Buffer ? bytes : Buffer.from(bytes)\n const b64 = buffer.toString(alphabet)\n\n // @NOTE We strip padding for strict compatibility with\n // uint8arrays.toString behavior. Tests failing because of the presence of\n // padding are not really synonymous with an actual error and we might\n // (should?) actually want to keep the padding at some point.\n return b64.charCodeAt(b64.length - 1) === /* '=' */ 0x3d\n ? b64.charCodeAt(b64.length - 2) === /* '=' */ 0x3d\n ? b64.slice(0, -2) // '=='\n : b64.slice(0, -1) // '='\n : b64\n }\n : /* v8 ignore next -- @preserve */ null\n\nexport function toBase64Ponyfill(\n bytes: Uint8Array,\n alphabet: Base64Alphabet = 'base64',\n): string {\n return toString(bytes, alphabet)\n}\n"]}
|
package/dist/uint8array.d.ts
CHANGED
|
@@ -114,5 +114,5 @@ export declare function ui8Equals(a: Uint8Array, b: Uint8Array): boolean;
|
|
|
114
114
|
* ui8Concat([a, b]) // Uint8Array([1, 2, 3, 4])
|
|
115
115
|
* ```
|
|
116
116
|
*/
|
|
117
|
-
export declare const ui8Concat: (array: readonly Uint8Array[]) => Uint8Array
|
|
117
|
+
export declare const ui8Concat: (array: readonly Uint8Array[]) => Uint8Array<ArrayBuffer>;
|
|
118
118
|
//# sourceMappingURL=uint8array.d.ts.map
|
package/dist/uint8array.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8array.d.ts","sourceRoot":"","sources":["../src/uint8array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAavD,YAAY,EAAE,cAAc,EAAE,CAAA;AAO9B;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,QAAQ,EAAE,CACrB,KAAK,EAAE,UAAU,EACjB,QAAQ,CAAC,EAAE,cAAc,KACtB,MAGa,CAAA;AAElB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,UAAU,EAAE,CACvB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,cAAc,KACtB,UAGe,CAAA;AAUpB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAMnE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAkBnE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAY/D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"uint8array.d.ts","sourceRoot":"","sources":["../src/uint8array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAavD,YAAY,EAAE,cAAc,EAAE,CAAA;AAO9B;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,QAAQ,EAAE,CACrB,KAAK,EAAE,UAAU,EACjB,QAAQ,CAAC,EAAE,cAAc,KACtB,MAGa,CAAA;AAElB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,UAAU,EAAE,CACvB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,cAAc,KACtB,UAGe,CAAA;AAUpB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAMnE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAkBnE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAY/D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,SAAS,2DACgD,CAAA"}
|
package/dist/uint8array.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.ifUint8Array = ifUint8Array;
|
|
5
|
-
exports.asUint8Array = asUint8Array;
|
|
6
|
-
exports.ui8Equals = ui8Equals;
|
|
7
|
-
const uint8array_concat_js_1 = require("./uint8array-concat.js");
|
|
8
|
-
const uint8array_from_base64_js_1 = require("./uint8array-from-base64.js");
|
|
9
|
-
const uint8array_to_base64_js_1 = require("./uint8array-to-base64.js");
|
|
1
|
+
import { ui8ConcatNode, ui8ConcatPonyfill } from './uint8array-concat.js';
|
|
2
|
+
import { fromBase64Native, fromBase64Node, fromBase64Ponyfill, } from './uint8array-from-base64.js';
|
|
3
|
+
import { toBase64Native, toBase64Node, toBase64Ponyfill, } from './uint8array-to-base64.js';
|
|
10
4
|
// @TODO drop dependency on uint8arrays package once Uint8Array.fromBase64 /
|
|
11
5
|
// Uint8Array.prototype.toBase64 is widely supported, and mark fromBase64 /
|
|
12
6
|
// toBase64 as deprecated. We can also drop NodeJS specific implementations
|
|
@@ -30,10 +24,10 @@ const uint8array_to_base64_js_1 = require("./uint8array-to-base64.js");
|
|
|
30
24
|
* toBase64(bytes, 'base64url') // 'SGVsbG8' (URL-safe, no padding)
|
|
31
25
|
* ```
|
|
32
26
|
*/
|
|
33
|
-
|
|
34
|
-
/* v8 ignore next -- @preserve */
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
export const toBase64 =
|
|
28
|
+
/* v8 ignore next -- @preserve */ toBase64Native ??
|
|
29
|
+
toBase64Node ??
|
|
30
|
+
toBase64Ponyfill;
|
|
37
31
|
/**
|
|
38
32
|
* Decodes a base64 string into a Uint8Array.
|
|
39
33
|
*
|
|
@@ -54,12 +48,12 @@ exports.toBase64 =
|
|
|
54
48
|
* fromBase64('SGVsbG8', 'base64url') // Same, URL-safe alphabet
|
|
55
49
|
* ```
|
|
56
50
|
*/
|
|
57
|
-
|
|
58
|
-
/* v8 ignore next -- @preserve */
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
export const fromBase64 =
|
|
52
|
+
/* v8 ignore next -- @preserve */ fromBase64Native ??
|
|
53
|
+
fromBase64Node ??
|
|
54
|
+
fromBase64Ponyfill;
|
|
61
55
|
/* v8 ignore next -- @preserve */
|
|
62
|
-
if (
|
|
56
|
+
if (toBase64 === toBase64Ponyfill || fromBase64 === fromBase64Ponyfill) {
|
|
63
57
|
/*#__PURE__*/
|
|
64
58
|
console.warn('[@atproto/lex-data]: Uint8Array.fromBase64 / Uint8Array.prototype.toBase64 not available in this environment. Falling back to ponyfill implementation.');
|
|
65
59
|
}
|
|
@@ -78,7 +72,7 @@ if (exports.toBase64 === uint8array_to_base64_js_1.toBase64Ponyfill || exports.f
|
|
|
78
72
|
* ifUint8Array(new ArrayBuffer(4)) // undefined
|
|
79
73
|
* ```
|
|
80
74
|
*/
|
|
81
|
-
function ifUint8Array(input) {
|
|
75
|
+
export function ifUint8Array(input) {
|
|
82
76
|
if (input instanceof Uint8Array) {
|
|
83
77
|
return input;
|
|
84
78
|
}
|
|
@@ -105,7 +99,7 @@ function ifUint8Array(input) {
|
|
|
105
99
|
* asUint8Array('string') // undefined
|
|
106
100
|
* ```
|
|
107
101
|
*/
|
|
108
|
-
function asUint8Array(input) {
|
|
102
|
+
export function asUint8Array(input) {
|
|
109
103
|
if (input instanceof Uint8Array) {
|
|
110
104
|
return input;
|
|
111
105
|
}
|
|
@@ -133,7 +127,7 @@ function asUint8Array(input) {
|
|
|
133
127
|
* ui8Equals(new Uint8Array([1]), new Uint8Array([1, 2])) // false
|
|
134
128
|
* ```
|
|
135
129
|
*/
|
|
136
|
-
function ui8Equals(a, b) {
|
|
130
|
+
export function ui8Equals(a, b) {
|
|
137
131
|
if (a.byteLength !== b.byteLength) {
|
|
138
132
|
return false;
|
|
139
133
|
}
|
|
@@ -162,6 +156,6 @@ function ui8Equals(a, b) {
|
|
|
162
156
|
* ui8Concat([a, b]) // Uint8Array([1, 2, 3, 4])
|
|
163
157
|
* ```
|
|
164
158
|
*/
|
|
165
|
-
|
|
166
|
-
/* v8 ignore next -- @preserve */
|
|
159
|
+
export const ui8Concat =
|
|
160
|
+
/* v8 ignore next -- @preserve */ ui8ConcatNode ?? ui8ConcatPonyfill;
|
|
167
161
|
//# sourceMappingURL=uint8array.js.map
|
package/dist/uint8array.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8array.js","sourceRoot":"","sources":["../src/uint8array.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"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C,iBAAiB,CAChD,CAAA;IACH,CAAC;IAED,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;QACjC,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,SAAS,CAAC,CAAa,EAAE,CAAa;IACpD,IAAI,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU,EAAE,CAAC;QAClC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAClB,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,SAAS;AACpB,iCAAiC,CAAC,aAAa,IAAI,iBAAiB,CAAA","sourcesContent":["import { Base64Alphabet } from './uint8array-base64.js'\nimport { ui8ConcatNode, ui8ConcatPonyfill } from './uint8array-concat.js'\nimport {\n fromBase64Native,\n fromBase64Node,\n fromBase64Ponyfill,\n} from './uint8array-from-base64.js'\nimport {\n toBase64Native,\n toBase64Node,\n toBase64Ponyfill,\n} from './uint8array-to-base64.js'\n\nexport type { Base64Alphabet }\n\n// @TODO drop dependency on uint8arrays package once Uint8Array.fromBase64 /\n// Uint8Array.prototype.toBase64 is widely supported, and mark fromBase64 /\n// toBase64 as deprecated. We can also drop NodeJS specific implementations\n// once NodeJS <24 is no longer supported.\n\n/**\n * Encodes a Uint8Array into a base64 string.\n *\n * Uses native Uint8Array.prototype.toBase64 when available (Node.js 24+, modern browsers),\n * falling back to Node.js Buffer or a ponyfill implementation.\n *\n * @param bytes - The binary data to encode\n * @param alphabet - The base64 alphabet to use ('base64' or 'base64url'), defaults to 'base64'\n * @returns The base64 encoded string\n *\n * @example\n * ```typescript\n * import { toBase64 } from '@atproto/lex-data'\n *\n * const bytes = new Uint8Array([72, 101, 108, 108, 111])\n * toBase64(bytes) // 'SGVsbG8='\n * toBase64(bytes, 'base64url') // 'SGVsbG8' (URL-safe, no padding)\n * ```\n */\nexport const toBase64: (\n bytes: Uint8Array,\n alphabet?: Base64Alphabet,\n) => string =\n /* v8 ignore next -- @preserve */ toBase64Native ??\n toBase64Node ??\n toBase64Ponyfill\n\n/**\n * Decodes a base64 string into a Uint8Array.\n *\n * Supports both padded and unpadded base64 strings. Uses native\n * Uint8Array.fromBase64 when available, falling back to Node.js Buffer\n * or a ponyfill implementation.\n *\n * @param b64 - The base64 string to decode\n * @param alphabet - The base64 alphabet to use ('base64' or 'base64url'), defaults to 'base64'\n * @returns The decoded binary data\n * @throws If the input is not a valid base64 string\n *\n * @example\n * ```typescript\n * import { fromBase64 } from '@atproto/lex-data'\n *\n * fromBase64('SGVsbG8=') // Uint8Array([72, 101, 108, 108, 111])\n * fromBase64('SGVsbG8', 'base64url') // Same, URL-safe alphabet\n * ```\n */\nexport const fromBase64: (\n b64: string,\n alphabet?: Base64Alphabet,\n) => Uint8Array =\n /* v8 ignore next -- @preserve */ fromBase64Native ??\n fromBase64Node ??\n fromBase64Ponyfill\n\n/* v8 ignore next -- @preserve */\nif (toBase64 === toBase64Ponyfill || fromBase64 === fromBase64Ponyfill) {\n /*#__PURE__*/\n console.warn(\n '[@atproto/lex-data]: Uint8Array.fromBase64 / Uint8Array.prototype.toBase64 not available in this environment. Falling back to ponyfill implementation.',\n )\n}\n\n/**\n * Returns the input if it is a Uint8Array, otherwise returns undefined.\n *\n * @param input - The value to check\n * @returns The input if it's a Uint8Array, otherwise undefined\n *\n * @example\n * ```typescript\n * import { ifUint8Array } from '@atproto/lex-data'\n *\n * ifUint8Array(new Uint8Array([1, 2])) // Uint8Array([1, 2])\n * ifUint8Array('not binary') // undefined\n * ifUint8Array(new ArrayBuffer(4)) // undefined\n * ```\n */\nexport function ifUint8Array(input: unknown): Uint8Array | undefined {\n if (input instanceof Uint8Array) {\n return input\n }\n\n return undefined\n}\n\n/**\n * Coerces various binary data representations into a Uint8Array.\n *\n * Handles the following input types:\n * - `Uint8Array` - Returned as-is\n * - `ArrayBufferView` (e.g., DataView, other TypedArrays) - Converted to Uint8Array\n * - `ArrayBuffer` - Wrapped in a Uint8Array\n *\n * @param input - The value to convert\n * @returns A Uint8Array, or `undefined` if the input could not be converted\n *\n * @example\n * ```typescript\n * import { asUint8Array } from '@atproto/lex-data'\n *\n * asUint8Array(new Uint8Array([1, 2])) // Uint8Array([1, 2])\n * asUint8Array(new ArrayBuffer(4)) // Uint8Array of length 4\n * asUint8Array(new Int16Array([1, 2])) // Uint8Array view of the buffer\n * asUint8Array('string') // undefined\n * ```\n */\nexport function asUint8Array(input: unknown): Uint8Array | undefined {\n if (input instanceof Uint8Array) {\n return input\n }\n\n if (ArrayBuffer.isView(input)) {\n return new Uint8Array(\n input.buffer,\n input.byteOffset,\n input.byteLength / Uint8Array.BYTES_PER_ELEMENT,\n )\n }\n\n if (input instanceof ArrayBuffer) {\n return new Uint8Array(input)\n }\n\n return undefined\n}\n\n/**\n * Compares two Uint8Arrays for byte-by-byte equality.\n *\n * @param a - First Uint8Array to compare\n * @param b - Second Uint8Array to compare\n * @returns `true` if both arrays have the same length and identical bytes\n *\n * @example\n * ```typescript\n * import { ui8Equals } from '@atproto/lex-data'\n *\n * ui8Equals(new Uint8Array([1, 2]), new Uint8Array([1, 2])) // true\n * ui8Equals(new Uint8Array([1, 2]), new Uint8Array([1, 3])) // false\n * ui8Equals(new Uint8Array([1]), new Uint8Array([1, 2])) // false\n * ```\n */\nexport function ui8Equals(a: Uint8Array, b: Uint8Array): boolean {\n if (a.byteLength !== b.byteLength) {\n return false\n }\n\n for (let i = 0; i < a.byteLength; i++) {\n if (a[i] !== b[i]) {\n return false\n }\n }\n\n return true\n}\n\n/**\n * Concatenates multiple Uint8Arrays into a single Uint8Array.\n *\n * Uses Node.js Buffer.concat when available for performance,\n * falling back to a ponyfill implementation.\n *\n * @param arrays - The Uint8Arrays to concatenate\n * @returns A new Uint8Array containing all input bytes in order\n *\n * @example\n * ```typescript\n * import { ui8Concat } from '@atproto/lex-data'\n *\n * const a = new Uint8Array([1, 2])\n * const b = new Uint8Array([3, 4])\n * ui8Concat([a, b]) // Uint8Array([1, 2, 3, 4])\n * ```\n */\nexport const ui8Concat =\n /* v8 ignore next -- @preserve */ ui8ConcatNode ?? ui8ConcatPonyfill\n"]}
|
package/dist/utf8-from-base64.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const from_string_1 = require("uint8arrays/from-string");
|
|
6
|
-
const nodejs_buffer_js_1 = require("./lib/nodejs-buffer.js");
|
|
7
|
-
const Buffer = nodejs_buffer_js_1.NodeJSBuffer;
|
|
8
|
-
exports.utf8FromBase64Node = Buffer
|
|
1
|
+
import { fromString } from 'uint8arrays/from-string';
|
|
2
|
+
import { NodeJSBuffer } from './lib/nodejs-buffer.js';
|
|
3
|
+
const Buffer = NodeJSBuffer;
|
|
4
|
+
export const utf8FromBase64Node = Buffer
|
|
9
5
|
? function utf8FromBase64Node(b64, alphabet = 'base64') {
|
|
10
6
|
return Buffer.from(b64, alphabet).toString('utf8');
|
|
11
7
|
}
|
|
12
8
|
: /* v8 ignore next -- @preserve */ null;
|
|
13
9
|
const textDecoder = /*#__PURE__*/ new TextDecoder();
|
|
14
|
-
function utf8FromBase64Ponyfill(b64, alphabet) {
|
|
15
|
-
const bytes =
|
|
10
|
+
export function utf8FromBase64Ponyfill(b64, alphabet) {
|
|
11
|
+
const bytes = fromString(b64, alphabet);
|
|
16
12
|
return textDecoder.decode(bytes);
|
|
17
13
|
}
|
|
18
14
|
//# sourceMappingURL=utf8-from-base64.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utf8-from-base64.js","sourceRoot":"","sources":["../src/utf8-from-base64.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utf8-from-base64.js","sourceRoot":"","sources":["../src/utf8-from-base64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAGrD,MAAM,MAAM,GAAG,YAAY,CAAA;AAE3B,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM;IACtC,CAAC,CAAC,SAAS,kBAAkB,CACzB,GAAW,EACX,WAA2B,QAAQ;QAEnC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACpD,CAAC;IACH,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE1C,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,WAAW,EAAE,CAAA;AACnD,MAAM,UAAU,sBAAsB,CACpC,GAAW,EACX,QAAyB;IAEzB,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;IACvC,OAAO,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAClC,CAAC","sourcesContent":["import { fromString } from 'uint8arrays/from-string'\nimport { NodeJSBuffer } from './lib/nodejs-buffer.js'\nimport { Base64Alphabet } from './uint8array-base64.js'\n\nconst Buffer = NodeJSBuffer\n\nexport const utf8FromBase64Node = Buffer\n ? function utf8FromBase64Node(\n b64: string,\n alphabet: Base64Alphabet = 'base64',\n ): string {\n return Buffer.from(b64, alphabet).toString('utf8')\n }\n : /* v8 ignore next -- @preserve */ null\n\nconst textDecoder = /*#__PURE__*/ new TextDecoder()\nexport function utf8FromBase64Ponyfill(\n b64: string,\n alphabet?: Base64Alphabet,\n): string {\n const bytes = fromString(b64, alphabet)\n return textDecoder.decode(bytes)\n}\n"]}
|