@atproto/lex-data 0.0.15 → 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 +14 -0
- package/dist/blob.js +16 -26
- 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 +3 -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.js +4 -8
- package/dist/utf8-from-bytes.js.map +1 -1
- 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.js +15 -18
- package/dist/utf8.js.map +1 -1
- package/package.json +7 -8
- 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 +5 -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/tsconfig.tests.json +1 -1
|
@@ -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":"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","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"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uint8array-to-base64.js","sourceRoot":"","sources":["../src/uint8array-to-base64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAGrD,MAAM,MAAM,GAAG,YAAY,CAAA;AAe3B,MAAM,CAAC,MAAM,cAAc,GACzB,OAAO,UAAU,CAAC,SAAS,CAAC,QAAQ,KAAK,UAAU;IACjD,CAAC,CAAC,SAAS,cAAc,CACrB,KAAiB,EACjB,WAA2B,QAAQ;QAEnC,OAAO,KAAK,CAAC,QAAS,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;IACzD,CAAC;IACH,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE5C,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM;IAChC,CAAC,CAAC,SAAS,YAAY,CACnB,KAAiB,EACjB,WAA2B,QAAQ;QAEnC,MAAM,MAAM,GAAG,KAAK,YAAY,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACnE,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QAErC,uDAAuD;QACvD,0EAA0E;QAC1E,sEAAsE;QACtE,6DAA6D;QAC7D,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,SAAS,CAAC,IAAI;YACtD,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,SAAS,CAAC,IAAI;gBACjD,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO;gBAC1B,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,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":"uint8array.js","sourceRoot":"","sources":["../src/uint8array.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AACzE,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,kBAAkB,GACnB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,cAAc,EACd,YAAY,EACZ,gBAAgB,GACjB,MAAM,2BAA2B,CAAA;AAIlC,4EAA4E;AAC5E,2EAA2E;AAC3E,2EAA2E;AAC3E,0CAA0C;AAE1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,QAAQ;AAInB,iCAAiC,CAAC,cAAc;IAChD,YAAY;IACZ,gBAAgB,CAAA;AAElB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,UAAU;AAIrB,iCAAiC,CAAC,gBAAgB;IAClD,cAAc;IACd,kBAAkB,CAAA;AAEpB,iCAAiC;AACjC,IAAI,QAAQ,KAAK,gBAAgB,IAAI,UAAU,KAAK,kBAAkB,EAAE,CAAC;IACvE,aAAa;IACb,OAAO,CAAC,IAAI,CACV,wJAAwJ,CACzJ,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QAChC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QAChC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,IAAI,UAAU,CACnB,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,UAAU,GAAG,UAAU,CAAC,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"]}
|
package/dist/utf8-from-bytes.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.utf8FromBytesNative = utf8FromBytesNative;
|
|
5
|
-
const nodejs_buffer_js_1 = require("./lib/nodejs-buffer.js");
|
|
6
|
-
const Buffer = nodejs_buffer_js_1.NodeJSBuffer;
|
|
7
|
-
exports.utf8FromBytesNode = Buffer
|
|
1
|
+
import { NodeJSBuffer } from './lib/nodejs-buffer.js';
|
|
2
|
+
const Buffer = NodeJSBuffer;
|
|
3
|
+
export const utf8FromBytesNode = Buffer
|
|
8
4
|
? function utf8FromBytesNode(bytes) {
|
|
9
5
|
// @NOTE Buffer.from(bytes) creates a copy of the ArrayBuffer. The following
|
|
10
6
|
// allows us to avoid the copy by creating a Buffer that shares the same
|
|
@@ -13,7 +9,7 @@ exports.utf8FromBytesNode = Buffer
|
|
|
13
9
|
return buffer.toString('utf8');
|
|
14
10
|
}
|
|
15
11
|
: /* v8 ignore next -- @preserve */ null;
|
|
16
|
-
function utf8FromBytesNative(bytes) {
|
|
12
|
+
export function utf8FromBytesNative(bytes) {
|
|
17
13
|
return new TextDecoder('utf-8').decode(bytes);
|
|
18
14
|
}
|
|
19
15
|
//# sourceMappingURL=utf8-from-bytes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utf8-from-bytes.js","sourceRoot":"","sources":["../src/utf8-from-bytes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utf8-from-bytes.js","sourceRoot":"","sources":["../src/utf8-from-bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAErD,MAAM,MAAM,GAAG,YAAY,CAAA;AAE3B,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM;IACrC,CAAC,CAAC,SAAS,iBAAiB,CAAC,KAAiB;QAC1C,4EAA4E;QAC5E,wEAAwE;QACxE,kCAAkC;QAClC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CACxB,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,UAAU,CACjB,CAAA;QACD,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAChC,CAAC;IACH,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE1C,MAAM,UAAU,mBAAmB,CAAC,KAAiB;IACnD,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC/C,CAAC","sourcesContent":["import { NodeJSBuffer } from './lib/nodejs-buffer.js'\n\nconst Buffer = NodeJSBuffer\n\nexport const utf8FromBytesNode = Buffer\n ? function utf8FromBytesNode(bytes: Uint8Array): string {\n // @NOTE Buffer.from(bytes) creates a copy of the ArrayBuffer. The following\n // allows us to avoid the copy by creating a Buffer that shares the same\n // memory as the input Uint8Array.\n const buffer = Buffer.from(\n bytes.buffer,\n bytes.byteOffset,\n bytes.byteLength,\n )\n return buffer.toString('utf8')\n }\n : /* v8 ignore next -- @preserve */ null\n\nexport function utf8FromBytesNative(bytes: Uint8Array): string {\n return new TextDecoder('utf-8').decode(bytes)\n}\n"]}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.graphemeLenNative = void 0;
|
|
4
|
-
exports.graphemeLenPonyfill = graphemeLenPonyfill;
|
|
5
|
-
const grapheme_1 = require("unicode-segmenter/grapheme");
|
|
1
|
+
import { countGraphemes } from 'unicode-segmenter/grapheme';
|
|
6
2
|
// @TODO: Drop usage of "unicode-segmenter" package when Intl.Segmenter is
|
|
7
3
|
// widely supported.
|
|
8
4
|
// https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter
|
|
9
5
|
const segmenter = 'Segmenter' in Intl && typeof Intl.Segmenter === 'function'
|
|
10
6
|
? /*#__PURE__*/ new Intl.Segmenter()
|
|
11
7
|
: /* v8 ignore next -- @preserve */ null;
|
|
12
|
-
|
|
8
|
+
export const graphemeLenNative = segmenter
|
|
13
9
|
? function graphemeLenNative(str) {
|
|
14
10
|
let length = 0;
|
|
15
11
|
for (const _ of segmenter.segment(str))
|
|
@@ -17,7 +13,7 @@ exports.graphemeLenNative = segmenter
|
|
|
17
13
|
return length;
|
|
18
14
|
}
|
|
19
15
|
: /* v8 ignore next -- @preserve */ null;
|
|
20
|
-
function graphemeLenPonyfill(str) {
|
|
21
|
-
return
|
|
16
|
+
export function graphemeLenPonyfill(str) {
|
|
17
|
+
return countGraphemes(str);
|
|
22
18
|
}
|
|
23
19
|
//# sourceMappingURL=utf8-grapheme-len.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utf8-grapheme-len.js","sourceRoot":"","sources":["../src/utf8-grapheme-len.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utf8-grapheme-len.js","sourceRoot":"","sources":["../src/utf8-grapheme-len.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAE3D,0EAA0E;AAC1E,oBAAoB;AACpB,+FAA+F;AAC/F,MAAM,SAAS,GACb,WAAW,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,SAAS,KAAK,UAAU;IACzD,CAAC,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,SAAS,EAAE;IACpC,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE5C,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS;IACxC,CAAC,CAAC,SAAS,iBAAiB,CAAC,GAAW;QACpC,IAAI,MAAM,GAAG,CAAC,CAAA;QACd,KAAK,MAAM,CAAC,IAAI,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC;YAAE,MAAM,EAAE,CAAA;QAChD,OAAO,MAAM,CAAA;IACf,CAAC;IACH,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE1C,MAAM,UAAU,mBAAmB,CAAC,GAAW;IAC7C,OAAO,cAAc,CAAC,GAAG,CAAC,CAAA;AAC5B,CAAC","sourcesContent":["import { countGraphemes } from 'unicode-segmenter/grapheme'\n\n// @TODO: Drop usage of \"unicode-segmenter\" package when Intl.Segmenter is\n// widely supported.\n// https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter\nconst segmenter =\n 'Segmenter' in Intl && typeof Intl.Segmenter === 'function'\n ? /*#__PURE__*/ new Intl.Segmenter()\n : /* v8 ignore next -- @preserve */ null\n\nexport const graphemeLenNative = segmenter\n ? function graphemeLenNative(str: string): number {\n let length = 0\n for (const _ of segmenter.segment(str)) length++\n return length\n }\n : /* v8 ignore next -- @preserve */ null\n\nexport function graphemeLenPonyfill(str: string): number {\n return countGraphemes(str)\n}\n"]}
|
package/dist/utf8-len.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.utf8LenNode = void 0;
|
|
4
|
-
exports.utf8LenCompute = utf8LenCompute;
|
|
5
|
-
const nodejs_buffer_js_1 = require("./lib/nodejs-buffer.js");
|
|
1
|
+
import { NodeJSBuffer } from './lib/nodejs-buffer.js';
|
|
6
2
|
// @NOTE This file is not meant to be exported directly. Instead, we re-export
|
|
7
3
|
// public functions from ./utf8.ts. The reason for this separation is that this
|
|
8
4
|
// file allows to test both the NodeJS-optimized and ponyfill implementations.
|
|
9
|
-
|
|
5
|
+
export const utf8LenNode = NodeJSBuffer
|
|
10
6
|
? function utf8LenNode(string) {
|
|
11
|
-
return
|
|
7
|
+
return NodeJSBuffer.byteLength(string, 'utf8');
|
|
12
8
|
}
|
|
13
9
|
: /* v8 ignore next -- @preserve */ null;
|
|
14
|
-
function utf8LenCompute(string) {
|
|
10
|
+
export function utf8LenCompute(string) {
|
|
15
11
|
// The code below is similar to TextEncoder's implementation of UTF-8
|
|
16
12
|
// encoding. However, using TextEncoder to get the byte length is slower
|
|
17
13
|
// as it requires allocating a new Uint8Array and copying data:
|
package/dist/utf8-len.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utf8-len.js","sourceRoot":"","sources":["../src/utf8-len.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utf8-len.js","sourceRoot":"","sources":["../src/utf8-len.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAErD,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAE9E,MAAM,CAAC,MAAM,WAAW,GAAG,YAAY;IACrC,CAAC,CAAC,SAAS,WAAW,CAAC,MAAc;QACjC,OAAO,YAAa,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACjD,CAAC;IACH,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE1C,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,qEAAqE;IACrE,wEAAwE;IACxE,+DAA+D;IAE/D,qDAAqD;IAErD,mDAAmD;IACnD,IAAI,GAAG,GAAG,MAAM,CAAC,MAAM,CAAA;IACvB,IAAI,IAAY,CAAA;IAEhB,gEAAgE;IAChE,uBAAuB;IACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1C,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QAE3B,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;YACjB,gBAAgB;QAClB,CAAC;aAAM,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,eAAe;YACf,GAAG,IAAI,CAAC,CAAA;QACV,CAAC;aAAM,CAAC;YACN,eAAe;YACf,GAAG,IAAI,CAAC,CAAA;YACR,sEAAsE;YACtE,+DAA+D;YAC/D,wEAAwE;YACxE,OAAO;YACP,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACrC,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;gBAC/B,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;oBACrC,CAAC,EAAE,CAAA;gBACL,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["import { NodeJSBuffer } from './lib/nodejs-buffer.js'\n\n// @NOTE This file is not meant to be exported directly. Instead, we re-export\n// public functions from ./utf8.ts. The reason for this separation is that this\n// file allows to test both the NodeJS-optimized and ponyfill implementations.\n\nexport const utf8LenNode = NodeJSBuffer\n ? function utf8LenNode(string: string): number {\n return NodeJSBuffer!.byteLength(string, 'utf8')\n }\n : /* v8 ignore next -- @preserve */ null\n\nexport function utf8LenCompute(string: string): number {\n // The code below is similar to TextEncoder's implementation of UTF-8\n // encoding. However, using TextEncoder to get the byte length is slower\n // as it requires allocating a new Uint8Array and copying data:\n\n // return new TextEncoder().encode(string).byteLength\n\n // The base length is the string length (all ASCII)\n let len = string.length\n let code: number\n\n // The loop calculates the number of additional bytes needed for\n // non-ASCII characters\n for (let i = 0; i < string.length; i += 1) {\n code = string.charCodeAt(i)\n\n if (code <= 0x7f) {\n // ASCII, 1 byte\n } else if (code <= 0x7ff) {\n // 2 bytes char\n len += 1\n } else {\n // 3 bytes char\n len += 2\n // If the current char is a high surrogate, and the next char is a low\n // surrogate, skip the next char as the total is a 4 bytes char\n // (represented as a surrogate pair in UTF-16) and was already accounted\n // for.\n if (code >= 0xd800 && code <= 0xdbff) {\n code = string.charCodeAt(i + 1)\n if (code >= 0xdc00 && code <= 0xdfff) {\n i++\n }\n }\n }\n }\n\n return len\n}\n"]}
|
package/dist/utf8-to-base64.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const nodejs_buffer_js_1 = require("./lib/nodejs-buffer.js");
|
|
7
|
-
const uint8array_to_base64_js_1 = require("./uint8array-to-base64.js");
|
|
8
|
-
const Buffer = nodejs_buffer_js_1.NodeJSBuffer;
|
|
9
|
-
exports.utf8ToBase64Node = Buffer
|
|
1
|
+
import { toString } from 'uint8arrays/to-string';
|
|
2
|
+
import { NodeJSBuffer } from './lib/nodejs-buffer.js';
|
|
3
|
+
import { toBase64Node } from './uint8array-to-base64.js';
|
|
4
|
+
const Buffer = NodeJSBuffer;
|
|
5
|
+
export const utf8ToBase64Node = Buffer
|
|
10
6
|
? function utf8ToBase64Node(text, alphabet) {
|
|
11
7
|
const buffer = Buffer.from(text, 'utf8');
|
|
12
|
-
return
|
|
8
|
+
return toBase64Node(buffer, alphabet);
|
|
13
9
|
}
|
|
14
10
|
: /* v8 ignore next -- @preserve */ null;
|
|
15
11
|
const textEncoder = /*#__PURE__*/ new TextEncoder();
|
|
16
|
-
function utf8ToBase64Ponyfill(text, alphabet) {
|
|
12
|
+
export function utf8ToBase64Ponyfill(text, alphabet) {
|
|
17
13
|
const bytes = textEncoder.encode(text);
|
|
18
|
-
return
|
|
14
|
+
return toString(bytes, alphabet);
|
|
19
15
|
}
|
|
20
16
|
//# sourceMappingURL=utf8-to-base64.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utf8-to-base64.js","sourceRoot":"","sources":["../src/utf8-to-base64.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utf8-to-base64.js","sourceRoot":"","sources":["../src/utf8-to-base64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAExD,MAAM,MAAM,GAAG,YAAY,CAAA;AAE3B,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM;IACpC,CAAC,CAAC,SAAS,gBAAgB,CAAC,IAAY,EAAE,QAAyB;QAC/D,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QACxC,OAAO,YAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IACxC,CAAC;IACH,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE1C,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,WAAW,EAAE,CAAA;AACnD,MAAM,UAAU,oBAAoB,CAClC,IAAY,EACZ,QAAyB;IAEzB,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACtC,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'\nimport { toBase64Node } from './uint8array-to-base64.js'\n\nconst Buffer = NodeJSBuffer\n\nexport const utf8ToBase64Node = Buffer\n ? function utf8ToBase64Node(text: string, alphabet?: Base64Alphabet): string {\n const buffer = Buffer.from(text, 'utf8')\n return toBase64Node!(buffer, alphabet)\n }\n : /* v8 ignore next -- @preserve */ null\n\nconst textEncoder = /*#__PURE__*/ new TextEncoder()\nexport function utf8ToBase64Ponyfill(\n text: string,\n alphabet?: Base64Alphabet,\n): string {\n const bytes = textEncoder.encode(text)\n return toString(bytes, alphabet)\n}\n"]}
|
package/dist/utf8.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const utf8_grapheme_len_js_1 = require("./utf8-grapheme-len.js");
|
|
7
|
-
const utf8_len_js_1 = require("./utf8-len.js");
|
|
8
|
-
const utf8_to_base64_js_1 = require("./utf8-to-base64.js");
|
|
1
|
+
import { utf8FromBase64Node, utf8FromBase64Ponyfill, } from './utf8-from-base64.js';
|
|
2
|
+
import { utf8FromBytesNative, utf8FromBytesNode } from './utf8-from-bytes.js';
|
|
3
|
+
import { graphemeLenNative, graphemeLenPonyfill } from './utf8-grapheme-len.js';
|
|
4
|
+
import { utf8LenCompute, utf8LenNode } from './utf8-len.js';
|
|
5
|
+
import { utf8ToBase64Node, utf8ToBase64Ponyfill } from './utf8-to-base64.js';
|
|
9
6
|
/**
|
|
10
7
|
* Converts a Uint8Array to a UTF-8 string.
|
|
11
8
|
*
|
|
@@ -23,7 +20,7 @@ const utf8_to_base64_js_1 = require("./utf8-to-base64.js");
|
|
|
23
20
|
* utf8FromBytes(bytes) // 'Hello'
|
|
24
21
|
* ```
|
|
25
22
|
*/
|
|
26
|
-
|
|
23
|
+
export const utf8FromBytes = utf8FromBytesNode ?? utf8FromBytesNative;
|
|
27
24
|
/**
|
|
28
25
|
* Counts the number of grapheme clusters (user-perceived characters) in a string.
|
|
29
26
|
*
|
|
@@ -47,10 +44,10 @@ exports.utf8FromBytes = utf8_from_bytes_js_1.utf8FromBytesNode ?? utf8_from_byte
|
|
|
47
44
|
* graphemeLen('\u{1F468}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}') // 1 (family emoji)
|
|
48
45
|
* ```
|
|
49
46
|
*/
|
|
50
|
-
|
|
51
|
-
/* v8 ignore next -- @preserve */
|
|
47
|
+
export const graphemeLen =
|
|
48
|
+
/* v8 ignore next -- @preserve */ graphemeLenNative ?? graphemeLenPonyfill;
|
|
52
49
|
/* v8 ignore next -- @preserve */
|
|
53
|
-
if (
|
|
50
|
+
if (graphemeLen === graphemeLenPonyfill) {
|
|
54
51
|
/*#__PURE__*/
|
|
55
52
|
console.warn('[@atproto/lex-data]: Intl.Segmenter is not available in this environment. Falling back to ponyfill implementation.');
|
|
56
53
|
}
|
|
@@ -76,8 +73,8 @@ if (exports.graphemeLen === utf8_grapheme_len_js_1.graphemeLenPonyfill) {
|
|
|
76
73
|
* utf8Len('\u{1F468}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}') // 25 (family emoji)
|
|
77
74
|
* ```
|
|
78
75
|
*/
|
|
79
|
-
|
|
80
|
-
/* v8 ignore next -- @preserve */
|
|
76
|
+
export const utf8Len =
|
|
77
|
+
/* v8 ignore next -- @preserve */ utf8LenNode ?? utf8LenCompute;
|
|
81
78
|
/**
|
|
82
79
|
* Encodes a UTF-8 string to base64.
|
|
83
80
|
*
|
|
@@ -94,8 +91,8 @@ exports.utf8Len =
|
|
|
94
91
|
* utf8ToBase64('Hello') // 'SGVsbG8='
|
|
95
92
|
* ```
|
|
96
93
|
*/
|
|
97
|
-
|
|
98
|
-
/* v8 ignore next -- @preserve */
|
|
94
|
+
export const utf8ToBase64 =
|
|
95
|
+
/* v8 ignore next -- @preserve */ utf8ToBase64Node ?? utf8ToBase64Ponyfill;
|
|
99
96
|
/**
|
|
100
97
|
* Decodes a base64 string to UTF-8.
|
|
101
98
|
*
|
|
@@ -112,6 +109,6 @@ exports.utf8ToBase64 =
|
|
|
112
109
|
* utf8FromBase64('SGVsbG8=') // 'Hello'
|
|
113
110
|
* ```
|
|
114
111
|
*/
|
|
115
|
-
|
|
116
|
-
/* v8 ignore next -- @preserve */
|
|
112
|
+
export const utf8FromBase64 =
|
|
113
|
+
/* v8 ignore next -- @preserve */ utf8FromBase64Node ?? utf8FromBase64Ponyfill;
|
|
117
114
|
//# sourceMappingURL=utf8.js.map
|
package/dist/utf8.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utf8.js","sourceRoot":"","sources":["../src/utf8.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utf8.js","sourceRoot":"","sources":["../src/utf8.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC/E,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAE5E;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,IAAI,mBAAmB,CAAA;AAErE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,WAAW;AACtB,iCAAiC,CAAC,iBAAiB,IAAI,mBAAmB,CAAA;AAE5E,iCAAiC;AACjC,IAAI,WAAW,KAAK,mBAAmB,EAAE,CAAC;IACxC,aAAa;IACb,OAAO,CAAC,IAAI,CACV,oHAAoH,CACrH,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,OAAO;AAClB,iCAAiC,CAAC,WAAW,IAAI,cAAc,CAAA;AAEjE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,YAAY;AACvB,iCAAiC,CAAC,gBAAgB,IAAI,oBAAoB,CAAA;AAE5E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,cAAc;AAIzB,iCAAiC,CAAC,kBAAkB,IAAI,sBAAsB,CAAA","sourcesContent":["import { Base64Alphabet } from './uint8array.js'\nimport {\n utf8FromBase64Node,\n utf8FromBase64Ponyfill,\n} from './utf8-from-base64.js'\nimport { utf8FromBytesNative, utf8FromBytesNode } from './utf8-from-bytes.js'\nimport { graphemeLenNative, graphemeLenPonyfill } from './utf8-grapheme-len.js'\nimport { utf8LenCompute, utf8LenNode } from './utf8-len.js'\nimport { utf8ToBase64Node, utf8ToBase64Ponyfill } from './utf8-to-base64.js'\n\n/**\n * Converts a Uint8Array to a UTF-8 string.\n *\n * Uses Node.js Buffer when available for performance, falling back to\n * TextDecoder in environments without Buffer support.\n *\n * @param bytes - The binary data to decode\n * @returns The decoded string (as UTF-16 JavaScript string)\n *\n * @example\n * ```typescript\n * import { utf8FromBytes } from '@atproto/lex-data'\n *\n * const bytes = new Uint8Array([72, 101, 108, 108, 111])\n * utf8FromBytes(bytes) // 'Hello'\n * ```\n */\nexport const utf8FromBytes = utf8FromBytesNode ?? utf8FromBytesNative\n\n/**\n * Counts the number of grapheme clusters (user-perceived characters) in a string.\n *\n * Grapheme clusters represent what users typically think of as \"characters\",\n * handling complex cases like:\n * - Emoji with skin tones and ZWJ sequences (e.g., family emoji)\n * - Combined characters (e.g., 'e' + combining accent)\n * - Regional indicator pairs (flag emoji)\n *\n * Uses native {@link Intl.Segmenter} when available, falling back to a ponyfill.\n *\n * @param str - The string to measure\n * @returns The number of grapheme clusters\n *\n * @example\n * ```typescript\n * import { graphemeLen } from '@atproto/lex-data'\n *\n * graphemeLen('hello') // 5\n * graphemeLen('cafe\\u0301') // 4 (cafe with combining accent)\n * graphemeLen('\\u{1F468}\\u{200D}\\u{1F469}\\u{200D}\\u{1F467}\\u{200D}\\u{1F466}') // 1 (family emoji)\n * ```\n */\nexport const graphemeLen: (str: string) => number =\n /* v8 ignore next -- @preserve */ graphemeLenNative ?? graphemeLenPonyfill\n\n/* v8 ignore next -- @preserve */\nif (graphemeLen === graphemeLenPonyfill) {\n /*#__PURE__*/\n console.warn(\n '[@atproto/lex-data]: Intl.Segmenter is not available in this environment. Falling back to ponyfill implementation.',\n )\n}\n\n/**\n * Calculates the UTF-8 byte length of a string.\n *\n * Returns the number of bytes the string would occupy when encoded as UTF-8.\n * This is important for Lexicon validation where schemas specify byte limits.\n *\n * Uses Node.js Buffer.byteLength when available for performance,\n * falling back to a computed implementation.\n *\n * @param str - The string to measure\n * @returns The UTF-8 byte length\n *\n * @example\n * ```typescript\n * import { utf8Len } from '@atproto/lex-data'\n *\n * utf8Len('hello') // 5 (ASCII: 1 byte per char)\n * utf8Len('\\u00e9') // 2 (e with accent: 2 bytes)\n * utf8Len('\\u{1F600}') // 4 (emoji: 4 bytes)\n * utf8Len('\\u{1F468}\\u{200D}\\u{1F469}\\u{200D}\\u{1F467}\\u{200D}\\u{1F466}') // 25 (family emoji)\n * ```\n */\nexport const utf8Len: (string: string) => number =\n /* v8 ignore next -- @preserve */ utf8LenNode ?? utf8LenCompute\n\n/**\n * Encodes a UTF-8 string to base64.\n *\n * First encodes the string as UTF-8 bytes, then encodes those bytes as base64.\n *\n * @param str - The string to encode\n * @param alphabet - The base64 alphabet to use ('base64' or 'base64url')\n * @returns The base64-encoded string\n *\n * @example\n * ```typescript\n * import { utf8ToBase64 } from '@atproto/lex-data'\n *\n * utf8ToBase64('Hello') // 'SGVsbG8='\n * ```\n */\nexport const utf8ToBase64: (str: string, alphabet?: Base64Alphabet) => string =\n /* v8 ignore next -- @preserve */ utf8ToBase64Node ?? utf8ToBase64Ponyfill\n\n/**\n * Decodes a base64 string to UTF-8.\n *\n * Decodes the base64 to bytes, then interprets those bytes as UTF-8 text.\n *\n * @param b64 - The base64 string to decode\n * @param alphabet - The base64 alphabet to use ('base64' or 'base64url')\n * @returns The decoded UTF-8 string\n *\n * @example\n * ```typescript\n * import { utf8FromBase64 } from '@atproto/lex-data'\n *\n * utf8FromBase64('SGVsbG8=') // 'Hello'\n * ```\n */\nexport const utf8FromBase64: (\n b64: string,\n alphabet?: Base64Alphabet,\n) => string =\n /* v8 ignore next -- @preserve */ utf8FromBase64Node ?? utf8FromBase64Ponyfill\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lex-data",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.1.0-next.0",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=22"
|
|
6
|
+
},
|
|
4
7
|
"license": "MIT",
|
|
5
8
|
"description": "Core utilities for AT Lexicons",
|
|
6
9
|
"keywords": [
|
|
@@ -23,21 +26,17 @@
|
|
|
23
26
|
"./CHANGELOG.md"
|
|
24
27
|
],
|
|
25
28
|
"sideEffects": false,
|
|
26
|
-
"type": "
|
|
27
|
-
"main": "./dist/index.js",
|
|
28
|
-
"types": "./dist/index.d.ts",
|
|
29
|
+
"type": "module",
|
|
29
30
|
"exports": {
|
|
30
31
|
".": {
|
|
31
32
|
"types": "./dist/index.d.ts",
|
|
32
|
-
"browser": "./dist/index.js",
|
|
33
|
-
"import": "./dist/index.js",
|
|
34
33
|
"default": "./dist/index.js"
|
|
35
34
|
}
|
|
36
35
|
},
|
|
37
36
|
"dependencies": {
|
|
38
|
-
"multiformats": "^
|
|
37
|
+
"multiformats": "^13.0.0",
|
|
39
38
|
"tslib": "^2.8.1",
|
|
40
|
-
"uint8arrays": "
|
|
39
|
+
"uint8arrays": "^5.0.0",
|
|
41
40
|
"unicode-segmenter": "^0.14.0"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
@@ -58,13 +58,13 @@ describe(BytesCid, () => {
|
|
|
58
58
|
it('throws an error for invalid CID bytes', () => {
|
|
59
59
|
expect(
|
|
60
60
|
() => new BytesCid(new Uint8Array([2, 0x55, 0x12, 3, 1, 2, 3])),
|
|
61
|
-
).
|
|
62
|
-
expect(() => new BytesCid(new Uint8Array([1, 0x55, 0x12]))).
|
|
61
|
+
).toThrow('Unsupported CID version')
|
|
62
|
+
expect(() => new BytesCid(new Uint8Array([1, 0x55, 0x12]))).toThrow(
|
|
63
63
|
'CID bytes are too short',
|
|
64
64
|
)
|
|
65
65
|
expect(
|
|
66
66
|
() => new BytesCid(new Uint8Array([1, 0x55, 0x12, 4, 1, 2, 3])),
|
|
67
|
-
).
|
|
67
|
+
).toThrow('CID bytes length mismatch')
|
|
68
68
|
})
|
|
69
69
|
})
|
|
70
70
|
|