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.
- package/README.md +162 -63
- package/dist/cjs/bases.d.ts +152 -45
- package/dist/cjs/bases.d.ts.map +1 -1
- package/dist/cjs/bases.js +90 -77
- package/dist/cjs/bases.js.map +1 -1
- package/dist/cjs/bufferbase.d.ts +21 -27
- package/dist/cjs/bufferbase.d.ts.map +1 -1
- package/dist/cjs/bufferbase.js +21 -31
- 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 +25 -111
- package/dist/cjs/codec.d.ts.map +1 -1
- package/dist/cjs/codec.js +50 -228
- package/dist/cjs/codec.js.map +1 -1
- package/dist/cjs/codecs.d.ts +8 -59
- package/dist/cjs/codecs.d.ts.map +1 -1
- package/dist/cjs/codecs.js +6 -79
- package/dist/cjs/codecs.js.map +1 -1
- package/dist/cjs/errors.d.ts +65 -48
- package/dist/cjs/errors.d.ts.map +1 -1
- package/dist/cjs/errors.js +89 -51
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/example.js +44 -21
- package/dist/cjs/example.js.map +1 -1
- package/dist/cjs/functions.d.ts +27 -31
- package/dist/cjs/functions.d.ts.map +1 -1
- package/dist/cjs/functions.js +25 -47
- package/dist/cjs/functions.js.map +1 -1
- package/dist/cjs/index.d.ts +7 -5
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +17 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/package.json +12 -7
- package/dist/cjs/types.d.ts +108 -71
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/bases.d.ts +152 -45
- package/dist/esm/bases.d.ts.map +1 -1
- package/dist/esm/bases.js +88 -75
- package/dist/esm/bases.js.map +1 -1
- package/dist/esm/bufferbase.d.ts +21 -27
- package/dist/esm/bufferbase.d.ts.map +1 -1
- package/dist/esm/bufferbase.js +18 -30
- 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 +25 -111
- package/dist/esm/codec.d.ts.map +1 -1
- package/dist/esm/codec.js +44 -226
- package/dist/esm/codec.js.map +1 -1
- package/dist/esm/codecs.d.ts +8 -59
- package/dist/esm/codecs.d.ts.map +1 -1
- package/dist/esm/codecs.js +7 -80
- package/dist/esm/codecs.js.map +1 -1
- package/dist/esm/errors.d.ts +65 -48
- package/dist/esm/errors.d.ts.map +1 -1
- package/dist/esm/errors.js +83 -50
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/example.js +45 -22
- package/dist/esm/example.js.map +1 -1
- package/dist/esm/functions.d.ts +27 -31
- package/dist/esm/functions.d.ts.map +1 -1
- package/dist/esm/functions.js +26 -48
- package/dist/esm/functions.js.map +1 -1
- package/dist/esm/index.d.ts +7 -5
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/package.json +12 -7
- package/dist/esm/types.d.ts +108 -71
- package/dist/esm/types.d.ts.map +1 -1
- package/package.json +12 -7
- package/src/algorithms.test.ts +442 -0
- package/src/bases.ts +98 -76
- package/src/bufferbase.ts +26 -36
- 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 +17 -9
- package/src/codec.ts +48 -247
- package/src/codecs.ts +11 -105
- package/src/errors.ts +90 -50
- package/src/example.ts +47 -22
- package/src/functions.ts +34 -54
- package/src/index.ts +27 -7
- package/src/types.ts +113 -86
package/dist/cjs/errors.js
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnknownBaseError = exports.BufferSizeError = exports.InvalidCharacterError = void 0;
|
|
3
|
+
exports.CheckSymbolError = exports.ValueRangeError = exports.InvalidCodecError = exports.NonCanonicalError = exports.InvalidLengthError = exports.UnknownBaseError = exports.BufferSizeError = exports.InvalidCharacterError = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Error thrown when an invalid character is encountered during decoding.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { decode, InvalidCharacterError } from 'bufferbase';
|
|
10
|
-
*
|
|
11
|
-
* try {
|
|
12
|
-
* decode('invalid!', 'base58');
|
|
13
|
-
* } catch (e) {
|
|
14
|
-
* if (e instanceof InvalidCharacterError) {
|
|
15
|
-
* console.log(e.message); // "Invalid character found: '!'"
|
|
16
|
-
* }
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
6
|
*/
|
|
20
7
|
class InvalidCharacterError extends Error {
|
|
21
8
|
/**
|
|
@@ -29,24 +16,8 @@ class InvalidCharacterError extends Error {
|
|
|
29
16
|
}
|
|
30
17
|
exports.InvalidCharacterError = InvalidCharacterError;
|
|
31
18
|
/**
|
|
32
|
-
* Error thrown when decoded buffer
|
|
33
|
-
*
|
|
34
|
-
* This error is thrown when using the `size` option in decode operations
|
|
35
|
-
* and the decoded data is larger than the specified size.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* import { decode, BufferSizeError } from 'bufferbase';
|
|
40
|
-
*
|
|
41
|
-
* try {
|
|
42
|
-
* // Trying to decode into a buffer too small
|
|
43
|
-
* decode('72k1xXWG59fYdzSNoA', 'base58', { size: 2 });
|
|
44
|
-
* } catch (e) {
|
|
45
|
-
* if (e instanceof BufferSizeError) {
|
|
46
|
-
* console.log(e.message); // "Buffer size 13 exceeds specified size 2"
|
|
47
|
-
* }
|
|
48
|
-
* }
|
|
49
|
-
* ```
|
|
19
|
+
* Error thrown when the decoded buffer does not have the size requested
|
|
20
|
+
* through `DecodeOptions.size`.
|
|
50
21
|
*/
|
|
51
22
|
class BufferSizeError extends Error {
|
|
52
23
|
/**
|
|
@@ -54,39 +25,106 @@ class BufferSizeError extends Error {
|
|
|
54
25
|
* @param expected - The expected (specified) buffer size
|
|
55
26
|
*/
|
|
56
27
|
constructor(actual, expected) {
|
|
57
|
-
super(`Buffer size ${actual}
|
|
28
|
+
super(`Buffer size ${actual} does not match specified size ${expected}`);
|
|
58
29
|
this.name = 'BufferSizeError';
|
|
59
30
|
}
|
|
60
31
|
}
|
|
61
32
|
exports.BufferSizeError = BufferSizeError;
|
|
62
33
|
/**
|
|
63
34
|
* Error thrown when an unknown base name is provided.
|
|
64
|
-
*
|
|
65
|
-
* This error is thrown when using the function API with an invalid base name
|
|
66
|
-
* that is neither a known encoding name nor a valid custom character set
|
|
67
|
-
* (character sets must be longer than 15 characters).
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* import { encode, UnknownBaseError } from 'bufferbase';
|
|
72
|
-
*
|
|
73
|
-
* try {
|
|
74
|
-
* encode(Buffer.from('test'), 'invalidbase');
|
|
75
|
-
* } catch (e) {
|
|
76
|
-
* if (e instanceof UnknownBaseError) {
|
|
77
|
-
* console.log(e.message); // "Unknown base encoding: 'invalidbase'"
|
|
78
|
-
* }
|
|
79
|
-
* }
|
|
80
|
-
* ```
|
|
81
35
|
*/
|
|
82
36
|
class UnknownBaseError extends Error {
|
|
83
37
|
/**
|
|
84
38
|
* @param name - The unknown base name that was provided
|
|
85
39
|
*/
|
|
86
40
|
constructor(name) {
|
|
87
|
-
super(`Unknown base encoding: '${name}'`
|
|
41
|
+
super(`Unknown base encoding: '${name}'. ` +
|
|
42
|
+
'Pass a CodecSpec such as { alphabet, algorithm: \'radix\' } to use a custom alphabet.');
|
|
88
43
|
this.name = 'UnknownBaseError';
|
|
89
44
|
}
|
|
90
45
|
}
|
|
91
46
|
exports.UnknownBaseError = UnknownBaseError;
|
|
47
|
+
/**
|
|
48
|
+
* Error thrown when a string cannot be the encoding of any byte sequence
|
|
49
|
+
* because of its length.
|
|
50
|
+
*
|
|
51
|
+
* A Base64 string of 5 characters, for example, describes 30 bits: too many
|
|
52
|
+
* for 3 bytes and too few for 4.
|
|
53
|
+
*/
|
|
54
|
+
class InvalidLengthError extends Error {
|
|
55
|
+
/**
|
|
56
|
+
* @param length - The length that cannot occur
|
|
57
|
+
* @param detail - What the length should have been
|
|
58
|
+
*/
|
|
59
|
+
constructor(length, detail) {
|
|
60
|
+
super(`Invalid encoded length ${length}: ${detail}`);
|
|
61
|
+
this.name = 'InvalidLengthError';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.InvalidLengthError = InvalidLengthError;
|
|
65
|
+
/**
|
|
66
|
+
* Error thrown when input is well-formed but is not the canonical encoding of
|
|
67
|
+
* the bytes it decodes to (RFC 4648 §3.5).
|
|
68
|
+
*
|
|
69
|
+
* Accepting such input makes decoding non-injective: `'Zm8='` and `'Zm9='`
|
|
70
|
+
* would both decode to `'fo'`. Pass `strict: false` in the codec spec to allow
|
|
71
|
+
* it.
|
|
72
|
+
*/
|
|
73
|
+
class NonCanonicalError extends Error {
|
|
74
|
+
/**
|
|
75
|
+
* @param detail - What made the input non-canonical
|
|
76
|
+
*/
|
|
77
|
+
constructor(detail) {
|
|
78
|
+
super(`Non-canonical encoding: ${detail}`);
|
|
79
|
+
this.name = 'NonCanonicalError';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.NonCanonicalError = NonCanonicalError;
|
|
83
|
+
/**
|
|
84
|
+
* Error thrown when a codec spec cannot be realised, such as a `'block'`
|
|
85
|
+
* algorithm with an alphabet whose length is not a power of two.
|
|
86
|
+
*/
|
|
87
|
+
class InvalidCodecError extends Error {
|
|
88
|
+
/**
|
|
89
|
+
* @param detail - Why the spec is unusable
|
|
90
|
+
*/
|
|
91
|
+
constructor(detail) {
|
|
92
|
+
super(`Invalid codec: ${detail}`);
|
|
93
|
+
this.name = 'InvalidCodecError';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.InvalidCodecError = InvalidCodecError;
|
|
97
|
+
/**
|
|
98
|
+
* Error thrown when a group of characters denotes a number too large for the
|
|
99
|
+
* bytes it is supposed to encode.
|
|
100
|
+
*
|
|
101
|
+
* In an Ascii85 group, five characters must denote a value below 2^32; `'s8W-!'`
|
|
102
|
+
* does not, so it encodes nothing. Unlike `NonCanonicalError` this is never
|
|
103
|
+
* allowed, because there is no byte sequence to decode to.
|
|
104
|
+
*/
|
|
105
|
+
class ValueRangeError extends Error {
|
|
106
|
+
/**
|
|
107
|
+
* @param group - The group of characters that is out of range
|
|
108
|
+
*/
|
|
109
|
+
constructor(group) {
|
|
110
|
+
super(`Encoded group '${group}' exceeds the maximum value for its block`);
|
|
111
|
+
this.name = 'ValueRangeError';
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.ValueRangeError = ValueRangeError;
|
|
115
|
+
/**
|
|
116
|
+
* Error thrown when a trailing check symbol does not match the value it
|
|
117
|
+
* follows, which means the string was mistyped or corrupted.
|
|
118
|
+
*/
|
|
119
|
+
class CheckSymbolError extends Error {
|
|
120
|
+
/**
|
|
121
|
+
* @param found - The check symbol present in the input
|
|
122
|
+
* @param expected - The check symbol the value calls for
|
|
123
|
+
*/
|
|
124
|
+
constructor(found, expected) {
|
|
125
|
+
super(`Check symbol '${found}' does not match the expected '${expected}'`);
|
|
126
|
+
this.name = 'CheckSymbolError';
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.CheckSymbolError = CheckSymbolError;
|
|
92
130
|
//# sourceMappingURL=errors.js.map
|
package/dist/cjs/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,qBAAsB,SAAQ,KAAK;IAC9C;;OAEG;IACH,YAAY,IAAa;QACvB,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,6BAA6B,IAAI,GAAG,CAAC,CAAC,CAAC,yBAAyB,CAAC;QACxF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AATD,sDASC;AAED;;;GAGG;AACH,MAAa,eAAgB,SAAQ,KAAK;IACxC;;;OAGG;IACH,YAAY,MAAc,EAAE,QAAgB;QAC1C,KAAK,CAAC,eAAe,MAAM,kCAAkC,QAAQ,EAAE,CAAC,CAAC;QACzE,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AATD,0CASC;AAED;;GAEG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IACzC;;OAEG;IACH,YAAY,IAAY;QACtB,KAAK,CACH,2BAA2B,IAAI,KAAK;YAClC,uFAAuF,CAC1F,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAXD,4CAWC;AAED;;;;;;GAMG;AACH,MAAa,kBAAmB,SAAQ,KAAK;IAC3C;;;OAGG;IACH,YAAY,MAAc,EAAE,MAAc;QACxC,KAAK,CAAC,0BAA0B,MAAM,KAAK,MAAM,EAAE,CAAC,CAAC;QACrD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AATD,gDASC;AAED;;;;;;;GAOG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IAC1C;;OAEG;IACH,YAAY,MAAc;QACxB,KAAK,CAAC,2BAA2B,MAAM,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AARD,8CAQC;AAED;;;GAGG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IAC1C;;OAEG;IACH,YAAY,MAAc;QACxB,KAAK,CAAC,kBAAkB,MAAM,EAAE,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AARD,8CAQC;AAED;;;;;;;GAOG;AACH,MAAa,eAAgB,SAAQ,KAAK;IACxC;;OAEG;IACH,YAAY,KAAa;QACvB,KAAK,CAAC,kBAAkB,KAAK,2CAA2C,CAAC,CAAC;QAC1E,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AARD,0CAQC;AAED;;;GAGG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IACzC;;;OAGG;IACH,YAAY,KAAa,EAAE,QAAgB;QACzC,KAAK,CAAC,iBAAiB,KAAK,kCAAkC,QAAQ,GAAG,CAAC,CAAC;QAC3E,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AATD,4CASC"}
|
package/dist/cjs/example.js
CHANGED
|
@@ -2,31 +2,54 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const node_buffer_1 = require("node:buffer");
|
|
4
4
|
const index_js_1 = require("./index.js");
|
|
5
|
-
// Example buffer
|
|
6
5
|
const bytes = node_buffer_1.Buffer.from('Hello, World!', 'utf8');
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
// The same bytes under each algorithm.
|
|
7
|
+
console.log('=== Algorithms ===');
|
|
8
|
+
console.table({
|
|
9
|
+
'block base64': (0, index_js_1.encode)(bytes, 'base64'),
|
|
10
|
+
'block base32': (0, index_js_1.encode)(bytes, 'base32'),
|
|
11
|
+
'block85 ascii85': (0, index_js_1.encode)(bytes, 'ascii85'),
|
|
12
|
+
'radix base58': (0, index_js_1.encode)(bytes, 'base58'),
|
|
13
|
+
'radix base32crockford': (0, index_js_1.encode)(bytes, 'base32crockford'),
|
|
14
|
+
});
|
|
15
|
+
// Converting goes through the bytes, so any pair works.
|
|
16
|
+
console.log('\n=== Function API ===');
|
|
17
|
+
const base58 = (0, index_js_1.encode)(bytes, 'base58');
|
|
18
|
+
const base64url = (0, index_js_1.convert)(base58, 'base58', 'base64url');
|
|
14
19
|
console.table({
|
|
15
20
|
bytes: bytes.toString('utf8'),
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
base58,
|
|
22
|
+
base64url,
|
|
23
|
+
valid: (0, index_js_1.validate)(base64url, 'base64url'),
|
|
24
|
+
decoded: (0, index_js_1.decode)(base64url, 'base64url').toString('utf8'),
|
|
25
|
+
});
|
|
26
|
+
// validate() agrees with decode(): it checks length, padding and canonicality.
|
|
27
|
+
console.log('\n=== Rejected input ===');
|
|
28
|
+
console.table({
|
|
29
|
+
"'Zm8=' (canonical)": (0, index_js_1.validate)('Zm8=', 'base64'),
|
|
30
|
+
"'Zm9=' (spare bits set)": (0, index_js_1.validate)('Zm9=', 'base64'),
|
|
31
|
+
"'Zm9vd' (5 characters)": (0, index_js_1.validate)('Zm9vd', 'base64'),
|
|
32
|
+
});
|
|
33
|
+
// Crockford's Base32 reads what a person is likely to have written down.
|
|
34
|
+
console.log('\n=== Crockford ===');
|
|
35
|
+
const crockford = (0, index_js_1.encode)(bytes, 'base32crockfordcheck');
|
|
36
|
+
console.table({
|
|
37
|
+
encoded: crockford,
|
|
38
|
+
'as typed': (0, index_js_1.decode)(`${crockford.slice(0, 4)}-${crockford.slice(4)}`.toLowerCase(), 'base32crockfordcheck').toString('utf8'),
|
|
39
|
+
'one character changed': (0, index_js_1.validate)(`${crockford.slice(0, -2)}Z${crockford.slice(-1)}`, 'base32crockfordcheck'),
|
|
40
|
+
});
|
|
41
|
+
// Codecs, and a custom alphabet.
|
|
42
|
+
console.log('\n=== Codecs and custom alphabets ===');
|
|
43
|
+
const binary = (0, index_js_1.createCodec)('01');
|
|
44
|
+
const adobe = (0, index_js_1.createCodec)({
|
|
45
|
+
alphabet: index_js_1.Chars.Ascii85,
|
|
46
|
+
algorithm: 'block85',
|
|
47
|
+
zeroShortcut: true,
|
|
48
|
+
delimiters: true,
|
|
21
49
|
});
|
|
22
|
-
// Using Codecs object
|
|
23
|
-
console.log('\n=== Codecs API ===');
|
|
24
|
-
const encoded = index_js_1.Codecs.base58.encode(bytes);
|
|
25
|
-
const converted = index_js_1.Codecs.base58.convertTo(index_js_1.Codecs.base64url, encoded);
|
|
26
50
|
console.table({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
valid: index_js_1.Codecs.base64url.validate(converted),
|
|
51
|
+
'Codecs.base58': index_js_1.Codecs.base58.encode(bytes),
|
|
52
|
+
'binary of [5]': binary.encode(Uint8Array.of(5)),
|
|
53
|
+
'adobe ascii85': adobe.encode(bytes),
|
|
31
54
|
});
|
|
32
55
|
//# sourceMappingURL=example.js.map
|
package/dist/cjs/example.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"example.js","sourceRoot":"","sources":["../../src/example.ts"],"names":[],"mappings":";;AAAA,6CAAqC;AACrC,
|
|
1
|
+
{"version":3,"file":"example.js","sourceRoot":"","sources":["../../src/example.ts"],"names":[],"mappings":"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"}
|
package/dist/cjs/functions.d.ts
CHANGED
|
@@ -1,62 +1,58 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BufferLike, CodecSpec, DecodeOptions } from './types.js';
|
|
2
|
+
import type { Buffer } from 'node:buffer';
|
|
3
|
+
import { type BaseName } from './bases.js';
|
|
4
|
+
/** A named encoding, or a spec describing one directly. */
|
|
5
|
+
export type Base = BaseName | CodecSpec;
|
|
2
6
|
/**
|
|
3
7
|
* Encodes a buffer to a base-encoded string.
|
|
4
8
|
*
|
|
5
9
|
* @param buffer - Buffer or Uint8Array to encode
|
|
6
|
-
* @param base - Base name (e.g
|
|
7
|
-
* @returns Encoded string
|
|
10
|
+
* @param base - Base name (e.g. `'base58'`) or a codec spec
|
|
8
11
|
*
|
|
9
12
|
* @example
|
|
10
13
|
* ```typescript
|
|
11
|
-
* //
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* // Browser Uint8Array
|
|
15
|
-
* const encoded = encode(new Uint8Array([72, 101, 108, 108, 111]), 'base58');
|
|
14
|
+
* encode(Buffer.from('fo'), 'base64'); // 'Zm8='
|
|
15
|
+
* encode(Uint8Array.of(5), { alphabet: '01', algorithm: 'radix' }); // '101'
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
export declare function encode(buffer: BufferLike, base:
|
|
18
|
+
export declare function encode(buffer: BufferLike, base: Base): string;
|
|
19
19
|
/**
|
|
20
20
|
* Decodes a base-encoded string to a buffer.
|
|
21
21
|
*
|
|
22
22
|
* @param encoded - String to decode
|
|
23
|
-
* @param base - Base name (e.g
|
|
24
|
-
* @param options - Decode options
|
|
25
|
-
* @
|
|
23
|
+
* @param base - Base name (e.g. `'base58'`) or a codec spec
|
|
24
|
+
* @param options - Decode options, such as a required `size`
|
|
25
|
+
* @throws {InvalidCharacterError} If a character is not in the alphabet
|
|
26
|
+
* @throws {InvalidLengthError} If the length cannot encode a whole number of bytes
|
|
27
|
+
* @throws {NonCanonicalError} If spare bits are set and the codec is strict
|
|
28
|
+
* @throws {BufferSizeError} If the result does not have the requested `size`
|
|
26
29
|
*
|
|
27
30
|
* @example
|
|
28
31
|
* ```typescript
|
|
29
|
-
*
|
|
30
|
-
*
|
|
32
|
+
* decode('Zm8=', 'base64'); // Buffer('fo')
|
|
33
|
+
* decode('9Ajdvzr', 'base58', { size: 32 });
|
|
31
34
|
* ```
|
|
32
35
|
*/
|
|
33
|
-
export declare function decode(encoded: string, base:
|
|
36
|
+
export declare function decode(encoded: string, base: Base, options?: DecodeOptions): Buffer;
|
|
34
37
|
/**
|
|
35
|
-
* Converts a string from one base to another.
|
|
36
|
-
*
|
|
37
|
-
* @param input - String to convert
|
|
38
|
-
* @param from - Source base name or character set
|
|
39
|
-
* @param to - Target base name or character set
|
|
40
|
-
* @returns Converted string
|
|
38
|
+
* Converts a string from one base to another, through the bytes they describe.
|
|
41
39
|
*
|
|
42
40
|
* @example
|
|
43
41
|
* ```typescript
|
|
44
|
-
*
|
|
42
|
+
* convert('9Ajdvzr', 'base58', 'base64url');
|
|
43
|
+
* convert(legacy, 'radix64', 'base64'); // migrate data written by bufferbase 2
|
|
45
44
|
* ```
|
|
46
45
|
*/
|
|
47
|
-
export declare function convert(input: string, from:
|
|
46
|
+
export declare function convert(input: string, from: Base, to: Base): string;
|
|
48
47
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @param input - String to validate
|
|
52
|
-
* @param base - Base name or character set
|
|
53
|
-
* @returns true if valid, false otherwise
|
|
48
|
+
* Reports whether `decode` would succeed for this input.
|
|
54
49
|
*
|
|
55
50
|
* @example
|
|
56
51
|
* ```typescript
|
|
57
|
-
* validate('
|
|
58
|
-
* validate('
|
|
52
|
+
* validate('Zm8=', 'base64'); // true
|
|
53
|
+
* validate('Zm9=', 'base64'); // false — spare bits are not zero
|
|
54
|
+
* validate('Zm9vd', 'base64'); // false — 5 characters cannot be whole bytes
|
|
59
55
|
* ```
|
|
60
56
|
*/
|
|
61
|
-
export declare function validate(input: string, base:
|
|
57
|
+
export declare function validate(input: string, base: Base): boolean;
|
|
62
58
|
//# sourceMappingURL=functions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../src/functions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../src/functions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGxD,2DAA2D;AAC3D,MAAM,MAAM,IAAI,GAAG,QAAQ,GAAG,SAAS,CAAC;AAExC;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAEnF;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,GAAG,MAAM,CAInE;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAE3D"}
|
package/dist/cjs/functions.js
CHANGED
|
@@ -4,90 +4,68 @@ exports.encode = encode;
|
|
|
4
4
|
exports.decode = decode;
|
|
5
5
|
exports.convert = convert;
|
|
6
6
|
exports.validate = validate;
|
|
7
|
-
const codec_js_1 = require("./codec.js");
|
|
8
7
|
const bases_js_1 = require("./bases.js");
|
|
9
|
-
|
|
10
|
-
const codecCache = new Map();
|
|
11
|
-
/**
|
|
12
|
-
* Gets or creates a codec for the specified base.
|
|
13
|
-
*/
|
|
14
|
-
function getCodec(base) {
|
|
15
|
-
const chars = (0, bases_js_1.resolveChars)(base);
|
|
16
|
-
let codec = codecCache.get(chars);
|
|
17
|
-
if (!codec) {
|
|
18
|
-
codec = new codec_js_1.Codec(chars);
|
|
19
|
-
codecCache.set(chars, codec);
|
|
20
|
-
}
|
|
21
|
-
return codec;
|
|
22
|
-
}
|
|
8
|
+
const codec_js_1 = require("./codec.js");
|
|
23
9
|
/**
|
|
24
10
|
* Encodes a buffer to a base-encoded string.
|
|
25
11
|
*
|
|
26
12
|
* @param buffer - Buffer or Uint8Array to encode
|
|
27
|
-
* @param base - Base name (e.g
|
|
28
|
-
* @returns Encoded string
|
|
13
|
+
* @param base - Base name (e.g. `'base58'`) or a codec spec
|
|
29
14
|
*
|
|
30
15
|
* @example
|
|
31
16
|
* ```typescript
|
|
32
|
-
* //
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* // Browser Uint8Array
|
|
36
|
-
* 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'
|
|
37
19
|
* ```
|
|
38
20
|
*/
|
|
39
21
|
function encode(buffer, base) {
|
|
40
|
-
return getCodec(base).encode(buffer);
|
|
22
|
+
return (0, codec_js_1.getCodec)((0, bases_js_1.resolveSpec)(base)).encode(buffer);
|
|
41
23
|
}
|
|
42
24
|
/**
|
|
43
25
|
* Decodes a base-encoded string to a buffer.
|
|
44
26
|
*
|
|
45
27
|
* @param encoded - String to decode
|
|
46
|
-
* @param base - Base name (e.g
|
|
47
|
-
* @param options - Decode options
|
|
48
|
-
* @
|
|
28
|
+
* @param base - Base name (e.g. `'base58'`) or a codec spec
|
|
29
|
+
* @param options - Decode options, such as a required `size`
|
|
30
|
+
* @throws {InvalidCharacterError} If a character is not in the alphabet
|
|
31
|
+
* @throws {InvalidLengthError} If the length cannot encode a whole number of bytes
|
|
32
|
+
* @throws {NonCanonicalError} If spare bits are set and the codec is strict
|
|
33
|
+
* @throws {BufferSizeError} If the result does not have the requested `size`
|
|
49
34
|
*
|
|
50
35
|
* @example
|
|
51
36
|
* ```typescript
|
|
52
|
-
*
|
|
53
|
-
*
|
|
37
|
+
* decode('Zm8=', 'base64'); // Buffer('fo')
|
|
38
|
+
* decode('9Ajdvzr', 'base58', { size: 32 });
|
|
54
39
|
* ```
|
|
55
40
|
*/
|
|
56
41
|
function decode(encoded, base, options) {
|
|
57
|
-
return getCodec(base).decode(encoded, options);
|
|
42
|
+
return (0, codec_js_1.getCodec)((0, bases_js_1.resolveSpec)(base)).decode(encoded, options);
|
|
58
43
|
}
|
|
59
44
|
/**
|
|
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
|
|
45
|
+
* Converts a string from one base to another, through the bytes they describe.
|
|
66
46
|
*
|
|
67
47
|
* @example
|
|
68
48
|
* ```typescript
|
|
69
|
-
*
|
|
49
|
+
* convert('9Ajdvzr', 'base58', 'base64url');
|
|
50
|
+
* convert(legacy, 'radix64', 'base64'); // migrate data written by bufferbase 2
|
|
70
51
|
* ```
|
|
71
52
|
*/
|
|
72
53
|
function convert(input, from, to) {
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
return
|
|
54
|
+
const source = (0, codec_js_1.getCodec)((0, bases_js_1.resolveSpec)(from));
|
|
55
|
+
const target = (0, codec_js_1.getCodec)((0, bases_js_1.resolveSpec)(to));
|
|
56
|
+
return source.convertTo(target, input);
|
|
76
57
|
}
|
|
77
58
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @param input - String to validate
|
|
81
|
-
* @param base - Base name or character set
|
|
82
|
-
* @returns true if valid, false otherwise
|
|
59
|
+
* Reports whether `decode` would succeed for this input.
|
|
83
60
|
*
|
|
84
61
|
* @example
|
|
85
62
|
* ```typescript
|
|
86
|
-
* validate('
|
|
87
|
-
* validate('
|
|
63
|
+
* validate('Zm8=', 'base64'); // true
|
|
64
|
+
* validate('Zm9=', 'base64'); // false — spare bits are not zero
|
|
65
|
+
* validate('Zm9vd', 'base64'); // false — 5 characters cannot be whole bytes
|
|
88
66
|
* ```
|
|
89
67
|
*/
|
|
90
68
|
function validate(input, base) {
|
|
91
|
-
return getCodec(base).validate(input);
|
|
69
|
+
return (0, codec_js_1.getCodec)((0, bases_js_1.resolveSpec)(base)).validate(input);
|
|
92
70
|
}
|
|
93
71
|
//# sourceMappingURL=functions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/functions.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/functions.ts"],"names":[],"mappings":";;AAoBA,wBAEC;AAmBD,wBAEC;AAWD,0BAIC;AAYD,4BAEC;AAtED,yCAAwD;AACxD,yCAAsC;AAKtC;;;;;;;;;;;GAWG;AACH,SAAgB,MAAM,CAAC,MAAkB,EAAE,IAAU;IACnD,OAAO,IAAA,mBAAQ,EAAC,IAAA,sBAAW,EAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACpD,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,MAAM,CAAC,OAAe,EAAE,IAAU,EAAE,OAAuB;IACzE,OAAO,IAAA,mBAAQ,EAAC,IAAA,sBAAW,EAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,OAAO,CAAC,KAAa,EAAE,IAAU,EAAE,EAAQ;IACzD,MAAM,MAAM,GAAG,IAAA,mBAAQ,EAAC,IAAA,sBAAW,EAAC,IAAI,CAAC,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,IAAA,mBAAQ,EAAC,IAAA,sBAAW,EAAC,EAAE,CAAC,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,QAAQ,CAAC,KAAa,EAAE,IAAU;IAChD,OAAO,IAAA,mBAAQ,EAAC,IAAA,sBAAW,EAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { Algorithm, Block85Spec, BlockSpec, BufferLike, CodecSpec, DecodeOptions, ICodec, RadixSpec, } from './types.js';
|
|
2
|
+
export type { BaseName } from './bases.js';
|
|
3
|
+
export type { Base } from './functions.js';
|
|
2
4
|
export type { CodecName } from './codecs.js';
|
|
3
|
-
export { InvalidCharacterError,
|
|
4
|
-
export { Codec, createCodec } from './codec.js';
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
5
|
+
export { BufferSizeError, CheckSymbolError, InvalidCharacterError, InvalidCodecError, InvalidLengthError, NonCanonicalError, UnknownBaseError, ValueRangeError, } from './errors.js';
|
|
6
|
+
export { Block85Codec, BlockCodec, Codec, RadixCodec, createCodec, getCodec } from './codec.js';
|
|
7
|
+
export { Bases, Chars, isBaseName, resolveSpec } from './bases.js';
|
|
8
|
+
export { convert, decode, encode, validate } from './functions.js';
|
|
7
9
|
export { Codecs } from './codecs.js';
|
|
8
10
|
export { BufferEncoder, Converter, Validator } from './bufferbase.js';
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,SAAS,EACT,WAAW,EACX,SAAS,EACT,UAAU,EACV,SAAS,EACT,aAAa,EACb,MAAM,EACN,SAAS,GACV,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,YAAY,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,GAChB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGhG,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGnE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAGnE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Validator = exports.Converter = exports.BufferEncoder = exports.Codecs = exports.validate = exports.
|
|
3
|
+
exports.Validator = exports.Converter = exports.BufferEncoder = exports.Codecs = exports.validate = exports.encode = exports.decode = exports.convert = exports.resolveSpec = exports.isBaseName = exports.Chars = exports.Bases = exports.getCodec = exports.createCodec = exports.RadixCodec = exports.Codec = exports.BlockCodec = exports.Block85Codec = exports.ValueRangeError = exports.UnknownBaseError = exports.NonCanonicalError = exports.InvalidLengthError = exports.InvalidCodecError = exports.InvalidCharacterError = exports.CheckSymbolError = exports.BufferSizeError = void 0;
|
|
4
4
|
// Errors
|
|
5
5
|
var errors_js_1 = require("./errors.js");
|
|
6
|
-
Object.defineProperty(exports, "InvalidCharacterError", { enumerable: true, get: function () { return errors_js_1.InvalidCharacterError; } });
|
|
7
6
|
Object.defineProperty(exports, "BufferSizeError", { enumerable: true, get: function () { return errors_js_1.BufferSizeError; } });
|
|
7
|
+
Object.defineProperty(exports, "CheckSymbolError", { enumerable: true, get: function () { return errors_js_1.CheckSymbolError; } });
|
|
8
|
+
Object.defineProperty(exports, "InvalidCharacterError", { enumerable: true, get: function () { return errors_js_1.InvalidCharacterError; } });
|
|
9
|
+
Object.defineProperty(exports, "InvalidCodecError", { enumerable: true, get: function () { return errors_js_1.InvalidCodecError; } });
|
|
10
|
+
Object.defineProperty(exports, "InvalidLengthError", { enumerable: true, get: function () { return errors_js_1.InvalidLengthError; } });
|
|
11
|
+
Object.defineProperty(exports, "NonCanonicalError", { enumerable: true, get: function () { return errors_js_1.NonCanonicalError; } });
|
|
8
12
|
Object.defineProperty(exports, "UnknownBaseError", { enumerable: true, get: function () { return errors_js_1.UnknownBaseError; } });
|
|
9
|
-
|
|
13
|
+
Object.defineProperty(exports, "ValueRangeError", { enumerable: true, get: function () { return errors_js_1.ValueRangeError; } });
|
|
14
|
+
// Codec implementations and factory
|
|
10
15
|
var codec_js_1 = require("./codec.js");
|
|
16
|
+
Object.defineProperty(exports, "Block85Codec", { enumerable: true, get: function () { return codec_js_1.Block85Codec; } });
|
|
17
|
+
Object.defineProperty(exports, "BlockCodec", { enumerable: true, get: function () { return codec_js_1.BlockCodec; } });
|
|
11
18
|
Object.defineProperty(exports, "Codec", { enumerable: true, get: function () { return codec_js_1.Codec; } });
|
|
19
|
+
Object.defineProperty(exports, "RadixCodec", { enumerable: true, get: function () { return codec_js_1.RadixCodec; } });
|
|
12
20
|
Object.defineProperty(exports, "createCodec", { enumerable: true, get: function () { return codec_js_1.createCodec; } });
|
|
13
|
-
|
|
21
|
+
Object.defineProperty(exports, "getCodec", { enumerable: true, get: function () { return codec_js_1.getCodec; } });
|
|
22
|
+
// Character sets, encoding definitions, and lookup helpers
|
|
14
23
|
var bases_js_1 = require("./bases.js");
|
|
24
|
+
Object.defineProperty(exports, "Bases", { enumerable: true, get: function () { return bases_js_1.Bases; } });
|
|
15
25
|
Object.defineProperty(exports, "Chars", { enumerable: true, get: function () { return bases_js_1.Chars; } });
|
|
16
|
-
Object.defineProperty(exports, "resolveChars", { enumerable: true, get: function () { return bases_js_1.resolveChars; } });
|
|
17
26
|
Object.defineProperty(exports, "isBaseName", { enumerable: true, get: function () { return bases_js_1.isBaseName; } });
|
|
27
|
+
Object.defineProperty(exports, "resolveSpec", { enumerable: true, get: function () { return bases_js_1.resolveSpec; } });
|
|
18
28
|
// Simple function API
|
|
19
29
|
var functions_js_1 = require("./functions.js");
|
|
20
|
-
Object.defineProperty(exports, "encode", { enumerable: true, get: function () { return functions_js_1.encode; } });
|
|
21
|
-
Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return functions_js_1.decode; } });
|
|
22
30
|
Object.defineProperty(exports, "convert", { enumerable: true, get: function () { return functions_js_1.convert; } });
|
|
31
|
+
Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return functions_js_1.decode; } });
|
|
32
|
+
Object.defineProperty(exports, "encode", { enumerable: true, get: function () { return functions_js_1.encode; } });
|
|
23
33
|
Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return functions_js_1.validate; } });
|
|
24
34
|
// Pre-defined codecs (namespaced)
|
|
25
35
|
var codecs_js_1 = require("./codecs.js");
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAeA,SAAS;AACT,yCASqB;AARnB,4GAAA,eAAe,OAAA;AACf,6GAAA,gBAAgB,OAAA;AAChB,kHAAA,qBAAqB,OAAA;AACrB,8GAAA,iBAAiB,OAAA;AACjB,+GAAA,kBAAkB,OAAA;AAClB,8GAAA,iBAAiB,OAAA;AACjB,6GAAA,gBAAgB,OAAA;AAChB,4GAAA,eAAe,OAAA;AAGjB,oCAAoC;AACpC,uCAAgG;AAAvF,wGAAA,YAAY,OAAA;AAAE,sGAAA,UAAU,OAAA;AAAE,iGAAA,KAAK,OAAA;AAAE,sGAAA,UAAU,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,oGAAA,QAAQ,OAAA;AAE3E,2DAA2D;AAC3D,uCAAmE;AAA1D,iGAAA,KAAK,OAAA;AAAE,iGAAA,KAAK,OAAA;AAAE,sGAAA,UAAU,OAAA;AAAE,uGAAA,WAAW,OAAA;AAE9C,sBAAsB;AACtB,+CAAmE;AAA1D,uGAAA,OAAO,OAAA;AAAE,sGAAA,MAAM,OAAA;AAAE,sGAAA,MAAM,OAAA;AAAE,wGAAA,QAAQ,OAAA;AAE1C,kCAAkC;AAClC,yCAAqC;AAA5B,mGAAA,MAAM,OAAA;AAEf,gDAAgD;AAChD,iDAAsE;AAA7D,8GAAA,aAAa,OAAA;AAAE,0GAAA,SAAS,OAAA;AAAE,0GAAA,SAAS,OAAA"}
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bufferbase",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Buffer-to-BaseN
|
|
3
|
+
"version": "3.0.1",
|
|
4
|
+
"description": "Buffer-to-BaseN encoding: RFC 4648 block encodings, Ascii85/Z85, and Base58-style radix conversion",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"scripts": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"build:esm": "tsc -p tsconfig.json",
|
|
11
11
|
"prepublishOnly": "bun run build",
|
|
12
12
|
"example": "bun src/example.ts",
|
|
13
|
-
"test": "bun test"
|
|
13
|
+
"test": "bun test",
|
|
14
|
+
"release": "bin/release"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
16
17
|
"@types/bun": "^1.1.0",
|
|
@@ -27,19 +28,23 @@
|
|
|
27
28
|
"src"
|
|
28
29
|
],
|
|
29
30
|
"keywords": [
|
|
30
|
-
"number",
|
|
31
31
|
"encode",
|
|
32
|
+
"decode",
|
|
32
33
|
"convert",
|
|
33
|
-
"decimal",
|
|
34
34
|
"base",
|
|
35
|
+
"rfc4648",
|
|
35
36
|
"base16",
|
|
37
|
+
"hex",
|
|
36
38
|
"base32",
|
|
39
|
+
"base32hex",
|
|
37
40
|
"crockford",
|
|
38
41
|
"base36",
|
|
39
42
|
"base58",
|
|
40
43
|
"base64",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
44
|
+
"base64url",
|
|
45
|
+
"ascii85",
|
|
46
|
+
"z85",
|
|
47
|
+
"radix"
|
|
43
48
|
],
|
|
44
49
|
"author": "misebox",
|
|
45
50
|
"license": "ISC",
|