@depthbomb/common 1.3.2 → 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.
Files changed (62) hide show
  1. package/README.md +286 -1
  2. package/dist/collections.cjs +1 -0
  3. package/dist/{queue.d.cts → collections.d.cts} +28 -5
  4. package/dist/{queue.d.mts → collections.d.mts} +28 -5
  5. package/dist/collections.mjs +1 -0
  6. package/dist/{fn.d.cts → functional.d.cts} +1 -1
  7. package/dist/{fn.d.mts → functional.d.mts} +1 -1
  8. package/dist/guards.cjs +1 -0
  9. package/dist/guards.d.cts +7 -0
  10. package/dist/guards.d.mts +7 -0
  11. package/dist/guards.mjs +1 -0
  12. package/dist/index.cjs +1 -1
  13. package/dist/index.d.cts +12 -7
  14. package/dist/index.d.mts +12 -7
  15. package/dist/index.mjs +1 -1
  16. package/dist/lazy.cjs +1 -1
  17. package/dist/lazy.d.cts +1 -5
  18. package/dist/lazy.d.mts +1 -5
  19. package/dist/lazy.mjs +1 -1
  20. package/dist/number.cjs +1 -0
  21. package/dist/number.d.cts +8 -0
  22. package/dist/number.d.mts +8 -0
  23. package/dist/number.mjs +1 -0
  24. package/dist/promise.cjs +1 -0
  25. package/dist/promise.d.cts +48 -0
  26. package/dist/promise.d.mts +48 -0
  27. package/dist/promise.mjs +1 -0
  28. package/dist/random.cjs +1 -0
  29. package/dist/random.d.cts +11 -0
  30. package/dist/random.d.mts +11 -0
  31. package/dist/random.mjs +1 -0
  32. package/dist/state.cjs +1 -0
  33. package/dist/state.d.cts +88 -0
  34. package/dist/state.d.mts +88 -0
  35. package/dist/state.mjs +1 -0
  36. package/dist/timing.cjs +1 -0
  37. package/dist/timing.d.cts +71 -0
  38. package/dist/timing.d.mts +71 -0
  39. package/dist/timing.mjs +1 -0
  40. package/dist/typing.cjs +1 -0
  41. package/dist/typing.d.cts +26 -0
  42. package/dist/typing.d.mts +26 -0
  43. package/dist/typing.mjs +1 -0
  44. package/dist/url.cjs +1 -0
  45. package/dist/{urllib.d.cts → url.d.cts} +12 -2
  46. package/dist/{urllib.d.mts → url.d.mts} +12 -2
  47. package/dist/url.mjs +1 -0
  48. package/package.json +103 -83
  49. package/dist/async.cjs +0 -1
  50. package/dist/async.d.cts +0 -44
  51. package/dist/async.d.mts +0 -44
  52. package/dist/async.mjs +0 -1
  53. package/dist/queue.cjs +0 -1
  54. package/dist/queue.mjs +0 -1
  55. package/dist/types.cjs +0 -1
  56. package/dist/types.d.cts +0 -9
  57. package/dist/types.d.mts +0 -9
  58. package/dist/types.mjs +0 -1
  59. package/dist/urllib.cjs +0 -1
  60. package/dist/urllib.mjs +0 -1
  61. /package/dist/{fn.cjs → functional.cjs} +0 -0
  62. /package/dist/{fn.mjs → functional.mjs} +0 -0
package/package.json CHANGED
@@ -1,83 +1,103 @@
1
- {
2
- "name": "@depthbomb/common",
3
- "version": "1.3.2",
4
- "description": "A set of common utilities for TypeScript/JavaScript",
5
- "license": "MIT",
6
- "engines": {
7
- "node": ">=22"
8
- },
9
- "keywords": [
10
- "typescript",
11
- "utilities"
12
- ],
13
- "exports": {
14
- ".": {
15
- "import": "./dist/index.mjs",
16
- "require": "./dist/index.cjs"
17
- },
18
- "./async": {
19
- "import": "./dist/async.mjs",
20
- "require": "./dist/async.cjs"
21
- },
22
- "./decorators": {
23
- "import": "./dist/decorators.mjs",
24
- "require": "./dist/decorators.cjs"
25
- },
26
- "./fn": {
27
- "import": "./dist/fn.mjs",
28
- "require": "./dist/fn.cjs"
29
- },
30
- "./lazy": {
31
- "import": "./dist/lazy.mjs",
32
- "require": "./dist/lazy.cjs"
33
- },
34
- "./queue": {
35
- "import": "./dist/queue.mjs",
36
- "require": "./dist/queue.cjs"
37
- },
38
- "./types": {
39
- "import": "./dist/types.mjs",
40
- "require": "./dist/types.cjs"
41
- },
42
- "./urllib": {
43
- "import": "./dist/urllib.mjs",
44
- "require": "./dist/urllib.cjs"
45
- }
46
- },
47
- "main": "./dist/index.cjs",
48
- "module": "./dist/index.mjs",
49
- "types": "./dist/index.d.cts",
50
- "files": [
51
- "dist"
52
- ],
53
- "sideEffects": false,
54
- "publishConfig": {
55
- "access": "public"
56
- },
57
- "repository": {
58
- "type": "git",
59
- "url": "git+https://github.com/depthbomb/js-common.git"
60
- },
61
- "bugs": {
62
- "url": "https://github.com/depthbomb/js-common/issues"
63
- },
64
- "scripts": {
65
- "build": "tsc",
66
- "dist": "tsdown",
67
- "release": "yarn dist && release-it",
68
- "lint": "eslint ./src --ext .ts",
69
- "test": "vitest"
70
- },
71
- "devDependencies": {
72
- "@types/eslint": "^9.6.1",
73
- "@types/node": "^24.10.13",
74
- "@typescript-eslint/eslint-plugin": "^8.55.0",
75
- "@typescript-eslint/parser": "^8.55.0",
76
- "eslint": "^10.0.0",
77
- "release-it": "^19.2.4",
78
- "tsdown": "^0.20.3",
79
- "typescript": "^5.9.3",
80
- "vitest": "^4.0.18"
81
- },
82
- "packageManager": "yarn@4.12.0"
83
- }
1
+ {
2
+ "name": "@depthbomb/common",
3
+ "version": "2.0.0",
4
+ "description": "A set of common utilities for TypeScript/JavaScript",
5
+ "license": "MIT",
6
+ "engines": {
7
+ "node": ">=22"
8
+ },
9
+ "keywords": [
10
+ "typescript",
11
+ "utilities"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.cjs"
17
+ },
18
+ "./collections": {
19
+ "import": "./dist/collections.mjs",
20
+ "require": "./dist/collections.cjs"
21
+ },
22
+ "./decorators": {
23
+ "import": "./dist/decorators.mjs",
24
+ "require": "./dist/decorators.cjs"
25
+ },
26
+ "./functional": {
27
+ "import": "./dist/functional.mjs",
28
+ "require": "./dist/functional.cjs"
29
+ },
30
+ "./guards": {
31
+ "import": "./dist/guards.mjs",
32
+ "require": "./dist/guards.cjs"
33
+ },
34
+ "./lazy": {
35
+ "import": "./dist/lazy.mjs",
36
+ "require": "./dist/lazy.cjs"
37
+ },
38
+ "./number": {
39
+ "import": "./dist/number.mjs",
40
+ "require": "./dist/number.cjs"
41
+ },
42
+ "./promise": {
43
+ "import": "./dist/promise.mjs",
44
+ "require": "./dist/promise.cjs"
45
+ },
46
+ "./random": {
47
+ "import": "./dist/random.mjs",
48
+ "require": "./dist/random.cjs"
49
+ },
50
+ "./state": {
51
+ "import": "./dist/state.mjs",
52
+ "require": "./dist/state.cjs"
53
+ },
54
+ "./timing": {
55
+ "import": "./dist/timing.mjs",
56
+ "require": "./dist/timing.cjs"
57
+ },
58
+ "./typing": {
59
+ "import": "./dist/typing.mjs",
60
+ "require": "./dist/typing.cjs"
61
+ },
62
+ "./url": {
63
+ "import": "./dist/url.mjs",
64
+ "require": "./dist/url.cjs"
65
+ }
66
+ },
67
+ "main": "./dist/index.cjs",
68
+ "module": "./dist/index.mjs",
69
+ "types": "./dist/index.d.cts",
70
+ "files": [
71
+ "dist"
72
+ ],
73
+ "sideEffects": false,
74
+ "publishConfig": {
75
+ "access": "public"
76
+ },
77
+ "repository": {
78
+ "type": "git",
79
+ "url": "git+https://github.com/depthbomb/js-common.git"
80
+ },
81
+ "bugs": {
82
+ "url": "https://github.com/depthbomb/js-common/issues"
83
+ },
84
+ "scripts": {
85
+ "build": "tsc",
86
+ "dist": "tsdown",
87
+ "release": "yarn dist && release-it",
88
+ "lint": "eslint ./src --ext .ts",
89
+ "test": "vitest"
90
+ },
91
+ "devDependencies": {
92
+ "@types/eslint": "^9.6.1",
93
+ "@types/node": "^24.12.0",
94
+ "@typescript-eslint/eslint-plugin": "^8.57.2",
95
+ "@typescript-eslint/parser": "^8.57.2",
96
+ "eslint": "^10.1.0",
97
+ "release-it": "^19.2.4",
98
+ "tsdown": "^0.21.5",
99
+ "typescript": "^6.0.2",
100
+ "vitest": "^4.1.2"
101
+ },
102
+ "packageManager": "yarn@4.13.0"
103
+ }
package/dist/async.cjs DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){return new Promise(t=>setTimeout(t,e))}function t(e){return new Promise((t,n)=>setTimeout(n,e))}async function n(t,n=100,r=5e3){let i=Date.now();for(;!await t();){if(Date.now()-i>r)throw Error(`Timeout exceeded`);await e(n)}}async function r(e,t){let n;try{return await Promise.race([e,new Promise((e,r)=>{n=setTimeout(()=>r(Error(`Operation timed out`)),t)})])}finally{n!==void 0&&clearTimeout(n)}}async function i(e){return(await Promise.allSettled(e)).filter(e=>e.status===`fulfilled`).map(e=>e.value)}async function a(e){let t=[];for(let n of e)t.push(await n());return t}exports.allSettledSuccessful=i,exports.pollUntil=n,exports.rejectionTimeout=t,exports.sequential=a,exports.timeout=e,exports.withTimeout=r;
package/dist/async.d.cts DELETED
@@ -1,44 +0,0 @@
1
- //#region src/async.d.ts
2
- /**
3
- * Returns a promise after the provided {@link ms} has passed
4
- * @param ms The number of milliseconds to wait
5
- */
6
- declare function timeout(ms: number): Promise<unknown>;
7
- /**
8
- * Rejects a promise after the provided {@link ms} has passed
9
- * @param ms The number of milliseconds to wait
10
- */
11
- declare function rejectionTimeout(ms: number): Promise<unknown>;
12
- /**
13
- * Polls until the provided condition is met, or the timeout is exceeded.
14
- *
15
- * @param condition A function that returns a boolean or a promise that resolves to a boolean
16
- * @param interval The interval in milliseconds to wait between checks
17
- * @param timeoutMs The maximum time in milliseconds to wait before throwing an error
18
- */
19
- declare function pollUntil(condition: () => boolean | Promise<boolean>, interval?: number, timeoutMs?: number): Promise<void>;
20
- /**
21
- * Wraps a promise with a timeout. If the promise does not resolve within the specified time, an error is thrown.
22
- *
23
- * @param promise The promise to wrap with a timeout
24
- * @param ms The number of milliseconds to wait before timing out
25
- *
26
- * @returns The result of the promise if it resolves before the timeout, otherwise throws an error
27
- */
28
- declare function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T>;
29
- /**
30
- * Waits for all promises to settle and returns an array of successful results.
31
- *
32
- * @param promises An array of promises to wait for
33
- * @returns A promise that resolves to an array of successful results
34
- */
35
- declare function allSettledSuccessful<T>(promises: Promise<T>[]): Promise<T[]>;
36
- /**
37
- * Executes an array of asynchronous tasks sequentially.
38
- *
39
- * @param tasks An array of functions that return promises
40
- * @returns A promise that resolves to an array of results from the input tasks
41
- */
42
- declare function sequential<T>(tasks: (() => Promise<T>)[]): Promise<T[]>;
43
- //#endregion
44
- export { allSettledSuccessful, pollUntil, rejectionTimeout, sequential, timeout, withTimeout };
package/dist/async.d.mts DELETED
@@ -1,44 +0,0 @@
1
- //#region src/async.d.ts
2
- /**
3
- * Returns a promise after the provided {@link ms} has passed
4
- * @param ms The number of milliseconds to wait
5
- */
6
- declare function timeout(ms: number): Promise<unknown>;
7
- /**
8
- * Rejects a promise after the provided {@link ms} has passed
9
- * @param ms The number of milliseconds to wait
10
- */
11
- declare function rejectionTimeout(ms: number): Promise<unknown>;
12
- /**
13
- * Polls until the provided condition is met, or the timeout is exceeded.
14
- *
15
- * @param condition A function that returns a boolean or a promise that resolves to a boolean
16
- * @param interval The interval in milliseconds to wait between checks
17
- * @param timeoutMs The maximum time in milliseconds to wait before throwing an error
18
- */
19
- declare function pollUntil(condition: () => boolean | Promise<boolean>, interval?: number, timeoutMs?: number): Promise<void>;
20
- /**
21
- * Wraps a promise with a timeout. If the promise does not resolve within the specified time, an error is thrown.
22
- *
23
- * @param promise The promise to wrap with a timeout
24
- * @param ms The number of milliseconds to wait before timing out
25
- *
26
- * @returns The result of the promise if it resolves before the timeout, otherwise throws an error
27
- */
28
- declare function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T>;
29
- /**
30
- * Waits for all promises to settle and returns an array of successful results.
31
- *
32
- * @param promises An array of promises to wait for
33
- * @returns A promise that resolves to an array of successful results
34
- */
35
- declare function allSettledSuccessful<T>(promises: Promise<T>[]): Promise<T[]>;
36
- /**
37
- * Executes an array of asynchronous tasks sequentially.
38
- *
39
- * @param tasks An array of functions that return promises
40
- * @returns A promise that resolves to an array of results from the input tasks
41
- */
42
- declare function sequential<T>(tasks: (() => Promise<T>)[]): Promise<T[]>;
43
- //#endregion
44
- export { allSettledSuccessful, pollUntil, rejectionTimeout, sequential, timeout, withTimeout };
package/dist/async.mjs DELETED
@@ -1 +0,0 @@
1
- function e(e){return new Promise(t=>setTimeout(t,e))}function t(e){return new Promise((t,n)=>setTimeout(n,e))}async function n(t,n=100,r=5e3){let i=Date.now();for(;!await t();){if(Date.now()-i>r)throw Error(`Timeout exceeded`);await e(n)}}async function r(e,t){let n;try{return await Promise.race([e,new Promise((e,r)=>{n=setTimeout(()=>r(Error(`Operation timed out`)),t)})])}finally{n!==void 0&&clearTimeout(n)}}async function i(e){return(await Promise.allSettled(e)).filter(e=>e.status===`fulfilled`).map(e=>e.value)}async function a(e){let t=[];for(let n of e)t.push(await n());return t}export{i as allSettledSuccessful,n as pollUntil,t as rejectionTimeout,a as sequential,e as timeout,r as withTimeout};
package/dist/queue.cjs DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class{items=[];head=0;constructor(e){e&&(this.items=[...e])}get size(){return this.items.length-this.head}get isEmpty(){return this.size===0}enqueue(e){this.items.push(e)}dequeue(){if(this.head>=this.items.length)return;let e=this.items[this.head++];return this.head>=64&&this.head*2>=this.items.length&&(this.items=this.items.slice(this.head),this.head=0),e}peek(){return this.items[this.head]}clear(){this.items=[],this.head=0}[Symbol.iterator](){return this.toArray()[Symbol.iterator]()}toArray(){return this.items.slice(this.head)}};exports.Queue=e;
package/dist/queue.mjs DELETED
@@ -1 +0,0 @@
1
- var e=class{items=[];head=0;constructor(e){e&&(this.items=[...e])}get size(){return this.items.length-this.head}get isEmpty(){return this.size===0}enqueue(e){this.items.push(e)}dequeue(){if(this.head>=this.items.length)return;let e=this.items[this.head++];return this.head>=64&&this.head*2>=this.items.length&&(this.items=this.items.slice(this.head),this.head=0),e}peek(){return this.items[this.head]}clear(){this.items=[],this.head=0}[Symbol.iterator](){return this.toArray()[Symbol.iterator]()}toArray(){return this.items.slice(this.head)}};export{e as Queue};
package/dist/types.cjs DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=e=>e;function t(e){}function n(e){return Object.entries(e)}exports.assume=t,exports.cast=e,exports.typedEntries=n;
package/dist/types.d.cts DELETED
@@ -1,9 +0,0 @@
1
- //#region src/types.d.ts
2
- type Awaitable<T> = PromiseLike<T> | T;
3
- type Maybe<T> = T | undefined;
4
- type Nullable<T> = T | null;
5
- declare const cast: <T, U extends T>(value: U) => U;
6
- declare function assume<T>(value: unknown): asserts value is T;
7
- declare function typedEntries<T extends object>(obj: T): { [K in keyof T]: [K, T[K]] }[keyof T][];
8
- //#endregion
9
- export { Awaitable, Maybe, Nullable, assume, cast, typedEntries };
package/dist/types.d.mts DELETED
@@ -1,9 +0,0 @@
1
- //#region src/types.d.ts
2
- type Awaitable<T> = PromiseLike<T> | T;
3
- type Maybe<T> = T | undefined;
4
- type Nullable<T> = T | null;
5
- declare const cast: <T, U extends T>(value: U) => U;
6
- declare function assume<T>(value: unknown): asserts value is T;
7
- declare function typedEntries<T extends object>(obj: T): { [K in keyof T]: [K, T[K]] }[keyof T][];
8
- //#endregion
9
- export { Awaitable, Maybe, Nullable, assume, cast, typedEntries };
package/dist/types.mjs DELETED
@@ -1 +0,0 @@
1
- const e=e=>e;function t(e){}function n(e){return Object.entries(e)}export{t as assume,e as cast,n as typedEntries};
package/dist/urllib.cjs DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(t,n,r){if(r!=null){if(Array.isArray(r)){for(let i of r)e(t,n,i);return}if(typeof r==`object`){try{t.append(n,JSON.stringify(r))}catch{t.append(n,String(r))}return}t.append(n,String(r))}}var t=class t{#e;constructor(e,n){e instanceof t||e instanceof URL?this.#e=new URL(e.toString()):n?this.#e=new URL(e,n.toString()):this.#e=new URL(e)}get protocol(){return this.#e.protocol}get host(){return this.#e.host}get hostname(){return this.#e.hostname}get port(){return this.#e.port}get origin(){return this.#e.origin}get username(){return this.#e.username}get password(){return this.#e.password}get hash(){return this.#e.hash}get search(){return this.#e.search}get searchParams(){return new URLSearchParams(this.#e.search)}get pathname(){return this.#e.pathname}get parts(){return this.#e.pathname.split(`/`).filter(Boolean).map(decodeURIComponent)}get name(){return this.parts.at(-1)??``}get suffix(){let e=this.name,t=e.lastIndexOf(`.`);return t>=0?e.slice(t):``}get stem(){let e=this.name,t=e.lastIndexOf(`.`);return t>=0?e.slice(0,t):e}get parent(){let e=this.parts.slice(0,-1);return this.withPath(e)}joinpath(...e){let t=[...this.parts,...e.map(e=>e.replace(/^\/+|\/+$/g,``))];return this.withPath(t)}div(...e){return this.joinpath(...e)}withPath(e){let n=new URL(this.#e.toString());return n.pathname=`/`+e.map(encodeURIComponent).join(`/`),new t(n)}withQuery(n){let r=new URL(this.#e.toString());for(let[t,i]of Object.entries(n))r.searchParams.delete(t),e(r.searchParams,t,i);return new t(r)}withoutQuery(...e){let n=new URL(this.#e.toString());for(let t of e)n.searchParams.delete(t);return new t(n)}withHash(e){let n=new URL(this.#e.toString());return n.hash=e.startsWith(`#`)?e:`#${e}`,new t(n)}withoutHash(){let e=new URL(this.#e.toString());return e.hash=``,new t(e)}async fetch(e){return fetch(this.#e,e)}resolve(e){return new t(e,this)}equals(e){return this.toString()===new t(e).toString()}toURL(){return new URL(this.#e.toString())}toString(){return this.#e.toString()}valueOf(){return this.toString()}[Symbol.toPrimitive](){return this.toString()}static from(e,n){return new t(e,n)}static parse(e){return new t(e)}};exports.URLPath=t;
package/dist/urllib.mjs DELETED
@@ -1 +0,0 @@
1
- function e(t,n,r){if(r!=null){if(Array.isArray(r)){for(let i of r)e(t,n,i);return}if(typeof r==`object`){try{t.append(n,JSON.stringify(r))}catch{t.append(n,String(r))}return}t.append(n,String(r))}}var t=class t{#e;constructor(e,n){e instanceof t||e instanceof URL?this.#e=new URL(e.toString()):n?this.#e=new URL(e,n.toString()):this.#e=new URL(e)}get protocol(){return this.#e.protocol}get host(){return this.#e.host}get hostname(){return this.#e.hostname}get port(){return this.#e.port}get origin(){return this.#e.origin}get username(){return this.#e.username}get password(){return this.#e.password}get hash(){return this.#e.hash}get search(){return this.#e.search}get searchParams(){return new URLSearchParams(this.#e.search)}get pathname(){return this.#e.pathname}get parts(){return this.#e.pathname.split(`/`).filter(Boolean).map(decodeURIComponent)}get name(){return this.parts.at(-1)??``}get suffix(){let e=this.name,t=e.lastIndexOf(`.`);return t>=0?e.slice(t):``}get stem(){let e=this.name,t=e.lastIndexOf(`.`);return t>=0?e.slice(0,t):e}get parent(){let e=this.parts.slice(0,-1);return this.withPath(e)}joinpath(...e){let t=[...this.parts,...e.map(e=>e.replace(/^\/+|\/+$/g,``))];return this.withPath(t)}div(...e){return this.joinpath(...e)}withPath(e){let n=new URL(this.#e.toString());return n.pathname=`/`+e.map(encodeURIComponent).join(`/`),new t(n)}withQuery(n){let r=new URL(this.#e.toString());for(let[t,i]of Object.entries(n))r.searchParams.delete(t),e(r.searchParams,t,i);return new t(r)}withoutQuery(...e){let n=new URL(this.#e.toString());for(let t of e)n.searchParams.delete(t);return new t(n)}withHash(e){let n=new URL(this.#e.toString());return n.hash=e.startsWith(`#`)?e:`#${e}`,new t(n)}withoutHash(){let e=new URL(this.#e.toString());return e.hash=``,new t(e)}async fetch(e){return fetch(this.#e,e)}resolve(e){return new t(e,this)}equals(e){return this.toString()===new t(e).toString()}toURL(){return new URL(this.#e.toString())}toString(){return this.#e.toString()}valueOf(){return this.toString()}[Symbol.toPrimitive](){return this.toString()}static from(e,n){return new t(e,n)}static parse(e){return new t(e)}};export{t as URLPath};
File without changes
File without changes