foxts 5.1.0 → 5.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Common characters:
3
+ *
4
+ * base32: 0123456789ABCDEFGHJKMNPQRSTVWXYZ
5
+ * z-base-32: ybndrfg8ejkmcpqxot1uwisza345h769
6
+ * base36: 0123456789abcdefghijklmnopqrstuvwxyz
7
+ * base58: 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
8
+ * base62: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
9
+ * base64: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
10
+ * base67: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~
11
+ * base94: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
12
+ */
13
+ declare function base(ALPHABET: string): {
14
+ encode: (source: Uint8Array) => string;
15
+ decode: (source: string) => Uint8Array;
16
+ };
17
+
18
+ export { base };
@@ -0,0 +1 @@
1
+ "use strict";exports.base=function(r){if(r.length>=255)throw TypeError("Alphabet too long");const t=new Uint8Array(256);for(let r=0;r<256;r++)t[r]=255;const o=r.length;for(let e=0;e<o;e++){const o=r.charAt(e),n=o.charCodeAt(0);if(255!==t[n])throw TypeError("Alphabet contains ambiguous characters: "+o);t[n]=e}const e=r.charAt(0),n=Math.log(o)/Math.log(256),l=Math.log(256)/Math.log(o);return{encode:function(t){if(0===t.length)return"";let n=0,a=0,c=0;const h=t.length;for(;c!==h&&0===t[c];)c++,n++;const f=(h-c)*l+1>>>0,i=new Uint8Array(f);for(;c!==h;){let r=t[c],e=0;for(let t=f-1;(0!==r||e<a)&&-1!==t;t--,e++)r+=256*i[t]>>>0,i[t]=r%o>>>0,r=r/o>>>0;if(0!==r)throw Error("Non-zero carry");a=e,c++}let s=f-a;for(;s!==f&&0===i[s];)s++;let g=e.repeat(n);for(;s<f;++s)g+=r.charAt(i[s]);return g},decode:function(r){if(0===r.length)return new Uint8Array(0);let l=0,a=0,c=0;for(;r[l]===e;)a++,l++;const h=(r.length-l)*n+1>>>0,f=new Uint8Array(h);for(;l<r.length;){let e=t[r.charCodeAt(l)],n=0;for(let r=h-1;(0!==e||n<c)&&-1!==r;r--,n++)e+=o*f[r]>>>0,f[r]=e%256>>>0,e=e/256>>>0;if(0!==e)throw Error("Non-zero carry");c=n,l++}let i=h-c;for(;i!==h&&0===f[i];)i++;const s=new Uint8Array(a+(h-i));let g=a;for(;i!==h;)s[g++]=f[i++];return s}}};
@@ -0,0 +1 @@
1
+ function r(r){if(r.length>=255)throw TypeError("Alphabet too long");const t=new Uint8Array(256);for(let r=0;r<256;r++)t[r]=255;const o=r.length;for(let e=0;e<o;e++){const o=r.charAt(e),n=o.charCodeAt(0);if(255!==t[n])throw TypeError("Alphabet contains ambiguous characters: "+o);t[n]=e}const e=r.charAt(0),n=Math.log(o)/Math.log(256),l=Math.log(256)/Math.log(o);return{encode:function(t){if(0===t.length)return"";let n=0,a=0,c=0;const h=t.length;for(;c!==h&&0===t[c];)c++,n++;const f=(h-c)*l+1>>>0,i=new Uint8Array(f);for(;c!==h;){let r=t[c],e=0;for(let t=f-1;(0!==r||e<a)&&-1!==t;t--,e++)r+=256*i[t]>>>0,i[t]=r%o>>>0,r=r/o>>>0;if(0!==r)throw Error("Non-zero carry");a=e,c++}let g=f-a;for(;g!==f&&0===i[g];)g++;let s=e.repeat(n);for(;g<f;++g)s+=r.charAt(i[g]);return s},decode:function(r){if(0===r.length)return new Uint8Array(0);let l=0,a=0,c=0;for(;r[l]===e;)a++,l++;const h=(r.length-l)*n+1>>>0,f=new Uint8Array(h);for(;l<r.length;){let e=t[r.charCodeAt(l)],n=0;for(let r=h-1;(0!==e||n<c)&&-1!==r;r--,n++)e+=o*f[r]>>>0,f[r]=e%256>>>0,e=e/256>>>0;if(0!==e)throw Error("Non-zero carry");c=n,l++}let i=h-c;for(;i!==h&&0===f[i];)i++;const g=new Uint8Array(a+(h-i));let s=a;for(;i!==h;)g[s++]=f[i++];return g}}}export{r as base};
@@ -1,4 +1,4 @@
1
- declare function uint8ArrayToBase92(source: Uint8Array): string;
2
- declare function base92ToUint8Array(source: string): Uint8Array;
1
+ declare const uint8ArrayToBase92: (source: Uint8Array) => string;
2
+ declare const base92ToUint8Array: (source: string) => Uint8Array;
3
3
 
4
4
  export { base92ToUint8Array, uint8ArrayToBase92 };
@@ -1 +1 @@
1
- "use strict";const r=[33,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126],t=new Uint8Array(256);for(let r=0;r<t.length;r++)t[r]=255;for(let o=0;o<92;o++)t[r[o]]=o;const o=String.fromCharCode(r[0]),e=Math.log(92)/Math.log(256),n=Math.log(256)/Math.log(92);exports.base92ToUint8Array=function(r){if(0===r.length)return new Uint8Array(0);let n=0,l=0,f=0;for(;r[n]===o;)l++,n++;const a=(r.length-n)*e+1>>>0,i=new Uint8Array(a);for(;n<r.length;){let o=t[r.charCodeAt(n)],e=0;for(let r=a-1;(0!==o||e<f)&&-1!==r;r--,e++)o+=92*i[r]>>>0,i[r]=o%256>>>0,o=o/256>>>0;if(0!==o)throw Error("Non-zero carry");f=e,n++}let h=a-f;for(;h!==a&&0===i[h];)h++;const c=new Uint8Array(l+(a-h));let g=l;for(;h!==a;)c[g++]=i[h++];return c},exports.uint8ArrayToBase92=function(t){if(0===t.length)return"";let e=0,l=0,f=0;const a=t.length;for(;f!==a&&0===t[f];)f++,e++;const i=(a-f)*n+1>>>0,h=new Uint8Array(i);for(;f!==a;){let r=t[f],o=0;for(let t=i-1;(0!==r||o<l)&&-1!==t;t--,o++)r+=256*h[t]>>>0,h[t]=r%92>>>0,r=r/92>>>0;if(0!==r)throw Error("Non-zero carry");l=o,f++}let c=i-l;for(;c!==i&&0===h[c];)c++;let g=o.repeat(e);for(;c<i;++c)g+=String.fromCharCode(r[h[c]]);return g};
1
+ "use strict";const{encode:e,decode:r}=require("../base/index.js").base(String.raw`!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~`);exports.base92ToUint8Array=r,exports.uint8ArrayToBase92=e;
@@ -1 +1 @@
1
- const r=[33,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126],t=new Uint8Array(256);for(let r=0;r<t.length;r++)t[r]=255;for(let o=0;o<92;o++)t[r[o]]=o;const o=String.fromCharCode(r[0]),e=Math.log(92)/Math.log(256),n=Math.log(256)/Math.log(92);function l(t){if(0===t.length)return"";let e=0,l=0,f=0;const a=t.length;for(;f!==a&&0===t[f];)f++,e++;const h=(a-f)*n+1>>>0,i=new Uint8Array(h);for(;f!==a;){let r=t[f],o=0;for(let t=h-1;(0!==r||o<l)&&-1!==t;t--,o++)r+=256*i[t]>>>0,i[t]=r%92>>>0,r=r/92>>>0;if(0!==r)throw Error("Non-zero carry");l=o,f++}let g=h-l;for(;g!==h&&0===i[g];)g++;let c=o.repeat(e);for(;g<h;++g)c+=String.fromCharCode(r[i[g]]);return c}function f(r){if(0===r.length)return new Uint8Array(0);let n=0,l=0,f=0;for(;r[n]===o;)l++,n++;const a=(r.length-n)*e+1>>>0,h=new Uint8Array(a);for(;n<r.length;){let o=t[r.charCodeAt(n)],e=0;for(let r=a-1;(0!==o||e<f)&&-1!==r;r--,e++)o+=92*h[r]>>>0,h[r]=o%256>>>0,o=o/256>>>0;if(0!==o)throw Error("Non-zero carry");f=e,n++}let i=a-f;for(;i!==a&&0===h[i];)i++;const g=new Uint8Array(l+(a-i));let c=l;for(;i!==a;)g[c++]=h[i++];return g}export{f as base92ToUint8Array,l as uint8ArrayToBase92};
1
+ import{base as e}from"../base/index.mjs";const{encode:r,decode:o}=e(String.raw`!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~`);export{o as base92ToUint8Array,r as uint8ArrayToBase92};
@@ -1,4 +1,4 @@
1
- declare function stringToUint8Array(str: string): Uint8Array;
1
+ declare function stringToUint8Array(str: string): Uint8Array<ArrayBuffer>;
2
2
  declare function uint8ArrayToString(array: ArrayBuffer | ArrayBufferView, encoding?: string): string;
3
3
  declare function base64ToUint8Array(base64String: string): Uint8Array;
4
4
  declare function uint8ArrayToBase64(array: Uint8Array, urlSafe?: boolean): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foxts",
3
- "version": "5.1.0",
3
+ "version": "5.2.1",
4
4
  "description": "Opinionated collection of common TypeScript utils by @SukkaW",
5
5
  "repository": {
6
6
  "url": "https://github.com/SukkaW/foxts"
@@ -64,6 +64,12 @@
64
64
  "require": "./dist/available-parallelism/index.js",
65
65
  "default": "./dist/available-parallelism/index.js"
66
66
  },
67
+ "./base": {
68
+ "types": "./dist/base/index.d.ts",
69
+ "import": "./dist/base/index.mjs",
70
+ "require": "./dist/base/index.js",
71
+ "default": "./dist/base/index.js"
72
+ },
67
73
  "./base92": {
68
74
  "types": "./dist/base92/index.d.ts",
69
75
  "import": "./dist/base92/index.mjs",
@@ -355,7 +361,7 @@
355
361
  "scripts": {
356
362
  "lint": "eslint --format=sukka .",
357
363
  "build-ts-xor": "SWC_NODE_IGNORE_DYNAMIC=1 node --require @swc-node/register ./src/ts-xor/_build.ts",
358
- "test": "SWC_NODE_IGNORE_DYNAMIC=1 SWC_NODE_INLINE_SOURCE_MAP=1 nyc mocha --require @swc-node/register --parallel --full-trace ./src/**/*.test.ts",
364
+ "test": "SWC_NODE_IGNORE_DYNAMIC=1 SWC_NODE_INLINE_SOURCE_MAP=1 nyc mocha --require @swc-node/register --full-trace ./src/**/*.test.ts",
359
365
  "bench": "SWC_NODE_IGNORE_DYNAMIC=1 node --require @swc-node/register",
360
366
  "bench:all": "SWC_NODE_IGNORE_DYNAMIC=1 node --require @swc-node/register ./src/**/*.bench.ts",
361
367
  "build": "rollup -c rollup.config.ts --bundleConfigAsCjs --configPlugin swc3",