bufferbase 1.2.3 → 2.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 +99 -18
- package/dist/cjs/bases.d.ts +82 -0
- package/dist/cjs/bases.d.ts.map +1 -0
- package/dist/cjs/bases.js +121 -0
- package/dist/cjs/bases.js.map +1 -0
- package/dist/cjs/bufferbase.d.ts +43 -0
- package/dist/cjs/bufferbase.d.ts.map +1 -0
- package/dist/cjs/bufferbase.js +66 -0
- package/dist/cjs/bufferbase.js.map +1 -0
- package/dist/cjs/codec.d.ts +124 -0
- package/dist/cjs/codec.d.ts.map +1 -0
- package/dist/cjs/codec.js +247 -0
- package/dist/cjs/codec.js.map +1 -0
- package/dist/cjs/codecs.d.ts +71 -0
- package/dist/cjs/codecs.d.ts.map +1 -0
- package/dist/cjs/codecs.js +92 -0
- package/dist/cjs/codecs.js.map +1 -0
- package/dist/cjs/errors.d.ts +76 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +92 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/{example.d.ts.map → cjs/example.d.ts.map} +1 -1
- package/dist/cjs/example.js +32 -0
- package/dist/cjs/example.js.map +1 -0
- package/dist/cjs/functions.d.ts +62 -0
- package/dist/cjs/functions.d.ts.map +1 -0
- package/dist/cjs/functions.js +93 -0
- package/dist/cjs/functions.js.map +1 -0
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +32 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +50 -0
- package/dist/cjs/types.d.ts +107 -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 +82 -0
- package/dist/esm/bases.d.ts.map +1 -0
- package/dist/esm/bases.js +116 -0
- package/dist/esm/bases.js.map +1 -0
- package/dist/esm/bufferbase.d.ts +43 -0
- package/dist/esm/bufferbase.d.ts.map +1 -0
- package/dist/esm/bufferbase.js +59 -0
- package/dist/esm/bufferbase.js.map +1 -0
- package/dist/esm/codec.d.ts +124 -0
- package/dist/esm/codec.d.ts.map +1 -0
- package/dist/esm/codec.js +242 -0
- package/dist/esm/codec.js.map +1 -0
- package/dist/esm/codecs.d.ts +71 -0
- package/dist/esm/codecs.d.ts.map +1 -0
- package/dist/esm/codecs.js +89 -0
- package/dist/esm/codecs.js.map +1 -0
- package/dist/esm/errors.d.ts +76 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +86 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/example.d.ts +2 -0
- package/dist/esm/example.d.ts.map +1 -0
- package/dist/esm/example.js +30 -0
- package/dist/esm/example.js.map +1 -0
- package/dist/esm/functions.d.ts +62 -0
- package/dist/esm/functions.d.ts.map +1 -0
- package/dist/esm/functions.js +87 -0
- package/dist/esm/functions.js.map +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +50 -0
- package/dist/esm/types.d.ts +107 -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 +26 -11
- package/src/bases.ts +120 -0
- package/src/bufferbase.test.ts +44 -27
- package/src/bufferbase.ts +31 -106
- package/src/codec.test.ts +320 -0
- package/src/codec.ts +266 -0
- package/src/codecs.ts +118 -0
- package/src/errors.ts +87 -0
- package/src/example.ts +20 -30
- package/src/functions.ts +93 -0
- package/src/index.ts +21 -8
- package/src/types.ts +129 -0
- package/dist/bufferbase.d.ts +0 -60
- package/dist/bufferbase.d.ts.map +0 -1
- package/dist/bufferbase.js +0 -141
- package/dist/bufferbase.js.map +0 -1
- package/dist/example.js +0 -37
- package/dist/example.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/sample.d.ts +0 -2
- package/dist/sample.d.ts.map +0 -1
- package/dist/sample.js +0 -37
- package/dist/sample.js.map +0 -1
- /package/dist/{example.d.ts → cjs/example.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,33 +1,114 @@
|
|
|
1
1
|
# bufferbase
|
|
2
2
|
|
|
3
|
-
Buffer-to-BaseN
|
|
4
|
-
|
|
5
|
-
bufferbase is a Node.js library that provides straightforward encoding and decoding of buffer objects into various BaseN formats. It's designed to be simple, efficient, and flexible for different application needs.
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- Supports multiple base encoding formats.
|
|
10
|
-
- Optimized for Node.js buffer handling.
|
|
11
|
-
- Intuitive API for easy integration.
|
|
12
|
-
- Suitable for various data types.
|
|
13
|
-
- Consistent and reliable performance.
|
|
3
|
+
Buffer-to-BaseN encoding and decoding for Node.js.
|
|
14
4
|
|
|
15
5
|
## Installation
|
|
16
6
|
|
|
17
|
-
Install bufferbase using npm:
|
|
18
|
-
|
|
19
7
|
```bash
|
|
20
8
|
npm install bufferbase
|
|
21
9
|
```
|
|
22
10
|
|
|
23
11
|
## Usage
|
|
24
12
|
|
|
25
|
-
|
|
13
|
+
### Simple Function API
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { encode, decode, convert, validate } from 'bufferbase';
|
|
17
|
+
|
|
18
|
+
// Encode buffer to base58
|
|
19
|
+
const encoded = encode(Buffer.from('Hello'), 'base58');
|
|
20
|
+
|
|
21
|
+
// Decode base58 string to buffer
|
|
22
|
+
const decoded = decode(encoded, 'base58');
|
|
23
|
+
|
|
24
|
+
// Decode with fixed size (pads with leading zeros)
|
|
25
|
+
const fixed = decode(encoded, 'base58', { size: 32 });
|
|
26
|
+
|
|
27
|
+
// Convert between bases
|
|
28
|
+
const base64 = convert(encoded, 'base58', 'base64url');
|
|
29
|
+
|
|
30
|
+
// Validate string
|
|
31
|
+
validate('9Ajdvz', 'base58'); // true
|
|
32
|
+
validate('0Ajdvz', 'base58'); // false ('0' not in base58)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Pre-defined Codecs
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { Codecs } from 'bufferbase';
|
|
39
|
+
|
|
40
|
+
const encoded = Codecs.base58.encode(Buffer.from('Hello'));
|
|
41
|
+
const decoded = Codecs.base58.decode(encoded);
|
|
42
|
+
|
|
43
|
+
// Convert between codecs
|
|
44
|
+
const base64 = Codecs.base58.convertTo(Codecs.base64url, encoded);
|
|
45
|
+
|
|
46
|
+
// Validate
|
|
47
|
+
Codecs.base58.validate('9Ajdvz'); // true
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Custom Character Set
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { createCodec } from 'bufferbase';
|
|
54
|
+
|
|
55
|
+
const binary = createCodec('01');
|
|
56
|
+
binary.encode(Buffer.from([5])); // '101'
|
|
57
|
+
binary.decode('101'); // Buffer([5])
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Supported Encodings
|
|
61
|
+
|
|
62
|
+
| Name | Characters |
|
|
63
|
+
|------|------------|
|
|
64
|
+
| `decimal` | 0-9 |
|
|
65
|
+
| `base16` / `hex` | 0-9A-F |
|
|
66
|
+
| `base32` | A-Z2-7 |
|
|
67
|
+
| `base32crockford` | 0-9A-HJKMNP-TV-Z |
|
|
68
|
+
| `base36` | 0-9A-Z |
|
|
69
|
+
| `base52` | A-Za-z |
|
|
70
|
+
| `base58` | Bitcoin alphabet (no 0OIl) |
|
|
71
|
+
| `base64` | A-Za-z0-9+/ |
|
|
72
|
+
| `base64url` | A-Za-z0-9-_ |
|
|
73
|
+
| `base64xml` | A-Za-z0-9._ |
|
|
74
|
+
| `base64xmlname` | A-Za-z0-9_: |
|
|
75
|
+
| `ascii85` | ASCII85 |
|
|
76
|
+
| `base85` | Base85 |
|
|
77
|
+
| `z85` | ZeroMQ Z85 |
|
|
78
|
+
|
|
79
|
+
## API
|
|
80
|
+
|
|
81
|
+
### Functions
|
|
82
|
+
|
|
83
|
+
- `encode(buffer, base)` - Encode buffer to string
|
|
84
|
+
- `decode(encoded, base, options?)` - Decode string to buffer
|
|
85
|
+
- `convert(input, from, to)` - Convert between bases
|
|
86
|
+
- `validate(input, base)` - Check if string is valid for base
|
|
87
|
+
- `createCodec(chars)` - Create codec with custom character set
|
|
88
|
+
|
|
89
|
+
### Codecs Object
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
Codecs.base58.encode(buffer)
|
|
93
|
+
Codecs.base58.decode(encoded, options?)
|
|
94
|
+
Codecs.base58.validate(input)
|
|
95
|
+
Codecs.base58.convertTo(targetCodec, input)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Options
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
interface DecodeOptions {
|
|
102
|
+
size?: number; // Expected buffer size (pads with zeros if smaller)
|
|
103
|
+
}
|
|
104
|
+
```
|
|
26
105
|
|
|
106
|
+
### Errors
|
|
27
107
|
|
|
28
|
-
|
|
108
|
+
- `InvalidCharacterError` - Invalid character in decode input
|
|
109
|
+
- `BufferSizeError` - Decoded buffer exceeds specified size
|
|
110
|
+
- `UnknownBaseError` - Unknown base name
|
|
29
111
|
|
|
30
|
-
|
|
31
|
-
License
|
|
112
|
+
## License
|
|
32
113
|
|
|
33
|
-
|
|
114
|
+
ISC
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { BaseName } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Character sets for common base encodings.
|
|
4
|
+
*
|
|
5
|
+
* Use these with `createCodec()` or the deprecated `BufferEncoder` class
|
|
6
|
+
* when you need direct access to character sets.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { Chars, createCodec } from 'bufferbase';
|
|
11
|
+
*
|
|
12
|
+
* const codec = createCodec(Chars.Base58);
|
|
13
|
+
* const encoded = codec.encode(Buffer.from('Hello'));
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const Chars: {
|
|
17
|
+
/** Base 10: 0-9 */
|
|
18
|
+
readonly Decimal: "0123456789";
|
|
19
|
+
/** Hexadecimal: 0-9A-F */
|
|
20
|
+
readonly Base16: "0123456789ABCDEF";
|
|
21
|
+
/** RFC 4648 Base32: A-Z2-7 */
|
|
22
|
+
readonly Base32: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
23
|
+
/** Crockford's Base32: 0-9A-HJKMNP-TV-Z (no I, L, O, U) */
|
|
24
|
+
readonly Base32Crockford: "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
25
|
+
/** Alphanumeric: 0-9A-Z */
|
|
26
|
+
readonly Base36: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
27
|
+
/** Letters only: A-Za-z */
|
|
28
|
+
readonly Base52: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
29
|
+
/** Bitcoin alphabet: 1-9A-HJ-NP-Za-km-z (no 0, O, I, l) */
|
|
30
|
+
readonly Base58: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
31
|
+
/** Standard Base64: A-Za-z0-9+/ */
|
|
32
|
+
readonly Base64: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
33
|
+
/** URL-safe Base64: A-Za-z0-9-_ */
|
|
34
|
+
readonly Base64Url: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
35
|
+
/** XML token Base64: A-Za-z0-9._ */
|
|
36
|
+
readonly Base64Xml: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
|
|
37
|
+
/** XML name Base64: A-Za-z0-9_: */
|
|
38
|
+
readonly Base64XmlName: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_:";
|
|
39
|
+
/** ASCII85 encoding */
|
|
40
|
+
readonly Ascii85: "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstu";
|
|
41
|
+
/** Base85 encoding */
|
|
42
|
+
readonly Base85: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&()*+-;<=>?@^_`{|}~";
|
|
43
|
+
/** ZeroMQ Z85 encoding */
|
|
44
|
+
readonly Z85: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#";
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Resolves a base name or character set string to a character set.
|
|
48
|
+
*
|
|
49
|
+
* This function is used internally by the function API to convert
|
|
50
|
+
* base names (like `'base58'`) to their character sets.
|
|
51
|
+
*
|
|
52
|
+
* @param base - Base name (e.g., `'base58'`) or custom character set string
|
|
53
|
+
* @returns The character set string
|
|
54
|
+
* @throws {UnknownBaseError} If base name is not recognized and string length <= 15
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { resolveChars } from 'bufferbase';
|
|
59
|
+
*
|
|
60
|
+
* resolveChars('base58'); // Returns Bitcoin alphabet
|
|
61
|
+
* resolveChars('0123456789ABCDEF'); // Returns the string as-is (custom charset)
|
|
62
|
+
* resolveChars('invalid'); // Throws UnknownBaseError
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function resolveChars(base: BaseName | string): string;
|
|
66
|
+
/**
|
|
67
|
+
* Checks if a string is a valid base name.
|
|
68
|
+
*
|
|
69
|
+
* @param value - The string to check
|
|
70
|
+
* @returns `true` if the value is a valid `BaseName`, `false` otherwise
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* import { isBaseName } from 'bufferbase';
|
|
75
|
+
*
|
|
76
|
+
* isBaseName('base58'); // true
|
|
77
|
+
* isBaseName('BASE58'); // true (case-insensitive)
|
|
78
|
+
* isBaseName('unknown'); // false
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function isBaseName(value: string): value is BaseName;
|
|
82
|
+
//# 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,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK;IAChB,mBAAmB;;IAEnB,0BAA0B;;IAE1B,8BAA8B;;IAE9B,2DAA2D;;IAE3D,2BAA2B;;IAE3B,2BAA2B;;IAE3B,2DAA2D;;IAE3D,mCAAmC;;IAEnC,mCAAmC;;IAEnC,oCAAoC;;IAEpC,mCAAmC;;IAEnC,uBAAuB;;IAEvB,sBAAsB;;IAEtB,0BAA0B;;CAElB,CAAC;AAwBX;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAW5D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,QAAQ,CAE3D"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Chars = void 0;
|
|
4
|
+
exports.resolveChars = resolveChars;
|
|
5
|
+
exports.isBaseName = isBaseName;
|
|
6
|
+
const errors_js_1 = require("./errors.js");
|
|
7
|
+
/**
|
|
8
|
+
* Character sets for common base encodings.
|
|
9
|
+
*
|
|
10
|
+
* Use these with `createCodec()` or the deprecated `BufferEncoder` class
|
|
11
|
+
* when you need direct access to character sets.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { Chars, createCodec } from 'bufferbase';
|
|
16
|
+
*
|
|
17
|
+
* const codec = createCodec(Chars.Base58);
|
|
18
|
+
* const encoded = codec.encode(Buffer.from('Hello'));
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
exports.Chars = {
|
|
22
|
+
/** Base 10: 0-9 */
|
|
23
|
+
Decimal: '0123456789',
|
|
24
|
+
/** Hexadecimal: 0-9A-F */
|
|
25
|
+
Base16: '0123456789ABCDEF',
|
|
26
|
+
/** RFC 4648 Base32: A-Z2-7 */
|
|
27
|
+
Base32: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
|
|
28
|
+
/** Crockford's Base32: 0-9A-HJKMNP-TV-Z (no I, L, O, U) */
|
|
29
|
+
Base32Crockford: '0123456789ABCDEFGHJKMNPQRSTVWXYZ',
|
|
30
|
+
/** Alphanumeric: 0-9A-Z */
|
|
31
|
+
Base36: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
32
|
+
/** Letters only: A-Za-z */
|
|
33
|
+
Base52: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
|
34
|
+
/** Bitcoin alphabet: 1-9A-HJ-NP-Za-km-z (no 0, O, I, l) */
|
|
35
|
+
Base58: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz',
|
|
36
|
+
/** Standard Base64: A-Za-z0-9+/ */
|
|
37
|
+
Base64: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
|
|
38
|
+
/** URL-safe Base64: A-Za-z0-9-_ */
|
|
39
|
+
Base64Url: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
|
|
40
|
+
/** XML token Base64: A-Za-z0-9._ */
|
|
41
|
+
Base64Xml: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._',
|
|
42
|
+
/** XML name Base64: A-Za-z0-9_: */
|
|
43
|
+
Base64XmlName: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_:',
|
|
44
|
+
/** ASCII85 encoding */
|
|
45
|
+
Ascii85: '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstu',
|
|
46
|
+
/** Base85 encoding */
|
|
47
|
+
Base85: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&()*+-;<=>?@^_`{|}~',
|
|
48
|
+
/** ZeroMQ Z85 encoding */
|
|
49
|
+
Z85: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#',
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Internal mapping from base names to character sets.
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
const baseNameToChars = {
|
|
56
|
+
decimal: exports.Chars.Decimal,
|
|
57
|
+
base16: exports.Chars.Base16,
|
|
58
|
+
hex: exports.Chars.Base16,
|
|
59
|
+
base32: exports.Chars.Base32,
|
|
60
|
+
base32crockford: exports.Chars.Base32Crockford,
|
|
61
|
+
base36: exports.Chars.Base36,
|
|
62
|
+
base52: exports.Chars.Base52,
|
|
63
|
+
base58: exports.Chars.Base58,
|
|
64
|
+
base64: exports.Chars.Base64,
|
|
65
|
+
base64url: exports.Chars.Base64Url,
|
|
66
|
+
base64xml: exports.Chars.Base64Xml,
|
|
67
|
+
base64xmlname: exports.Chars.Base64XmlName,
|
|
68
|
+
ascii85: exports.Chars.Ascii85,
|
|
69
|
+
base85: exports.Chars.Base85,
|
|
70
|
+
z85: exports.Chars.Z85,
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Resolves a base name or character set string to a character set.
|
|
74
|
+
*
|
|
75
|
+
* This function is used internally by the function API to convert
|
|
76
|
+
* base names (like `'base58'`) to their character sets.
|
|
77
|
+
*
|
|
78
|
+
* @param base - Base name (e.g., `'base58'`) or custom character set string
|
|
79
|
+
* @returns The character set string
|
|
80
|
+
* @throws {UnknownBaseError} If base name is not recognized and string length <= 15
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* import { resolveChars } from 'bufferbase';
|
|
85
|
+
*
|
|
86
|
+
* resolveChars('base58'); // Returns Bitcoin alphabet
|
|
87
|
+
* resolveChars('0123456789ABCDEF'); // Returns the string as-is (custom charset)
|
|
88
|
+
* resolveChars('invalid'); // Throws UnknownBaseError
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
function resolveChars(base) {
|
|
92
|
+
const normalized = base.toLowerCase();
|
|
93
|
+
if (normalized in baseNameToChars) {
|
|
94
|
+
return baseNameToChars[normalized];
|
|
95
|
+
}
|
|
96
|
+
// If not a known base name, treat as custom character set
|
|
97
|
+
// (must be longer than 15 chars to distinguish from typos)
|
|
98
|
+
if (base.length > 15) {
|
|
99
|
+
return base;
|
|
100
|
+
}
|
|
101
|
+
throw new errors_js_1.UnknownBaseError(base);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Checks if a string is a valid base name.
|
|
105
|
+
*
|
|
106
|
+
* @param value - The string to check
|
|
107
|
+
* @returns `true` if the value is a valid `BaseName`, `false` otherwise
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* import { isBaseName } from 'bufferbase';
|
|
112
|
+
*
|
|
113
|
+
* isBaseName('base58'); // true
|
|
114
|
+
* isBaseName('BASE58'); // true (case-insensitive)
|
|
115
|
+
* isBaseName('unknown'); // false
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
function isBaseName(value) {
|
|
119
|
+
return value.toLowerCase() in baseNameToChars;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=bases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bases.js","sourceRoot":"","sources":["../../src/bases.ts"],"names":[],"mappings":";;;AAyFA,oCAWC;AAiBD,gCAEC;AAtHD,2CAA+C;AAE/C;;;;;;;;;;;;;GAaG;AACU,QAAA,KAAK,GAAG;IACnB,mBAAmB;IACnB,OAAO,EAAE,YAAY;IACrB,0BAA0B;IAC1B,MAAM,EAAE,kBAAkB;IAC1B,8BAA8B;IAC9B,MAAM,EAAE,kCAAkC;IAC1C,2DAA2D;IAC3D,eAAe,EAAE,kCAAkC;IACnD,2BAA2B;IAC3B,MAAM,EAAE,sCAAsC;IAC9C,2BAA2B;IAC3B,MAAM,EAAE,sDAAsD;IAC9D,2DAA2D;IAC3D,MAAM,EAAE,4DAA4D;IACpE,mCAAmC;IACnC,MAAM,EAAE,kEAAkE;IAC1E,mCAAmC;IACnC,SAAS,EAAE,kEAAkE;IAC7E,oCAAoC;IACpC,SAAS,EAAE,kEAAkE;IAC7E,mCAAmC;IACnC,aAAa,EAAE,kEAAkE;IACjF,uBAAuB;IACvB,OAAO,EAAE,uFAAuF;IAChG,sBAAsB;IACtB,MAAM,EAAE,uFAAuF;IAC/F,0BAA0B;IAC1B,GAAG,EAAE,uFAAuF;CACpF,CAAC;AAEX;;;GAGG;AACH,MAAM,eAAe,GAA6B;IAChD,OAAO,EAAE,aAAK,CAAC,OAAO;IACtB,MAAM,EAAE,aAAK,CAAC,MAAM;IACpB,GAAG,EAAE,aAAK,CAAC,MAAM;IACjB,MAAM,EAAE,aAAK,CAAC,MAAM;IACpB,eAAe,EAAE,aAAK,CAAC,eAAe;IACtC,MAAM,EAAE,aAAK,CAAC,MAAM;IACpB,MAAM,EAAE,aAAK,CAAC,MAAM;IACpB,MAAM,EAAE,aAAK,CAAC,MAAM;IACpB,MAAM,EAAE,aAAK,CAAC,MAAM;IACpB,SAAS,EAAE,aAAK,CAAC,SAAS;IAC1B,SAAS,EAAE,aAAK,CAAC,SAAS;IAC1B,aAAa,EAAE,aAAK,CAAC,aAAa;IAClC,OAAO,EAAE,aAAK,CAAC,OAAO;IACtB,MAAM,EAAE,aAAK,CAAC,MAAM;IACpB,GAAG,EAAE,aAAK,CAAC,GAAG;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,YAAY,CAAC,IAAuB;IAClD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAc,CAAC;IAClD,IAAI,UAAU,IAAI,eAAe,EAAE,CAAC;QAClC,OAAO,eAAe,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IACD,0DAA0D;IAC1D,2DAA2D;IAC3D,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,IAAI,4BAAgB,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,UAAU,CAAC,KAAa;IACtC,OAAO,KAAK,CAAC,WAAW,EAAE,IAAI,eAAe,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Use the new API instead:
|
|
3
|
+
* - `encode(buffer, 'base58')` or `base58.encode(buffer)`
|
|
4
|
+
* - `decode(encoded, 'base58')` or `base58.decode(encoded)`
|
|
5
|
+
* - `convert(input, 'base58', 'base64')` or `base58.convertTo(base64, input)`
|
|
6
|
+
* - `validate(input, 'base58')` or `base58.validate(input)`
|
|
7
|
+
*/
|
|
8
|
+
import { Buffer } from 'node:buffer';
|
|
9
|
+
import { InvalidCharacterError, BufferSizeError } from './errors.js';
|
|
10
|
+
export { Chars } from './bases.js';
|
|
11
|
+
export { InvalidCharacterError, BufferSizeError };
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use `Codec` or `createCodec()` instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare class BufferEncoder {
|
|
16
|
+
private baseChars;
|
|
17
|
+
private codec;
|
|
18
|
+
constructor(baseChars: string);
|
|
19
|
+
encode(buffer: Buffer): string;
|
|
20
|
+
decode(encoded: string, bufferSize?: number): Buffer;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Use `convert()` function or `codec.convertTo()` instead.
|
|
24
|
+
*/
|
|
25
|
+
export declare class Converter {
|
|
26
|
+
decoder: BufferEncoder;
|
|
27
|
+
encoder: BufferEncoder;
|
|
28
|
+
constructor(inputBase: string, outputBase: string);
|
|
29
|
+
convert(input: string): string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use `validate()` function or `codec.validate()` instead.
|
|
33
|
+
*/
|
|
34
|
+
export declare class Validator {
|
|
35
|
+
private codec;
|
|
36
|
+
constructor(inputBase: string);
|
|
37
|
+
validate(input: string): boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use `validate()` from the main module instead.
|
|
41
|
+
*/
|
|
42
|
+
export declare const validate: (input: string, base: string) => boolean;
|
|
43
|
+
//# sourceMappingURL=bufferbase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bufferbase.d.ts","sourceRoot":"","sources":["../../src/bufferbase.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGrE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,CAAC;AAElD;;GAEG;AACH,qBAAa,aAAa;IAGZ,OAAO,CAAC,SAAS;IAF7B,OAAO,CAAC,KAAK,CAAQ;gBAED,SAAS,EAAE,MAAM;IAIrC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAI9B,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM;CAGrD;AAED;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,aAAa,CAAC;gBAEX,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAKjD,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAG/B;AAED;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAAQ;gBAET,SAAS,EAAE,MAAM;IAI7B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAGjC;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,EAAE,MAAM,MAAM,KAAG,OAEtD,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use the new API instead:
|
|
4
|
+
* - `encode(buffer, 'base58')` or `base58.encode(buffer)`
|
|
5
|
+
* - `decode(encoded, 'base58')` or `base58.decode(encoded)`
|
|
6
|
+
* - `convert(input, 'base58', 'base64')` or `base58.convertTo(base64, input)`
|
|
7
|
+
* - `validate(input, 'base58')` or `base58.validate(input)`
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.validate = exports.Validator = exports.Converter = exports.BufferEncoder = exports.BufferSizeError = exports.InvalidCharacterError = exports.Chars = void 0;
|
|
11
|
+
const codec_js_1 = require("./codec.js");
|
|
12
|
+
const errors_js_1 = require("./errors.js");
|
|
13
|
+
Object.defineProperty(exports, "InvalidCharacterError", { enumerable: true, get: function () { return errors_js_1.InvalidCharacterError; } });
|
|
14
|
+
Object.defineProperty(exports, "BufferSizeError", { enumerable: true, get: function () { return errors_js_1.BufferSizeError; } });
|
|
15
|
+
// Re-export Chars for backward compatibility
|
|
16
|
+
var bases_js_1 = require("./bases.js");
|
|
17
|
+
Object.defineProperty(exports, "Chars", { enumerable: true, get: function () { return bases_js_1.Chars; } });
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use `Codec` or `createCodec()` instead.
|
|
20
|
+
*/
|
|
21
|
+
class BufferEncoder {
|
|
22
|
+
constructor(baseChars) {
|
|
23
|
+
this.baseChars = baseChars;
|
|
24
|
+
this.codec = new codec_js_1.Codec(baseChars);
|
|
25
|
+
}
|
|
26
|
+
encode(buffer) {
|
|
27
|
+
return this.codec.encode(buffer);
|
|
28
|
+
}
|
|
29
|
+
decode(encoded, bufferSize) {
|
|
30
|
+
return this.codec.decode(encoded, bufferSize !== undefined ? { size: bufferSize } : undefined);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.BufferEncoder = BufferEncoder;
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated Use `convert()` function or `codec.convertTo()` instead.
|
|
36
|
+
*/
|
|
37
|
+
class Converter {
|
|
38
|
+
constructor(inputBase, outputBase) {
|
|
39
|
+
this.decoder = new BufferEncoder(inputBase);
|
|
40
|
+
this.encoder = new BufferEncoder(outputBase);
|
|
41
|
+
}
|
|
42
|
+
convert(input) {
|
|
43
|
+
return this.encoder.encode(this.decoder.decode(input));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.Converter = Converter;
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated Use `validate()` function or `codec.validate()` instead.
|
|
49
|
+
*/
|
|
50
|
+
class Validator {
|
|
51
|
+
constructor(inputBase) {
|
|
52
|
+
this.codec = new codec_js_1.Codec(inputBase);
|
|
53
|
+
}
|
|
54
|
+
validate(input) {
|
|
55
|
+
return this.codec.validate(input);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.Validator = Validator;
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated Use `validate()` from the main module instead.
|
|
61
|
+
*/
|
|
62
|
+
const validate = (input, base) => {
|
|
63
|
+
return new Validator(base).validate(input);
|
|
64
|
+
};
|
|
65
|
+
exports.validate = validate;
|
|
66
|
+
//# sourceMappingURL=bufferbase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bufferbase.js","sourceRoot":"","sources":["../../src/bufferbase.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAGH,yCAAmC;AACnC,2CAAqE;AAM5D,sGANA,iCAAqB,OAMA;AAAE,gGANA,2BAAe,OAMA;AAJ/C,6CAA6C;AAC7C,uCAAmC;AAA1B,iGAAA,KAAK,OAAA;AAKd;;GAEG;AACH,MAAa,aAAa;IAGxB,YAAoB,SAAiB;QAAjB,cAAS,GAAT,SAAS,CAAQ;QACnC,IAAI,CAAC,KAAK,GAAG,IAAI,gBAAK,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,MAAc;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,OAAe,EAAE,UAAmB;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACjG,CAAC;CACF;AAdD,sCAcC;AAED;;GAEG;AACH,MAAa,SAAS;IAIpB,YAAY,SAAiB,EAAE,UAAkB;QAC/C,IAAI,CAAC,OAAO,GAAG,IAAI,aAAa,CAAC,SAAS,CAAC,CAAC;QAC5C,IAAI,CAAC,OAAO,GAAG,IAAI,aAAa,CAAC,UAAU,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,CAAC,KAAa;QACnB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACzD,CAAC;CACF;AAZD,8BAYC;AAED;;GAEG;AACH,MAAa,SAAS;IAGpB,YAAY,SAAiB;QAC3B,IAAI,CAAC,KAAK,GAAG,IAAI,gBAAK,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,QAAQ,CAAC,KAAa;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;CACF;AAVD,8BAUC;AAED;;GAEG;AACI,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAE,IAAY,EAAW,EAAE;IAC/D,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import type { ICodec, DecodeOptions, BufferLike } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Codec for encoding and decoding buffers to/from a specific base.
|
|
5
|
+
*
|
|
6
|
+
* Use pre-defined codecs from `Codecs` for common encodings,
|
|
7
|
+
* or create custom codecs with `createCodec()`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { Codec, Codecs, createCodec } from 'bufferbase';
|
|
12
|
+
*
|
|
13
|
+
* // Use pre-defined codec
|
|
14
|
+
* const encoded = Codecs.base58.encode(Buffer.from('Hello'));
|
|
15
|
+
*
|
|
16
|
+
* // Create custom codec
|
|
17
|
+
* const binary = createCodec('01');
|
|
18
|
+
* const bits = binary.encode(Buffer.from([5])); // '101'
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class Codec implements ICodec {
|
|
22
|
+
/** Character set used for encoding. */
|
|
23
|
+
readonly chars: string;
|
|
24
|
+
/** @internal */
|
|
25
|
+
private readonly charToIndex;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new codec with the specified character set.
|
|
28
|
+
* @param chars - The character set to use for encoding/decoding
|
|
29
|
+
*/
|
|
30
|
+
constructor(chars: string);
|
|
31
|
+
/**
|
|
32
|
+
* Encodes a buffer to a base-encoded string.
|
|
33
|
+
*
|
|
34
|
+
* Leading zero bytes in the buffer are preserved as the first character
|
|
35
|
+
* of the encoding alphabet (e.g., '1' for Base58).
|
|
36
|
+
*
|
|
37
|
+
* @param input - The buffer or Uint8Array to encode
|
|
38
|
+
* @returns Base-encoded string
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const codec = Codecs.base58;
|
|
43
|
+
* codec.encode(Buffer.from('Hello')); // '9Ajdvzr'
|
|
44
|
+
* codec.encode(new Uint8Array([0, 0, 1])); // '112' (preserves leading zeros)
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
encode(input: BufferLike): string;
|
|
48
|
+
/**
|
|
49
|
+
* Decodes a base-encoded string to a buffer.
|
|
50
|
+
*
|
|
51
|
+
* Leading characters that represent zero (first char of alphabet)
|
|
52
|
+
* are converted to leading zero bytes in the result.
|
|
53
|
+
*
|
|
54
|
+
* @param encoded - The string to decode
|
|
55
|
+
* @param options - Decode options
|
|
56
|
+
* @returns Decoded buffer
|
|
57
|
+
* @throws {InvalidCharacterError} If the string contains invalid characters
|
|
58
|
+
* @throws {BufferSizeError} If the result exceeds the specified size
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const codec = Codecs.base58;
|
|
63
|
+
* codec.decode('9Ajdvzr'); // Buffer('Hello')
|
|
64
|
+
* codec.decode('9Ajdvzr', { size: 32 }); // Pads to 32 bytes
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
decode(encoded: string, options?: DecodeOptions): Buffer;
|
|
68
|
+
/**
|
|
69
|
+
* Validates if a string contains only valid characters for this base.
|
|
70
|
+
*
|
|
71
|
+
* This is a fast check that doesn't perform full decoding.
|
|
72
|
+
*
|
|
73
|
+
* @param input - The string to validate
|
|
74
|
+
* @returns `true` if all characters are valid, `false` otherwise
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* Codecs.base58.validate('9Ajdvzr'); // true
|
|
79
|
+
* Codecs.base58.validate('0invalid'); // false ('0' not in Base58)
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
validate(input: string): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Converts a string from this base to another base.
|
|
85
|
+
*
|
|
86
|
+
* Internally decodes to a buffer, then encodes with the target codec.
|
|
87
|
+
*
|
|
88
|
+
* @param target - Target codec to convert to
|
|
89
|
+
* @param input - The string to convert
|
|
90
|
+
* @returns String in the target base encoding
|
|
91
|
+
* @throws {InvalidCharacterError} If the input contains invalid characters
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const base58str = '9Ajdvzr';
|
|
96
|
+
* const base64str = Codecs.base58.convertTo(Codecs.base64url, base58str);
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
convertTo(target: ICodec, input: string): string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Creates a new codec with the specified character set.
|
|
103
|
+
*
|
|
104
|
+
* Use this to create codecs for custom base encodings.
|
|
105
|
+
* The base is determined by the length of the character set.
|
|
106
|
+
*
|
|
107
|
+
* @param chars - The character set to use for encoding/decoding
|
|
108
|
+
* @returns A new Codec instance
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* import { createCodec } from 'bufferbase';
|
|
113
|
+
*
|
|
114
|
+
* // Binary codec (base 2)
|
|
115
|
+
* const binary = createCodec('01');
|
|
116
|
+
* binary.encode(Buffer.from([5])); // '101'
|
|
117
|
+
*
|
|
118
|
+
* // Octal codec (base 8)
|
|
119
|
+
* const octal = createCodec('01234567');
|
|
120
|
+
* octal.encode(Buffer.from([255])); // '377'
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function createCodec(chars: string): Codec;
|
|
124
|
+
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAcpE;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,KAAM,YAAW,MAAM;IAClC,uCAAuC;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,gBAAgB;IAChB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsB;IAElD;;;OAGG;gBACS,KAAK,EAAE,MAAM;IAQzB;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM;IA6CjC;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM;IAgExD;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAShC;;;;;;;;;;;;;;;OAeG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;CAIjD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAEhD"}
|