@ctrl/ts-base32 4.2.0 → 4.2.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 CHANGED
@@ -1,8 +1,8 @@
1
- # ts-base32 [![npm](https://badgen.net/npm/v/@ctrl/ts-base32)](https://www.npmjs.com/package/@ctrl/ts-base32) [![coverage](https://badgen.net/codecov/c/github/scttcper/ts-base32)](https://codecov.io/gh/scttcper/ts-base32) [![bundlesize](https://badgen.net/bundlephobia/min/@ctrl/ts-base32)](https://bundlephobia.com/result?p=@ctrl/ts-base32)
1
+ # ts-base32 [![npm](https://badgen.net/npm/v/@ctrl/ts-base32)](https://www.npmjs.com/package/@ctrl/ts-base32) [![bundlesize](https://badgen.net/bundlephobia/min/@ctrl/ts-base32)](https://bundlephobia.com/result?p=@ctrl/ts-base32)
2
2
 
3
3
  Base32 encode and decode in typescript exported as both commonjs and tree shakeable modules. Support for RFC4648, RFC4648_HEX, and CROCKFORD base32 encoding. Mostly directly taken from LinusU's packages.
4
4
 
5
- Demo: https://ts-base32.vercel.app
5
+ Demo: https://ts-base32.ep.workers.dev
6
6
 
7
7
  ### Install
8
8
 
package/dist/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-bitwise */
1
2
  const RFC4648 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
2
3
  const RFC4648_HEX = '0123456789ABCDEFGHIJKLMNOPQRSTUV';
3
4
  const CROCKFORD = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
@@ -6,21 +7,24 @@ export function base32Encode(input, variant = 'RFC4648', options = {}) {
6
7
  let defaultPadding;
7
8
  switch (variant) {
8
9
  case 'RFC3548':
9
- case 'RFC4648':
10
+ case 'RFC4648': {
10
11
  alphabet = RFC4648;
11
12
  defaultPadding = true;
12
13
  break;
13
- case 'RFC4648-HEX':
14
+ }
15
+ case 'RFC4648-HEX': {
14
16
  alphabet = RFC4648_HEX;
15
17
  defaultPadding = true;
16
18
  break;
17
- case 'Crockford':
19
+ }
20
+ case 'Crockford': {
18
21
  alphabet = CROCKFORD;
19
22
  defaultPadding = false;
20
23
  break;
21
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
22
- default:
24
+ }
25
+ default: {
23
26
  throw new Error(`Unknown base32 variant: ${variant}`);
27
+ }
24
28
  }
25
29
  const padding = options.padding ?? defaultPadding;
26
30
  const length = input.byteLength;
@@ -49,7 +53,7 @@ export function base32Encode(input, variant = 'RFC4648', options = {}) {
49
53
  function readChar(alphabet, char) {
50
54
  const idx = alphabet.indexOf(char);
51
55
  if (idx === -1) {
52
- throw new Error('Invalid character found: ' + char);
56
+ throw new Error(`Invalid character found: ${char}`);
53
57
  }
54
58
  return idx;
55
59
  }
@@ -58,27 +62,30 @@ export function base32Decode(input, variant = 'RFC4648') {
58
62
  let cleanedInput;
59
63
  switch (variant) {
60
64
  case 'RFC3548':
61
- case 'RFC4648':
65
+ case 'RFC4648': {
62
66
  alphabet = RFC4648;
63
67
  cleanedInput = input.toUpperCase().replace(/=+$/, '');
64
68
  break;
65
- case 'RFC4648-HEX':
69
+ }
70
+ case 'RFC4648-HEX': {
66
71
  alphabet = RFC4648_HEX;
67
72
  cleanedInput = input.toUpperCase().replace(/=+$/, '');
68
73
  break;
69
- case 'Crockford':
74
+ }
75
+ case 'Crockford': {
70
76
  alphabet = CROCKFORD;
71
77
  cleanedInput = input.toUpperCase().replace(/O/g, '0').replace(/[IL]/g, '1');
72
78
  break;
73
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
74
- default:
79
+ }
80
+ default: {
75
81
  throw new Error(`Unknown base32 variant: ${variant}`);
82
+ }
76
83
  }
77
84
  const { length } = cleanedInput;
78
85
  let bits = 0;
79
86
  let value = 0;
80
87
  let index = 0;
81
- const output = new Uint8Array(((length * 5) / 8) | 0);
88
+ const output = new Uint8Array(Math.trunc((length * 5) / 8));
82
89
  for (let i = 0; i < length; i++) {
83
90
  value = (value << 5) | readChar(alphabet, cleanedInput[i]);
84
91
  bits += 5;
@@ -98,7 +105,7 @@ export function hexToUint8Array(hex) {
98
105
  }
99
106
  const view = new Uint8Array(hex.length / 2);
100
107
  for (let i = 0; i < hex.length; i += 2) {
101
- view[i / 2] = parseInt(hex.substring(i, i + 2), 16);
108
+ view[i / 2] = Number.parseInt(hex.slice(i, i + 2), 16);
102
109
  }
103
110
  return view;
104
111
  }
package/package.json CHANGED
@@ -1,74 +1,51 @@
1
1
  {
2
2
  "name": "@ctrl/ts-base32",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "description": "Base32 encoder/decoder with support for multiple variants",
5
- "author": "Scott Cooper <scttcper@gmail.com>",
6
- "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/scttcper/ts-base32.git"
10
- },
11
- "homepage": "https://ts-base32.vercel.app",
12
5
  "keywords": [
13
6
  "base32",
7
+ "crockford",
14
8
  "rfc3548",
15
9
  "rfc4648",
16
- "crockford",
17
10
  "typescript"
18
11
  ],
19
- "type": "module",
20
- "exports": "./dist/src/index.js",
21
- "types": "./dist/src/index.d.ts",
12
+ "homepage": "https://ts-base32.ep.workers.dev",
13
+ "license": "MIT",
14
+ "author": "Scott Cooper <scttcper@gmail.com>",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/scttcper/ts-base32.git"
18
+ },
22
19
  "files": [
23
20
  "dist/src"
24
21
  ],
22
+ "type": "module",
25
23
  "sideEffects": false,
24
+ "types": "./dist/src/index.d.ts",
25
+ "exports": "./dist/src/index.js",
26
+ "publishConfig": {
27
+ "access": "public",
28
+ "provenance": true
29
+ },
26
30
  "scripts": {
27
31
  "demo:build": "pnpm run -r build",
28
32
  "demo:watch": "pnpm run -r dev",
29
- "lint": "oxlint . && prettier --check . --experimental-cli",
30
- "lint:fix": "oxlint . --fix && prettier --write . --log-level=error --experimental-cli",
33
+ "lint": "oxfmt --check && oxlint .",
34
+ "lint:fix": "oxfmt && oxlint . --fix",
31
35
  "prepare": "npm run build",
32
36
  "build": "tsc",
33
37
  "test": "vitest run",
34
- "test:watch": "vitest",
35
- "test:ci": "vitest run --coverage --reporter=junit --outputFile=./junit.xml"
38
+ "test:watch": "vitest"
36
39
  },
37
40
  "devDependencies": {
38
- "@ctrl/eslint-config-biome": "5.0.1",
39
- "@sindresorhus/tsconfig": "8.0.1",
40
- "@trivago/prettier-plugin-sort-imports": "5.2.2",
41
- "@types/node": "24.5.2",
42
- "@vitest/coverage-v8": "3.2.4",
43
- "oxlint": "1.18.0",
44
- "prettier": "3.6.2",
45
- "typescript": "5.9.2",
41
+ "@ctrl/oxlint-config": "1.4.0",
42
+ "@sindresorhus/tsconfig": "8.1.0",
43
+ "@types/node": "25.2.3",
44
+ "oxfmt": "0.32.0",
45
+ "oxlint": "1.47.0",
46
+ "typescript": "5.9.3",
46
47
  "uint8array-extras": "1.5.0",
47
- "vitest": "3.2.4"
48
- },
49
- "prettier": {
50
- "singleQuote": true,
51
- "trailingComma": "all",
52
- "arrowParens": "avoid",
53
- "semi": true,
54
- "printWidth": 100,
55
- "plugins": [
56
- "@trivago/prettier-plugin-sort-imports"
57
- ],
58
- "importOrder": [
59
- "^node:.*$",
60
- "<THIRD_PARTY_MODULES>",
61
- "^(@ctrl)(/.*|$)",
62
- "^\\.\\./(?!.*\\.css$)",
63
- "^\\./(?!.*\\.css$)(?=.*/)",
64
- "^\\./(?!.*\\.css$)(?!.*/)"
65
- ],
66
- "importOrderSeparation": true,
67
- "importOrderSortSpecifiers": false
68
- },
69
- "publishConfig": {
70
- "access": "public",
71
- "provenance": true
48
+ "vitest": "4.0.18"
72
49
  },
73
50
  "release": {
74
51
  "branches": [
@@ -76,6 +53,6 @@
76
53
  ]
77
54
  },
78
55
  "engines": {
79
- "node": ">=18"
56
+ "node": ">20"
80
57
  }
81
58
  }