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.
- package/README.md +186 -17
- package/dist/cjs/bases.d.ts +189 -0
- package/dist/cjs/bases.d.ts.map +1 -0
- package/dist/cjs/bases.js +134 -0
- package/dist/cjs/bases.js.map +1 -0
- package/dist/cjs/bufferbase.d.ts +22 -45
- package/dist/cjs/bufferbase.d.ts.map +1 -1
- package/dist/cjs/bufferbase.js +26 -120
- package/dist/cjs/bufferbase.js.map +1 -1
- package/dist/cjs/codec-base.d.ts +56 -0
- package/dist/cjs/codec-base.d.ts.map +1 -0
- package/dist/cjs/codec-base.js +132 -0
- package/dist/cjs/codec-base.js.map +1 -0
- package/dist/cjs/codec-block.d.ts +47 -0
- package/dist/cjs/codec-block.d.ts.map +1 -0
- package/dist/cjs/codec-block.js +213 -0
- package/dist/cjs/codec-block.js.map +1 -0
- package/dist/cjs/codec-block85.d.ts +56 -0
- package/dist/cjs/codec-block85.d.ts.map +1 -0
- package/dist/cjs/codec-block85.js +271 -0
- package/dist/cjs/codec-block85.js.map +1 -0
- package/dist/cjs/codec-radix.d.ts +46 -0
- package/dist/cjs/codec-radix.d.ts.map +1 -0
- package/dist/cjs/codec-radix.js +181 -0
- package/dist/cjs/codec-radix.js.map +1 -0
- package/dist/cjs/codec.d.ts +38 -0
- package/dist/cjs/codec.d.ts.map +1 -0
- package/dist/cjs/codec.js +69 -0
- package/dist/cjs/codec.js.map +1 -0
- package/dist/cjs/codecs.d.ts +20 -0
- package/dist/cjs/codecs.d.ts.map +1 -0
- package/dist/cjs/codecs.js +19 -0
- package/dist/cjs/codecs.js.map +1 -0
- package/dist/cjs/errors.d.ts +93 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +130 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/example.js +49 -33
- package/dist/cjs/example.js.map +1 -1
- package/dist/cjs/functions.d.ts +58 -0
- package/dist/cjs/functions.d.ts.map +1 -0
- package/dist/cjs/functions.js +71 -0
- package/dist/cjs/functions.js.map +1 -0
- package/dist/cjs/index.d.ts +10 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +35 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/package.json +17 -12
- package/dist/cjs/types.d.ts +144 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/bases.d.ts +189 -0
- package/dist/esm/bases.d.ts.map +1 -0
- package/dist/esm/bases.js +129 -0
- package/dist/esm/bases.js.map +1 -0
- package/dist/esm/bufferbase.d.ts +22 -45
- package/dist/esm/bufferbase.d.ts.map +1 -1
- package/dist/esm/bufferbase.js +21 -115
- package/dist/esm/bufferbase.js.map +1 -1
- package/dist/esm/codec-base.d.ts +56 -0
- package/dist/esm/codec-base.d.ts.map +1 -0
- package/dist/esm/codec-base.js +127 -0
- package/dist/esm/codec-base.js.map +1 -0
- package/dist/esm/codec-block.d.ts +47 -0
- package/dist/esm/codec-block.d.ts.map +1 -0
- package/dist/esm/codec-block.js +209 -0
- package/dist/esm/codec-block.js.map +1 -0
- package/dist/esm/codec-block85.d.ts +56 -0
- package/dist/esm/codec-block85.d.ts.map +1 -0
- package/dist/esm/codec-block85.js +267 -0
- package/dist/esm/codec-block85.js.map +1 -0
- package/dist/esm/codec-radix.d.ts +46 -0
- package/dist/esm/codec-radix.d.ts.map +1 -0
- package/dist/esm/codec-radix.js +177 -0
- package/dist/esm/codec-radix.js.map +1 -0
- package/dist/esm/codec.d.ts +38 -0
- package/dist/esm/codec.d.ts.map +1 -0
- package/dist/esm/codec.js +60 -0
- package/dist/esm/codec.js.map +1 -0
- package/dist/esm/codecs.d.ts +20 -0
- package/dist/esm/codecs.d.ts.map +1 -0
- package/dist/esm/codecs.js +16 -0
- package/dist/esm/codecs.js.map +1 -0
- package/dist/esm/errors.d.ts +93 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +119 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/example.js +48 -32
- package/dist/esm/example.js.map +1 -1
- package/dist/esm/functions.d.ts +58 -0
- package/dist/esm/functions.d.ts.map +1 -0
- package/dist/esm/functions.js +65 -0
- package/dist/esm/functions.js.map +1 -0
- package/dist/esm/index.d.ts +10 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +12 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/package.json +17 -12
- package/dist/esm/types.d.ts +144 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +19 -14
- package/src/algorithms.test.ts +442 -0
- package/src/bases.ts +142 -0
- package/src/bufferbase.test.ts +44 -27
- package/src/bufferbase.ts +32 -117
- package/src/codec-base.ts +181 -0
- package/src/codec-block.ts +258 -0
- package/src/codec-block85.ts +315 -0
- package/src/codec-radix.ts +206 -0
- package/src/codec.test.ts +328 -0
- package/src/codec.ts +67 -0
- package/src/codecs.ts +24 -0
- package/src/errors.ts +127 -0
- package/src/example.ts +49 -34
- package/src/functions.ts +73 -0
- package/src/index.ts +39 -6
- package/src/types.ts +156 -0
- package/dist/cjs/bufferbase.d.mts +0 -60
- package/dist/cjs/bufferbase.d.mts.map +0 -1
- package/dist/cjs/bufferbase.mjs +0 -150
- package/dist/cjs/bufferbase.mjs.map +0 -1
- package/dist/cjs/example.d.mts +0 -2
- package/dist/cjs/example.d.mts.map +0 -1
- package/dist/cjs/example.mjs +0 -39
- package/dist/cjs/example.mjs.map +0 -1
- package/dist/cjs/index.d.mts +0 -2
- package/dist/cjs/index.d.mts.map +0 -1
- package/dist/cjs/index.mjs +0 -11
- package/dist/cjs/index.mjs.map +0 -1
- package/dist/esm/bufferbase.d.mts +0 -60
- package/dist/esm/bufferbase.d.mts.map +0 -1
- package/dist/esm/bufferbase.mjs +0 -141
- package/dist/esm/bufferbase.mjs.map +0 -1
- package/dist/esm/example.d.mts +0 -2
- package/dist/esm/example.d.mts.map +0 -1
- package/dist/esm/example.mjs +0 -37
- package/dist/esm/example.mjs.map +0 -1
- package/dist/esm/index.d.mts +0 -2
- package/dist/esm/index.d.mts.map +0 -1
- package/dist/esm/index.mjs +0 -2
- package/dist/esm/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,33 +1,202 @@
|
|
|
1
1
|
# bufferbase
|
|
2
2
|
|
|
3
|
-
Buffer-to-BaseN
|
|
3
|
+
Buffer-to-BaseN encoding for Node.js and the browser, across three algorithms:
|
|
4
|
+
RFC 4648 bit-block encodings, Ascii85/Z85, and Base58-style radix conversion.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
## Installation
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
```bash
|
|
9
|
+
npm install bufferbase
|
|
10
|
+
```
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
- Optimized for Node.js buffer handling.
|
|
11
|
-
- Intuitive API for easy integration.
|
|
12
|
-
- Suitable for various data types.
|
|
13
|
-
- Consistent and reliable performance.
|
|
12
|
+
## The three algorithms
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
An alphabet does not describe an encoding on its own. The same 64 characters
|
|
15
|
+
can be read as a radix conversion or as a bit-block encoding, and the two
|
|
16
|
+
produce different strings for the same bytes. Every codec here therefore names
|
|
17
|
+
its algorithm.
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
| Algorithm | How it works | Alphabet | Used by |
|
|
20
|
+
|---|---|---|---|
|
|
21
|
+
| `block` | Regroups the bit stream into `log2(n)`-bit chunks, per RFC 4648 | 2, 4, 8, 16, 32, or 64 characters | Base16, Base32, Base64 |
|
|
22
|
+
| `block85` | Converts each 4-byte block to 5 characters | exactly 85 characters | Ascii85, Z85 |
|
|
23
|
+
| `radix` | Reads the buffer as one integer and rewrites it in base `n` | any length | Base58, Base36, Crockford |
|
|
18
24
|
|
|
19
|
-
```
|
|
20
|
-
|
|
25
|
+
```typescript
|
|
26
|
+
import { encode } from 'bufferbase';
|
|
27
|
+
|
|
28
|
+
encode(Buffer.from('fo'), 'base64'); // 'Zm8=' — RFC 4648
|
|
29
|
+
encode(Buffer.from('fo'), 'radix64'); // 'GZv' — radix conversion
|
|
21
30
|
```
|
|
22
31
|
|
|
32
|
+
Only `radix` accepts an alphabet of any length, and only `radix` preserves
|
|
33
|
+
leading zero bytes as leading characters. Only `block` and `block85` have an
|
|
34
|
+
output length that is a fixed function of the input length.
|
|
35
|
+
|
|
36
|
+
## Supported encodings
|
|
37
|
+
|
|
38
|
+
| Name | Algorithm | Characters | Notes |
|
|
39
|
+
|---|---|---|---|
|
|
40
|
+
| `base16`, `hex` | `block` | 0-9A-F | RFC 4648 Table 5, unpadded |
|
|
41
|
+
| `base32` | `block` | A-Z2-7 | RFC 4648 Table 3 |
|
|
42
|
+
| `base32hex` | `block` | 0-9A-V | RFC 4648 Table 4 |
|
|
43
|
+
| `base64` | `block` | A-Za-z0-9+/ | RFC 4648 Table 1 |
|
|
44
|
+
| `base64url` | `block` | A-Za-z0-9-_ | RFC 4648 Table 2, unpadded |
|
|
45
|
+
| `base64xml` | `block` | A-Za-z0-9._ | unpadded |
|
|
46
|
+
| `base64xmlname` | `block` | A-Za-z0-9_: | unpadded |
|
|
47
|
+
| `ascii85` | `block85` | `!` to `u` | zero-block shortcut on |
|
|
48
|
+
| `z85` | `block85` | ZeroMQ RFC 32 | whole 4-byte blocks only |
|
|
49
|
+
| `base58` | `radix` | Bitcoin alphabet | |
|
|
50
|
+
| `base32crockford` | `radix` | 0-9A-HJKMNP-TV-Z | |
|
|
51
|
+
| `base32crockfordcheck` | `radix` | as above, plus `*~$=U` | carries a check symbol |
|
|
52
|
+
| `base36` | `radix` | 0-9A-Z | case-insensitive |
|
|
53
|
+
| `base52` | `radix` | A-Za-z | |
|
|
54
|
+
| `decimal` | `radix` | 0-9 | |
|
|
55
|
+
| `radix16`, `radix32`, `radix64`, `radix64url` | `radix` | the RFC alphabets | radix conversion, not RFC 4648 |
|
|
56
|
+
|
|
57
|
+
Base16, Base32, Base32hex, Base36 and both Crockford codecs decode in either
|
|
58
|
+
case.
|
|
59
|
+
|
|
23
60
|
## Usage
|
|
24
61
|
|
|
25
|
-
|
|
62
|
+
### Functions
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { encode, decode, convert, validate } from 'bufferbase';
|
|
66
|
+
|
|
67
|
+
encode(Buffer.from('Hello'), 'base58'); // '9Ajdvzr'
|
|
68
|
+
decode('9Ajdvzr', 'base58'); // Buffer('Hello')
|
|
69
|
+
decode('9Ajdvzr', 'base58', { size: 32 }); // padded to 32 bytes
|
|
70
|
+
convert('9Ajdvzr', 'base58', 'base64url'); // through the bytes
|
|
71
|
+
validate('Zm8=', 'base64'); // true
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`validate(input, base)` returns `true` exactly when `decode(input, base)`
|
|
75
|
+
succeeds, so the two never disagree.
|
|
76
|
+
|
|
77
|
+
### Codecs
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { Codecs } from 'bufferbase';
|
|
81
|
+
|
|
82
|
+
Codecs.base64.encode(Buffer.from('fo')); // 'Zm8='
|
|
83
|
+
Codecs.base58.convertTo(Codecs.base64url, '9Ajdvzr');
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Custom codecs
|
|
87
|
+
|
|
88
|
+
Pass a spec anywhere a base name is accepted.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { createCodec, encode } from 'bufferbase';
|
|
92
|
+
|
|
93
|
+
encode(Uint8Array.of(5), { alphabet: '01', algorithm: 'radix' }); // '101'
|
|
94
|
+
|
|
95
|
+
const lowerHex = createCodec({ alphabet: '0123456789abcdef', algorithm: 'block', pad: false });
|
|
96
|
+
lowerHex.encode(Uint8Array.of(0, 1)); // '0001'
|
|
97
|
+
|
|
98
|
+
createCodec('01'); // a bare string means a radix codec over that alphabet
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Crockford's Base32
|
|
102
|
+
|
|
103
|
+
Crockford's specification describes a notation for numbers rather than for byte
|
|
104
|
+
streams, so a radix conversion is the right reading of it. Decoding accepts
|
|
105
|
+
either case, reads `I` and `L` as `1` and `O` as `0`, and ignores the hyphens
|
|
106
|
+
that may be inserted for readability. Encoding emits only the alphabet.
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
decode('91jprv3f', 'base32crockford'); // Buffer('Hello')
|
|
110
|
+
decode('91JP-RV3F', 'base32crockford'); // the same
|
|
111
|
+
decode('9IJPRV3F', 'base32crockford'); // the same, reading I as 1
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`base32crockfordcheck` appends the check symbol, the value modulo 37 written
|
|
115
|
+
with the alphabet extended by `*~$=U`. Decoding verifies it, so a mistyped
|
|
116
|
+
character is caught rather than decoded into different bytes.
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
encode(Buffer.from('Hello'), 'base32crockfordcheck'); // '91JPRV3FG'
|
|
120
|
+
validate('91JPRV3XG', 'base32crockfordcheck'); // false
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Ascii85 variants
|
|
124
|
+
|
|
125
|
+
Several incompatible encodings share the Ascii85 algorithm and alphabet,
|
|
126
|
+
differing only in the shortcuts and framing they add. They are options rather
|
|
127
|
+
than separate codecs. The `ascii85` default is `zeroShortcut` alone, which
|
|
128
|
+
matches Python's `base64.a85encode`.
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { createCodec, Chars } from 'bufferbase';
|
|
132
|
+
|
|
133
|
+
const btoa = createCodec({
|
|
134
|
+
alphabet: Chars.Ascii85, algorithm: 'block85',
|
|
135
|
+
zeroShortcut: true, spaceShortcut: true, // ' ' -> 'y'
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const adobe = createCodec({
|
|
139
|
+
alphabet: Chars.Ascii85, algorithm: 'block85',
|
|
140
|
+
zeroShortcut: true, delimiters: true, // '<~ ... ~>'
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Canonical encodings
|
|
145
|
+
|
|
146
|
+
A trailing partial block leaves spare bits in the final character. RFC 4648
|
|
147
|
+
§3.5 requires them to be zero; input that sets them decodes to the same bytes
|
|
148
|
+
as the canonical form, so accepting it makes decoding non-injective.
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
decode('Zm8=', 'base64'); // Buffer('fo')
|
|
152
|
+
decode('Zm9=', 'base64'); // throws NonCanonicalError — also 'fo'
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
This is rejected by default. Pass `strict: false` to read data from a lenient
|
|
156
|
+
encoder.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
createCodec({ alphabet: Chars.Base64, algorithm: 'block', strict: false });
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The same check rejects lengths that cannot be a whole number of bytes
|
|
163
|
+
(`'Zm9vd'`), misplaced or excess padding, and Ascii85 groups above 2^32.
|
|
164
|
+
|
|
165
|
+
## API
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
encode(buffer, base) // string
|
|
169
|
+
decode(encoded, base, options?) // Buffer
|
|
170
|
+
convert(input, from, to) // string
|
|
171
|
+
validate(input, base) // boolean
|
|
172
|
+
createCodec(spec | alphabet) // ICodec
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
`base` is a name from the table above or a `CodecSpec`. Every spec accepts
|
|
176
|
+
`strict`, `caseInsensitive`, `aliases` and `ignore`:
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
type CodecSpec =
|
|
180
|
+
| { alphabet: string; algorithm: 'radix'; checkSymbols?: string }
|
|
181
|
+
| { alphabet: string; algorithm: 'block'; pad?: string | false }
|
|
182
|
+
| { alphabet: string; algorithm: 'block85';
|
|
183
|
+
zeroShortcut?: boolean; spaceShortcut?: boolean;
|
|
184
|
+
delimiters?: boolean; requireFullBlocks?: boolean };
|
|
185
|
+
```
|
|
26
186
|
|
|
187
|
+
### Errors
|
|
27
188
|
|
|
28
|
-
|
|
189
|
+
| Error | Thrown when |
|
|
190
|
+
|---|---|
|
|
191
|
+
| `InvalidCharacterError` | a character is not in the alphabet |
|
|
192
|
+
| `InvalidLengthError` | the length cannot encode a whole number of bytes |
|
|
193
|
+
| `NonCanonicalError` | spare bits are set and the codec is strict |
|
|
194
|
+
| `ValueRangeError` | a block85 group is 2^32 or above |
|
|
195
|
+
| `CheckSymbolError` | a check symbol does not match the value it follows |
|
|
196
|
+
| `BufferSizeError` | the result does not have the requested `size` |
|
|
197
|
+
| `UnknownBaseError` | the base name is not known |
|
|
198
|
+
| `InvalidCodecError` | the spec cannot be realised |
|
|
29
199
|
|
|
30
|
-
|
|
31
|
-
License
|
|
200
|
+
## License
|
|
32
201
|
|
|
33
|
-
|
|
202
|
+
ISC
|
|
@@ -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,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Bases = exports.Chars = void 0;
|
|
4
|
+
exports.resolveSpec = resolveSpec;
|
|
5
|
+
exports.isBaseName = isBaseName;
|
|
6
|
+
const errors_js_1 = require("./errors.js");
|
|
7
|
+
/**
|
|
8
|
+
* Character sets, ordered by value.
|
|
9
|
+
*
|
|
10
|
+
* A character set does not by itself describe an encoding — see `Bases` for
|
|
11
|
+
* the alphabet/algorithm pairs that do.
|
|
12
|
+
*/
|
|
13
|
+
exports.Chars = {
|
|
14
|
+
/** Base 10: 0-9 */
|
|
15
|
+
Decimal: '0123456789',
|
|
16
|
+
/** RFC 4648 Table 5 — Base16: 0-9A-F */
|
|
17
|
+
Base16: '0123456789ABCDEF',
|
|
18
|
+
/** RFC 4648 Table 3 — Base32: A-Z2-7 */
|
|
19
|
+
Base32: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
|
|
20
|
+
/** RFC 4648 Table 4 — Base32 with extended hex alphabet: 0-9A-V */
|
|
21
|
+
Base32Hex: '0123456789ABCDEFGHIJKLMNOPQRSTUV',
|
|
22
|
+
/** Crockford's Base32: 0-9A-HJKMNP-TV-Z (no I, L, O, U) */
|
|
23
|
+
Base32Crockford: '0123456789ABCDEFGHJKMNPQRSTVWXYZ',
|
|
24
|
+
/** Alphanumeric: 0-9A-Z */
|
|
25
|
+
Base36: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
26
|
+
/** Letters only: A-Za-z */
|
|
27
|
+
Base52: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
|
28
|
+
/** Bitcoin alphabet: 1-9A-HJ-NP-Za-km-z (no 0, O, I, l) */
|
|
29
|
+
Base58: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz',
|
|
30
|
+
/** RFC 4648 Table 1 — Base64: A-Za-z0-9+/ */
|
|
31
|
+
Base64: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
|
|
32
|
+
/** RFC 4648 Table 2 — URL-safe Base64: A-Za-z0-9-_ */
|
|
33
|
+
Base64Url: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
|
|
34
|
+
/** XML token Base64: A-Za-z0-9._ */
|
|
35
|
+
Base64Xml: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._',
|
|
36
|
+
/** XML name Base64: A-Za-z0-9_: */
|
|
37
|
+
Base64XmlName: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_:',
|
|
38
|
+
/** Ascii85: the 85 printable characters from `!` (0x21) to `u` (0x75) */
|
|
39
|
+
Ascii85: '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstu',
|
|
40
|
+
/** ZeroMQ Z85 (RFC 32): avoids the quote and backslash characters */
|
|
41
|
+
Z85: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#',
|
|
42
|
+
/** The five symbols Crockford's Base32 adds for its check symbol, giving a modulus of 37 */
|
|
43
|
+
CrockfordCheck: '*~$=U',
|
|
44
|
+
};
|
|
45
|
+
/** The characters Crockford's Base32 reads as the digit they resemble. */
|
|
46
|
+
const CROCKFORD_ALIASES = { I: '1', L: '1', O: '0' };
|
|
47
|
+
/**
|
|
48
|
+
* The encodings this package knows by name.
|
|
49
|
+
*
|
|
50
|
+
* Each entry pairs an alphabet with the algorithm that reads it, because the
|
|
51
|
+
* alphabet alone is ambiguous: `base64` and `radix64` share Table 1 but
|
|
52
|
+
* produce different strings for the same bytes.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { encode, Bases } from 'bufferbase';
|
|
57
|
+
*
|
|
58
|
+
* encode(Buffer.from('fo'), 'base64'); // 'Zm8=' — RFC 4648
|
|
59
|
+
* encode(Buffer.from('fo'), 'radix64'); // 'GZv' — radix conversion
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
exports.Bases = {
|
|
63
|
+
// Radix conversion. No external standard fixes these, so nothing here can
|
|
64
|
+
// disagree with one.
|
|
65
|
+
decimal: { alphabet: exports.Chars.Decimal, algorithm: 'radix' },
|
|
66
|
+
base36: { alphabet: exports.Chars.Base36, algorithm: 'radix', caseInsensitive: true },
|
|
67
|
+
base52: { alphabet: exports.Chars.Base52, algorithm: 'radix' },
|
|
68
|
+
base58: { alphabet: exports.Chars.Base58, algorithm: 'radix' },
|
|
69
|
+
/**
|
|
70
|
+
* Crockford's Base32, which specifies a notation for numbers rather than for
|
|
71
|
+
* byte streams, so a radix conversion is the right reading of it.
|
|
72
|
+
*
|
|
73
|
+
* Decoding accepts either case, reads `I` and `L` as `1` and `O` as `0`, and
|
|
74
|
+
* ignores hyphens.
|
|
75
|
+
*/
|
|
76
|
+
base32crockford: {
|
|
77
|
+
alphabet: exports.Chars.Base32Crockford,
|
|
78
|
+
algorithm: 'radix',
|
|
79
|
+
caseInsensitive: true,
|
|
80
|
+
aliases: CROCKFORD_ALIASES,
|
|
81
|
+
ignore: '-',
|
|
82
|
+
},
|
|
83
|
+
/** Crockford's Base32 carrying its trailing check symbol. */
|
|
84
|
+
base32crockfordcheck: {
|
|
85
|
+
alphabet: exports.Chars.Base32Crockford,
|
|
86
|
+
algorithm: 'radix',
|
|
87
|
+
caseInsensitive: true,
|
|
88
|
+
aliases: CROCKFORD_ALIASES,
|
|
89
|
+
ignore: '-',
|
|
90
|
+
checkSymbols: exports.Chars.CrockfordCheck,
|
|
91
|
+
},
|
|
92
|
+
// Bit-block encoding, RFC 4648.
|
|
93
|
+
base16: { alphabet: exports.Chars.Base16, algorithm: 'block', pad: false, caseInsensitive: true },
|
|
94
|
+
hex: { alphabet: exports.Chars.Base16, algorithm: 'block', pad: false, caseInsensitive: true },
|
|
95
|
+
base32: { alphabet: exports.Chars.Base32, algorithm: 'block', caseInsensitive: true },
|
|
96
|
+
base32hex: { alphabet: exports.Chars.Base32Hex, algorithm: 'block', caseInsensitive: true },
|
|
97
|
+
base64: { alphabet: exports.Chars.Base64, algorithm: 'block' },
|
|
98
|
+
/** Unpadded, as used by JWT and other URL-facing formats. */
|
|
99
|
+
base64url: { alphabet: exports.Chars.Base64Url, algorithm: 'block', pad: false },
|
|
100
|
+
base64xml: { alphabet: exports.Chars.Base64Xml, algorithm: 'block', pad: false },
|
|
101
|
+
base64xmlname: { alphabet: exports.Chars.Base64XmlName, algorithm: 'block', pad: false },
|
|
102
|
+
// Four bytes to five characters.
|
|
103
|
+
/** Ascii85 with the zero-block shortcut, matching Python's `a85encode`. */
|
|
104
|
+
ascii85: { alphabet: exports.Chars.Ascii85, algorithm: 'block85', zeroShortcut: true },
|
|
105
|
+
/** ZeroMQ Z85, which has no padding and so encodes whole blocks only. */
|
|
106
|
+
z85: { alphabet: exports.Chars.Z85, algorithm: 'block85', requireFullBlocks: true },
|
|
107
|
+
// Radix conversion over the RFC alphabets.
|
|
108
|
+
radix16: { alphabet: exports.Chars.Base16, algorithm: 'radix' },
|
|
109
|
+
radix32: { alphabet: exports.Chars.Base32, algorithm: 'radix' },
|
|
110
|
+
radix64: { alphabet: exports.Chars.Base64, algorithm: 'radix' },
|
|
111
|
+
radix64url: { alphabet: exports.Chars.Base64Url, algorithm: 'radix' },
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Resolves a base name to its codec spec, and passes a spec through unchanged.
|
|
115
|
+
*
|
|
116
|
+
* @throws {UnknownBaseError} If the name is not one of `Bases`
|
|
117
|
+
*/
|
|
118
|
+
function resolveSpec(base) {
|
|
119
|
+
if (typeof base !== 'string') {
|
|
120
|
+
return base;
|
|
121
|
+
}
|
|
122
|
+
const spec = exports.Bases[base.toLowerCase()];
|
|
123
|
+
if (spec === undefined) {
|
|
124
|
+
throw new errors_js_1.UnknownBaseError(base);
|
|
125
|
+
}
|
|
126
|
+
return spec;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Checks whether a string names one of the encodings in `Bases`.
|
|
130
|
+
*/
|
|
131
|
+
function isBaseName(value) {
|
|
132
|
+
return value.toLowerCase() in exports.Bases;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=bases.js.map
|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AC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,KAAa;IACtC,OAAO,KAAK,CAAC,WAAW,EAAE,IAAI,aAAK,CAAC;AACtC,CAAC"}
|
package/dist/cjs/bufferbase.d.ts
CHANGED
|
@@ -1,60 +1,37 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Base52: string;
|
|
12
|
-
Base58: string;
|
|
13
|
-
Base64_STD: string;
|
|
14
|
-
Base64_URL_SAFE: string;
|
|
15
|
-
Base64_XML_NMTOKEN: string;
|
|
16
|
-
Base64_XML_NAME: string;
|
|
17
|
-
Ascii85: string;
|
|
18
|
-
Base85: string;
|
|
19
|
-
Z85: string;
|
|
20
|
-
};
|
|
21
|
-
export declare class InvalidCharacterError extends Error {
|
|
22
|
-
message: string;
|
|
23
|
-
}
|
|
24
|
-
export declare class BufferSizeError extends Error {
|
|
25
|
-
message: string;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Encodes and decodes buffers to and from a base.
|
|
2
|
+
* @deprecated Use the current API instead:
|
|
3
|
+
* - `encode(buffer, 'base58')` or `Codecs.base58.encode(buffer)`
|
|
4
|
+
* - `decode(encoded, 'base58')` or `Codecs.base58.decode(encoded)`
|
|
5
|
+
* - `convert(input, 'base58', 'base64')` or `Codecs.base58.convertTo(...)`
|
|
6
|
+
* - `validate(input, 'base58')` or `Codecs.base58.validate(input)`
|
|
7
|
+
*
|
|
8
|
+
* These classes take a bare alphabet, which always meant a radix conversion,
|
|
9
|
+
* so they keep behaving exactly as they did.
|
|
29
10
|
*/
|
|
11
|
+
import type { Buffer } from 'node:buffer';
|
|
12
|
+
import type { BufferLike } from './types.js';
|
|
13
|
+
/** @deprecated Import `Chars` from the package root. */
|
|
14
|
+
export { Chars } from './bases.js';
|
|
15
|
+
/** @deprecated Import these from the package root. */
|
|
16
|
+
export { BufferSizeError, InvalidCharacterError } from './errors.js';
|
|
17
|
+
/** @deprecated Use `createCodec(alphabet)`. */
|
|
30
18
|
export declare class BufferEncoder {
|
|
31
|
-
private
|
|
19
|
+
private readonly codec;
|
|
32
20
|
constructor(baseChars: string);
|
|
33
|
-
|
|
34
|
-
* Encodes a buffer to a string.
|
|
35
|
-
*/
|
|
36
|
-
encode(buffer: Buffer): string;
|
|
37
|
-
/**
|
|
38
|
-
* Decodes a string to a buffer.
|
|
39
|
-
*/
|
|
21
|
+
encode(buffer: BufferLike): string;
|
|
40
22
|
decode(encoded: string, bufferSize?: number): Buffer;
|
|
41
23
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Creates a converter function that can convert between two bases.
|
|
44
|
-
*/
|
|
24
|
+
/** @deprecated Use `convert()` or `codec.convertTo()`. */
|
|
45
25
|
export declare class Converter {
|
|
46
|
-
decoder: BufferEncoder;
|
|
47
|
-
encoder: BufferEncoder;
|
|
26
|
+
readonly decoder: BufferEncoder;
|
|
27
|
+
readonly encoder: BufferEncoder;
|
|
48
28
|
constructor(inputBase: string, outputBase: string);
|
|
49
|
-
/**
|
|
50
|
-
* Converts a string from the input base to the output base.
|
|
51
|
-
*/
|
|
52
29
|
convert(input: string): string;
|
|
53
30
|
}
|
|
31
|
+
/** @deprecated Use `validate()` or `codec.validate()`. */
|
|
54
32
|
export declare class Validator {
|
|
55
|
-
|
|
33
|
+
private readonly codec;
|
|
56
34
|
constructor(inputBase: string);
|
|
57
35
|
validate(input: string): boolean;
|
|
58
36
|
}
|
|
59
|
-
export declare const validate: (input: string, base: string) => boolean;
|
|
60
37
|
//# sourceMappingURL=bufferbase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bufferbase.d.ts","sourceRoot":"","sources":["../../src/bufferbase.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bufferbase.d.ts","sourceRoot":"","sources":["../../src/bufferbase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C,wDAAwD;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,sDAAsD;AACtD,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAErE,+CAA+C;AAC/C,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;gBAEvB,SAAS,EAAE,MAAM;IAI7B,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM;IAIlC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM;CAGrD;AAED,0DAA0D;AAC1D,qBAAa,SAAS;IACpB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;gBAEpB,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAKjD,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAG/B;AAED,0DAA0D;AAC1D,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;gBAEvB,SAAS,EAAE,MAAM;IAI7B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAGjC"}
|