@baseworks/core 0.2.0 → 0.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.
@@ -0,0 +1,20 @@
1
+ // src/codec.ts
2
+ function base64urlEncode(input) {
3
+ const bytes = input instanceof ArrayBuffer ? new Uint8Array(input) : input;
4
+ return btoa(Array.from(bytes, (b) => String.fromCharCode(b)).join("")).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
5
+ }
6
+ function base64urlDecode(input) {
7
+ const padded = input.replace(/-/g, "+").replace(/_/g, "/");
8
+ const pad = (4 - padded.length % 4) % 4;
9
+ const b64 = padded + "=".repeat(pad);
10
+ return Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
11
+ }
12
+ function base64urlDecodeString(input) {
13
+ return new TextDecoder().decode(base64urlDecode(input));
14
+ }
15
+
16
+ export {
17
+ base64urlEncode,
18
+ base64urlDecode,
19
+ base64urlDecodeString
20
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Base64url encode/decode utilities.
3
+ * Runtime-agnostic: Workers, Node 20+, browser.
4
+ * RFC 4648 §5 — URL-safe alphabet, no padding.
5
+ */
6
+ declare function base64urlEncode(input: Uint8Array | ArrayBuffer): string;
7
+ declare function base64urlDecode(input: string): Uint8Array;
8
+ declare function base64urlDecodeString(input: string): string;
9
+
10
+ export { base64urlDecode, base64urlDecodeString, base64urlEncode };
package/dist/codec.js ADDED
@@ -0,0 +1,10 @@
1
+ import {
2
+ base64urlDecode,
3
+ base64urlDecodeString,
4
+ base64urlEncode
5
+ } from "./chunk-ZX7RRJ5W.js";
6
+ export {
7
+ base64urlDecode,
8
+ base64urlDecodeString,
9
+ base64urlEncode
10
+ };
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { generateId, generateShortId, generateSlug } from './id.js';
2
+ export { base64urlDecode, base64urlDecodeString, base64urlEncode } from './codec.js';
package/dist/index.js CHANGED
@@ -3,7 +3,15 @@ import {
3
3
  generateShortId,
4
4
  generateSlug
5
5
  } from "./chunk-PRA7F4WX.js";
6
+ import {
7
+ base64urlDecode,
8
+ base64urlDecodeString,
9
+ base64urlEncode
10
+ } from "./chunk-ZX7RRJ5W.js";
6
11
  export {
12
+ base64urlDecode,
13
+ base64urlDecodeString,
14
+ base64urlEncode,
7
15
  generateId,
8
16
  generateShortId,
9
17
  generateSlug
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@baseworks/core",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
7
- "./id": "./dist/id.js"
7
+ "./id": "./dist/id.js",
8
+ "./codec": "./dist/codec.js"
8
9
  },
9
- "files": ["dist", "src"],
10
+ "files": [
11
+ "dist",
12
+ "src"
13
+ ],
10
14
  "scripts": {
11
15
  "build": "tsup",
12
16
  "typecheck": "tsc --noEmit"
package/src/codec.ts ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Base64url encode/decode utilities.
3
+ * Runtime-agnostic: Workers, Node 20+, browser.
4
+ * RFC 4648 §5 — URL-safe alphabet, no padding.
5
+ */
6
+
7
+ export function base64urlEncode(input: Uint8Array | ArrayBuffer): string {
8
+ const bytes = input instanceof ArrayBuffer ? new Uint8Array(input) : input
9
+ return btoa(Array.from(bytes, (b) => String.fromCharCode(b)).join(''))
10
+ .replace(/\+/g, '-')
11
+ .replace(/\//g, '_')
12
+ .replace(/=+$/, '')
13
+ }
14
+
15
+ export function base64urlDecode(input: string): Uint8Array {
16
+ const padded = input.replace(/-/g, '+').replace(/_/g, '/')
17
+ const pad = (4 - (padded.length % 4)) % 4
18
+ const b64 = padded + '='.repeat(pad)
19
+ return Uint8Array.from(atob(b64), (c) => c.charCodeAt(0))
20
+ }
21
+
22
+ export function base64urlDecodeString(input: string): string {
23
+ return new TextDecoder().decode(base64urlDecode(input))
24
+ }
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { generateId, generateShortId, generateSlug } from './id';
2
+ export { base64urlEncode, base64urlDecode, base64urlDecodeString } from './codec';