foxts 5.5.0 → 5.6.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.
- package/dist/async-retry/index.js +1 -1
- package/dist/async-retry/index.mjs +1 -1
- package/dist/clamp/index.d.ts +4 -0
- package/dist/clamp/index.js +1 -0
- package/dist/clamp/index.mjs +1 -0
- package/dist/counter/index.d.ts +5 -2
- package/dist/counter/index.js +1 -1
- package/dist/counter/index.mjs +1 -1
- package/dist/uint8array-utils/index.js +1 -1
- package/dist/uint8array-utils/index.mjs +1 -1
- package/package.json +19 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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"),i=require("../wait/index.js");const{round:n}=Math,a=Error,s=TypeError;function c(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 \u{2265} ${r}.`)}class u extends a{name="AsyncRetryAbortError";cause;constructor(e){if(super("string"==typeof e?e:t.extractErrorMessage(e,!1)??"Aborted"),"string"==typeof e){const t=new a(e);t.stack=this.stack,this.cause=t}else t.isErrorLikeObject(e)?(this.cause=e,this.message=e.message):this.cause=e}}async function m(t,o,a,c,m){if(t instanceof u)throw t.cause;if(t instanceof s&&!r.isNetworkError(t)||e.isAbortErrorLike(t))throw t;const f=a.retries-(o-1),w={error:t,attemptNumber:o,retriesLeft:f};await a.onFailedAttempt(w),o>1&&await a.onRetry(t,o-1);const h=Date.now();if(h-c>=m||o>=a.retries+1||!await a.shouldRetry(w))throw t;let d=n((a.randomize?Math.random()+1:1)*a.minTimeout*a.factor**(o-1));d>a.maxTimeout&&(d=a.maxTimeout);const b=m-(h-c);if(b<=0)throw t;let x=d;d>b&&(x=b),x>0&&await i.waitWithAbort(x,a.signal,a.unref),a.signal?.throwIfAborted()}function f(e){throw new u(e??"Aborted")}async function w(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),c("retries",r.retries,0,!0),c("factor",r.factor,0,!1),c("minTimeout",r.minTimeout,0,!1),c("maxTimeout",r.maxTimeout,0,!0);const i=r.maxRetryTime??1/0;c("maxRetryTime",i,0,!0),r.minTimeout<1&&(r.minTimeout=1),r.factor<=0&&(r.factor=1);let n=0;const s=Date.now();for(;n<r.retries+1;){n++;try{r.signal?.throwIfAborted();const t=await e(f,n);return r.signal?.throwIfAborted(),t}catch(t){let e=t;"object"==typeof t&&t&&"bail"in t&&t.bail&&(e=new u(t)),await m(e,n,r,s,i)}}throw new a("Retry attempts exhausted without throwing an error.")}exports.AsyncRetryAbortError=u,exports.asyncRetry=w,exports.makeRetriable=function(e,t){return function(...r){return w(()=>e.apply(this,r),t)}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isAbortErrorLike as t}from"../abort-error/index.mjs";import{extractErrorMessage as e}from"../extract-error-message/index.mjs";import{isNetworkError as
|
|
1
|
+
import{isAbortErrorLike as t}from"../abort-error/index.mjs";import{extractErrorMessage as e,isErrorLikeObject as r}from"../extract-error-message/index.mjs";import{isNetworkError as o}from"../is-network-error/index.mjs";import{noop as i,trueFn as n}from"../noop/index.mjs";import{waitWithAbort as a}from"../wait/index.mjs";const{round:s}=Math,m=Error,c=TypeError;function f(t,e,r=0,o=!1){if(Number.isNaN(e))throw new c(`Expected \`${t}\` to be a valid number${o?" or Infinity":""}, got NaN.`);if(!o&&!Number.isFinite(e))throw new c(`Expected \`${t}\` to be a finite number.`);if(e<r)throw new c(`Expected \`${t}\` to be \u{2265} ${r}.`)}class u extends m{name="AsyncRetryAbortError";cause;constructor(t){if(super("string"==typeof t?t:e(t,!1)??"Aborted"),"string"==typeof t){const e=new m(t);e.stack=this.stack,this.cause=e}else r(t)?(this.cause=t,this.message=t.message):this.cause=t}}async function w(e,r,i,n,m){if(e instanceof u)throw e.cause;if(e instanceof c&&!o(e)||t(e))throw e;const f=i.retries-(r-1),w={error:e,attemptNumber:r,retriesLeft:f};await i.onFailedAttempt(w),r>1&&await i.onRetry(e,r-1);const h=Date.now();if(h-n>=m||r>=i.retries+1||!await i.shouldRetry(w))throw e;let d=s((i.randomize?Math.random()+1:1)*i.minTimeout*i.factor**(r-1));d>i.maxTimeout&&(d=i.maxTimeout);const y=m-(h-n);if(y<=0)throw e;let b=d;d>y&&(b=y),b>0&&await a(b,i.signal,i.unref),i.signal?.throwIfAborted()}function h(t){throw new u(t??"Aborted")}async function d(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??=i,r.onRetry??=i,r.shouldRetry??=n,r.forever&&(r.retries=1/0),f("retries",r.retries,0,!0),f("factor",r.factor,0,!1),f("minTimeout",r.minTimeout,0,!1),f("maxTimeout",r.maxTimeout,0,!0);const o=r.maxRetryTime??1/0;f("maxRetryTime",o,0,!0),r.minTimeout<1&&(r.minTimeout=1),r.factor<=0&&(r.factor=1);let a=0;const s=Date.now();for(;a<r.retries+1;){a++;try{r.signal?.throwIfAborted();const e=await t(h,a);return r.signal?.throwIfAborted(),e}catch(e){let t=e;"object"==typeof e&&e&&"bail"in e&&e.bail&&(t=new u(e)),await w(t,a,r,s,o)}}throw new m("Retry attempts exhausted without throwing an error.")}function y(t,e){return function(...r){return d(()=>t.apply(this,r),e)}}export{u as AsyncRetryAbortError,d as asyncRetry,y as makeRetriable};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";exports.clamp=function(t,r,c){return void 0===c?c=>c<t?t:c>r?r:c:t<r?r:t>c?c:t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function n(n,o,r){return void 0===r?r=>r<n?n:r>o?o:r:n<o?o:n>r?r:n}export{n as clamp};
|
package/dist/counter/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
declare class Counter<K extends string> {
|
|
2
2
|
private readonly map;
|
|
3
3
|
constructor(init?: Array<[K, number]> | Record<K, number>);
|
|
4
|
+
forEach(callbackfn: (value: number, key: K, map: Map<K, number>) => void, thisArg?: any): void;
|
|
5
|
+
[Symbol.toStringTag]: string;
|
|
4
6
|
get size(): number;
|
|
5
7
|
clear(): void;
|
|
6
8
|
delete(key: K): boolean;
|
|
@@ -8,8 +10,9 @@ declare class Counter<K extends string> {
|
|
|
8
10
|
get(key: K): number;
|
|
9
11
|
incr(key: K, n?: number): this;
|
|
10
12
|
decr(key: K, n?: number): this;
|
|
11
|
-
entries():
|
|
12
|
-
|
|
13
|
+
entries(): MapIterator<[K, number]>;
|
|
14
|
+
[Symbol.iterator](): MapIterator<[K, number]>;
|
|
15
|
+
keys(): MapIterator<K>;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
export { Counter };
|
package/dist/counter/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";class
|
|
1
|
+
"use strict";var t,r;t=Symbol.toStringTag,r=Symbol.iterator;class e{map=new Map;constructor(t){if(Array.isArray(t))for(const[r,e]of t)this.incr(r,e);else if(void 0!==t)for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&this.incr(r,t[r])}forEach(t,r){this.map.forEach(t,r)}[t]="Counter";get size(){return this.map.size}clear(){this.map.clear()}delete(t){return this.map.delete(t)}has(t){return this.map.has(t)}get(t){const r=this.map.get(t);return void 0===r?0:r}incr(t,r=1){if(r<0)throw TypeError(`Counter#incr only accepts positive values: ${r}`);return this.map.set(t,this.get(t)+r),this}decr(t,r=1){if(r<0)throw TypeError(`Counter#decr only accepts positive values: ${r}`);const e=this.get(t);return e<=r?this.map.delete(t):this.map.set(t,e-r),this}entries(){return this.map.entries()}[r](){return this.map[Symbol.iterator]()}keys(){return this.map.keys()}}exports.Counter=e;
|
package/dist/counter/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class
|
|
1
|
+
var t,r;t=Symbol.toStringTag,r=Symbol.iterator;class e{map=new Map;constructor(t){if(Array.isArray(t))for(const[r,e]of t)this.incr(r,e);else if(void 0!==t)for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&this.incr(r,t[r])}forEach(t,r){this.map.forEach(t,r)}[t]="Counter";get size(){return this.map.size}clear(){this.map.clear()}delete(t){return this.map.delete(t)}has(t){return this.map.has(t)}get(t){const r=this.map.get(t);return void 0===r?0:r}incr(t,r=1){if(r<0)throw TypeError(`Counter#incr only accepts positive values: ${r}`);return this.map.set(t,this.get(t)+r),this}decr(t,r=1){if(r<0)throw TypeError(`Counter#decr only accepts positive values: ${r}`);const e=this.get(t);return e<=r?this.map.delete(t):this.map.set(t,e-r),this}entries(){return this.map.entries()}[r](){return this.map[Symbol.iterator]()}keys(){return this.map.keys()}}export{e as Counter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../guard/index.js");const t=Uint8Array,r=ArrayBuffer,n=TextDecoder,o=new TextEncoder,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
1
|
+
"use strict";var e=require("../guard/index.js");const t=Uint8Array,r=ArrayBuffer,n=TextDecoder,o=new TextEncoder,c=/=+$/,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",l=new Uint8Array(256);for(let e=0;e<a.length;e++)l[a.charCodeAt(e)]=e;const u={utf8:new n("utf8")};exports.base64ToUint8Array=function(e){const t=function(e){const t=e.replaceAll("-","+").replaceAll("_","/"),r=(4-t.length%4)%4;return t+"=".repeat(r)}(e),r=t.length;let n=.75*t.length,o,c=0,a,u,i,f;"="===t[t.length-1]&&(n--,"="===t[t.length-2]&&n--);const s=new Uint8Array(new ArrayBuffer(n));for(o=0;o<r;o+=4)a=l[t.charCodeAt(o)],u=l[t.charCodeAt(o+1)],i=l[t.charCodeAt(o+2)],f=l[t.charCodeAt(o+3)],s[c++]=a<<2|u>>4,s[c++]=(15&u)<<4|i>>2,s[c++]=(3&i)<<6|63&f;return s},exports.concatUint8Arrays=function(e,r){if(0===e.length)return new t(0);const n=new t(r??=e.reduce((e,t)=>e+t.length,0));let o=0;for(let t=0,r=e.length;t<r;t++){const r=e[t];n.set(r,o),o+=r.length}return n},exports.stringToUint8Array=function(e){return o.encode(e)},exports.toUint8Array=function(n){return n instanceof r?new t(n):r.isView(n)?new t(n.buffer,n.byteOffset,n.byteLength):void e.never(n,"value must be ArrayBuffer or ArrayBufferView")},exports.uint8ArrayToBase64=function(e,t=!1){let r="";const n=e.length;for(let t=0;t<n;t+=3)r+=a[e[t]>>2],r+=a[(3&e[t])<<4|e[t+1]>>4],r+=a[(15&e[t+1])<<2|e[t+2]>>6],r+=a[63&e[t+2]];return n%3==2?r=r.slice(0,Math.max(0,r.length-1))+"=":n%3==1&&(r=r.slice(0,Math.max(0,r.length-2))+"=="),t?r.replaceAll("+","-").replaceAll("/","_").replace(c,""):r},exports.uint8ArrayToString=function(e,t="utf8"){return u[t]??=new n(t),u[t].decode(e)};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{never as e}from"../guard/index.mjs";const t=Uint8Array,r=ArrayBuffer,n=TextDecoder,o=new TextEncoder,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
1
|
+
import{never as e}from"../guard/index.mjs";const t=Uint8Array,r=ArrayBuffer,n=TextDecoder,o=new TextEncoder,c=/=+$/,l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=new Uint8Array(256);for(let e=0;e<l.length;e++)a[l.charCodeAt(e)]=e;function f(e){return o.encode(e)}const u={utf8:new n("utf8")};function i(e,t="utf8"){return u[t]??=new n(t),u[t].decode(e)}function A(e){const t=function(e){const t=e.replaceAll("-","+").replaceAll("_","/"),r=(4-t.length%4)%4;return t+"=".repeat(r)}(e),r=t.length;let n=.75*t.length,o,c=0,l,f,u,i;"="===t[t.length-1]&&(n--,"="===t[t.length-2]&&n--);const A=new Uint8Array(new ArrayBuffer(n));for(o=0;o<r;o+=4)l=a[t.charCodeAt(o)],f=a[t.charCodeAt(o+1)],u=a[t.charCodeAt(o+2)],i=a[t.charCodeAt(o+3)],A[c++]=l<<2|f>>4,A[c++]=(15&f)<<4|u>>2,A[c++]=(3&u)<<6|63&i;return A}function h(e,t=!1){let r="";const n=e.length;for(let t=0;t<n;t+=3)r+=l[e[t]>>2],r+=l[(3&e[t])<<4|e[t+1]>>4],r+=l[(15&e[t+1])<<2|e[t+2]>>6],r+=l[63&e[t+2]];return n%3==2?r=r.slice(0,Math.max(0,r.length-1))+"=":n%3==1&&(r=r.slice(0,Math.max(0,r.length-2))+"=="),t?r.replaceAll("+","-").replaceAll("/","_").replace(c,""):r}function s(e,r){if(0===e.length)return new t(0);const n=new t(r??=e.reduce((e,t)=>e+t.length,0));let o=0;for(let t=0,r=e.length;t<r;t++){const r=e[t];n.set(r,o),o+=r.length}return n}function g(n){return n instanceof r?new t(n):r.isView(n)?new t(n.buffer,n.byteOffset,n.byteLength):void e(n,"value must be ArrayBuffer or ArrayBufferView")}export{A as base64ToUint8Array,s as concatUint8Arrays,f as stringToUint8Array,g as toUint8Array,h as uint8ArrayToBase64,i as uint8ArrayToString};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foxts",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"description": "Opinionated collection of common TypeScript utils by @SukkaW",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://github.com/SukkaW/foxts"
|
|
@@ -94,6 +94,12 @@
|
|
|
94
94
|
"require": "./dist/chunk/index.js",
|
|
95
95
|
"default": "./dist/chunk/index.js"
|
|
96
96
|
},
|
|
97
|
+
"./clamp": {
|
|
98
|
+
"types": "./dist/clamp/index.d.ts",
|
|
99
|
+
"import": "./dist/clamp/index.mjs",
|
|
100
|
+
"require": "./dist/clamp/index.js",
|
|
101
|
+
"default": "./dist/clamp/index.js"
|
|
102
|
+
},
|
|
97
103
|
"./compare-source": {
|
|
98
104
|
"types": "./dist/compare-source/index.d.ts",
|
|
99
105
|
"import": "./dist/compare-source/index.mjs",
|
|
@@ -338,43 +344,43 @@
|
|
|
338
344
|
"author": "SukkaW <https://skk.moe>",
|
|
339
345
|
"license": "MIT",
|
|
340
346
|
"devDependencies": {
|
|
341
|
-
"@eslint-sukka/node": "^8.
|
|
342
|
-
"@happy-dom/global-registrator": "^20.10.
|
|
347
|
+
"@eslint-sukka/node": "^8.13.4",
|
|
348
|
+
"@happy-dom/global-registrator": "^20.10.6",
|
|
343
349
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
344
350
|
"@mitata/counters": "^0.0.8",
|
|
345
|
-
"@monyone/aho-corasick": "^1.1.
|
|
351
|
+
"@monyone/aho-corasick": "^1.1.12",
|
|
346
352
|
"@package-json/types": "^0.0.13",
|
|
347
353
|
"@swc-node/register": "^1.11.1",
|
|
348
|
-
"@swc/core": "^1.15.
|
|
354
|
+
"@swc/core": "^1.15.43",
|
|
349
355
|
"@types/mocha": "^10.0.10",
|
|
350
|
-
"@types/node": "^22.
|
|
356
|
+
"@types/node": "^22.20.0",
|
|
351
357
|
"@types/sinon": "^21.0.1",
|
|
352
358
|
"bumpp": "^10.4.1",
|
|
353
359
|
"earl": "^2.0.0",
|
|
354
|
-
"eslint": "^10.
|
|
355
|
-
"eslint-config-sukka": "^8.
|
|
356
|
-
"eslint-formatter-sukka": "^8.
|
|
360
|
+
"eslint": "^10.6.0",
|
|
361
|
+
"eslint-config-sukka": "^8.13.4",
|
|
362
|
+
"eslint-formatter-sukka": "^8.13.4",
|
|
357
363
|
"fastscan": "^1.0.6",
|
|
358
|
-
"happy-dom": "^20.10.
|
|
364
|
+
"happy-dom": "^20.10.6",
|
|
359
365
|
"is-ci": "^4.1.0",
|
|
360
366
|
"is-network-error": "^1.3.2",
|
|
361
367
|
"mitata": "^1.0.34",
|
|
362
368
|
"mocha": "^11.7.6",
|
|
363
369
|
"modern-ahocorasick": "^2.0.4",
|
|
364
370
|
"nyc": "^18.0.0",
|
|
365
|
-
"rollup": "^4.
|
|
371
|
+
"rollup": "^4.62.2",
|
|
366
372
|
"rollup-plugin-dts": "^6.4.1",
|
|
367
373
|
"rollup-plugin-oxc-resolve": "^0.0.5",
|
|
368
374
|
"rollup-plugin-swc3": "^0.12.1",
|
|
369
375
|
"sinon": "^21.1.2",
|
|
370
|
-
"ts-dedent": "^2.
|
|
376
|
+
"ts-dedent": "^2.3.0",
|
|
371
377
|
"typescript": "^6.0.3",
|
|
372
378
|
"word-list": "3.0.0"
|
|
373
379
|
},
|
|
374
380
|
"scripts": {
|
|
375
381
|
"lint": "eslint --format=sukka .",
|
|
376
382
|
"build-ts-xor": "SWC_NODE_IGNORE_DYNAMIC=1 node --require @swc-node/register ./src/ts-xor/_build.ts",
|
|
377
|
-
"test": "SWC_NODE_IGNORE_DYNAMIC=1 SWC_NODE_INLINE_SOURCE_MAP=1 nyc mocha --require @swc-node/register --full-trace
|
|
383
|
+
"test": "SWC_NODE_IGNORE_DYNAMIC=1 SWC_NODE_INLINE_SOURCE_MAP=1 nyc mocha --require @swc-node/register --full-trace 'src/**/*.test.ts'",
|
|
378
384
|
"bench": "SWC_NODE_IGNORE_DYNAMIC=1 node --require @swc-node/register",
|
|
379
385
|
"bench:all": "SWC_NODE_IGNORE_DYNAMIC=1 node --require @swc-node/register ./src/**/*.bench.ts",
|
|
380
386
|
"build": "rollup -c rollup.config.ts --bundleConfigAsCjs --configPlugin swc3",
|