bufferbase 1.3.0 → 3.0.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.
Files changed (144) hide show
  1. package/README.md +186 -17
  2. package/dist/cjs/bases.d.ts +189 -0
  3. package/dist/cjs/bases.d.ts.map +1 -0
  4. package/dist/cjs/bases.js +134 -0
  5. package/dist/cjs/bases.js.map +1 -0
  6. package/dist/cjs/bufferbase.d.ts +22 -45
  7. package/dist/cjs/bufferbase.d.ts.map +1 -1
  8. package/dist/cjs/bufferbase.js +26 -120
  9. package/dist/cjs/bufferbase.js.map +1 -1
  10. package/dist/cjs/codec-base.d.ts +56 -0
  11. package/dist/cjs/codec-base.d.ts.map +1 -0
  12. package/dist/cjs/codec-base.js +132 -0
  13. package/dist/cjs/codec-base.js.map +1 -0
  14. package/dist/cjs/codec-block.d.ts +47 -0
  15. package/dist/cjs/codec-block.d.ts.map +1 -0
  16. package/dist/cjs/codec-block.js +213 -0
  17. package/dist/cjs/codec-block.js.map +1 -0
  18. package/dist/cjs/codec-block85.d.ts +56 -0
  19. package/dist/cjs/codec-block85.d.ts.map +1 -0
  20. package/dist/cjs/codec-block85.js +271 -0
  21. package/dist/cjs/codec-block85.js.map +1 -0
  22. package/dist/cjs/codec-radix.d.ts +46 -0
  23. package/dist/cjs/codec-radix.d.ts.map +1 -0
  24. package/dist/cjs/codec-radix.js +181 -0
  25. package/dist/cjs/codec-radix.js.map +1 -0
  26. package/dist/cjs/codec.d.ts +38 -0
  27. package/dist/cjs/codec.d.ts.map +1 -0
  28. package/dist/cjs/codec.js +69 -0
  29. package/dist/cjs/codec.js.map +1 -0
  30. package/dist/cjs/codecs.d.ts +20 -0
  31. package/dist/cjs/codecs.d.ts.map +1 -0
  32. package/dist/cjs/codecs.js +19 -0
  33. package/dist/cjs/codecs.js.map +1 -0
  34. package/dist/cjs/errors.d.ts +93 -0
  35. package/dist/cjs/errors.d.ts.map +1 -0
  36. package/dist/cjs/errors.js +130 -0
  37. package/dist/cjs/errors.js.map +1 -0
  38. package/dist/cjs/example.js +49 -33
  39. package/dist/cjs/example.js.map +1 -1
  40. package/dist/cjs/functions.d.ts +58 -0
  41. package/dist/cjs/functions.d.ts.map +1 -0
  42. package/dist/cjs/functions.js +71 -0
  43. package/dist/cjs/functions.js.map +1 -0
  44. package/dist/cjs/index.d.ts +10 -1
  45. package/dist/cjs/index.d.ts.map +1 -1
  46. package/dist/cjs/index.js +35 -4
  47. package/dist/cjs/index.js.map +1 -1
  48. package/dist/cjs/package.json +17 -12
  49. package/dist/cjs/types.d.ts +144 -0
  50. package/dist/cjs/types.d.ts.map +1 -0
  51. package/dist/cjs/types.js +3 -0
  52. package/dist/cjs/types.js.map +1 -0
  53. package/dist/esm/bases.d.ts +189 -0
  54. package/dist/esm/bases.d.ts.map +1 -0
  55. package/dist/esm/bases.js +129 -0
  56. package/dist/esm/bases.js.map +1 -0
  57. package/dist/esm/bufferbase.d.ts +22 -45
  58. package/dist/esm/bufferbase.d.ts.map +1 -1
  59. package/dist/esm/bufferbase.js +21 -115
  60. package/dist/esm/bufferbase.js.map +1 -1
  61. package/dist/esm/codec-base.d.ts +56 -0
  62. package/dist/esm/codec-base.d.ts.map +1 -0
  63. package/dist/esm/codec-base.js +127 -0
  64. package/dist/esm/codec-base.js.map +1 -0
  65. package/dist/esm/codec-block.d.ts +47 -0
  66. package/dist/esm/codec-block.d.ts.map +1 -0
  67. package/dist/esm/codec-block.js +209 -0
  68. package/dist/esm/codec-block.js.map +1 -0
  69. package/dist/esm/codec-block85.d.ts +56 -0
  70. package/dist/esm/codec-block85.d.ts.map +1 -0
  71. package/dist/esm/codec-block85.js +267 -0
  72. package/dist/esm/codec-block85.js.map +1 -0
  73. package/dist/esm/codec-radix.d.ts +46 -0
  74. package/dist/esm/codec-radix.d.ts.map +1 -0
  75. package/dist/esm/codec-radix.js +177 -0
  76. package/dist/esm/codec-radix.js.map +1 -0
  77. package/dist/esm/codec.d.ts +38 -0
  78. package/dist/esm/codec.d.ts.map +1 -0
  79. package/dist/esm/codec.js +60 -0
  80. package/dist/esm/codec.js.map +1 -0
  81. package/dist/esm/codecs.d.ts +20 -0
  82. package/dist/esm/codecs.d.ts.map +1 -0
  83. package/dist/esm/codecs.js +16 -0
  84. package/dist/esm/codecs.js.map +1 -0
  85. package/dist/esm/errors.d.ts +93 -0
  86. package/dist/esm/errors.d.ts.map +1 -0
  87. package/dist/esm/errors.js +119 -0
  88. package/dist/esm/errors.js.map +1 -0
  89. package/dist/esm/example.js +48 -32
  90. package/dist/esm/example.js.map +1 -1
  91. package/dist/esm/functions.d.ts +58 -0
  92. package/dist/esm/functions.d.ts.map +1 -0
  93. package/dist/esm/functions.js +65 -0
  94. package/dist/esm/functions.js.map +1 -0
  95. package/dist/esm/index.d.ts +10 -1
  96. package/dist/esm/index.d.ts.map +1 -1
  97. package/dist/esm/index.js +12 -1
  98. package/dist/esm/index.js.map +1 -1
  99. package/dist/esm/package.json +17 -12
  100. package/dist/esm/types.d.ts +144 -0
  101. package/dist/esm/types.d.ts.map +1 -0
  102. package/dist/esm/types.js +2 -0
  103. package/dist/esm/types.js.map +1 -0
  104. package/package.json +19 -14
  105. package/src/algorithms.test.ts +442 -0
  106. package/src/bases.ts +142 -0
  107. package/src/bufferbase.test.ts +44 -27
  108. package/src/bufferbase.ts +32 -117
  109. package/src/codec-base.ts +181 -0
  110. package/src/codec-block.ts +258 -0
  111. package/src/codec-block85.ts +315 -0
  112. package/src/codec-radix.ts +206 -0
  113. package/src/codec.test.ts +328 -0
  114. package/src/codec.ts +67 -0
  115. package/src/codecs.ts +24 -0
  116. package/src/errors.ts +127 -0
  117. package/src/example.ts +49 -34
  118. package/src/functions.ts +73 -0
  119. package/src/index.ts +39 -6
  120. package/src/types.ts +156 -0
  121. package/dist/cjs/bufferbase.d.mts +0 -60
  122. package/dist/cjs/bufferbase.d.mts.map +0 -1
  123. package/dist/cjs/bufferbase.mjs +0 -150
  124. package/dist/cjs/bufferbase.mjs.map +0 -1
  125. package/dist/cjs/example.d.mts +0 -2
  126. package/dist/cjs/example.d.mts.map +0 -1
  127. package/dist/cjs/example.mjs +0 -39
  128. package/dist/cjs/example.mjs.map +0 -1
  129. package/dist/cjs/index.d.mts +0 -2
  130. package/dist/cjs/index.d.mts.map +0 -1
  131. package/dist/cjs/index.mjs +0 -11
  132. package/dist/cjs/index.mjs.map +0 -1
  133. package/dist/esm/bufferbase.d.mts +0 -60
  134. package/dist/esm/bufferbase.d.mts.map +0 -1
  135. package/dist/esm/bufferbase.mjs +0 -141
  136. package/dist/esm/bufferbase.mjs.map +0 -1
  137. package/dist/esm/example.d.mts +0 -2
  138. package/dist/esm/example.d.mts.map +0 -1
  139. package/dist/esm/example.mjs +0 -37
  140. package/dist/esm/example.mjs.map +0 -1
  141. package/dist/esm/index.d.mts +0 -2
  142. package/dist/esm/index.d.mts.map +0 -1
  143. package/dist/esm/index.mjs +0 -2
  144. package/dist/esm/index.mjs.map +0 -1
package/dist/cjs/index.js CHANGED
@@ -1,11 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validate = exports.Validator = exports.InvalidCharacterError = exports.Converter = exports.BufferEncoder = exports.Chars = void 0;
3
+ exports.Validator = exports.Converter = exports.BufferEncoder = exports.Codecs = exports.validate = exports.encode = exports.decode = exports.convert = exports.resolveSpec = exports.isBaseName = exports.Chars = exports.Bases = exports.getCodec = exports.createCodec = exports.RadixCodec = exports.Codec = exports.BlockCodec = exports.Block85Codec = exports.ValueRangeError = exports.UnknownBaseError = exports.NonCanonicalError = exports.InvalidLengthError = exports.InvalidCodecError = exports.InvalidCharacterError = exports.CheckSymbolError = exports.BufferSizeError = void 0;
4
+ // Errors
5
+ var errors_js_1 = require("./errors.js");
6
+ Object.defineProperty(exports, "BufferSizeError", { enumerable: true, get: function () { return errors_js_1.BufferSizeError; } });
7
+ Object.defineProperty(exports, "CheckSymbolError", { enumerable: true, get: function () { return errors_js_1.CheckSymbolError; } });
8
+ Object.defineProperty(exports, "InvalidCharacterError", { enumerable: true, get: function () { return errors_js_1.InvalidCharacterError; } });
9
+ Object.defineProperty(exports, "InvalidCodecError", { enumerable: true, get: function () { return errors_js_1.InvalidCodecError; } });
10
+ Object.defineProperty(exports, "InvalidLengthError", { enumerable: true, get: function () { return errors_js_1.InvalidLengthError; } });
11
+ Object.defineProperty(exports, "NonCanonicalError", { enumerable: true, get: function () { return errors_js_1.NonCanonicalError; } });
12
+ Object.defineProperty(exports, "UnknownBaseError", { enumerable: true, get: function () { return errors_js_1.UnknownBaseError; } });
13
+ Object.defineProperty(exports, "ValueRangeError", { enumerable: true, get: function () { return errors_js_1.ValueRangeError; } });
14
+ // Codec implementations and factory
15
+ var codec_js_1 = require("./codec.js");
16
+ Object.defineProperty(exports, "Block85Codec", { enumerable: true, get: function () { return codec_js_1.Block85Codec; } });
17
+ Object.defineProperty(exports, "BlockCodec", { enumerable: true, get: function () { return codec_js_1.BlockCodec; } });
18
+ Object.defineProperty(exports, "Codec", { enumerable: true, get: function () { return codec_js_1.Codec; } });
19
+ Object.defineProperty(exports, "RadixCodec", { enumerable: true, get: function () { return codec_js_1.RadixCodec; } });
20
+ Object.defineProperty(exports, "createCodec", { enumerable: true, get: function () { return codec_js_1.createCodec; } });
21
+ Object.defineProperty(exports, "getCodec", { enumerable: true, get: function () { return codec_js_1.getCodec; } });
22
+ // Character sets, encoding definitions, and lookup helpers
23
+ var bases_js_1 = require("./bases.js");
24
+ Object.defineProperty(exports, "Bases", { enumerable: true, get: function () { return bases_js_1.Bases; } });
25
+ Object.defineProperty(exports, "Chars", { enumerable: true, get: function () { return bases_js_1.Chars; } });
26
+ Object.defineProperty(exports, "isBaseName", { enumerable: true, get: function () { return bases_js_1.isBaseName; } });
27
+ Object.defineProperty(exports, "resolveSpec", { enumerable: true, get: function () { return bases_js_1.resolveSpec; } });
28
+ // Simple function API
29
+ var functions_js_1 = require("./functions.js");
30
+ Object.defineProperty(exports, "convert", { enumerable: true, get: function () { return functions_js_1.convert; } });
31
+ Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return functions_js_1.decode; } });
32
+ Object.defineProperty(exports, "encode", { enumerable: true, get: function () { return functions_js_1.encode; } });
33
+ Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return functions_js_1.validate; } });
34
+ // Pre-defined codecs (namespaced)
35
+ var codecs_js_1 = require("./codecs.js");
36
+ Object.defineProperty(exports, "Codecs", { enumerable: true, get: function () { return codecs_js_1.Codecs; } });
37
+ // Deprecated exports for backward compatibility
4
38
  var bufferbase_js_1 = require("./bufferbase.js");
5
- Object.defineProperty(exports, "Chars", { enumerable: true, get: function () { return bufferbase_js_1.Chars; } });
6
39
  Object.defineProperty(exports, "BufferEncoder", { enumerable: true, get: function () { return bufferbase_js_1.BufferEncoder; } });
7
40
  Object.defineProperty(exports, "Converter", { enumerable: true, get: function () { return bufferbase_js_1.Converter; } });
8
- Object.defineProperty(exports, "InvalidCharacterError", { enumerable: true, get: function () { return bufferbase_js_1.InvalidCharacterError; } });
9
41
  Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return bufferbase_js_1.Validator; } });
10
- Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return bufferbase_js_1.validate; } });
11
42
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAOyB;AANvB,sGAAA,KAAK,OAAA;AACL,8GAAA,aAAa,OAAA;AACb,0GAAA,SAAS,OAAA;AACT,sHAAA,qBAAqB,OAAA;AACrB,0GAAA,SAAS,OAAA;AACT,yGAAA,QAAQ,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAeA,SAAS;AACT,yCASqB;AARnB,4GAAA,eAAe,OAAA;AACf,6GAAA,gBAAgB,OAAA;AAChB,kHAAA,qBAAqB,OAAA;AACrB,8GAAA,iBAAiB,OAAA;AACjB,+GAAA,kBAAkB,OAAA;AAClB,8GAAA,iBAAiB,OAAA;AACjB,6GAAA,gBAAgB,OAAA;AAChB,4GAAA,eAAe,OAAA;AAGjB,oCAAoC;AACpC,uCAAgG;AAAvF,wGAAA,YAAY,OAAA;AAAE,sGAAA,UAAU,OAAA;AAAE,iGAAA,KAAK,OAAA;AAAE,sGAAA,UAAU,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,oGAAA,QAAQ,OAAA;AAE3E,2DAA2D;AAC3D,uCAAmE;AAA1D,iGAAA,KAAK,OAAA;AAAE,iGAAA,KAAK,OAAA;AAAE,sGAAA,UAAU,OAAA;AAAE,uGAAA,WAAW,OAAA;AAE9C,sBAAsB;AACtB,+CAAmE;AAA1D,uGAAA,OAAO,OAAA;AAAE,sGAAA,MAAM,OAAA;AAAE,sGAAA,MAAM,OAAA;AAAE,wGAAA,QAAQ,OAAA;AAE1C,kCAAkC;AAClC,yCAAqC;AAA5B,mGAAA,MAAM,OAAA;AAEf,gDAAgD;AAChD,iDAAsE;AAA7D,8GAAA,aAAa,OAAA;AAAE,0GAAA,SAAS,OAAA;AAAE,0GAAA,SAAS,OAAA"}
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "bufferbase",
3
- "version": "1.3.0",
4
- "description": "Buffer-to-BaseN Encoder, Decoder, Converter, and Validator",
3
+ "version": "3.0.0",
4
+ "description": "Buffer-to-BaseN encoding: RFC 4648 block encodings, Ascii85/Z85, and Base58-style radix conversion",
5
5
  "sideEffects": false,
6
6
  "type": "commonjs",
7
7
  "scripts": {
8
- "build": "npm run build:esm && npm run build:cjs && tsconfig-to-dual-package",
8
+ "build": "bun run build:esm && bun run build:cjs && tsconfig-to-dual-package",
9
9
  "build:cjs": "tsc -p tsconfig.cjs.json",
10
10
  "build:esm": "tsc -p tsconfig.json",
11
- "prepublishOnly": "npm run build",
12
- "example": "tsx src/example.ts",
13
- "test": "tsx --test src/*.test.ts"
11
+ "prepublishOnly": "bun run build",
12
+ "example": "bun src/example.ts",
13
+ "test": "bun test",
14
+ "release": "bin/release"
14
15
  },
15
16
  "devDependencies": {
17
+ "@types/bun": "^1.1.0",
16
18
  "@types/node": "^20.11.5",
17
- "ts-loader": "^9.5.1",
18
19
  "tsconfig-to-dual-package": "^1.2.0",
19
- "tsx": "^4.7.0",
20
20
  "typescript": "^5.3.3"
21
21
  },
22
22
  "repository": {
@@ -28,19 +28,24 @@
28
28
  "src"
29
29
  ],
30
30
  "keywords": [
31
- "number",
32
31
  "encode",
32
+ "decode",
33
33
  "convert",
34
- "decimal",
35
34
  "base",
35
+ "rfc4648",
36
36
  "base16",
37
+ "hex",
37
38
  "base32",
39
+ "base32hex",
38
40
  "crockford",
39
41
  "base36",
40
42
  "base58",
41
43
  "base64",
42
- "Ascii85",
43
- "base85"
44
+ "base64url",
45
+ "ascii85",
46
+ "base85",
47
+ "z85",
48
+ "radix"
44
49
  ],
45
50
  "author": "misebox",
46
51
  "license": "ISC",
@@ -0,0 +1,144 @@
1
+ import { Buffer } from 'node:buffer';
2
+ /**
3
+ * Input type accepted by encode functions.
4
+ *
5
+ * Supports both Node.js `Buffer` and standard `Uint8Array` for browser compatibility.
6
+ */
7
+ export type BufferLike = Buffer | Uint8Array;
8
+ /**
9
+ * How bytes are mapped to characters.
10
+ *
11
+ * An alphabet alone does not determine an encoding: the same 64 characters can
12
+ * be used by a radix conversion or by a bit-block encoding, producing different
13
+ * output. Every codec therefore names its algorithm explicitly.
14
+ *
15
+ * - `'radix'` — treats the whole buffer as one big integer and rewrites it in
16
+ * base `alphabet.length`. Works with any alphabet and any input length.
17
+ * Leading zero bytes are preserved as leading `alphabet[0]` characters.
18
+ * Used by Base58, Base36, and custom alphabets. Not RFC 4648.
19
+ * - `'block'` — regroups the bit stream into `log2(alphabet.length)`-bit chunks,
20
+ * as specified by RFC 4648. Requires an alphabet of 2, 4, 8, 16, 32, or 64
21
+ * characters. Used by Base16, Base32, and Base64.
22
+ * - `'block85'` — converts each 4-byte block to 5 characters (85^5 > 2^32).
23
+ * Requires an alphabet of exactly 85 characters. Used by Ascii85 and Z85.
24
+ */
25
+ export type Algorithm = 'radix' | 'block' | 'block85';
26
+ /** Options shared by every algorithm. */
27
+ interface CommonSpec {
28
+ /** Characters used for encoding, ordered by value. */
29
+ readonly alphabet: string;
30
+ /**
31
+ * Reject input that is well-formed but not the canonical encoding of any
32
+ * byte sequence (RFC 4648 §3.5). Defaults to `true`.
33
+ *
34
+ * With `strict: false`, `'Zm9='` and `'Zm8='` both decode to `'fo'`, so
35
+ * decoding is no longer injective. Only disable it to read data produced by
36
+ * a lenient encoder.
37
+ */
38
+ readonly strict?: boolean;
39
+ /**
40
+ * Accept either letter case when decoding, and when validating.
41
+ * Requires an alphabet that does not contain both cases of the same letter.
42
+ * Defaults to `false`.
43
+ */
44
+ readonly caseInsensitive?: boolean;
45
+ /**
46
+ * Extra characters accepted when decoding, each mapped to the alphabet
47
+ * character it stands for.
48
+ *
49
+ * Crockford's Base32 uses `{ I: '1', L: '1', O: '0' }` so that a symbol
50
+ * written down by hand is read back as the digit it resembles. Encoding
51
+ * never emits them.
52
+ */
53
+ readonly aliases?: Readonly<Record<string, string>>;
54
+ /**
55
+ * Characters skipped when decoding, such as the hyphens Crockford's Base32
56
+ * allows for readability. Encoding never emits them.
57
+ */
58
+ readonly ignore?: string;
59
+ }
60
+ /** A codec that rewrites the buffer as an integer in base `alphabet.length`. */
61
+ export interface RadixSpec extends CommonSpec {
62
+ readonly algorithm: 'radix';
63
+ /**
64
+ * Symbols that extend the alphabet for a trailing check symbol, which
65
+ * encodes the value modulo `alphabet.length + checkSymbols.length`.
66
+ *
67
+ * Crockford's Base32 uses `'*~$=U'`, giving a modulus of 37. When set, every
68
+ * encoding carries the symbol and every decoding verifies it.
69
+ */
70
+ readonly checkSymbols?: string;
71
+ }
72
+ /** A codec that regroups the bit stream, as specified by RFC 4648. */
73
+ export interface BlockSpec extends CommonSpec {
74
+ readonly algorithm: 'block';
75
+ /**
76
+ * Character used to pad the final block to a whole number of characters,
77
+ * or `false` to emit no padding. Defaults to `'='`.
78
+ */
79
+ readonly pad?: string | false;
80
+ }
81
+ /** A codec that converts each 4-byte block to 5 characters. */
82
+ export interface Block85Spec extends CommonSpec {
83
+ readonly algorithm: 'block85';
84
+ /** Write a block of four zero bytes as `'z'`. Defaults to `false`. */
85
+ readonly zeroShortcut?: boolean;
86
+ /** Write a block of four spaces as `'y'`. Defaults to `false`. */
87
+ readonly spaceShortcut?: boolean;
88
+ /** Wrap the output in `'<~'` and `'~>'`. Defaults to `false`. */
89
+ readonly delimiters?: boolean;
90
+ /**
91
+ * Require the input length to be a multiple of 4 bytes, as Z85 does.
92
+ * Defaults to `false`, which encodes a trailing partial block as
93
+ * `length + 1` characters.
94
+ */
95
+ readonly requireFullBlocks?: boolean;
96
+ }
97
+ /**
98
+ * A complete codec definition: an alphabet plus the algorithm that uses it.
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * import { encode, type CodecSpec } from 'bufferbase';
103
+ *
104
+ * const binary: CodecSpec = { alphabet: '01', algorithm: 'radix' };
105
+ * encode(Uint8Array.of(5), binary); // '101'
106
+ * ```
107
+ */
108
+ export type CodecSpec = RadixSpec | BlockSpec | Block85Spec;
109
+ /**
110
+ * Options for decode operations.
111
+ */
112
+ export interface DecodeOptions {
113
+ /**
114
+ * Required byte length of the result.
115
+ *
116
+ * The decoded buffer must be exactly this long, otherwise `BufferSizeError`
117
+ * is thrown. Because leading zeros carry no value in a radix encoding, a
118
+ * `'radix'` codec pads a shorter result with leading zero bytes to reach it;
119
+ * `'block'` and `'block85'` codecs derive the length from the input and can
120
+ * only check it.
121
+ */
122
+ size?: number;
123
+ }
124
+ /**
125
+ * Codec interface for encoding/decoding operations.
126
+ *
127
+ * `validate(input)` returns `true` exactly when `decode(input)` succeeds.
128
+ */
129
+ export interface ICodec {
130
+ /** Character set used for encoding. */
131
+ readonly chars: string;
132
+ /** The algorithm this codec applies to `chars`. */
133
+ readonly algorithm: Algorithm;
134
+ /** Encodes a buffer to a base-encoded string. */
135
+ encode(buffer: BufferLike): string;
136
+ /** Decodes a base-encoded string to a buffer. */
137
+ decode(encoded: string, options?: DecodeOptions): Buffer;
138
+ /** Reports whether `decode` would succeed for this input. */
139
+ validate(input: string): boolean;
140
+ /** Decodes with this codec, then re-encodes with `target`. */
141
+ convertTo(target: ICodec, input: string): string;
142
+ }
143
+ export {};
144
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,UAAU,CAAC;AAE7C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;AAEtD,yCAAyC;AACzC,UAAU,UAAU;IAClB,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;IACnC;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,gFAAgF;AAChF,MAAM,WAAW,SAAU,SAAQ,UAAU;IAC3C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B;;;;;;OAMG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,sEAAsE;AACtE,MAAM,WAAW,SAAU,SAAQ,UAAU;IAC3C,QAAQ,CAAC,S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URL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,189 @@
1
+ import type { CodecSpec } from './types.js';
2
+ /**
3
+ * Character sets, ordered by value.
4
+ *
5
+ * A character set does not by itself describe an encoding — see `Bases` for
6
+ * the alphabet/algorithm pairs that do.
7
+ */
8
+ export declare const Chars: {
9
+ /** Base 10: 0-9 */
10
+ readonly Decimal: "0123456789";
11
+ /** RFC 4648 Table 5 — Base16: 0-9A-F */
12
+ readonly Base16: "0123456789ABCDEF";
13
+ /** RFC 4648 Table 3 — Base32: A-Z2-7 */
14
+ readonly Base32: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
15
+ /** RFC 4648 Table 4 — Base32 with extended hex alphabet: 0-9A-V */
16
+ readonly Base32Hex: "0123456789ABCDEFGHIJKLMNOPQRSTUV";
17
+ /** Crockford's Base32: 0-9A-HJKMNP-TV-Z (no I, L, O, U) */
18
+ readonly Base32Crockford: "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
19
+ /** Alphanumeric: 0-9A-Z */
20
+ readonly Base36: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
21
+ /** Letters only: A-Za-z */
22
+ readonly Base52: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
23
+ /** Bitcoin alphabet: 1-9A-HJ-NP-Za-km-z (no 0, O, I, l) */
24
+ readonly Base58: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
25
+ /** RFC 4648 Table 1 — Base64: A-Za-z0-9+/ */
26
+ readonly Base64: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
27
+ /** RFC 4648 Table 2 — URL-safe Base64: A-Za-z0-9-_ */
28
+ readonly Base64Url: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
29
+ /** XML token Base64: A-Za-z0-9._ */
30
+ readonly Base64Xml: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
31
+ /** XML name Base64: A-Za-z0-9_: */
32
+ readonly Base64XmlName: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_:";
33
+ /** Ascii85: the 85 printable characters from `!` (0x21) to `u` (0x75) */
34
+ readonly Ascii85: "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstu";
35
+ /** ZeroMQ Z85 (RFC 32): avoids the quote and backslash characters */
36
+ readonly Z85: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#";
37
+ /** The five symbols Crockford's Base32 adds for its check symbol, giving a modulus of 37 */
38
+ readonly CrockfordCheck: "*~$=U";
39
+ };
40
+ /**
41
+ * The encodings this package knows by name.
42
+ *
43
+ * Each entry pairs an alphabet with the algorithm that reads it, because the
44
+ * alphabet alone is ambiguous: `base64` and `radix64` share Table 1 but
45
+ * produce different strings for the same bytes.
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * import { encode, Bases } from 'bufferbase';
50
+ *
51
+ * encode(Buffer.from('fo'), 'base64'); // 'Zm8=' — RFC 4648
52
+ * encode(Buffer.from('fo'), 'radix64'); // 'GZv' — radix conversion
53
+ * ```
54
+ */
55
+ export declare const Bases: {
56
+ readonly decimal: {
57
+ readonly alphabet: "0123456789";
58
+ readonly algorithm: "radix";
59
+ };
60
+ readonly base36: {
61
+ readonly alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
62
+ readonly algorithm: "radix";
63
+ readonly caseInsensitive: true;
64
+ };
65
+ readonly base52: {
66
+ readonly alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
67
+ readonly algorithm: "radix";
68
+ };
69
+ readonly base58: {
70
+ readonly alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
71
+ readonly algorithm: "radix";
72
+ };
73
+ /**
74
+ * Crockford's Base32, which specifies a notation for numbers rather than for
75
+ * byte streams, so a radix conversion is the right reading of it.
76
+ *
77
+ * Decoding accepts either case, reads `I` and `L` as `1` and `O` as `0`, and
78
+ * ignores hyphens.
79
+ */
80
+ readonly base32crockford: {
81
+ readonly alphabet: "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
82
+ readonly algorithm: "radix";
83
+ readonly caseInsensitive: true;
84
+ readonly aliases: {
85
+ readonly I: "1";
86
+ readonly L: "1";
87
+ readonly O: "0";
88
+ };
89
+ readonly ignore: "-";
90
+ };
91
+ /** Crockford's Base32 carrying its trailing check symbol. */
92
+ readonly base32crockfordcheck: {
93
+ readonly alphabet: "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
94
+ readonly algorithm: "radix";
95
+ readonly caseInsensitive: true;
96
+ readonly aliases: {
97
+ readonly I: "1";
98
+ readonly L: "1";
99
+ readonly O: "0";
100
+ };
101
+ readonly ignore: "-";
102
+ readonly checkSymbols: "*~$=U";
103
+ };
104
+ readonly base16: {
105
+ readonly alphabet: "0123456789ABCDEF";
106
+ readonly algorithm: "block";
107
+ readonly pad: false;
108
+ readonly caseInsensitive: true;
109
+ };
110
+ readonly hex: {
111
+ readonly alphabet: "0123456789ABCDEF";
112
+ readonly algorithm: "block";
113
+ readonly pad: false;
114
+ readonly caseInsensitive: true;
115
+ };
116
+ readonly base32: {
117
+ readonly alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
118
+ readonly algorithm: "block";
119
+ readonly caseInsensitive: true;
120
+ };
121
+ readonly base32hex: {
122
+ readonly alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV";
123
+ readonly algorithm: "block";
124
+ readonly caseInsensitive: true;
125
+ };
126
+ readonly base64: {
127
+ readonly alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
128
+ readonly algorithm: "block";
129
+ };
130
+ /** Unpadded, as used by JWT and other URL-facing formats. */
131
+ readonly base64url: {
132
+ readonly alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
133
+ readonly algorithm: "block";
134
+ readonly pad: false;
135
+ };
136
+ readonly base64xml: {
137
+ readonly alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
138
+ readonly algorithm: "block";
139
+ readonly pad: false;
140
+ };
141
+ readonly base64xmlname: {
142
+ readonly alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_:";
143
+ readonly algorithm: "block";
144
+ readonly pad: false;
145
+ };
146
+ /** Ascii85 with the zero-block shortcut, matching Python's `a85encode`. */
147
+ readonly ascii85: {
148
+ readonly alphabet: "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstu";
149
+ readonly algorithm: "block85";
150
+ readonly zeroShortcut: true;
151
+ };
152
+ /** ZeroMQ Z85, which has no padding and so encodes whole blocks only. */
153
+ readonly z85: {
154
+ readonly alphabet: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#";
155
+ readonly algorithm: "block85";
156
+ readonly requireFullBlocks: true;
157
+ };
158
+ readonly radix16: {
159
+ readonly alphabet: "0123456789ABCDEF";
160
+ readonly algorithm: "radix";
161
+ };
162
+ readonly radix32: {
163
+ readonly alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
164
+ readonly algorithm: "radix";
165
+ };
166
+ readonly radix64: {
167
+ readonly alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
168
+ readonly algorithm: "radix";
169
+ };
170
+ readonly radix64url: {
171
+ readonly alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
172
+ readonly algorithm: "radix";
173
+ };
174
+ };
175
+ /**
176
+ * The names accepted wherever a base is expected.
177
+ */
178
+ export type BaseName = keyof typeof Bases;
179
+ /**
180
+ * Resolves a base name to its codec spec, and passes a spec through unchanged.
181
+ *
182
+ * @throws {UnknownBaseError} If the name is not one of `Bases`
183
+ */
184
+ export declare function resolveSpec(base: BaseName | CodecSpec): CodecSpec;
185
+ /**
186
+ * Checks whether a string names one of the encodings in `Bases`.
187
+ */
188
+ export declare function isBaseName(value: string): value is BaseName;
189
+ //# sourceMappingURL=bases.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bases.d.ts","sourceRoot":"","sources":["../../src/bases.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C;;;;;GAKG;AACH,eAAO,MAAM,KAAK;IAChB,mBAAmB;;IAEnB,wCAAwC;;IAExC,wCAAwC;;IAExC,mEAAmE;;IAEnE,2DAA2D;;IAE3D,2BAA2B;;IAE3B,2BAA2B;;IAE3B,2DAA2D;;IAE3D,6CAA6C;;IAE7C,sDAAsD;;IAEtD,oCAAoC;;IAEpC,mCAAmC;;IAEnC,yEAAyE;;IAEzE,qEAAqE;;IAErE,4FAA4F;;CAEpF,CAAC;AAKX;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;IAOhB;;;;;;OAMG;;;;;;;;;;;;IAQH,6DAA6D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgB7D,6DAA6D;;;;;;;;;;;;;;;;IAM7D,2EAA2E;;;;;;IAE3E,yEAAyE;;;;;;;;;;;;;;;;;;;;;;CAQ7B,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,KAAK,CAAC;AAE1C;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CASjE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,QAAQ,CAE3D"}
@@ -0,0 +1,129 @@
1
+ import { UnknownBaseError } from './errors.js';
2
+ /**
3
+ * Character sets, ordered by value.
4
+ *
5
+ * A character set does not by itself describe an encoding — see `Bases` for
6
+ * the alphabet/algorithm pairs that do.
7
+ */
8
+ export const Chars = {
9
+ /** Base 10: 0-9 */
10
+ Decimal: '0123456789',
11
+ /** RFC 4648 Table 5 — Base16: 0-9A-F */
12
+ Base16: '0123456789ABCDEF',
13
+ /** RFC 4648 Table 3 — Base32: A-Z2-7 */
14
+ Base32: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
15
+ /** RFC 4648 Table 4 — Base32 with extended hex alphabet: 0-9A-V */
16
+ Base32Hex: '0123456789ABCDEFGHIJKLMNOPQRSTUV',
17
+ /** Crockford's Base32: 0-9A-HJKMNP-TV-Z (no I, L, O, U) */
18
+ Base32Crockford: '0123456789ABCDEFGHJKMNPQRSTVWXYZ',
19
+ /** Alphanumeric: 0-9A-Z */
20
+ Base36: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
21
+ /** Letters only: A-Za-z */
22
+ Base52: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
23
+ /** Bitcoin alphabet: 1-9A-HJ-NP-Za-km-z (no 0, O, I, l) */
24
+ Base58: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz',
25
+ /** RFC 4648 Table 1 — Base64: A-Za-z0-9+/ */
26
+ Base64: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
27
+ /** RFC 4648 Table 2 — URL-safe Base64: A-Za-z0-9-_ */
28
+ Base64Url: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
29
+ /** XML token Base64: A-Za-z0-9._ */
30
+ Base64Xml: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._',
31
+ /** XML name Base64: A-Za-z0-9_: */
32
+ Base64XmlName: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_:',
33
+ /** Ascii85: the 85 printable characters from `!` (0x21) to `u` (0x75) */
34
+ Ascii85: '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstu',
35
+ /** ZeroMQ Z85 (RFC 32): avoids the quote and backslash characters */
36
+ Z85: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#',
37
+ /** The five symbols Crockford's Base32 adds for its check symbol, giving a modulus of 37 */
38
+ CrockfordCheck: '*~$=U',
39
+ };
40
+ /** The characters Crockford's Base32 reads as the digit they resemble. */
41
+ const CROCKFORD_ALIASES = { I: '1', L: '1', O: '0' };
42
+ /**
43
+ * The encodings this package knows by name.
44
+ *
45
+ * Each entry pairs an alphabet with the algorithm that reads it, because the
46
+ * alphabet alone is ambiguous: `base64` and `radix64` share Table 1 but
47
+ * produce different strings for the same bytes.
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * import { encode, Bases } from 'bufferbase';
52
+ *
53
+ * encode(Buffer.from('fo'), 'base64'); // 'Zm8=' — RFC 4648
54
+ * encode(Buffer.from('fo'), 'radix64'); // 'GZv' — radix conversion
55
+ * ```
56
+ */
57
+ export const Bases = {
58
+ // Radix conversion. No external standard fixes these, so nothing here can
59
+ // disagree with one.
60
+ decimal: { alphabet: Chars.Decimal, algorithm: 'radix' },
61
+ base36: { alphabet: Chars.Base36, algorithm: 'radix', caseInsensitive: true },
62
+ base52: { alphabet: Chars.Base52, algorithm: 'radix' },
63
+ base58: { alphabet: Chars.Base58, algorithm: 'radix' },
64
+ /**
65
+ * Crockford's Base32, which specifies a notation for numbers rather than for
66
+ * byte streams, so a radix conversion is the right reading of it.
67
+ *
68
+ * Decoding accepts either case, reads `I` and `L` as `1` and `O` as `0`, and
69
+ * ignores hyphens.
70
+ */
71
+ base32crockford: {
72
+ alphabet: Chars.Base32Crockford,
73
+ algorithm: 'radix',
74
+ caseInsensitive: true,
75
+ aliases: CROCKFORD_ALIASES,
76
+ ignore: '-',
77
+ },
78
+ /** Crockford's Base32 carrying its trailing check symbol. */
79
+ base32crockfordcheck: {
80
+ alphabet: Chars.Base32Crockford,
81
+ algorithm: 'radix',
82
+ caseInsensitive: true,
83
+ aliases: CROCKFORD_ALIASES,
84
+ ignore: '-',
85
+ checkSymbols: Chars.CrockfordCheck,
86
+ },
87
+ // Bit-block encoding, RFC 4648.
88
+ base16: { alphabet: Chars.Base16, algorithm: 'block', pad: false, caseInsensitive: true },
89
+ hex: { alphabet: Chars.Base16, algorithm: 'block', pad: false, caseInsensitive: true },
90
+ base32: { alphabet: Chars.Base32, algorithm: 'block', caseInsensitive: true },
91
+ base32hex: { alphabet: Chars.Base32Hex, algorithm: 'block', caseInsensitive: true },
92
+ base64: { alphabet: Chars.Base64, algorithm: 'block' },
93
+ /** Unpadded, as used by JWT and other URL-facing formats. */
94
+ base64url: { alphabet: Chars.Base64Url, algorithm: 'block', pad: false },
95
+ base64xml: { alphabet: Chars.Base64Xml, algorithm: 'block', pad: false },
96
+ base64xmlname: { alphabet: Chars.Base64XmlName, algorithm: 'block', pad: false },
97
+ // Four bytes to five characters.
98
+ /** Ascii85 with the zero-block shortcut, matching Python's `a85encode`. */
99
+ ascii85: { alphabet: Chars.Ascii85, algorithm: 'block85', zeroShortcut: true },
100
+ /** ZeroMQ Z85, which has no padding and so encodes whole blocks only. */
101
+ z85: { alphabet: Chars.Z85, algorithm: 'block85', requireFullBlocks: true },
102
+ // Radix conversion over the RFC alphabets.
103
+ radix16: { alphabet: Chars.Base16, algorithm: 'radix' },
104
+ radix32: { alphabet: Chars.Base32, algorithm: 'radix' },
105
+ radix64: { alphabet: Chars.Base64, algorithm: 'radix' },
106
+ radix64url: { alphabet: Chars.Base64Url, algorithm: 'radix' },
107
+ };
108
+ /**
109
+ * Resolves a base name to its codec spec, and passes a spec through unchanged.
110
+ *
111
+ * @throws {UnknownBaseError} If the name is not one of `Bases`
112
+ */
113
+ export function resolveSpec(base) {
114
+ if (typeof base !== 'string') {
115
+ return base;
116
+ }
117
+ const spec = Bases[base.toLowerCase()];
118
+ if (spec === undefined) {
119
+ throw new UnknownBaseError(base);
120
+ }
121
+ return spec;
122
+ }
123
+ /**
124
+ * Checks whether a string names one of the encodings in `Bases`.
125
+ */
126
+ export function isBaseName(value) {
127
+ return value.toLowerCase() in Bases;
128
+ }
129
+ //# sourceMappingURL=bases.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bases.js","sourceRoot":"","sources":["../../src/bases.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,mBAAmB;IACnB,OAAO,EAAE,YAAY;IACrB,wCAAwC;IACxC,MAAM,EAAE,kBAAkB;IAC1B,wCAAwC;IACxC,MAAM,EAAE,kCAAkC;IAC1C,mEAAmE;IACnE,SAAS,EAAE,kCAAkC;IAC7C,2DAA2D;IAC3D,eAAe,EAAE,kCAAkC;IACnD,2BAA2B;IAC3B,MAAM,EAAE,sCAAsC;IAC9C,2BAA2B;IAC3B,MAAM,EAAE,sDAAsD;IAC9D,2DAA2D;IAC3D,MAAM,EAAE,4DAA4D;IACpE,6CAA6C;IAC7C,MAAM,EAAE,kEAAkE;IAC1E,sDAAsD;IACtD,SAAS,EAAE,kEAAkE;IAC7E,oCAAoC;IAC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