foxts 4.3.1 → 4.5.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.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The only use case I have thought of so far would be @typescript-eslint/await-thenable banning
3
+ *
4
+ * `await Promise.all(Array<Promise | null | undefined>)`
5
+ *
6
+ * So instead of `.filter(not('nullish'))` which need to iterate through array, we use this when pushing
7
+ * things to array in the first place
8
+ */
9
+ declare function arrayPushNonNullish<T>(arr: T[], itemOrItems: T | null | undefined | Array<T | null | undefined>): void;
10
+
11
+ export { arrayPushNonNullish };
@@ -0,0 +1 @@
1
+ "use strict";exports.arrayPushNonNullish=function(s,l){if(Array.isArray(l))for(let r=0,u=l.length;r<u;r++){const u=l[r];null!=u&&s.push(u)}else null!=l&&s.push(l)};
@@ -0,0 +1 @@
1
+ function l(l,r){if(Array.isArray(r))for(let n=0,s=r.length;n<s;n++){const s=r[n];null!=s&&l.push(s)}else null!=r&&l.push(r)}export{l as arrayPushNonNullish};
@@ -1,3 +1,4 @@
1
+ declare const E: ErrorConstructor;
1
2
  interface AsyncRetryContext {
2
3
  readonly error: unknown;
3
4
  readonly attemptNumber: number;
@@ -70,9 +71,9 @@ interface AsyncRetryOptions {
70
71
  */
71
72
  unref?: boolean;
72
73
  }
73
- declare class AsyncRetryAbortError extends Error {
74
+ declare class AsyncRetryAbortError extends E {
74
75
  name: string;
75
- cause: unknown;
76
+ cause?: unknown;
76
77
  constructor(message: string | Error | unknown);
77
78
  }
78
79
  declare function asyncRetry<T>(callback: (bail: (reason?: unknown) => void, attemptNumber: number) => PromiseLike<T> | T, retryOptions?: AsyncRetryOptions): Promise<T>;
@@ -1 +1 @@
1
- "use strict";var r=require("../abort-error/index.js"),t=require("../extract-error-message/index.js"),e=require("../is-network-error/index.js"),o=require("../noop/index.js");function i(r,t,{min:e=0,allowInfinity:o=!1}={}){if(Number.isNaN(t))throw TypeError(`Expected \`${r}\` to be a valid number${o?" or Infinity":""}, got NaN.`);if(!o&&!Number.isFinite(t))throw TypeError(`Expected \`${r}\` to be a finite number.`);if(t<e)throw TypeError(`Expected \`${r}\` to be \u2265 ${e}.`)}class n extends Error{name="AsyncRetryAbortError";cause;constructor(r){if(super("string"==typeof r?r:t.extractErrorMessage(r,!1)??"Aborted"),"string"==typeof r){const t=Error(r);t.stack=this.stack,this.cause=t}else r instanceof Error?(this.cause=r,this.message=r.message):this.cause=r}}async function a(t,o,i,a,s){if(t instanceof n)throw t.cause;if(t instanceof TypeError&&!e.isNetworkError(t)||r.isAbortErrorLike(t))throw t;const c=i.retries-(o-1),m={error:t,attemptNumber:o,retriesLeft:c};await i.onFailedAttempt(m),o>1&&await i.onRetry(t,o-1);const u=Date.now();if(u-a>=s||o>=i.retries+1||!await i.shouldRetry(m))throw t;let f=Math.round((i.randomize?Math.random()+1:1)*i.minTimeout*i.factor**(o-1));f=Math.min(f,i.maxTimeout);const l=s-(u-a);if(l<=0)throw t;const w=Math.min(f,l);w>0&&await new Promise((r,t)=>{const e=setTimeout(()=>{i.signal?.removeEventListener("abort",o),r()},w);function o(){clearTimeout(e),i.signal?.removeEventListener("abort",o),t(i.signal?.reason)}i.unref&&"object"==typeof e&&"unref"in e&&"function"==typeof e.unref&&e.unref(),i.signal?.addEventListener("abort",o,{once:!0})}),i.signal?.throwIfAborted()}function s(r){throw new n(r??"Aborted")}async function c(r,t={}){const e={...t};e.retries??=10,e.forever??=!1,e.factor??=2,e.minTimeout??=1e3,e.maxTimeout??=1/0,e.randomize??=!0,e.onFailedAttempt??=o.noop,e.onRetry??=o.noop,e.shouldRetry??=o.trueFn,e.forever&&(e.retries=1/0),i("retries",e.retries,{min:0,allowInfinity:!0}),i("factor",e.factor,{min:0,allowInfinity:!1}),i("minTimeout",e.minTimeout,{min:0,allowInfinity:!1}),i("maxTimeout",e.maxTimeout,{min:0,allowInfinity:!0});const m=e.maxRetryTime??1/0;i("maxRetryTime",m,{min:0,allowInfinity:!0}),e.minTimeout=Math.max(e.minTimeout,1),e.factor<=0&&(e.factor=1),e.signal?.throwIfAborted();let u=0;const f=Date.now();for(;u<e.retries+1;){u++;try{e.signal?.throwIfAborted();const t=await r(s,u);return e.signal?.throwIfAborted(),t}catch(t){let r=t;"object"==typeof t&&t&&"bail"in t&&t.bail&&(r=new n(t)),await a(r,u,e,f,m)}}throw Error("Retry attempts exhausted without throwing an error.")}exports.AsyncRetryAbortError=n,exports.asyncRetry=c,exports.makeRetriable=function(r,t){return function(...e){return c(()=>r.apply(this,e),t)}};
1
+ "use strict";var e=require("../abort-error/index.js"),t=require("../extract-error-message/index.js"),r=require("../is-network-error/index.js"),o=require("../noop/index.js");const{round:n}=Math,i=Error,s=TypeError;function a(e,t,r=0,o=!1){if(Number.isNaN(t))throw new s(`Expected \`${e}\` to be a valid number${o?" or Infinity":""}, got NaN.`);if(!o&&!Number.isFinite(t))throw new s(`Expected \`${e}\` to be a finite number.`);if(t<r)throw new s(`Expected \`${e}\` to be \u2265 ${r}.`)}class c extends i{name="AsyncRetryAbortError";cause;constructor(e){if(super("string"==typeof e?e:t.extractErrorMessage(e,!1)??"Aborted"),"string"==typeof e){const t=new i(e);t.stack=this.stack,this.cause=t}else e instanceof i?(this.cause=e,this.message=e.message):this.cause=e}}async function u(t,o,i,a,u){if(t instanceof c)throw t.cause;if(t instanceof s&&!r.isNetworkError(t)||e.isAbortErrorLike(t))throw t;const m=i.retries-(o-1),f={error:t,attemptNumber:o,retriesLeft:m};await i.onFailedAttempt(f),o>1&&await i.onRetry(t,o-1);const w=Date.now();if(w-a>=u||o>=i.retries+1||!await i.shouldRetry(f))throw t;let h=n((i.randomize?Math.random()+1:1)*i.minTimeout*i.factor**(o-1));h>i.maxTimeout&&(h=i.maxTimeout);const d=u-(w-a);if(d<=0)throw t;let b=h;h>d&&(b=d),b>0&&await new Promise((e,t)=>{const r=setTimeout(()=>{i.signal?.removeEventListener("abort",o),e()},b);function o(){clearTimeout(r),i.signal?.removeEventListener("abort",o),t(i.signal?.reason)}i.unref&&"object"==typeof r&&"unref"in r&&"function"==typeof r.unref&&r.unref(),i.signal?.addEventListener("abort",o,{once:!0})}),i.signal?.throwIfAborted()}function m(e){throw new c(e??"Aborted")}async function f(e,t={}){t.signal?.throwIfAborted();const r={...t};r.retries??=10,r.forever??=!1,r.factor??=2,r.minTimeout??=1e3,r.maxTimeout??=1/0,r.randomize??=!0,r.onFailedAttempt??=o.noop,r.onRetry??=o.noop,r.shouldRetry??=o.trueFn,r.forever&&(r.retries=1/0),a("retries",r.retries,0,!0),a("factor",r.factor,0,!1),a("minTimeout",r.minTimeout,0,!1),a("maxTimeout",r.maxTimeout,0,!0);const n=r.maxRetryTime??1/0;a("maxRetryTime",n,0,!0),r.minTimeout<1&&(r.minTimeout=1),r.factor<=0&&(r.factor=1);let s=0;const w=Date.now();for(;s<r.retries+1;){s++;try{r.signal?.throwIfAborted();const t=await e(m,s);return r.signal?.throwIfAborted(),t}catch(t){let e=t;"object"==typeof t&&t&&"bail"in t&&t.bail&&(e=new c(t)),await u(e,s,r,w,n)}}throw new i("Retry attempts exhausted without throwing an error.")}exports.AsyncRetryAbortError=c,exports.asyncRetry=f,exports.makeRetriable=function(e,t){return function(...r){return f(()=>e.apply(this,r),t)}};
@@ -1 +1 @@
1
- import{isAbortErrorLike as t}from"../abort-error/index.mjs";import{extractErrorMessage as r}from"../extract-error-message/index.mjs";import{isNetworkError as e}from"../is-network-error/index.mjs";import{noop as o,trueFn as i}from"../noop/index.mjs";function n(t,r,{min:e=0,allowInfinity:o=!1}={}){if(Number.isNaN(r))throw TypeError(`Expected \`${t}\` to be a valid number${o?" or Infinity":""}, got NaN.`);if(!o&&!Number.isFinite(r))throw TypeError(`Expected \`${t}\` to be a finite number.`);if(r<e)throw TypeError(`Expected \`${t}\` to be \u2265 ${e}.`)}class a extends Error{name="AsyncRetryAbortError";cause;constructor(t){if(super("string"==typeof t?t:r(t,!1)??"Aborted"),"string"==typeof t){const r=Error(t);r.stack=this.stack,this.cause=r}else t instanceof Error?(this.cause=t,this.message=t.message):this.cause=t}}async function s(r,o,i,n,s){if(r instanceof a)throw r.cause;if(r instanceof TypeError&&!e(r)||t(r))throw r;const m=i.retries-(o-1),c={error:r,attemptNumber:o,retriesLeft:m};await i.onFailedAttempt(c),o>1&&await i.onRetry(r,o-1);const f=Date.now();if(f-n>=s||o>=i.retries+1||!await i.shouldRetry(c))throw r;let u=Math.round((i.randomize?Math.random()+1:1)*i.minTimeout*i.factor**(o-1));u=Math.min(u,i.maxTimeout);const l=s-(f-n);if(l<=0)throw r;const w=Math.min(u,l);w>0&&await new Promise((t,r)=>{const e=setTimeout(()=>{i.signal?.removeEventListener("abort",o),t()},w);function o(){clearTimeout(e),i.signal?.removeEventListener("abort",o),r(i.signal?.reason)}i.unref&&"object"==typeof e&&"unref"in e&&"function"==typeof e.unref&&e.unref(),i.signal?.addEventListener("abort",o,{once:!0})}),i.signal?.throwIfAborted()}function m(t){throw new a(t??"Aborted")}async function c(t,r={}){const e={...r};e.retries??=10,e.forever??=!1,e.factor??=2,e.minTimeout??=1e3,e.maxTimeout??=1/0,e.randomize??=!0,e.onFailedAttempt??=o,e.onRetry??=o,e.shouldRetry??=i,e.forever&&(e.retries=1/0),n("retries",e.retries,{min:0,allowInfinity:!0}),n("factor",e.factor,{min:0,allowInfinity:!1}),n("minTimeout",e.minTimeout,{min:0,allowInfinity:!1}),n("maxTimeout",e.maxTimeout,{min:0,allowInfinity:!0});const f=e.maxRetryTime??1/0;n("maxRetryTime",f,{min:0,allowInfinity:!0}),e.minTimeout=Math.max(e.minTimeout,1),e.factor<=0&&(e.factor=1),e.signal?.throwIfAborted();let u=0;const l=Date.now();for(;u<e.retries+1;){u++;try{e.signal?.throwIfAborted();const r=await t(m,u);return e.signal?.throwIfAborted(),r}catch(r){let t=r;"object"==typeof r&&r&&"bail"in r&&r.bail&&(t=new a(r)),await s(t,u,e,l,f)}}throw Error("Retry attempts exhausted without throwing an error.")}function f(t,r){return function(...e){return c(()=>t.apply(this,e),r)}}export{a as AsyncRetryAbortError,c as asyncRetry,f as makeRetriable};
1
+ import{isAbortErrorLike as t}from"../abort-error/index.mjs";import{extractErrorMessage as e}from"../extract-error-message/index.mjs";import{isNetworkError as r}from"../is-network-error/index.mjs";import{noop as o,trueFn as n}from"../noop/index.mjs";const{round:i}=Math,a=Error,s=TypeError;function m(t,e,r=0,o=!1){if(Number.isNaN(e))throw new s(`Expected \`${t}\` to be a valid number${o?" or Infinity":""}, got NaN.`);if(!o&&!Number.isFinite(e))throw new s(`Expected \`${t}\` to be a finite number.`);if(e<r)throw new s(`Expected \`${t}\` to be \u2265 ${r}.`)}class c extends a{name="AsyncRetryAbortError";cause;constructor(t){if(super("string"==typeof t?t:e(t,!1)??"Aborted"),"string"==typeof t){const e=new a(t);e.stack=this.stack,this.cause=e}else t instanceof a?(this.cause=t,this.message=t.message):this.cause=t}}async function f(e,o,n,a,m){if(e instanceof c)throw e.cause;if(e instanceof s&&!r(e)||t(e))throw e;const f=n.retries-(o-1),u={error:e,attemptNumber:o,retriesLeft:f};await n.onFailedAttempt(u),o>1&&await n.onRetry(e,o-1);const w=Date.now();if(w-a>=m||o>=n.retries+1||!await n.shouldRetry(u))throw e;let h=i((n.randomize?Math.random()+1:1)*n.minTimeout*n.factor**(o-1));h>n.maxTimeout&&(h=n.maxTimeout);const d=m-(w-a);if(d<=0)throw e;let b=h;h>d&&(b=d),b>0&&await new Promise((t,e)=>{const r=setTimeout(()=>{n.signal?.removeEventListener("abort",o),t()},b);function o(){clearTimeout(r),n.signal?.removeEventListener("abort",o),e(n.signal?.reason)}n.unref&&"object"==typeof r&&"unref"in r&&"function"==typeof r.unref&&r.unref(),n.signal?.addEventListener("abort",o,{once:!0})}),n.signal?.throwIfAborted()}function u(t){throw new c(t??"Aborted")}async function w(t,e={}){e.signal?.throwIfAborted();const r={...e};r.retries??=10,r.forever??=!1,r.factor??=2,r.minTimeout??=1e3,r.maxTimeout??=1/0,r.randomize??=!0,r.onFailedAttempt??=o,r.onRetry??=o,r.shouldRetry??=n,r.forever&&(r.retries=1/0),m("retries",r.retries,0,!0),m("factor",r.factor,0,!1),m("minTimeout",r.minTimeout,0,!1),m("maxTimeout",r.maxTimeout,0,!0);const i=r.maxRetryTime??1/0;m("maxRetryTime",i,0,!0),r.minTimeout<1&&(r.minTimeout=1),r.factor<=0&&(r.factor=1);let s=0;const h=Date.now();for(;s<r.retries+1;){s++;try{r.signal?.throwIfAborted();const e=await t(u,s);return r.signal?.throwIfAborted(),e}catch(e){let t=e;"object"==typeof e&&e&&"bail"in e&&e.bail&&(t=new c(e)),await f(t,s,r,h,i)}}throw new a("Retry attempts exhausted without throwing an error.")}function h(t,e){return function(...r){return w(()=>t.apply(this,r),e)}}export{c as AsyncRetryAbortError,w as asyncRetry,h as makeRetriable};
@@ -0,0 +1,3 @@
1
+ declare function castArray<T>(value?: T | T[] | null): T[];
2
+
3
+ export { castArray };
@@ -0,0 +1 @@
1
+ "use strict";exports.castArray=function(r){return Array.isArray(r??=[])?r:[r]};
@@ -0,0 +1 @@
1
+ function r(r){return Array.isArray(r??=[])?r:[r]}export{r as castArray};
@@ -1 +1 @@
1
- "use strict";function r(r){switch(r){case null:return r=>null!==r;case void 0:return r=>void 0!==r;case!1:return r=>!1!==r;case"nullish":return r=>null!=r;case"falsy":return r=>!!r;default:l(r,"argument")}}function n(r){switch(r){case null:return r=>null===r;case void 0:return r=>void 0===r;case!1:return r=>!1===r;case"nullish":return r=>null==r;case"falsy":return r=>!r;case"truthy":return r=>!!r;default:l(r,"argument")}}const e=n("truthy"),t=n("falsy"),u=r(null),s=r("nullish");function l(r,n="value"){throw TypeError(`Unexpected ${n}: ${r} as ${JSON.stringify(typeof r)}, should be "never"`)}exports.invariant=function(r,n='[foxts/invariant] "value" is null or undefined'){if(null==r)throw TypeError(n)},exports.is=n,exports.isFalsy=t,exports.isNonNull=u,exports.isNonNullish=s,exports.isTruthy=e,exports.never=l,exports.not=r,exports.nullthrow=function(r,n='[foxts/invariant] "value" is null or undefined'){if(null==r)throw TypeError(n);return r};
1
+ "use strict";const r=r=>null!==r,e=r=>void 0!==r,n=r=>!1!==r,t=r=>null!=r,u=r=>!!r,s=r=>null===r,l=r=>void 0===r,o=r=>!1===r,i=r=>null==r,a=r=>!r,c=r=>!!r;function f(r,e="value"){throw TypeError(`Unexpected ${e}: ${r} as ${JSON.stringify(typeof r)}, should be "never"`)}exports.invariant=function(r,e='[foxts/invariant] "value" is null or undefined'){if(null==r)throw TypeError(e)},exports.is=function(r){switch(r){case null:return s;case void 0:return l;case!1:return o;case"nullish":return i;case"falsy":return a;case"truthy":return c;default:f(r,"argument")}},exports.isFalsy=a,exports.isNonNull=r,exports.isNonNullish=t,exports.isTruthy=c,exports.never=f,exports.not=function(s){switch(s){case null:return r;case void 0:return e;case!1:return n;case"nullish":return t;case"falsy":return u;default:f(s,"argument")}},exports.nullthrow=function(r,e='[foxts/invariant] "value" is null or undefined'){if(null==r)throw TypeError(e);return r};
@@ -1 +1 @@
1
- function n(n){switch(n){case null:return n=>null!==n;case void 0:return n=>void 0!==n;case!1:return n=>!1!==n;case"nullish":return n=>null!=n;case"falsy":return n=>!!n;default:a(n,"argument")}}function r(n){switch(n){case null:return n=>null===n;case void 0:return n=>void 0===n;case!1:return n=>!1===n;case"nullish":return n=>null==n;case"falsy":return n=>!n;case"truthy":return n=>!!n;default:a(n,"argument")}}const e=r("truthy"),u=r("falsy"),l=n(null),t=n("nullish");function i(n,r='[foxts/invariant] "value" is null or undefined'){if(null==n)throw TypeError(r);return n}function s(n,r='[foxts/invariant] "value" is null or undefined'){if(null==n)throw TypeError(r)}function a(n,r="value"){throw TypeError(`Unexpected ${r}: ${n} as ${JSON.stringify(typeof n)}, should be "never"`)}export{s as invariant,r as is,u as isFalsy,l as isNonNull,t as isNonNullish,e as isTruthy,a as never,n as not,i as nullthrow};
1
+ const n=n=>null!==n,r=n=>void 0!==n,e=n=>!1!==n,u=n=>null!=n,t=n=>!!n;function l(l){switch(l){case null:return n;case void 0:return r;case!1:return e;case"nullish":return u;case"falsy":return t;default:x(l,"argument")}}const s=n=>null===n,i=n=>void 0===n,o=n=>!1===n,a=n=>null==n,c=n=>!n,f=n=>!!n;function d(n){switch(n){case null:return s;case void 0:return i;case!1:return o;case"nullish":return a;case"falsy":return c;case"truthy":return f;default:x(n,"argument")}}const h=f,v=c,y=n,p=u;function w(n,r='[foxts/invariant] "value" is null or undefined'){if(null==n)throw TypeError(r);return n}function N(n,r='[foxts/invariant] "value" is null or undefined'){if(null==n)throw TypeError(r)}function x(n,r="value"){throw TypeError(`Unexpected ${r}: ${n} as ${JSON.stringify(typeof n)}, should be "never"`)}export{N as invariant,d as is,v as isFalsy,y as isNonNull,p as isNonNullish,h as isTruthy,x as never,l as not,w as nullthrow};
@@ -0,0 +1,3 @@
1
+ declare function joinReadableStreams<T>(streams: Array<ReadableStream<T>>): ReadableStream<T>;
2
+
3
+ export { joinReadableStreams };
@@ -0,0 +1 @@
1
+ "use strict";exports.joinReadableStreams=function(e){return new ReadableStream({async start(r){try{for(const a of e){const e=a.getReader();try{for(;;){const a=await e.read();if(a.done)break;r.enqueue(a.value)}}finally{e.releaseLock()}}r.close()}catch(e){r.error(e)}}})};
@@ -0,0 +1 @@
1
+ function e(e){return new ReadableStream({async start(r){try{for(const a of e){const e=a.getReader();try{for(;;){const a=await e.read();if(a.done)break;r.enqueue(a.value)}}finally{e.releaseLock()}}r.close()}catch(e){r.error(e)}}})}export{e as joinReadableStreams};
@@ -1,4 +1,4 @@
1
- type HeadersInitLike = string[][] | Record<string, string | readonly string[]> | Headers | null | undefined;
1
+ type HeadersInitLike = Array<[string, string]> | Record<string, string> | Headers | null | undefined;
2
2
  type IncomingHttpHeadersLike = Record<string, string | string[] | undefined> | undefined | null;
3
3
  type OutgoingHttpHeadersLike = Record<string, number | string | string[] | undefined> | undefined | null;
4
4
  declare function mergeHeaders(dest: HeadersInitLike, source: HeadersInitLike,
@@ -1 +1 @@
1
- "use strict";exports.mergeHeaders=function(e,n,r=null){if(null==e)return null==n?new Headers:new Headers(n);if(null==n)return new Headers(e);const t=new Headers(e),s=new Headers(n);if(null==r)return s.forEach((e,n)=>{t.set(n,e)}),t;if("function"!=typeof r){const e=new Set(r);r=n=>e.has(n)}return s.forEach((e,n)=>{r(n)&&t.set(n,e)}),t},exports.mergeNodeHttpHeaders=function(e,n){return null==e?null==n?{}:n:null==n?e:Object.assign({},e,n)};
1
+ "use strict";const e=Headers;exports.mergeHeaders=function(n,t,r=null){if(null==n)return null==t?new e:new e(t);if(null==t)return new e(n);const u=new e(n),l=new e(t);if(null==r)return l.forEach((e,n)=>{u.set(n,e)}),u;if("function"!=typeof r){const e=new Set(r);r=n=>e.has(n)}return l.forEach((e,n)=>{r(n)&&u.set(n,e)}),u},exports.mergeNodeHttpHeaders=function(e,n){return null==e?null==n?{}:n:null==n?e:Object.assign({},e,n)};
@@ -1 +1 @@
1
- function e(n,r,t=null){if(null==n)return null==r?new Headers:new Headers(r);if(null==r)return new Headers(n);const l=new Headers(n),u=new Headers(r);if(null==t)return u.forEach((e,n)=>{l.set(n,e)}),l;if("function"!=typeof t){const e=new Set(t);t=n=>e.has(n)}return u.forEach((e,n)=>{t(n)&&l.set(n,e)}),l}function n(e,n){return null==e?null==n?{}:n:null==n?e:Object.assign({},e,n)}export{e as mergeHeaders,n as mergeNodeHttpHeaders};
1
+ const n=Headers;function e(t,r,l=null){if(null==t)return null==r?new n:new n(r);if(null==r)return new n(t);const u=new n(t),o=new n(r);if(null==l)return o.forEach((n,e)=>{u.set(e,n)}),u;if("function"!=typeof l){const n=new Set(l);l=e=>n.has(e)}return o.forEach((n,e)=>{l(e)&&u.set(e,n)}),u}function t(n,e){return null==n?null==e?{}:e:null==e?n:Object.assign({},n,e)}export{e as mergeHeaders,t as mergeNodeHttpHeaders};
@@ -1 +1 @@
1
- "use strict";var r=require("../guard/index.js");const e=new TextEncoder,t={utf8:new TextDecoder("utf8")};exports.base64ToUint8Array=function(r){return Uint8Array.from(atob(function(r){const e=r.replaceAll("-","+").replaceAll("_","/"),t=(4-e.length%4)%4;return e+"=".repeat(t)}(r)),r=>r.charCodeAt(0))},exports.concatUint8Arrays=function(r,e){if(0===r.length)return new Uint8Array(0);const t=new Uint8Array(e??=r.reduce((r,e)=>r+e.length,0));let n=0;for(let e=0,o=r.length;e<o;e++){const o=r[e];t.set(o,n),n+=o.length}return t},exports.stringToUint8Array=function(r){return e.encode(r)},exports.toUint8Array=function(e){return e instanceof ArrayBuffer?new Uint8Array(e):ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):void r.never(e,"value must be ArrayBuffer or ArrayBufferView")},exports.uint8ArrayToBase64=function(r,e=!1){let t="";for(let e=0;e<r.length;e+=65535){const n=r.subarray(e,e+65535);t+=globalThis.btoa(String.fromCharCode.apply(void 0,n))}return e?t.replaceAll("+","-").replaceAll("/","_").replace(/=+$/,""):t},exports.uint8ArrayToString=function(r,e="utf8"){return t[e]??=new TextDecoder(e),t[e].decode(r)};
1
+ "use strict";var e=require("../guard/index.js");const r=Uint8Array,t=ArrayBuffer,n=TextDecoder,o=new TextEncoder,u={utf8:new n("utf8")};exports.base64ToUint8Array=function(e){return r.from(atob(function(e){const r=e.replaceAll("-","+").replaceAll("_","/"),t=(4-r.length%4)%4;return r+"=".repeat(t)}(e)),e=>e.charCodeAt(0))},exports.concatUint8Arrays=function(e,t){if(0===e.length)return new r(0);const n=new r(t??=e.reduce((e,r)=>e+r.length,0));let o=0;for(let r=0,t=e.length;r<t;r++){const t=e[r];n.set(t,o),o+=t.length}return n},exports.stringToUint8Array=function(e){return o.encode(e)},exports.toUint8Array=function(n){return n instanceof t?new r(n):t.isView(n)?new r(n.buffer,n.byteOffset,n.byteLength):void e.never(n,"value must be ArrayBuffer or ArrayBufferView")},exports.uint8ArrayToBase64=function(e,r=!1){let t="";for(let r=0;r<e.length;r+=65535){const n=e.subarray(r,r+65535);t+=btoa(String.fromCharCode.apply(void 0,n))}return r?t.replaceAll("+","-").replaceAll("/","_").replace(/=+$/,""):t},exports.uint8ArrayToString=function(e,r="utf8"){return u[r]??=new n(r),u[r].decode(e)};
@@ -1 +1 @@
1
- import{never as r}from"../guard/index.mjs";const e=new TextEncoder;function t(r){return e.encode(r)}const n={utf8:new TextDecoder("utf8")};function o(r,e="utf8"){return n[e]??=new TextDecoder(e),n[e].decode(r)}function a(r){return Uint8Array.from(atob(function(r){const e=r.replaceAll("-","+").replaceAll("_","/"),t=(4-e.length%4)%4;return e+"=".repeat(t)}(r)),r=>r.charCodeAt(0))}function i(r,e=!1){let t="";for(let e=0;e<r.length;e+=65535){const n=r.subarray(e,e+65535);t+=globalThis.btoa(String.fromCharCode.apply(void 0,n))}return e?t.replaceAll("+","-").replaceAll("/","_").replace(/=+$/,""):t}function u(r,e){if(0===r.length)return new Uint8Array(0);const t=new Uint8Array(e??=r.reduce((r,e)=>r+e.length,0));let n=0;for(let e=0,o=r.length;e<o;e++){const o=r[e];t.set(o,n),n+=o.length}return t}function f(e){return e instanceof ArrayBuffer?new Uint8Array(e):ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):void r(e,"value must be ArrayBuffer or ArrayBufferView")}export{a as base64ToUint8Array,u as concatUint8Arrays,t as stringToUint8Array,f as toUint8Array,i as uint8ArrayToBase64,o as uint8ArrayToString};
1
+ import{never as e}from"../guard/index.mjs";const r=Uint8Array,t=ArrayBuffer,n=TextDecoder,o=new TextEncoder;function a(e){return o.encode(e)}const u={utf8:new n("utf8")};function c(e,r="utf8"){return u[r]??=new n(r),u[r].decode(e)}function f(e){return r.from(atob(function(e){const r=e.replaceAll("-","+").replaceAll("_","/"),t=(4-r.length%4)%4;return r+"=".repeat(t)}(e)),e=>e.charCodeAt(0))}function i(e,r=!1){let t="";for(let r=0;r<e.length;r+=65535){const n=e.subarray(r,r+65535);t+=btoa(String.fromCharCode.apply(void 0,n))}return r?t.replaceAll("+","-").replaceAll("/","_").replace(/=+$/,""):t}function l(e,t){if(0===e.length)return new r(0);const n=new r(t??=e.reduce((e,r)=>e+r.length,0));let o=0;for(let r=0,t=e.length;r<t;r++){const t=e[r];n.set(t,o),o+=t.length}return n}function s(n){return n instanceof t?new r(n):t.isView(n)?new r(n.buffer,n.byteOffset,n.byteLength):void e(n,"value must be ArrayBuffer or ArrayBufferView")}export{f as base64ToUint8Array,l as concatUint8Arrays,a as stringToUint8Array,s as toUint8Array,i as uint8ArrayToBase64,c as uint8ArrayToString};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foxts",
3
- "version": "4.3.1",
3
+ "version": "4.5.0",
4
4
  "description": "Opinionated collection of common TypeScript utils by @SukkaW",
5
5
  "repository": {
6
6
  "url": "https://github.com/SukkaW/foxts"
@@ -40,6 +40,12 @@
40
40
  "require": "./dist/append-set-elements-to-array/index.js",
41
41
  "default": "./dist/append-set-elements-to-array/index.js"
42
42
  },
43
+ "./array-push-non-nullish": {
44
+ "types": "./dist/array-push-non-nullish/index.d.ts",
45
+ "import": "./dist/array-push-non-nullish/index.mjs",
46
+ "require": "./dist/array-push-non-nullish/index.js",
47
+ "default": "./dist/array-push-non-nullish/index.js"
48
+ },
43
49
  "./async-retry": {
44
50
  "types": "./dist/async-retry/index.d.ts",
45
51
  "import": "./dist/async-retry/index.mjs",
@@ -64,6 +70,12 @@
64
70
  "require": "./dist/bitwise/index.js",
65
71
  "default": "./dist/bitwise/index.js"
66
72
  },
73
+ "./cast-array": {
74
+ "types": "./dist/cast-array/index.d.ts",
75
+ "import": "./dist/cast-array/index.mjs",
76
+ "require": "./dist/cast-array/index.js",
77
+ "default": "./dist/cast-array/index.js"
78
+ },
67
79
  "./chunk": {
68
80
  "types": "./dist/chunk/index.d.ts",
69
81
  "import": "./dist/chunk/index.mjs",
@@ -190,6 +202,12 @@
190
202
  "require": "./dist/is-probably-ip/index.js",
191
203
  "default": "./dist/is-probably-ip/index.js"
192
204
  },
205
+ "./join-readablestreams": {
206
+ "types": "./dist/join-readablestreams/index.d.ts",
207
+ "import": "./dist/join-readablestreams/index.mjs",
208
+ "require": "./dist/join-readablestreams/index.js",
209
+ "default": "./dist/join-readablestreams/index.js"
210
+ },
193
211
  "./lazy-promise": {
194
212
  "types": "./dist/lazy-promise/index.d.ts",
195
213
  "import": "./dist/lazy-promise/index.mjs",
@@ -312,8 +330,8 @@
312
330
  "fast-escape-regexp": "^1.0.1"
313
331
  },
314
332
  "devDependencies": {
315
- "@eslint-sukka/node": "^7.2.1",
316
- "@happy-dom/global-registrator": "^19.0.2",
333
+ "@eslint-sukka/node": "^7.3.3",
334
+ "@happy-dom/global-registrator": "^20.0.0",
317
335
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
318
336
  "@mitata/counters": "^0.0.8",
319
337
  "@monyone/aho-corasick": "^1.0.4",
@@ -321,16 +339,16 @@
321
339
  "@swc-node/register": "^1.11.1",
322
340
  "@swc/core": "^1.13.20",
323
341
  "@types/mocha": "^10.0.10",
324
- "@types/node": "^22.18.8",
342
+ "@types/node": "^22.18.9",
325
343
  "@types/sinon": "^17.0.4",
326
- "bumpp": "^10.2.3",
344
+ "bumpp": "^10.3.1",
327
345
  "devalue": "^5.3.2",
328
346
  "eslint": "^9.37.0",
329
- "eslint-config-sukka": "^7.2.1",
330
- "eslint-formatter-sukka": "^7.2.1",
347
+ "eslint-config-sukka": "^7.3.3",
348
+ "eslint-formatter-sukka": "^7.3.3",
331
349
  "expect": "^30.2.0",
332
350
  "fastscan": "^1.0.6",
333
- "happy-dom": "^19.0.2",
351
+ "happy-dom": "^20.0.0",
334
352
  "is-ci": "^4.1.0",
335
353
  "is-network-error": "^1.3.0",
336
354
  "mitata": "^1.0.34",
@@ -339,7 +357,7 @@
339
357
  "nyc": "^17.1.0",
340
358
  "rollup": "^4.52.4",
341
359
  "rollup-plugin-dts": "^6.2.3",
342
- "rollup-plugin-oxc-resolve": "^0.0.4",
360
+ "rollup-plugin-oxc-resolve": "^0.0.5",
343
361
  "rollup-plugin-swc3": "^0.12.1",
344
362
  "sinon": "^21.0.0",
345
363
  "typescript": "^5.9.3",