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/src/types.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Input type accepted by encode functions.
|
|
5
|
+
*
|
|
6
|
+
* Supports both Node.js `Buffer` and standard `Uint8Array` for browser compatibility.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Node.js Buffer
|
|
11
|
+
* encode(Buffer.from('Hello'), 'base58');
|
|
12
|
+
*
|
|
13
|
+
* // Browser Uint8Array
|
|
14
|
+
* encode(new Uint8Array([72, 101, 108, 108, 111]), 'base58');
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export type BufferLike = Buffer | Uint8Array;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Supported base encoding names.
|
|
21
|
+
*
|
|
22
|
+
* These names can be used with the function API:
|
|
23
|
+
* - `'decimal'` - Base 10 (0-9)
|
|
24
|
+
* - `'base16'` / `'hex'` - Hexadecimal (0-9A-F)
|
|
25
|
+
* - `'base32'` - RFC 4648 Base32 (A-Z2-7)
|
|
26
|
+
* - `'base32crockford'` - Crockford's Base32 (0-9A-HJKMNP-TV-Z)
|
|
27
|
+
* - `'base36'` - Alphanumeric (0-9A-Z)
|
|
28
|
+
* - `'base52'` - Letters only (A-Za-z)
|
|
29
|
+
* - `'base58'` - Bitcoin alphabet (no 0OIl)
|
|
30
|
+
* - `'base64'` - Standard Base64 (A-Za-z0-9+/)
|
|
31
|
+
* - `'base64url'` - URL-safe Base64 (A-Za-z0-9-_)
|
|
32
|
+
* - `'base64xml'` - XML token Base64 (A-Za-z0-9._)
|
|
33
|
+
* - `'base64xmlname'` - XML name Base64 (A-Za-z0-9_:)
|
|
34
|
+
* - `'ascii85'` - ASCII85 encoding
|
|
35
|
+
* - `'base85'` - Base85 encoding
|
|
36
|
+
* - `'z85'` - ZeroMQ Z85 encoding
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import { encode, decode } from 'bufferbase';
|
|
41
|
+
*
|
|
42
|
+
* const encoded = encode(Buffer.from('Hello'), 'base58');
|
|
43
|
+
* const decoded = decode(encoded, 'base58');
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export type BaseName =
|
|
47
|
+
| 'decimal'
|
|
48
|
+
| 'base16'
|
|
49
|
+
| 'hex'
|
|
50
|
+
| 'base32'
|
|
51
|
+
| 'base32crockford'
|
|
52
|
+
| 'base36'
|
|
53
|
+
| 'base52'
|
|
54
|
+
| 'base58'
|
|
55
|
+
| 'base64'
|
|
56
|
+
| 'base64url'
|
|
57
|
+
| 'base64xml'
|
|
58
|
+
| 'base64xmlname'
|
|
59
|
+
| 'ascii85'
|
|
60
|
+
| 'base85'
|
|
61
|
+
| 'z85';
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Options for decode operations.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // Decode with fixed buffer size (pads with leading zeros)
|
|
69
|
+
* const buffer = decode(encoded, 'base58', { size: 32 });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export interface DecodeOptions {
|
|
73
|
+
/**
|
|
74
|
+
* Expected buffer size in bytes.
|
|
75
|
+
* - If decoded result is smaller, pads with leading zeros.
|
|
76
|
+
* - If decoded result is larger, throws `BufferSizeError`.
|
|
77
|
+
*/
|
|
78
|
+
size?: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Codec interface for encoding/decoding operations.
|
|
83
|
+
*
|
|
84
|
+
* Implemented by the `Codec` class and used by pre-defined codecs in `Codecs`.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* import { Codecs } from 'bufferbase';
|
|
89
|
+
*
|
|
90
|
+
* const encoded = Codecs.base58.encode(Buffer.from('Hello'));
|
|
91
|
+
* const decoded = Codecs.base58.decode(encoded);
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export interface ICodec {
|
|
95
|
+
/** Character set used for encoding. */
|
|
96
|
+
readonly chars: string;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Encodes a buffer to a base-encoded string.
|
|
100
|
+
* @param buffer - The buffer or Uint8Array to encode
|
|
101
|
+
* @returns Base-encoded string
|
|
102
|
+
*/
|
|
103
|
+
encode(buffer: BufferLike): string;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Decodes a base-encoded string to a buffer.
|
|
107
|
+
* @param encoded - The string to decode
|
|
108
|
+
* @param options - Decode options (e.g., fixed size)
|
|
109
|
+
* @returns Decoded buffer
|
|
110
|
+
* @throws {InvalidCharacterError} If the string contains invalid characters
|
|
111
|
+
* @throws {BufferSizeError} If the result exceeds the specified size
|
|
112
|
+
*/
|
|
113
|
+
decode(encoded: string, options?: DecodeOptions): Buffer;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Validates if a string contains only valid characters for this base.
|
|
117
|
+
* @param input - The string to validate
|
|
118
|
+
* @returns `true` if valid, `false` otherwise
|
|
119
|
+
*/
|
|
120
|
+
validate(input: string): boolean;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Converts a string from this base to another base.
|
|
124
|
+
* @param target - Target codec to convert to
|
|
125
|
+
* @param input - The string to convert
|
|
126
|
+
* @returns String in the target base encoding
|
|
127
|
+
*/
|
|
128
|
+
convertTo(target: ICodec, input: string): string;
|
|
129
|
+
}
|
package/dist/bufferbase.d.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/**
|
|
3
|
-
* A collection of common bases.
|
|
4
|
-
*/
|
|
5
|
-
export declare const Chars: {
|
|
6
|
-
Decimal: string;
|
|
7
|
-
Base16: string;
|
|
8
|
-
Base32: string;
|
|
9
|
-
Base32Crockford: string;
|
|
10
|
-
Base36: string;
|
|
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.
|
|
29
|
-
*/
|
|
30
|
-
export declare class BufferEncoder {
|
|
31
|
-
private baseChars;
|
|
32
|
-
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
|
-
*/
|
|
40
|
-
decode(encoded: string, bufferSize?: number): Buffer;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Creates a converter function that can convert between two bases.
|
|
44
|
-
*/
|
|
45
|
-
export declare class Converter {
|
|
46
|
-
decoder: BufferEncoder;
|
|
47
|
-
encoder: BufferEncoder;
|
|
48
|
-
constructor(inputBase: string, outputBase: string);
|
|
49
|
-
/**
|
|
50
|
-
* Converts a string from the input base to the output base.
|
|
51
|
-
*/
|
|
52
|
-
convert(input: string): string;
|
|
53
|
-
}
|
|
54
|
-
export declare class Validator {
|
|
55
|
-
decorder: BufferEncoder;
|
|
56
|
-
constructor(inputBase: string);
|
|
57
|
-
validate(input: string): boolean;
|
|
58
|
-
}
|
|
59
|
-
export declare const validate: (input: string, base: string) => boolean;
|
|
60
|
-
//# sourceMappingURL=bufferbase.d.ts.map
|
package/dist/bufferbase.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bufferbase.d.ts","sourceRoot":"","sources":["../src/bufferbase.ts"],"names":[],"mappings":";AAAA;;GAEG;AACH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;CAqBjB,CAAC;AAEF,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,OAAO,SAA6B;CACrC;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,OAAO,SAAwC;CAChD;AAED;;GAEG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,MAAM;IAErC;;OAEG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IA2B9B;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM;CAgCrD;AAED;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,aAAa,CAAC;gBAEX,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAKjD;;OAEG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAG/B;AAED,qBAAa,SAAS;IACpB,QAAQ,EAAE,aAAa,CAAC;gBAEZ,SAAS,EAAE,MAAM;IAI7B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAWjC;AAED,eAAO,MAAM,QAAQ,UAAW,MAAM,QAAQ,MAAM,KAAG,OAEtD,CAAC"}
|
package/dist/bufferbase.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A collection of common bases.
|
|
3
|
-
*/
|
|
4
|
-
export const Chars = {
|
|
5
|
-
Decimal: '0123456789',
|
|
6
|
-
Base16: '0123456789ABCDEF',
|
|
7
|
-
Base32: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
|
|
8
|
-
Base32Crockford: '0123456789ABCDEFGHJKMNPQRSTVWXYZ',
|
|
9
|
-
Base36: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
10
|
-
Base52: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
|
11
|
-
Base58: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz',
|
|
12
|
-
Base64_STD: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
|
|
13
|
-
Base64_URL_SAFE: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
|
|
14
|
-
Base64_XML_NMTOKEN: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._',
|
|
15
|
-
Base64_XML_NAME: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_:',
|
|
16
|
-
Ascii85: '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstu',
|
|
17
|
-
Base85: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&()*+-;<=>?@^_`{|}~',
|
|
18
|
-
Z85: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#',
|
|
19
|
-
};
|
|
20
|
-
export class InvalidCharacterError extends Error {
|
|
21
|
-
constructor() {
|
|
22
|
-
super(...arguments);
|
|
23
|
-
this.message = 'Invalid character found';
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export class BufferSizeError extends Error {
|
|
27
|
-
constructor() {
|
|
28
|
-
super(...arguments);
|
|
29
|
-
this.message = 'Buffer size exceeds specified size';
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Encodes and decodes buffers to and from a base.
|
|
34
|
-
*/
|
|
35
|
-
export class BufferEncoder {
|
|
36
|
-
constructor(baseChars) {
|
|
37
|
-
this.baseChars = baseChars;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Encodes a buffer to a string.
|
|
41
|
-
*/
|
|
42
|
-
encode(buffer) {
|
|
43
|
-
let result = [];
|
|
44
|
-
for (const byte of buffer) {
|
|
45
|
-
let carry = byte;
|
|
46
|
-
for (let j = 0; j < result.length; j++) {
|
|
47
|
-
carry += result[j] * 256;
|
|
48
|
-
result[j] = carry % this.baseChars.length;
|
|
49
|
-
carry = Math.floor(carry / this.baseChars.length);
|
|
50
|
-
}
|
|
51
|
-
while (carry > 0) {
|
|
52
|
-
result.push(carry % this.baseChars.length);
|
|
53
|
-
carry = Math.floor(carry / this.baseChars.length);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
for (const byte of buffer) {
|
|
57
|
-
if (byte === 0) {
|
|
58
|
-
result.push(0);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return result
|
|
65
|
-
.reverse()
|
|
66
|
-
.map((index) => this.baseChars[index])
|
|
67
|
-
.join('');
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Decodes a string to a buffer.
|
|
71
|
-
*/
|
|
72
|
-
decode(encoded, bufferSize) {
|
|
73
|
-
let result = Buffer.alloc(0);
|
|
74
|
-
for (const char of encoded) {
|
|
75
|
-
const value = this.baseChars.indexOf(char);
|
|
76
|
-
if (value === -1)
|
|
77
|
-
throw new InvalidCharacterError();
|
|
78
|
-
let carry = value;
|
|
79
|
-
let tempResult = Buffer.alloc(result.length);
|
|
80
|
-
let i;
|
|
81
|
-
for (i = 0; i < result.length; i++) {
|
|
82
|
-
carry += result[i] * this.baseChars.length;
|
|
83
|
-
tempResult[i] = carry % 256;
|
|
84
|
-
carry = Math.floor(carry / 256);
|
|
85
|
-
}
|
|
86
|
-
while (carry > 0) {
|
|
87
|
-
tempResult = Buffer.concat([tempResult, Buffer.from([carry % 256])]);
|
|
88
|
-
carry = Math.floor(carry / 256);
|
|
89
|
-
}
|
|
90
|
-
result = tempResult;
|
|
91
|
-
}
|
|
92
|
-
// buffer size
|
|
93
|
-
if (bufferSize && result.length < bufferSize) {
|
|
94
|
-
result = Buffer.concat([
|
|
95
|
-
result,
|
|
96
|
-
Buffer.from(Array(bufferSize - result.length).fill(0)),
|
|
97
|
-
]);
|
|
98
|
-
}
|
|
99
|
-
if (bufferSize && result.length > bufferSize) {
|
|
100
|
-
throw new BufferSizeError();
|
|
101
|
-
}
|
|
102
|
-
result.reverse();
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Creates a converter function that can convert between two bases.
|
|
108
|
-
*/
|
|
109
|
-
export class Converter {
|
|
110
|
-
constructor(inputBase, outputBase) {
|
|
111
|
-
this.decoder = new BufferEncoder(inputBase);
|
|
112
|
-
this.encoder = new BufferEncoder(outputBase);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Converts a string from the input base to the output base.
|
|
116
|
-
*/
|
|
117
|
-
convert(input) {
|
|
118
|
-
return this.encoder.encode(this.decoder.decode(input));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
export class Validator {
|
|
122
|
-
constructor(inputBase) {
|
|
123
|
-
this.decorder = new BufferEncoder(inputBase);
|
|
124
|
-
}
|
|
125
|
-
validate(input) {
|
|
126
|
-
try {
|
|
127
|
-
this.decorder.decode(input);
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
if (e instanceof InvalidCharacterError) {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
throw e;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
export const validate = (input, base) => {
|
|
139
|
-
return new Validator(base).validate(input);
|
|
140
|
-
};
|
|
141
|
-
//# sourceMappingURL=bufferbase.js.map
|
package/dist/bufferbase.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bufferbase.js","sourceRoot":"","sources":["../src/bufferbase.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,kBAAkB;IAC1B,MAAM,EAAE,kCAAkC;IAC1C,eAAe,EAAE,kCAAkC;IACnD,MAAM,EAAE,sCAAsC;IAC9C,MAAM,EAAE,sDAAsD;IAC9D,MAAM,EAAE,4DAA4D;IACpE,UAAU,EACR,kEAAkE;IACpE,eAAe,EACb,kEAAkE;IACpE,kBAAkB,EAChB,kEAAkE;IACpE,eAAe,EACb,kEAAkE;IACpE,OAAO,EACL,uFAAuF;IACzF,MAAM,EACJ,uFAAuF;IACzF,GAAG,EAAE,uFAAuF;CAC7F,CAAC;AAEF,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAAhD;;QACE,YAAO,GAAG,yBAAyB,CAAC;IACtC,CAAC;CAAA;AAED,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAA1C;;QACE,YAAO,GAAG,oCAAoC,CAAC;IACjD,CAAC;CAAA;AAED;;GAEG;AACH,MAAM,OAAO,aAAa;IACxB,YAAoB,SAAiB;QAAjB,cAAS,GAAT,SAAS,CAAQ;IAAG,CAAC;IAEzC;;OAEG;IACH,MAAM,CAAC,MAAc;QACnB,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;YAC1B,IAAI,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E,CAAC;QAC9B,CAAC;QACD,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,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;;OAEG;IACH,OAAO,CAAC,KAAa;QACnB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACzD,CAAC;CACF;AAED,MAAM,OAAO,SAAS;IAGpB,YAAY,SAAiB;QAC3B,IAAI,CAAC,QAAQ,GAAG,IAAI,aAAa,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;IAED,QAAQ,CAAC,KAAa;QACpB,IAAI,CAAC;YACH,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,qBAAqB,EAAE,CAAC;gBACvC,OAAO,KAAK,CAAC;YACf,CAAC;YACD,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,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"}
|
package/dist/example.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Chars, BufferEncoder, Converter, Validator } from './bufferbase.js';
|
|
2
|
-
// Example buffer
|
|
3
|
-
const bytes = Buffer.from('Hello, World!', 'utf8');
|
|
4
|
-
// Encoding buffer to Base32
|
|
5
|
-
const encoder = new BufferEncoder(Chars.Base32Crockford);
|
|
6
|
-
const base32encoded = encoder.encode(bytes);
|
|
7
|
-
// Converting Base32 to Base58
|
|
8
|
-
const converter_32to58 = new Converter(Chars.Base32Crockford, Chars.Base58);
|
|
9
|
-
const base58encoded = converter_32to58.convert(base32encoded);
|
|
10
|
-
// Converting Base32 to Base58
|
|
11
|
-
const converter_58to64 = new Converter(Chars.Base58, Chars.Base64_URL_SAFE);
|
|
12
|
-
const base64encoded = converter_58to64.convert(base58encoded);
|
|
13
|
-
// Validating Base64
|
|
14
|
-
const validatorB64 = new Validator(Chars.Base64_URL_SAFE);
|
|
15
|
-
const isValidAsBase64 = validatorB64.validate(base64encoded);
|
|
16
|
-
// Decoding Base64
|
|
17
|
-
const decoder = new BufferEncoder(Chars.Base64_URL_SAFE);
|
|
18
|
-
const decoded = decoder.decode(base64encoded);
|
|
19
|
-
console.table({
|
|
20
|
-
bytes: bytes.toString('utf8'),
|
|
21
|
-
base32encoded,
|
|
22
|
-
base58encoded,
|
|
23
|
-
base64encoded,
|
|
24
|
-
isValidAsBase64,
|
|
25
|
-
decoded: decoded.toString('utf8'),
|
|
26
|
-
});
|
|
27
|
-
// ┌─────────────────┬─────────────────────────┐
|
|
28
|
-
// │ (index) │ Values │
|
|
29
|
-
// ├─────────────────┼─────────────────────────┤
|
|
30
|
-
// │ bytes │ 'Hello, World!' │
|
|
31
|
-
// │ base32encoded │ '4GSBCDHQJR82QDXS6RS11' │
|
|
32
|
-
// │ base58encoded │ '72k1xXWG59fYdzSNoA' │
|
|
33
|
-
// │ base64encoded │ 'BIZWxsbywgV29ybGQh' │
|
|
34
|
-
// │ isValidAsBase64 │ true │
|
|
35
|
-
// │ decoded │ 'Hello, World!' │
|
|
36
|
-
// └─────────────────┴─────────────────────────┘
|
|
37
|
-
//# sourceMappingURL=example.js.map
|
package/dist/example.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-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AC,QAAQ,CAAC,MAAM,CAAC;CAClC,CAAC,CAAC;AACH,gDAAgD;AAChD,gDAAgD;AAChD,gDAAgD;AAChD,gDAAgD;AAChD,gDAAgD;AAChD,gDAAgD;AAChD,gDAAgD;AAChD,gDAAgD;AAChD,gDAAgD;AAChD,gDAAgD"}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EACrB,SAAS,EACT,QAAQ,GACT,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EACrB,SAAS,EACT,QAAQ,GACT,MAAM,iBAAiB,CAAC"}
|
package/dist/sample.d.ts
DELETED
package/dist/sample.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sample.d.ts","sourceRoot":"","sources":["../src/sample.ts"],"names":[],"mappings":""}
|
package/dist/sample.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Chars, BufferEncoder, Converter, Validator } from "./bufferbase.js";
|
|
2
|
-
// Example buffer
|
|
3
|
-
const bytes = Buffer.from("Hello, World!", "utf8");
|
|
4
|
-
// Encoding buffer to Base32
|
|
5
|
-
const encoder = new BufferEncoder(Chars.Base32Crockford);
|
|
6
|
-
const base32encoded = encoder.encode(bytes);
|
|
7
|
-
// Converting Base32 to Base58
|
|
8
|
-
const converter_32to58 = new Converter(Chars.Base32Crockford, Chars.Base58);
|
|
9
|
-
const base58encoded = converter_32to58.convert(base32encoded);
|
|
10
|
-
// Converting Base32 to Base58
|
|
11
|
-
const converter_58to64 = new Converter(Chars.Base58, Chars.Base64_URL_SAFE);
|
|
12
|
-
const base64encoded = converter_58to64.convert(base58encoded);
|
|
13
|
-
// Validating Base64
|
|
14
|
-
const validatorB64 = new Validator(Chars.Base64_URL_SAFE);
|
|
15
|
-
const isValidAsBase64 = validatorB64.validate(base64encoded);
|
|
16
|
-
// Decoding Base64
|
|
17
|
-
const decoder = new BufferEncoder(Chars.Base64_URL_SAFE);
|
|
18
|
-
const decoded = decoder.decode(base64encoded);
|
|
19
|
-
console.table({
|
|
20
|
-
bytes: bytes.toString("utf8"),
|
|
21
|
-
base32encoded,
|
|
22
|
-
base58encoded,
|
|
23
|
-
base64encoded,
|
|
24
|
-
isValidAsBase64,
|
|
25
|
-
decoded: decoded.toString("utf8"),
|
|
26
|
-
});
|
|
27
|
-
// ┌─────────────────┬─────────────────────────┐
|
|
28
|
-
// │ (index) │ Values │
|
|
29
|
-
// ├─────────────────┼─────────────────────────┤
|
|
30
|
-
// │ bytes │ 'Hello, World!' │
|
|
31
|
-
// │ base32encoded │ '4GSBCDHQJR82QDXS6RS11' │
|
|
32
|
-
// │ base58encoded │ '72k1xXWG59fYdzSNoA' │
|
|
33
|
-
// │ base64encoded │ 'BIZWxsbywgV29ybGQh' │
|
|
34
|
-
// │ isValidAsBase64 │ true │
|
|
35
|
-
// │ decoded │ 'Hello, World!' │
|
|
36
|
-
// └─────────────────┴─────────────────────────┘
|
|
37
|
-
//# sourceMappingURL=sample.js.map
|
package/dist/sample.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sample.js","sourceRoot":"","sources":["../src/sample.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE7E,iBAAiB;AACjB,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;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