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
@@ -1 +1 @@
1
- {"version":3,"file":"example.js","sourceRoot":"","sources":["../../src/example.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE7E,iBAAiB;AACjB,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;AAEnD,4BAA4B;AAC5B,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;AACzD,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAE5C,8BAA8B;AAC9B,MAAM,gBAAgB,GAAG,IAAI,SAAS,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;AAC5E,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;AAE9D,8BAA8B;AAC9B,MAAM,gBA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IACZ,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE,EAAE,sBAAsB,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC3H,uBAAuB,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,sBAAsB,CAAC;CAC9G,CAAC,CAAC;AAEH,iCAAiC;AACjC,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AACrD,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;AACjC,MAAM,KAAK,GAAG,WAAW,CAAC;IACxB,QAAQ,EAAE,KAAK,CAAC,OAAO;IACvB,SAAS,EAAE,SAAS;IACpB,YAAY,EAAE,IAAI;IAClB,UAAU,EAAE,IAAI;CACjB,CAAC,CAAC;AACH,OAAO,CAAC,KAAK,CAAC;IACZ,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;IAC5C,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAChD,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;CACrC,CAAC,CAAC"}
@@ -0,0 +1,58 @@
1
+ import type { BufferLike, CodecSpec, DecodeOptions } from './types.js';
2
+ import type { Buffer } from 'node:buffer';
3
+ import { type BaseName } from './bases.js';
4
+ /** A named encoding, or a spec describing one directly. */
5
+ export type Base = BaseName | CodecSpec;
6
+ /**
7
+ * Encodes a buffer to a base-encoded string.
8
+ *
9
+ * @param buffer - Buffer or Uint8Array to encode
10
+ * @param base - Base name (e.g. `'base58'`) or a codec spec
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * encode(Buffer.from('fo'), 'base64'); // 'Zm8='
15
+ * encode(Uint8Array.of(5), { alphabet: '01', algorithm: 'radix' }); // '101'
16
+ * ```
17
+ */
18
+ export declare function encode(buffer: BufferLike, base: Base): string;
19
+ /**
20
+ * Decodes a base-encoded string to a buffer.
21
+ *
22
+ * @param encoded - String to decode
23
+ * @param base - Base name (e.g. `'base58'`) or a codec spec
24
+ * @param options - Decode options, such as a required `size`
25
+ * @throws {InvalidCharacterError} If a character is not in the alphabet
26
+ * @throws {InvalidLengthError} If the length cannot encode a whole number of bytes
27
+ * @throws {NonCanonicalError} If spare bits are set and the codec is strict
28
+ * @throws {BufferSizeError} If the result does not have the requested `size`
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * decode('Zm8=', 'base64'); // Buffer('fo')
33
+ * decode('9Ajdvzr', 'base58', { size: 32 });
34
+ * ```
35
+ */
36
+ export declare function decode(encoded: string, base: Base, options?: DecodeOptions): Buffer;
37
+ /**
38
+ * Converts a string from one base to another, through the bytes they describe.
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * convert('9Ajdvzr', 'base58', 'base64url');
43
+ * convert(legacy, 'radix64', 'base64'); // migrate data written by bufferbase 2
44
+ * ```
45
+ */
46
+ export declare function convert(input: string, from: Base, to: Base): string;
47
+ /**
48
+ * Reports whether `decode` would succeed for this input.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * validate('Zm8=', 'base64'); // true
53
+ * validate('Zm9=', 'base64'); // false — spare bits are not zero
54
+ * validate('Zm9vd', 'base64'); // false — 5 characters cannot be whole bytes
55
+ * ```
56
+ */
57
+ export declare function validate(input: string, base: Base): boolean;
58
+ //# sourceMappingURL=functions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../src/functions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGxD,2DAA2D;AAC3D,MAAM,MAAM,IAAI,GAAG,QAAQ,GAAG,SAAS,CAAC;AAExC;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAEnF;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,GAAG,MAAM,CAInE;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAE3D"}
@@ -0,0 +1,65 @@
1
+ import { resolveSpec } from './bases.js';
2
+ import { getCodec } from './codec.js';
3
+ /**
4
+ * Encodes a buffer to a base-encoded string.
5
+ *
6
+ * @param buffer - Buffer or Uint8Array to encode
7
+ * @param base - Base name (e.g. `'base58'`) or a codec spec
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * encode(Buffer.from('fo'), 'base64'); // 'Zm8='
12
+ * encode(Uint8Array.of(5), { alphabet: '01', algorithm: 'radix' }); // '101'
13
+ * ```
14
+ */
15
+ export function encode(buffer, base) {
16
+ return getCodec(resolveSpec(base)).encode(buffer);
17
+ }
18
+ /**
19
+ * Decodes a base-encoded string to a buffer.
20
+ *
21
+ * @param encoded - String to decode
22
+ * @param base - Base name (e.g. `'base58'`) or a codec spec
23
+ * @param options - Decode options, such as a required `size`
24
+ * @throws {InvalidCharacterError} If a character is not in the alphabet
25
+ * @throws {InvalidLengthError} If the length cannot encode a whole number of bytes
26
+ * @throws {NonCanonicalError} If spare bits are set and the codec is strict
27
+ * @throws {BufferSizeError} If the result does not have the requested `size`
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * decode('Zm8=', 'base64'); // Buffer('fo')
32
+ * decode('9Ajdvzr', 'base58', { size: 32 });
33
+ * ```
34
+ */
35
+ export function decode(encoded, base, options) {
36
+ return getCodec(resolveSpec(base)).decode(encoded, options);
37
+ }
38
+ /**
39
+ * Converts a string from one base to another, through the bytes they describe.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * convert('9Ajdvzr', 'base58', 'base64url');
44
+ * convert(legacy, 'radix64', 'base64'); // migrate data written by bufferbase 2
45
+ * ```
46
+ */
47
+ export function convert(input, from, to) {
48
+ const source = getCodec(resolveSpec(from));
49
+ const target = getCodec(resolveSpec(to));
50
+ return source.convertTo(target, input);
51
+ }
52
+ /**
53
+ * Reports whether `decode` would succeed for this input.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * validate('Zm8=', 'base64'); // true
58
+ * validate('Zm9=', 'base64'); // false — spare bits are not zero
59
+ * validate('Zm9vd', 'base64'); // false — 5 characters cannot be whole bytes
60
+ * ```
61
+ */
62
+ export function validate(input, base) {
63
+ return getCodec(resolveSpec(base)).validate(input);
64
+ }
65
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/functions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAiB,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAKtC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,MAAM,CAAC,MAAkB,EAAE,IAAU;IACnD,OAAO,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACpD,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,MAAM,CAAC,OAAe,EAAE,IAAU,EAAE,OAAuB;IACzE,OAAO,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,IAAU,EAAE,EAAQ;IACzD,MAAM,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa,EAAE,IAAU;IAChD,OAAO,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC"}
@@ -1,2 +1,11 @@
1
- export { Chars, BufferEncoder, Converter, InvalidCharacterError, Validator, validate, } from './bufferbase.js';
1
+ export type { Algorithm, Block85Spec, BlockSpec, BufferLike, CodecSpec, DecodeOptions, ICodec, RadixSpec, } from './types.js';
2
+ export type { BaseName } from './bases.js';
3
+ export type { Base } from './functions.js';
4
+ export type { CodecName } from './codecs.js';
5
+ export { BufferSizeError, CheckSymbolError, InvalidCharacterError, InvalidCodecError, InvalidLengthError, NonCanonicalError, UnknownBaseError, ValueRangeError, } from './errors.js';
6
+ export { Block85Codec, BlockCodec, Codec, RadixCodec, createCodec, getCodec } from './codec.js';
7
+ export { Bases, Chars, isBaseName, resolveSpec } from './bases.js';
8
+ export { convert, decode, encode, validate } from './functions.js';
9
+ export { Codecs } from './codecs.js';
10
+ export { BufferEncoder, Converter, Validator } from './bufferbase.js';
2
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EACrB,SAAS,EACT,QAAQ,GACT,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,SAAS,EACT,WAAW,EACX,SAAS,EACT,UAAU,EACV,SAAS,EACT,aAAa,EACb,MAAM,EACN,SAAS,GACV,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,YAAY,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,GAChB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGhG,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGnE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAGnE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,2 +1,13 @@
1
- export { Chars, BufferEncoder, Converter, InvalidCharacterError, Validator, validate, } from './bufferbase.js';
1
+ // Errors
2
+ export { BufferSizeError, CheckSymbolError, InvalidCharacterError, InvalidCodecError, InvalidLengthError, NonCanonicalError, UnknownBaseError, ValueRangeError, } from './errors.js';
3
+ // Codec implementations and factory
4
+ export { Block85Codec, BlockCodec, Codec, RadixCodec, createCodec, getCodec } from './codec.js';
5
+ // Character sets, encoding definitions, and lookup helpers
6
+ export { Bases, Chars, isBaseName, resolveSpec } from './bases.js';
7
+ // Simple function API
8
+ export { convert, decode, encode, validate } from './functions.js';
9
+ // Pre-defined codecs (namespaced)
10
+ export { Codecs } from './codecs.js';
11
+ // Deprecated exports for backward compatibility
12
+ export { BufferEncoder, Converter, Validator } from './bufferbase.js';
2
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EACrB,SAAS,EACT,QAAQ,GACT,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAeA,SAAS;AACT,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,GAChB,MAAM,aAAa,CAAC;AAErB,oCAAoC;AACpC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEhG,2DAA2D;AAC3D,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEnE,sBAAsB;AACtB,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEnE,kCAAkC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,gDAAgD;AAChD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
@@ -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": "module",
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;IAC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AM,WAAW,MAAM;IACrB,uCAAuC;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,mDAAmD;IACnD,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAE9B,iDAAiD;IACjD,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC;IAEnC,iDAAiD;IACjD,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;IAEzD,6DAA6D;IAC7D,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAEjC,8DAA8D;IAC9D,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CAClD"}
@@ -0,0 +1,2 @@
1
+ import { Buffer } from 'node:buffer';
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
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": "module",
7
- "main": "./dist/cjs/index.mjs",
7
+ "main": "./dist/cjs/index.js",
8
8
  "module": "./dist/esm/index.js",
9
- "types": "./dist/esm/index.d.mts",
9
+ "types": "./dist/esm/index.d.ts",
10
10
  "exports": {
11
11
  ".": {
12
12
  "import": {
@@ -21,18 +21,18 @@
21
21
  }
22
22
  },
23
23
  "scripts": {
24
- "build": "npm run build:esm && npm run build:cjs && tsconfig-to-dual-package",
24
+ "build": "bun run build:esm && bun run build:cjs && tsconfig-to-dual-package",
25
25
  "build:cjs": "tsc -p tsconfig.cjs.json",
26
26
  "build:esm": "tsc -p tsconfig.json",
27
- "prepublishOnly": "npm run build",
28
- "example": "tsx src/example.ts",
29
- "test": "tsx --test src/*.test.ts"
27
+ "prepublishOnly": "bun run build",
28
+ "example": "bun src/example.ts",
29
+ "test": "bun test",
30
+ "release": "bin/release"
30
31
  },
31
32
  "devDependencies": {
33
+ "@types/bun": "^1.1.0",
32
34
  "@types/node": "^20.11.5",
33
- "ts-loader": "^9.5.1",
34
35
  "tsconfig-to-dual-package": "^1.2.0",
35
- "tsx": "^4.7.0",
36
36
  "typescript": "^5.3.3"
37
37
  },
38
38
  "repository": {
@@ -44,19 +44,24 @@
44
44
  "src"
45
45
  ],
46
46
  "keywords": [
47
- "number",
48
47
  "encode",
48
+ "decode",
49
49
  "convert",
50
- "decimal",
51
50
  "base",
51
+ "rfc4648",
52
52
  "base16",
53
+ "hex",
53
54
  "base32",
55
+ "base32hex",
54
56
  "crockford",
55
57
  "base36",
56
58
  "base58",
57
59
  "base64",
58
- "Ascii85",
59
- "base85"
60
+ "base64url",
61
+ "ascii85",
62
+ "base85",
63
+ "z85",
64
+ "radix"
60
65
  ],
61
66
  "author": "misebox",
62
67
  "license": "ISC",