bufferbase 2.0.0 → 3.0.1

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 (115) hide show
  1. package/README.md +162 -63
  2. package/dist/cjs/bases.d.ts +152 -45
  3. package/dist/cjs/bases.d.ts.map +1 -1
  4. package/dist/cjs/bases.js +90 -77
  5. package/dist/cjs/bases.js.map +1 -1
  6. package/dist/cjs/bufferbase.d.ts +21 -27
  7. package/dist/cjs/bufferbase.d.ts.map +1 -1
  8. package/dist/cjs/bufferbase.js +21 -31
  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 +25 -111
  27. package/dist/cjs/codec.d.ts.map +1 -1
  28. package/dist/cjs/codec.js +50 -228
  29. package/dist/cjs/codec.js.map +1 -1
  30. package/dist/cjs/codecs.d.ts +8 -59
  31. package/dist/cjs/codecs.d.ts.map +1 -1
  32. package/dist/cjs/codecs.js +6 -79
  33. package/dist/cjs/codecs.js.map +1 -1
  34. package/dist/cjs/errors.d.ts +65 -48
  35. package/dist/cjs/errors.d.ts.map +1 -1
  36. package/dist/cjs/errors.js +89 -51
  37. package/dist/cjs/errors.js.map +1 -1
  38. package/dist/cjs/example.js +44 -21
  39. package/dist/cjs/example.js.map +1 -1
  40. package/dist/cjs/functions.d.ts +27 -31
  41. package/dist/cjs/functions.d.ts.map +1 -1
  42. package/dist/cjs/functions.js +25 -47
  43. package/dist/cjs/functions.js.map +1 -1
  44. package/dist/cjs/index.d.ts +7 -5
  45. package/dist/cjs/index.d.ts.map +1 -1
  46. package/dist/cjs/index.js +17 -7
  47. package/dist/cjs/index.js.map +1 -1
  48. package/dist/cjs/package.json +12 -7
  49. package/dist/cjs/types.d.ts +108 -71
  50. package/dist/cjs/types.d.ts.map +1 -1
  51. package/dist/esm/bases.d.ts +152 -45
  52. package/dist/esm/bases.d.ts.map +1 -1
  53. package/dist/esm/bases.js +88 -75
  54. package/dist/esm/bases.js.map +1 -1
  55. package/dist/esm/bufferbase.d.ts +21 -27
  56. package/dist/esm/bufferbase.d.ts.map +1 -1
  57. package/dist/esm/bufferbase.js +18 -30
  58. package/dist/esm/bufferbase.js.map +1 -1
  59. package/dist/esm/codec-base.d.ts +56 -0
  60. package/dist/esm/codec-base.d.ts.map +1 -0
  61. package/dist/esm/codec-base.js +127 -0
  62. package/dist/esm/codec-base.js.map +1 -0
  63. package/dist/esm/codec-block.d.ts +47 -0
  64. package/dist/esm/codec-block.d.ts.map +1 -0
  65. package/dist/esm/codec-block.js +209 -0
  66. package/dist/esm/codec-block.js.map +1 -0
  67. package/dist/esm/codec-block85.d.ts +56 -0
  68. package/dist/esm/codec-block85.d.ts.map +1 -0
  69. package/dist/esm/codec-block85.js +267 -0
  70. package/dist/esm/codec-block85.js.map +1 -0
  71. package/dist/esm/codec-radix.d.ts +46 -0
  72. package/dist/esm/codec-radix.d.ts.map +1 -0
  73. package/dist/esm/codec-radix.js +177 -0
  74. package/dist/esm/codec-radix.js.map +1 -0
  75. package/dist/esm/codec.d.ts +25 -111
  76. package/dist/esm/codec.d.ts.map +1 -1
  77. package/dist/esm/codec.js +44 -226
  78. package/dist/esm/codec.js.map +1 -1
  79. package/dist/esm/codecs.d.ts +8 -59
  80. package/dist/esm/codecs.d.ts.map +1 -1
  81. package/dist/esm/codecs.js +7 -80
  82. package/dist/esm/codecs.js.map +1 -1
  83. package/dist/esm/errors.d.ts +65 -48
  84. package/dist/esm/errors.d.ts.map +1 -1
  85. package/dist/esm/errors.js +83 -50
  86. package/dist/esm/errors.js.map +1 -1
  87. package/dist/esm/example.js +45 -22
  88. package/dist/esm/example.js.map +1 -1
  89. package/dist/esm/functions.d.ts +27 -31
  90. package/dist/esm/functions.d.ts.map +1 -1
  91. package/dist/esm/functions.js +26 -48
  92. package/dist/esm/functions.js.map +1 -1
  93. package/dist/esm/index.d.ts +7 -5
  94. package/dist/esm/index.d.ts.map +1 -1
  95. package/dist/esm/index.js +6 -6
  96. package/dist/esm/index.js.map +1 -1
  97. package/dist/esm/package.json +12 -7
  98. package/dist/esm/types.d.ts +108 -71
  99. package/dist/esm/types.d.ts.map +1 -1
  100. package/package.json +12 -7
  101. package/src/algorithms.test.ts +442 -0
  102. package/src/bases.ts +98 -76
  103. package/src/bufferbase.ts +26 -36
  104. package/src/codec-base.ts +181 -0
  105. package/src/codec-block.ts +258 -0
  106. package/src/codec-block85.ts +315 -0
  107. package/src/codec-radix.ts +206 -0
  108. package/src/codec.test.ts +17 -9
  109. package/src/codec.ts +48 -247
  110. package/src/codecs.ts +11 -105
  111. package/src/errors.ts +90 -50
  112. package/src/example.ts +47 -22
  113. package/src/functions.ts +34 -54
  114. package/src/index.ts +27 -7
  115. package/src/types.ts +113 -86
package/src/functions.ts CHANGED
@@ -1,93 +1,73 @@
1
- import type { BaseName, DecodeOptions, BufferLike } from './types.js';
2
- import { Codec } from './codec.js';
3
- import { resolveChars } from './bases.js';
1
+ import type { BufferLike, CodecSpec, DecodeOptions } from './types.js';
2
+ import type { Buffer } from 'node:buffer';
3
+ import { resolveSpec, type BaseName } from './bases.js';
4
+ import { getCodec } from './codec.js';
4
5
 
5
- // Cache for codec instances
6
- const codecCache = new Map<string, Codec>();
7
-
8
- /**
9
- * Gets or creates a codec for the specified base.
10
- */
11
- function getCodec(base: BaseName | string): Codec {
12
- const chars = resolveChars(base);
13
- let codec = codecCache.get(chars);
14
- if (!codec) {
15
- codec = new Codec(chars);
16
- codecCache.set(chars, codec);
17
- }
18
- return codec;
19
- }
6
+ /** A named encoding, or a spec describing one directly. */
7
+ export type Base = BaseName | CodecSpec;
20
8
 
21
9
  /**
22
10
  * Encodes a buffer to a base-encoded string.
23
11
  *
24
12
  * @param buffer - Buffer or Uint8Array to encode
25
- * @param base - Base name (e.g., 'base58') or custom character set
26
- * @returns Encoded string
13
+ * @param base - Base name (e.g. `'base58'`) or a codec spec
27
14
  *
28
15
  * @example
29
16
  * ```typescript
30
- * // Node.js Buffer
31
- * const encoded = encode(Buffer.from('Hello'), 'base58');
32
- *
33
- * // Browser Uint8Array
34
- * const encoded = encode(new Uint8Array([72, 101, 108, 108, 111]), 'base58');
17
+ * encode(Buffer.from('fo'), 'base64'); // 'Zm8='
18
+ * encode(Uint8Array.of(5), { alphabet: '01', algorithm: 'radix' }); // '101'
35
19
  * ```
36
20
  */
37
- export function encode(buffer: BufferLike, base: BaseName | string): string {
38
- return getCodec(base).encode(buffer);
21
+ export function encode(buffer: BufferLike, base: Base): string {
22
+ return getCodec(resolveSpec(base)).encode(buffer);
39
23
  }
40
24
 
41
25
  /**
42
26
  * Decodes a base-encoded string to a buffer.
43
27
  *
44
28
  * @param encoded - String to decode
45
- * @param base - Base name (e.g., 'base58') or custom character set
46
- * @param options - Decode options (e.g., { size: 32 })
47
- * @returns Decoded buffer
29
+ * @param base - Base name (e.g. `'base58'`) or a codec spec
30
+ * @param options - Decode options, such as a required `size`
31
+ * @throws {InvalidCharacterError} If a character is not in the alphabet
32
+ * @throws {InvalidLengthError} If the length cannot encode a whole number of bytes
33
+ * @throws {NonCanonicalError} If spare bits are set and the codec is strict
34
+ * @throws {BufferSizeError} If the result does not have the requested `size`
48
35
  *
49
36
  * @example
50
37
  * ```typescript
51
- * const buffer = decode('9Ajdvz', 'base58');
52
- * const fixedSize = decode('9Ajdvz', 'base58', { size: 32 });
38
+ * decode('Zm8=', 'base64'); // Buffer('fo')
39
+ * decode('9Ajdvzr', 'base58', { size: 32 });
53
40
  * ```
54
41
  */
55
- export function decode(encoded: string, base: BaseName | string, options?: DecodeOptions): Buffer {
56
- return getCodec(base).decode(encoded, options);
42
+ export function decode(encoded: string, base: Base, options?: DecodeOptions): Buffer {
43
+ return getCodec(resolveSpec(base)).decode(encoded, options);
57
44
  }
58
45
 
59
46
  /**
60
- * Converts a string from one base to another.
61
- *
62
- * @param input - String to convert
63
- * @param from - Source base name or character set
64
- * @param to - Target base name or character set
65
- * @returns Converted string
47
+ * Converts a string from one base to another, through the bytes they describe.
66
48
  *
67
49
  * @example
68
50
  * ```typescript
69
- * const base64 = convert('9Ajdvz', 'base58', 'base64url');
51
+ * convert('9Ajdvzr', 'base58', 'base64url');
52
+ * convert(legacy, 'radix64', 'base64'); // migrate data written by bufferbase 2
70
53
  * ```
71
54
  */
72
- export function convert(input: string, from: BaseName | string, to: BaseName | string): string {
73
- const fromCodec = getCodec(from);
74
- const toCodec = getCodec(to);
75
- return fromCodec.convertTo(toCodec, input);
55
+ export function convert(input: string, from: Base, to: Base): string {
56
+ const source = getCodec(resolveSpec(from));
57
+ const target = getCodec(resolveSpec(to));
58
+ return source.convertTo(target, input);
76
59
  }
77
60
 
78
61
  /**
79
- * Validates if a string contains only valid characters for the specified base.
80
- *
81
- * @param input - String to validate
82
- * @param base - Base name or character set
83
- * @returns true if valid, false otherwise
62
+ * Reports whether `decode` would succeed for this input.
84
63
  *
85
64
  * @example
86
65
  * ```typescript
87
- * validate('9Ajdvz', 'base58'); // true
88
- * validate('0Ajdvz', 'base58'); // false ('0' is not in base58)
66
+ * validate('Zm8=', 'base64'); // true
67
+ * validate('Zm9=', 'base64'); // false spare bits are not zero
68
+ * validate('Zm9vd', 'base64'); // false — 5 characters cannot be whole bytes
89
69
  * ```
90
70
  */
91
- export function validate(input: string, base: BaseName | string): boolean {
92
- return getCodec(base).validate(input);
71
+ export function validate(input: string, base: Base): boolean {
72
+ return getCodec(resolveSpec(base)).validate(input);
93
73
  }
package/src/index.ts CHANGED
@@ -1,18 +1,38 @@
1
1
  // Types
2
- export type { BaseName, DecodeOptions, ICodec, BufferLike } from './types.js';
2
+ export type {
3
+ Algorithm,
4
+ Block85Spec,
5
+ BlockSpec,
6
+ BufferLike,
7
+ CodecSpec,
8
+ DecodeOptions,
9
+ ICodec,
10
+ RadixSpec,
11
+ } from './types.js';
12
+ export type { BaseName } from './bases.js';
13
+ export type { Base } from './functions.js';
3
14
  export type { CodecName } from './codecs.js';
4
15
 
5
16
  // Errors
6
- export { InvalidCharacterError, BufferSizeError, UnknownBaseError } from './errors.js';
17
+ export {
18
+ BufferSizeError,
19
+ CheckSymbolError,
20
+ InvalidCharacterError,
21
+ InvalidCodecError,
22
+ InvalidLengthError,
23
+ NonCanonicalError,
24
+ UnknownBaseError,
25
+ ValueRangeError,
26
+ } from './errors.js';
7
27
 
8
- // Codec class and factory
9
- export { Codec, createCodec } from './codec.js';
28
+ // Codec implementations and factory
29
+ export { Block85Codec, BlockCodec, Codec, RadixCodec, createCodec, getCodec } from './codec.js';
10
30
 
11
- // Character sets and utilities
12
- export { Chars, resolveChars, isBaseName } from './bases.js';
31
+ // Character sets, encoding definitions, and lookup helpers
32
+ export { Bases, Chars, isBaseName, resolveSpec } from './bases.js';
13
33
 
14
34
  // Simple function API
15
- export { encode, decode, convert, validate } from './functions.js';
35
+ export { convert, decode, encode, validate } from './functions.js';
16
36
 
17
37
  // Pre-defined codecs (namespaced)
18
38
  export { Codecs } from './codecs.js';
package/src/types.ts CHANGED
@@ -4,76 +4,128 @@ import { Buffer } from 'node:buffer';
4
4
  * Input type accepted by encode functions.
5
5
  *
6
6
  * Supports both Node.js `Buffer` and standard `Uint8Array` for browser compatibility.
7
- *
8
- * @example
9
- * ```typescript
10
- * // Node.js Buffer
11
- * encode(Buffer.from('Hello'), 'base58');
12
- *
13
- * // Browser Uint8Array
14
- * encode(new Uint8Array([72, 101, 108, 108, 111]), 'base58');
15
- * ```
16
7
  */
17
8
  export type BufferLike = Buffer | Uint8Array;
18
9
 
19
10
  /**
20
- * Supported base encoding names.
11
+ * How bytes are mapped to characters.
21
12
  *
22
- * These names can be used with the function API:
23
- * - `'decimal'` - Base 10 (0-9)
24
- * - `'base16'` / `'hex'` - Hexadecimal (0-9A-F)
25
- * - `'base32'` - RFC 4648 Base32 (A-Z2-7)
26
- * - `'base32crockford'` - Crockford's Base32 (0-9A-HJKMNP-TV-Z)
27
- * - `'base36'` - Alphanumeric (0-9A-Z)
28
- * - `'base52'` - Letters only (A-Za-z)
29
- * - `'base58'` - Bitcoin alphabet (no 0OIl)
30
- * - `'base64'` - Standard Base64 (A-Za-z0-9+/)
31
- * - `'base64url'` - URL-safe Base64 (A-Za-z0-9-_)
32
- * - `'base64xml'` - XML token Base64 (A-Za-z0-9._)
33
- * - `'base64xmlname'` - XML name Base64 (A-Za-z0-9_:)
34
- * - `'ascii85'` - ASCII85 encoding
35
- * - `'base85'` - Base85 encoding
36
- * - `'z85'` - ZeroMQ Z85 encoding
13
+ * An alphabet alone does not determine an encoding: the same 64 characters can
14
+ * be used by a radix conversion or by a bit-block encoding, producing different
15
+ * output. Every codec therefore names its algorithm explicitly.
16
+ *
17
+ * - `'radix'` treats the whole buffer as one big integer and rewrites it in
18
+ * base `alphabet.length`. Works with any alphabet and any input length.
19
+ * Leading zero bytes are preserved as leading `alphabet[0]` characters.
20
+ * Used by Base58, Base36, and custom alphabets. Not RFC 4648.
21
+ * - `'block'` regroups the bit stream into `log2(alphabet.length)`-bit chunks,
22
+ * as specified by RFC 4648. Requires an alphabet of 2, 4, 8, 16, 32, or 64
23
+ * characters. Used by Base16, Base32, and Base64.
24
+ * - `'block85'` — converts each 4-byte block to 5 characters (85^5 > 2^32).
25
+ * Requires an alphabet of exactly 85 characters. Used by Ascii85 and Z85.
26
+ */
27
+ export type Algorithm = 'radix' | 'block' | 'block85';
28
+
29
+ /** Options shared by every algorithm. */
30
+ interface CommonSpec {
31
+ /** Characters used for encoding, ordered by value. */
32
+ readonly alphabet: string;
33
+ /**
34
+ * Reject input that is well-formed but not the canonical encoding of any
35
+ * byte sequence (RFC 4648 §3.5). Defaults to `true`.
36
+ *
37
+ * With `strict: false`, `'Zm9='` and `'Zm8='` both decode to `'fo'`, so
38
+ * decoding is no longer injective. Only disable it to read data produced by
39
+ * a lenient encoder.
40
+ */
41
+ readonly strict?: boolean;
42
+ /**
43
+ * Accept either letter case when decoding, and when validating.
44
+ * Requires an alphabet that does not contain both cases of the same letter.
45
+ * Defaults to `false`.
46
+ */
47
+ readonly caseInsensitive?: boolean;
48
+ /**
49
+ * Extra characters accepted when decoding, each mapped to the alphabet
50
+ * character it stands for.
51
+ *
52
+ * Crockford's Base32 uses `{ I: '1', L: '1', O: '0' }` so that a symbol
53
+ * written down by hand is read back as the digit it resembles. Encoding
54
+ * never emits them.
55
+ */
56
+ readonly aliases?: Readonly<Record<string, string>>;
57
+ /**
58
+ * Characters skipped when decoding, such as the hyphens Crockford's Base32
59
+ * allows for readability. Encoding never emits them.
60
+ */
61
+ readonly ignore?: string;
62
+ }
63
+
64
+ /** A codec that rewrites the buffer as an integer in base `alphabet.length`. */
65
+ export interface RadixSpec extends CommonSpec {
66
+ readonly algorithm: 'radix';
67
+ /**
68
+ * Symbols that extend the alphabet for a trailing check symbol, which
69
+ * encodes the value modulo `alphabet.length + checkSymbols.length`.
70
+ *
71
+ * Crockford's Base32 uses `'*~$=U'`, giving a modulus of 37. When set, every
72
+ * encoding carries the symbol and every decoding verifies it.
73
+ */
74
+ readonly checkSymbols?: string;
75
+ }
76
+
77
+ /** A codec that regroups the bit stream, as specified by RFC 4648. */
78
+ export interface BlockSpec extends CommonSpec {
79
+ readonly algorithm: 'block';
80
+ /**
81
+ * Character used to pad the final block to a whole number of characters,
82
+ * or `false` to emit no padding. Defaults to `'='`.
83
+ */
84
+ readonly pad?: string | false;
85
+ }
86
+
87
+ /** A codec that converts each 4-byte block to 5 characters. */
88
+ export interface Block85Spec extends CommonSpec {
89
+ readonly algorithm: 'block85';
90
+ /** Write a block of four zero bytes as `'z'`. Defaults to `false`. */
91
+ readonly zeroShortcut?: boolean;
92
+ /** Write a block of four spaces as `'y'`. Defaults to `false`. */
93
+ readonly spaceShortcut?: boolean;
94
+ /** Wrap the output in `'<~'` and `'~>'`. Defaults to `false`. */
95
+ readonly delimiters?: boolean;
96
+ /**
97
+ * Require the input length to be a multiple of 4 bytes, as Z85 does.
98
+ * Defaults to `false`, which encodes a trailing partial block as
99
+ * `length + 1` characters.
100
+ */
101
+ readonly requireFullBlocks?: boolean;
102
+ }
103
+
104
+ /**
105
+ * A complete codec definition: an alphabet plus the algorithm that uses it.
37
106
  *
38
107
  * @example
39
108
  * ```typescript
40
- * import { encode, decode } from 'bufferbase';
109
+ * import { encode, type CodecSpec } from 'bufferbase';
41
110
  *
42
- * const encoded = encode(Buffer.from('Hello'), 'base58');
43
- * const decoded = decode(encoded, 'base58');
111
+ * const binary: CodecSpec = { alphabet: '01', algorithm: 'radix' };
112
+ * encode(Uint8Array.of(5), binary); // '101'
44
113
  * ```
45
114
  */
46
- export type BaseName =
47
- | 'decimal'
48
- | 'base16'
49
- | 'hex'
50
- | 'base32'
51
- | 'base32crockford'
52
- | 'base36'
53
- | 'base52'
54
- | 'base58'
55
- | 'base64'
56
- | 'base64url'
57
- | 'base64xml'
58
- | 'base64xmlname'
59
- | 'ascii85'
60
- | 'base85'
61
- | 'z85';
115
+ export type CodecSpec = RadixSpec | BlockSpec | Block85Spec;
62
116
 
63
117
  /**
64
118
  * Options for decode operations.
65
- *
66
- * @example
67
- * ```typescript
68
- * // Decode with fixed buffer size (pads with leading zeros)
69
- * const buffer = decode(encoded, 'base58', { size: 32 });
70
- * ```
71
119
  */
72
120
  export interface DecodeOptions {
73
121
  /**
74
- * Expected buffer size in bytes.
75
- * - If decoded result is smaller, pads with leading zeros.
76
- * - If decoded result is larger, throws `BufferSizeError`.
122
+ * Required byte length of the result.
123
+ *
124
+ * The decoded buffer must be exactly this long, otherwise `BufferSizeError`
125
+ * is thrown. Because leading zeros carry no value in a radix encoding, a
126
+ * `'radix'` codec pads a shorter result with leading zero bytes to reach it;
127
+ * `'block'` and `'block85'` codecs derive the length from the input and can
128
+ * only check it.
77
129
  */
78
130
  size?: number;
79
131
  }
@@ -81,49 +133,24 @@ export interface DecodeOptions {
81
133
  /**
82
134
  * Codec interface for encoding/decoding operations.
83
135
  *
84
- * Implemented by the `Codec` class and used by pre-defined codecs in `Codecs`.
85
- *
86
- * @example
87
- * ```typescript
88
- * import { Codecs } from 'bufferbase';
89
- *
90
- * const encoded = Codecs.base58.encode(Buffer.from('Hello'));
91
- * const decoded = Codecs.base58.decode(encoded);
92
- * ```
136
+ * `validate(input)` returns `true` exactly when `decode(input)` succeeds.
93
137
  */
94
138
  export interface ICodec {
95
139
  /** Character set used for encoding. */
96
140
  readonly chars: string;
97
141
 
98
- /**
99
- * Encodes a buffer to a base-encoded string.
100
- * @param buffer - The buffer or Uint8Array to encode
101
- * @returns Base-encoded string
102
- */
142
+ /** The algorithm this codec applies to `chars`. */
143
+ readonly algorithm: Algorithm;
144
+
145
+ /** Encodes a buffer to a base-encoded string. */
103
146
  encode(buffer: BufferLike): string;
104
147
 
105
- /**
106
- * Decodes a base-encoded string to a buffer.
107
- * @param encoded - The string to decode
108
- * @param options - Decode options (e.g., fixed size)
109
- * @returns Decoded buffer
110
- * @throws {InvalidCharacterError} If the string contains invalid characters
111
- * @throws {BufferSizeError} If the result exceeds the specified size
112
- */
148
+ /** Decodes a base-encoded string to a buffer. */
113
149
  decode(encoded: string, options?: DecodeOptions): Buffer;
114
150
 
115
- /**
116
- * Validates if a string contains only valid characters for this base.
117
- * @param input - The string to validate
118
- * @returns `true` if valid, `false` otherwise
119
- */
151
+ /** Reports whether `decode` would succeed for this input. */
120
152
  validate(input: string): boolean;
121
153
 
122
- /**
123
- * Converts a string from this base to another base.
124
- * @param target - Target codec to convert to
125
- * @param input - The string to convert
126
- * @returns String in the target base encoding
127
- */
154
+ /** Decodes with this codec, then re-encodes with `target`. */
128
155
  convertTo(target: ICodec, input: string): string;
129
156
  }