@depthbomb/common 1.3.0 → 1.3.2

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/dist/async.cjs CHANGED
@@ -1 +1 @@
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){return Promise.race([e,new Promise((e,n)=>setTimeout(()=>n(Error(`Operation timed out`)),t))])}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;
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.mjs CHANGED
@@ -1 +1 @@
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){return Promise.race([e,new Promise((e,n)=>setTimeout(()=>n(Error(`Operation timed out`)),t))])}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};
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};
@@ -1 +1 @@
1
- function e(e){let t=new WeakMap,n=0;function r(e){let i=typeof e;return e===null||i===`number`||i===`string`||i===`boolean`?e:i===`undefined`?`undefined`:i===`function`?`function:${e.name||`anon`}`:e instanceof Date?`date:${e.toISOString()}`:e instanceof RegExp?`regexp:${e.toString()}`:Array.isArray(e)?e.map(r):e instanceof Map?{map:[...e.entries()].map(([e,t])=>[r(e),r(t)])}:e instanceof Set?{set:[...e.values()].map(r).sort()}:typeof e==`object`?t.has(e)?{ref:t.get(e)}:(t.set(e,n++),{obj:Object.entries(e).sort(([e],[t])=>e<t?-1:1).map(([e,t])=>[e,r(t)])}):e}return JSON.stringify(e.map(r))}function t(t){return function(n,r){let i=new WeakMap;return async function(...r){let a=Date.now(),o=i.get(this);o||(o=new Map,i.set(this,o));let s=e(r),c=o.get(s);if(c&&c.expiry>a)return c.value;let l=n.apply(this,r),u=l instanceof Promise?await l:l;return o.set(s,{value:u,expiry:a+t}),u}}}exports.cache=t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=new WeakMap;let t=0;function n(n){let r=new WeakMap,i=0;function a(n){let o=typeof n;if(n===null||o===`number`||o===`string`||o===`boolean`)return n;if(o===`undefined`)return`undefined`;if(o===`bigint`)return`bigint:${n.toString()}`;if(o===`function`){let r=e.get(n);return r===void 0&&(r=t++,e.set(n,r)),{fn:r,name:n.name||`anon`}}return n instanceof Date?`date:${n.toISOString()}`:n instanceof RegExp?`regexp:${n.toString()}`:Array.isArray(n)?n.map(a):n instanceof Map?{map:[...n.entries()].map(([e,t])=>[a(e),a(t)])}:n instanceof Set?{set:[...n.values()].map(a).sort()}:typeof n==`object`?r.has(n)?{ref:r.get(n)}:(r.set(n,i++),{obj:Object.entries(n).sort(([e],[t])=>e<t?-1:1).map(([e,t])=>[e,a(t)])}):n}return JSON.stringify(n.map(a))}function r(e){return function(t,r){let i=new WeakMap;return function(...r){let a=Date.now(),o=i.get(this);if(o||(o={entries:new Map,calls:0},i.set(this,o)),o.calls++,o.calls%64==0&&o.entries.size>0)for(let[e,t]of o.entries)t.expiry<=a&&o.entries.delete(e);let s=n(r),c=o.entries.get(s);if(c&&c.expiry>a)return c.value;c&&o.entries.delete(s);let l=t.apply(this,r);if(l instanceof Promise){let t=l.catch(e=>{throw o.entries.delete(s),e});return o.entries.set(s,{value:t,expiry:a+e}),t}return o.entries.set(s,{value:l,expiry:a+e}),l}}}exports.cache=r;
@@ -5,6 +5,6 @@
5
5
  *
6
6
  * @param ttlMs How long the cached value should be returned after its last call in milliseconds.
7
7
  */
8
- declare function cache(ttlMs: number): <T extends object>(method: (this: T, ...args: any[]) => any, _ctx: ClassMethodDecoratorContext<T>) => (this: T, ...args: any[]) => Promise<any>;
8
+ declare function cache(ttlMs: number): <T extends object, Args extends any[], R>(method: (this: T, ...args: Args) => R, _ctx: ClassMethodDecoratorContext<T, (this: T, ...args: Args) => R>) => (this: T, ...args: Args) => R;
9
9
  //#endregion
10
10
  export { cache };
@@ -5,6 +5,6 @@
5
5
  *
6
6
  * @param ttlMs How long the cached value should be returned after its last call in milliseconds.
7
7
  */
8
- declare function cache(ttlMs: number): <T extends object>(method: (this: T, ...args: any[]) => any, _ctx: ClassMethodDecoratorContext<T>) => (this: T, ...args: any[]) => Promise<any>;
8
+ declare function cache(ttlMs: number): <T extends object, Args extends any[], R>(method: (this: T, ...args: Args) => R, _ctx: ClassMethodDecoratorContext<T, (this: T, ...args: Args) => R>) => (this: T, ...args: Args) => R;
9
9
  //#endregion
10
10
  export { cache };
@@ -1 +1 @@
1
- function e(e){let t=new WeakMap,n=0;function r(e){let i=typeof e;return e===null||i===`number`||i===`string`||i===`boolean`?e:i===`undefined`?`undefined`:i===`function`?`function:${e.name||`anon`}`:e instanceof Date?`date:${e.toISOString()}`:e instanceof RegExp?`regexp:${e.toString()}`:Array.isArray(e)?e.map(r):e instanceof Map?{map:[...e.entries()].map(([e,t])=>[r(e),r(t)])}:e instanceof Set?{set:[...e.values()].map(r).sort()}:typeof e==`object`?t.has(e)?{ref:t.get(e)}:(t.set(e,n++),{obj:Object.entries(e).sort(([e],[t])=>e<t?-1:1).map(([e,t])=>[e,r(t)])}):e}return JSON.stringify(e.map(r))}function t(t){return function(n,r){let i=new WeakMap;return async function(...r){let a=Date.now(),o=i.get(this);o||(o=new Map,i.set(this,o));let s=e(r),c=o.get(s);if(c&&c.expiry>a)return c.value;let l=n.apply(this,r),u=l instanceof Promise?await l:l;return o.set(s,{value:u,expiry:a+t}),u}}}export{t as cache};
1
+ const e=new WeakMap;let t=0;function n(n){let r=new WeakMap,i=0;function a(n){let o=typeof n;if(n===null||o===`number`||o===`string`||o===`boolean`)return n;if(o===`undefined`)return`undefined`;if(o===`bigint`)return`bigint:${n.toString()}`;if(o===`function`){let r=e.get(n);return r===void 0&&(r=t++,e.set(n,r)),{fn:r,name:n.name||`anon`}}return n instanceof Date?`date:${n.toISOString()}`:n instanceof RegExp?`regexp:${n.toString()}`:Array.isArray(n)?n.map(a):n instanceof Map?{map:[...n.entries()].map(([e,t])=>[a(e),a(t)])}:n instanceof Set?{set:[...n.values()].map(a).sort()}:typeof n==`object`?r.has(n)?{ref:r.get(n)}:(r.set(n,i++),{obj:Object.entries(n).sort(([e],[t])=>e<t?-1:1).map(([e,t])=>[e,a(t)])}):n}return JSON.stringify(n.map(a))}function r(e){return function(t,r){let i=new WeakMap;return function(...r){let a=Date.now(),o=i.get(this);if(o||(o={entries:new Map,calls:0},i.set(this,o)),o.calls++,o.calls%64==0&&o.entries.size>0)for(let[e,t]of o.entries)t.expiry<=a&&o.entries.delete(e);let s=n(r),c=o.entries.get(s);if(c&&c.expiry>a)return c.value;c&&o.entries.delete(s);let l=t.apply(this,r);if(l instanceof Promise){let t=l.catch(e=>{throw o.entries.delete(s),e});return o.entries.set(s,{value:t,expiry:a+e}),t}return o.entries.set(s,{value:l,expiry:a+e}),l}}}export{r as cache};
package/dist/fn.cjs CHANGED
@@ -1 +1 @@
1
- function e(e){let t=!1,n;return((...r)=>(t||=(n=e(...r),!0),n))}exports.once=e;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){let t=!1,n;return((...r)=>(t||=(n=e(...r),!0),n))}exports.once=e;
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- const e=require(`./async.cjs`),t=require(`./decorators.cjs`),n=require(`./fn.cjs`),r=require(`./lazy.cjs`),i=require(`./queue.cjs`),a=require(`./types.cjs`),o=require(`./urllib.cjs`);exports.Queue=i.Queue,exports.URLPath=o.URLPath,exports.allSettledSuccessful=e.allSettledSuccessful,exports.assume=a.assume,exports.cache=t.cache,exports.cast=a.cast,exports.lazy=r.lazy,exports.lazyAsync=r.lazyAsync,exports.once=n.once,exports.pollUntil=e.pollUntil,exports.rejectionTimeout=e.rejectionTimeout,exports.resettableLazy=r.resettableLazy,exports.sequential=e.sequential,exports.timeout=e.timeout,exports.typedEntries=a.typedEntries,exports.withTimeout=e.withTimeout;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./async.cjs`),t=require(`./decorators.cjs`),n=require(`./fn.cjs`),r=require(`./lazy.cjs`),i=require(`./queue.cjs`),a=require(`./types.cjs`),o=require(`./urllib.cjs`);exports.Queue=i.Queue,exports.URLPath=o.URLPath,exports.allSettledSuccessful=e.allSettledSuccessful,exports.assume=a.assume,exports.cache=t.cache,exports.cast=a.cast,exports.lazy=r.lazy,exports.lazyAsync=r.lazyAsync,exports.once=n.once,exports.pollUntil=e.pollUntil,exports.rejectionTimeout=e.rejectionTimeout,exports.resettableLazy=r.resettableLazy,exports.sequential=e.sequential,exports.timeout=e.timeout,exports.typedEntries=a.typedEntries,exports.withTimeout=e.withTimeout;
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ import { allSettledSuccessful, pollUntil, rejectionTimeout, sequential, timeout,
2
2
  import { cache } from "./decorators.cjs";
3
3
  import { once } from "./fn.cjs";
4
4
  import { lazy, lazyAsync, resettableLazy } from "./lazy.cjs";
5
- import { Queue } from "./queue.cjs";
6
5
  import { Awaitable, Maybe, Nullable, assume, cast, typedEntries } from "./types.cjs";
7
- import { URLLike, URLPath } from "./urllib.cjs";
8
- export { Awaitable, Maybe, Nullable, Queue, URLLike, URLPath, allSettledSuccessful, assume, cache, cast, lazy, lazyAsync, once, pollUntil, rejectionTimeout, resettableLazy, sequential, timeout, typedEntries, withTimeout };
6
+ import { Queue } from "./queue.cjs";
7
+ import { QueryObject, QueryValue, URLLike, URLPath } from "./urllib.cjs";
8
+ export { Awaitable, Maybe, Nullable, QueryObject, QueryValue, Queue, URLLike, URLPath, allSettledSuccessful, assume, cache, cast, lazy, lazyAsync, once, pollUntil, rejectionTimeout, resettableLazy, sequential, timeout, typedEntries, withTimeout };
package/dist/index.d.mts CHANGED
@@ -2,7 +2,7 @@ import { allSettledSuccessful, pollUntil, rejectionTimeout, sequential, timeout,
2
2
  import { cache } from "./decorators.mjs";
3
3
  import { once } from "./fn.mjs";
4
4
  import { lazy, lazyAsync, resettableLazy } from "./lazy.mjs";
5
- import { Queue } from "./queue.mjs";
6
5
  import { Awaitable, Maybe, Nullable, assume, cast, typedEntries } from "./types.mjs";
7
- import { URLLike, URLPath } from "./urllib.mjs";
8
- export { Awaitable, Maybe, Nullable, Queue, URLLike, URLPath, allSettledSuccessful, assume, cache, cast, lazy, lazyAsync, once, pollUntil, rejectionTimeout, resettableLazy, sequential, timeout, typedEntries, withTimeout };
6
+ import { Queue } from "./queue.mjs";
7
+ import { QueryObject, QueryValue, URLLike, URLPath } from "./urllib.mjs";
8
+ export { Awaitable, Maybe, Nullable, QueryObject, QueryValue, Queue, URLLike, URLPath, allSettledSuccessful, assume, cache, cast, lazy, lazyAsync, once, pollUntil, rejectionTimeout, resettableLazy, sequential, timeout, typedEntries, withTimeout };
package/dist/lazy.cjs CHANGED
@@ -1 +1 @@
1
- function e(e){let t,n=!1;return()=>(n||=(t=e(),!0),t)}function t(e){let t;return()=>(t||=e(),t)}function n(e){let t,n=!1;function r(){return n||=(t=e(),!0),t}function i(){n=!1,t=void 0}return{get:r,reset:i}}exports.lazy=e,exports.lazyAsync=t,exports.resettableLazy=n;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){let t,n=!1;return()=>(n||=(t=e(),!0),t)}function t(e){let t;return()=>(t||=e(),t)}function n(e){let t,n=!1;function r(){return n||=(t=e(),!0),t}function i(){n=!1,t=void 0}return{get:r,reset:i}}exports.lazy=e,exports.lazyAsync=t,exports.resettableLazy=n;
package/dist/queue.cjs CHANGED
@@ -1 +1 @@
1
- var e=class{items=[];constructor(e){e&&(this.items=[...e])}get size(){return this.items.length}get isEmpty(){return this.items.length===0}enqueue(e){this.items.push(e)}dequeue(){return this.items.shift()}peek(){return this.items[0]}clear(){this.items=[]}[Symbol.iterator](){return this.items[Symbol.iterator]()}toArray(){return[...this.items]}};exports.Queue=e;
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.d.cts CHANGED
@@ -1,6 +1,9 @@
1
+ import { Maybe } from "./types.cjs";
2
+
1
3
  //#region src/queue.d.ts
2
4
  declare class Queue<T> {
3
5
  private items;
6
+ private head;
4
7
  constructor(initial?: Iterable<T>);
5
8
  /**
6
9
  * Get the number of items in the queue.
@@ -21,13 +24,13 @@ declare class Queue<T> {
21
24
  *
22
25
  * @returns The item at the front of the queue, or undefined if the queue is empty
23
26
  */
24
- dequeue(): T | undefined;
27
+ dequeue(): Maybe<T>;
25
28
  /**
26
29
  * Return the item at the front of the queue without removing it.
27
30
  *
28
31
  * @returns The item at the front of the queue without removing it, or undefined if the queue is empty
29
32
  */
30
- peek(): T | undefined;
33
+ peek(): Maybe<T>;
31
34
  /**
32
35
  * Clear all items from the queue.
33
36
  */
package/dist/queue.d.mts CHANGED
@@ -1,6 +1,9 @@
1
+ import { Maybe } from "./types.mjs";
2
+
1
3
  //#region src/queue.d.ts
2
4
  declare class Queue<T> {
3
5
  private items;
6
+ private head;
4
7
  constructor(initial?: Iterable<T>);
5
8
  /**
6
9
  * Get the number of items in the queue.
@@ -21,13 +24,13 @@ declare class Queue<T> {
21
24
  *
22
25
  * @returns The item at the front of the queue, or undefined if the queue is empty
23
26
  */
24
- dequeue(): T | undefined;
27
+ dequeue(): Maybe<T>;
25
28
  /**
26
29
  * Return the item at the front of the queue without removing it.
27
30
  *
28
31
  * @returns The item at the front of the queue without removing it, or undefined if the queue is empty
29
32
  */
30
- peek(): T | undefined;
33
+ peek(): Maybe<T>;
31
34
  /**
32
35
  * Clear all items from the queue.
33
36
  */
package/dist/queue.mjs CHANGED
@@ -1 +1 @@
1
- var e=class{items=[];constructor(e){e&&(this.items=[...e])}get size(){return this.items.length}get isEmpty(){return this.items.length===0}enqueue(e){this.items.push(e)}dequeue(){return this.items.shift()}peek(){return this.items[0]}clear(){this.items=[]}[Symbol.iterator](){return this.items[Symbol.iterator]()}toArray(){return[...this.items]}};export{e as Queue};
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 CHANGED
@@ -1 +1 @@
1
- const e=e=>e;function t(e){}function n(e){return Object.entries(e)}exports.assume=t,exports.cast=e,exports.typedEntries=n;
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/urllib.cjs CHANGED
@@ -1 +1 @@
1
- var e=class e{#e;constructor(t,n){t instanceof e||t instanceof URL?this.#e=new URL(t.toString()):n?this.#e=new URL(t,n.toString()):this.#e=new URL(t)}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(t){let n=new URL(this.#e.toString());return n.pathname=`/`+t.map(encodeURIComponent).join(`/`),new e(n)}withQuery(t){let n=new URL(this.#e.toString());for(let[e,r]of Object.entries(t))r==null?n.searchParams.delete(e):n.searchParams.set(e,String(r));return new e(n)}withoutQuery(...t){let n=new URL(this.#e.toString());for(let e of t)n.searchParams.delete(e);return new e(n)}withHash(t){let n=new URL(this.#e.toString());return n.hash=t.startsWith(`#`)?t:`#${t}`,new e(n)}withoutHash(){let t=new URL(this.#e.toString());return t.hash=``,new e(t)}async fetch(e){return fetch(this.#e,e)}resolve(t){return new e(t,this)}equals(t){return this.toString()===new e(t).toString()}toURL(){return new URL(this.#e.toString())}toString(){return this.#e.toString()}valueOf(){return this.toString()}[Symbol.toPrimitive](){return this.toString()}static from(t,n){return new e(t,n)}static parse(t){return new e(t)}};exports.URLPath=e;
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.d.cts CHANGED
@@ -1,5 +1,7 @@
1
1
  //#region src/urllib.d.ts
2
2
  type URLLike = string | URL | URLPath;
3
+ type QueryValue = string | number | undefined | null | boolean | Array<QueryValue> | Record<string, any>;
4
+ type QueryObject = Record<string, QueryValue | QueryValue[]>;
3
5
  declare class URLPath {
4
6
  #private;
5
7
  constructor(input: URLLike, base?: URLLike);
@@ -22,7 +24,7 @@ declare class URLPath {
22
24
  joinpath(...segments: string[]): URLPath;
23
25
  div(...segments: string[]): URLPath;
24
26
  private withPath;
25
- withQuery(params: Record<string, string | number | boolean | null | undefined>): URLPath;
27
+ withQuery(params: QueryObject): URLPath;
26
28
  withoutQuery(...keys: string[]): URLPath;
27
29
  withHash(hash: string): URLPath;
28
30
  withoutHash(): URLPath;
@@ -37,4 +39,4 @@ declare class URLPath {
37
39
  static parse(input: string): URLPath;
38
40
  }
39
41
  //#endregion
40
- export { URLLike, URLPath };
42
+ export { QueryObject, QueryValue, URLLike, URLPath };
package/dist/urllib.d.mts CHANGED
@@ -1,5 +1,7 @@
1
1
  //#region src/urllib.d.ts
2
2
  type URLLike = string | URL | URLPath;
3
+ type QueryValue = string | number | undefined | null | boolean | Array<QueryValue> | Record<string, any>;
4
+ type QueryObject = Record<string, QueryValue | QueryValue[]>;
3
5
  declare class URLPath {
4
6
  #private;
5
7
  constructor(input: URLLike, base?: URLLike);
@@ -22,7 +24,7 @@ declare class URLPath {
22
24
  joinpath(...segments: string[]): URLPath;
23
25
  div(...segments: string[]): URLPath;
24
26
  private withPath;
25
- withQuery(params: Record<string, string | number | boolean | null | undefined>): URLPath;
27
+ withQuery(params: QueryObject): URLPath;
26
28
  withoutQuery(...keys: string[]): URLPath;
27
29
  withHash(hash: string): URLPath;
28
30
  withoutHash(): URLPath;
@@ -37,4 +39,4 @@ declare class URLPath {
37
39
  static parse(input: string): URLPath;
38
40
  }
39
41
  //#endregion
40
- export { URLLike, URLPath };
42
+ export { QueryObject, QueryValue, URLLike, URLPath };
package/dist/urllib.mjs CHANGED
@@ -1 +1 @@
1
- var e=class e{#e;constructor(t,n){t instanceof e||t instanceof URL?this.#e=new URL(t.toString()):n?this.#e=new URL(t,n.toString()):this.#e=new URL(t)}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(t){let n=new URL(this.#e.toString());return n.pathname=`/`+t.map(encodeURIComponent).join(`/`),new e(n)}withQuery(t){let n=new URL(this.#e.toString());for(let[e,r]of Object.entries(t))r==null?n.searchParams.delete(e):n.searchParams.set(e,String(r));return new e(n)}withoutQuery(...t){let n=new URL(this.#e.toString());for(let e of t)n.searchParams.delete(e);return new e(n)}withHash(t){let n=new URL(this.#e.toString());return n.hash=t.startsWith(`#`)?t:`#${t}`,new e(n)}withoutHash(){let t=new URL(this.#e.toString());return t.hash=``,new e(t)}async fetch(e){return fetch(this.#e,e)}resolve(t){return new e(t,this)}equals(t){return this.toString()===new e(t).toString()}toURL(){return new URL(this.#e.toString())}toString(){return this.#e.toString()}valueOf(){return this.toString()}[Symbol.toPrimitive](){return this.toString()}static from(t,n){return new e(t,n)}static parse(t){return new e(t)}};export{e as URLPath};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depthbomb/common",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "A set of common utilities for TypeScript/JavaScript",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -12,36 +12,36 @@
12
12
  ],
13
13
  "exports": {
14
14
  ".": {
15
- "require": "./dist/index.cjs",
16
- "import": "./dist/index.mjs"
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.cjs"
17
17
  },
18
18
  "./async": {
19
- "require": "./dist/async.cjs",
20
- "import": "./dist/async.mjs"
19
+ "import": "./dist/async.mjs",
20
+ "require": "./dist/async.cjs"
21
21
  },
22
22
  "./decorators": {
23
- "require": "./dist/decorators.cjs",
24
- "import": "./dist/decorators.mjs"
23
+ "import": "./dist/decorators.mjs",
24
+ "require": "./dist/decorators.cjs"
25
25
  },
26
26
  "./fn": {
27
- "require": "./dist/fn.cjs",
28
- "import": "./dist/fn.mjs"
27
+ "import": "./dist/fn.mjs",
28
+ "require": "./dist/fn.cjs"
29
29
  },
30
30
  "./lazy": {
31
- "require": "./dist/lazy.cjs",
32
- "import": "./dist/lazy.mjs"
31
+ "import": "./dist/lazy.mjs",
32
+ "require": "./dist/lazy.cjs"
33
33
  },
34
34
  "./queue": {
35
- "require": "./dist/queue.cjs",
36
- "import": "./dist/queue.mjs"
35
+ "import": "./dist/queue.mjs",
36
+ "require": "./dist/queue.cjs"
37
37
  },
38
38
  "./types": {
39
- "require": "./dist/types.cjs",
40
- "import": "./dist/types.mjs"
39
+ "import": "./dist/types.mjs",
40
+ "require": "./dist/types.cjs"
41
41
  },
42
42
  "./urllib": {
43
- "require": "./dist/urllib.cjs",
44
- "import": "./dist/urllib.mjs"
43
+ "import": "./dist/urllib.mjs",
44
+ "require": "./dist/urllib.cjs"
45
45
  }
46
46
  },
47
47
  "main": "./dist/index.cjs",
@@ -65,17 +65,19 @@
65
65
  "build": "tsc",
66
66
  "dist": "tsdown",
67
67
  "release": "yarn dist && release-it",
68
- "lint": "eslint ./src --ext .ts"
68
+ "lint": "eslint ./src --ext .ts",
69
+ "test": "vitest"
69
70
  },
70
71
  "devDependencies": {
71
72
  "@types/eslint": "^9.6.1",
72
- "@types/node": "^24.10.9",
73
- "@typescript-eslint/eslint-plugin": "^8.54.0",
74
- "@typescript-eslint/parser": "^8.54.0",
75
- "eslint": "^9.39.2",
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",
76
77
  "release-it": "^19.2.4",
77
- "tsdown": "^0.20.1",
78
- "typescript": "^5.9.3"
78
+ "tsdown": "^0.20.3",
79
+ "typescript": "^5.9.3",
80
+ "vitest": "^4.0.18"
79
81
  },
80
82
  "packageManager": "yarn@4.12.0"
81
83
  }