@vandeurenglenn/base16 1.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/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # bs32
2
+
3
+ module compatible base16
4
+
5
+ ## Usage
6
+
7
+ ``` js
8
+ import base16 from '@vandeurenglenn/base16'
9
+
10
+ const uint8Array = new TextEncoder().encode('hi')
11
+
12
+ const base16Encoded = base16.encode(uint8Array)
13
+
14
+ console.log(base16Encoded) // 2dj
15
+
16
+ const base16Decoded = base16.decode(base16Encoded)
17
+
18
+ const string = new TextDecoder().decode(base16Decoded)
19
+
20
+ console.log(string) // hi
21
+ ```
package/dist/base32.js ADDED
@@ -0,0 +1,35 @@
1
+ import baseX from '@vandeurenglenn/base-x';
2
+
3
+ const ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567';
4
+ const ALPHABET_HEX = '0123456789abcdefghijklmnopqrstuv';
5
+ const base32 = baseX(ALPHABET);
6
+ const base32Hex = baseX(ALPHABET_HEX);
7
+ const decode = base32.decode;
8
+ const decodeHex = base32Hex.decode;
9
+ const encode = base32.encode;
10
+ const encodeHex = base32Hex.encode;
11
+ const isBase32 = (string, hex = false) => {
12
+ try {
13
+ if (hex)
14
+ decodeHex(string);
15
+ else
16
+ decode(string);
17
+ return true;
18
+ }
19
+ catch (e) {
20
+ return false;
21
+ }
22
+ };
23
+ const isBase32Hex = (string) => {
24
+ return isBase32(string, true);
25
+ };
26
+ var base32$1 = {
27
+ encode,
28
+ decode,
29
+ encodeHex,
30
+ decodeHex,
31
+ isBase32,
32
+ isBase32Hex
33
+ };
34
+
35
+ export { decode, decodeHex, base32$1 as default, encode, encodeHex, isBase32, isBase32Hex };
package/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A base16String only contains [0-9][a-f]
3
+ */
4
+ type base16String = string;
5
+ export declare const decode: (source: string) => Uint8Array;
6
+ export declare const encode: (source: Uint8Array | ArrayBuffer) => string;
7
+ export declare const isBase16: (string: base16String) => boolean;
8
+ declare const _default: {
9
+ encode: (source: Uint8Array | ArrayBuffer) => string;
10
+ decode: (source: string) => Uint8Array;
11
+ isBase16: (string: string) => boolean;
12
+ };
13
+ export default _default;
package/index.js ADDED
@@ -0,0 +1,22 @@
1
+ import baseX from '@vandeurenglenn/base-x';
2
+
3
+ const ALPHABET = '0123456789abcdef';
4
+ const base32 = baseX(ALPHABET);
5
+ const decode = base32.decode;
6
+ const encode = base32.encode;
7
+ const isBase16 = (string) => {
8
+ try {
9
+ decode(string);
10
+ return true;
11
+ }
12
+ catch (e) {
13
+ return false;
14
+ }
15
+ };
16
+ var index = {
17
+ encode,
18
+ decode,
19
+ isBase16
20
+ };
21
+
22
+ export { decode, index as default, encode, isBase16 };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@vandeurenglenn/base16",
3
+ "version": "1.0.0",
4
+ "description": "Base16",
5
+ "keywords": [
6
+ "base",
7
+ "32",
8
+ "base16",
9
+ "bs32"
10
+ ],
11
+ "types": "index.d.ts",
12
+ "license": "MIT",
13
+ "repository": "git://github.com/vandeurenglenn/base16.git",
14
+ "homepage": "https://github.com/vandeurenglenn/base16",
15
+ "bugs": {
16
+ "url": "https://github.com/vandeurenglenn/base16/issues"
17
+ },
18
+ "author": "Vanduren Glenn <vandeurenglenn@gmail.com>",
19
+ "exports": {
20
+ ".": "./index.js"
21
+ },
22
+ "type": "module",
23
+ "scripts": {
24
+ "build": "rollup -c",
25
+ "test": "node test.js"
26
+ },
27
+ "dependencies": {
28
+ "@vandeurenglenn/base-x": "^1.1.0"
29
+ },
30
+ "devDependencies": {
31
+ "@rollup/plugin-typescript": "^10.0.1",
32
+ "rollup": "^2.70.2",
33
+ "tape": "^5.6.1",
34
+ "tslib": "^2.4.1"
35
+ }
36
+ }
@@ -0,0 +1,20 @@
1
+ import typescript from '@rollup/plugin-typescript';
2
+
3
+ export default [{
4
+ input: ['./src/index.ts'],
5
+ output: [{
6
+ dir: './',
7
+ format: 'es'
8
+ }],
9
+ external: [
10
+ '@vandeurenglenn/base-x'
11
+ ],
12
+ plugins: [
13
+ typescript({
14
+ "outDir": "./",
15
+ "allowJs": true,
16
+ "target": "es2022",
17
+ "declaration": true
18
+ })
19
+ ]
20
+ }]
package/src/index.ts ADDED
@@ -0,0 +1,29 @@
1
+ import baseX from '@vandeurenglenn/base-x'
2
+
3
+ /**
4
+ * A base16String only contains [0-9][a-f]
5
+ */
6
+ type base16String = string
7
+
8
+ const ALPHABET = '0123456789abcdef'
9
+
10
+ const base32 = baseX(ALPHABET)
11
+
12
+ export const decode = base32.decode
13
+
14
+ export const encode = base32.encode
15
+
16
+ export const isBase16 = (string: base16String): boolean => {
17
+ try {
18
+ decode(string)
19
+ return true;
20
+ } catch (e) {
21
+ return false;
22
+ }
23
+ }
24
+
25
+ export default {
26
+ encode,
27
+ decode,
28
+ isBase16
29
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./",
4
+ "allowJs": true,
5
+ "target": "es2022",
6
+ "declaration": true
7
+ },
8
+ "include": [
9
+ "./src/**/*"
10
+ ],
11
+ "exclude": ["./tsconfig.json"]
12
+ }