Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/arrays

Package Overview
Dependencies
Maintainers
1
Versions
190
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/arrays - npm Package Compare versions

Comparing version 0.8.5 to 0.9.0

bisect.d.ts

13

CHANGELOG.md

@@ -6,2 +6,15 @@ # Change Log

# [0.9.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/arrays@0.8.5...@thi.ng/arrays@0.9.0) (2021-01-02)
### Features
* **arrays:** add bisect(), bisectWith() ([17d06a4](https://github.com/thi-ng/umbrella/commit/17d06a43e338aca5f2dc61110382363639daecc5))
* **arrays:** add into(), sortByCachedKey() ([b94f64c](https://github.com/thi-ng/umbrella/commit/b94f64c2c351cfed5ea9ade5e42ad0b7076ef9e9))
* **arrays:** update sortByCachedKey(), add tests ([64e8f6e](https://github.com/thi-ng/umbrella/commit/64e8f6e4e83c26c73e23a4831483bd328b78bc49))
## [0.8.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/arrays@0.8.4...@thi.ng/arrays@0.8.5) (2020-12-22)

@@ -8,0 +21,0 @@

3

index.d.ts
export * from "./api";
export * from "./binary-search";
export * from "./bisect";
export * from "./ends-with";

@@ -10,2 +11,3 @@ export * from "./ensure-array";

export * from "./is-sorted";
export * from "./into";
export * from "./iterator";

@@ -16,2 +18,3 @@ export * from "./levenshtein";

export * from "./shuffle";
export * from "./sort-cached";
export * from "./starts-with";

@@ -18,0 +21,0 @@ export * from "./swap";

export * from "./api";
export * from "./binary-search";
export * from "./bisect";
export * from "./ends-with";

@@ -10,2 +11,3 @@ export * from "./ensure-array";

export * from "./is-sorted";
export * from "./into";
export * from "./iterator";

@@ -16,4 +18,5 @@ export * from "./levenshtein";

export * from "./shuffle";
export * from "./sort-cached";
export * from "./starts-with";
export * from "./swap";
export * from "./swizzle";

@@ -77,2 +77,11 @@ 'use strict';

const bisect = (src, i = src.length >>> 1) => [
src.slice(0, i),
src.slice(i),
];
const bisectWith = (src, pred) => {
const i = src.findIndex(pred);
return i >= 0 ? bisect(src, i) : [src, []];
};
const endsWith = (buf, needle, equiv$1 = equiv.equiv) => {

@@ -152,2 +161,11 @@ let i = buf.length;

const into = (dest, src, max = Infinity) => {
for (let x of src) {
if (--max < 0)
break;
dest.push(x);
}
return dest;
};
function* arrayIterator(buf, start = 0, end) {

@@ -342,2 +360,9 @@ if (!buf)

const sortByCachedKey = (src, key, cmp = compare.compare) => {
const keys = checks.isFunction(key) ? src.map(key) : key;
api.assert(keys.length === src.length, `keys.length != src.length`);
quickSort(keys, cmp, multiSwap(src));
return src;
};
const startsWith = (buf, needle, equiv$1 = equiv.equiv) => {

@@ -391,2 +416,4 @@ let i = buf.length;

exports.binarySearchNumeric = binarySearchNumeric;
exports.bisect = bisect;
exports.bisectWith = bisectWith;
exports.bsEQ = bsEQ;

@@ -406,2 +433,3 @@ exports.bsGE = bsGE;

exports.fuzzyMatch = fuzzyMatch;
exports.into = into;
exports.isSorted = isSorted;

@@ -415,4 +443,5 @@ exports.levenshtein = levenshtein;

exports.shuffleRange = shuffleRange;
exports.sortByCachedKey = sortByCachedKey;
exports.startsWith = startsWith;
exports.swap = swap;
exports.swizzle = swizzle;

2

lib/index.umd.js

@@ -1,1 +0,1 @@

!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@thi.ng/compare"),require("@thi.ng/equiv"),require("@thi.ng/checks"),require("@thi.ng/errors"),require("@thi.ng/api"),require("@thi.ng/random")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/compare","@thi.ng/equiv","@thi.ng/checks","@thi.ng/errors","@thi.ng/api","@thi.ng/random"],r):r(((e="undefined"!=typeof globalThis?globalThis:e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.arrays={}),e.thi.ng.compare,e.thi.ng.equiv,e.thi.ng.checks,e.thi.ng.errors,e.thi.ng.api,e.thi.ng.random)}(this,(function(e,r,t,n,i,o,u){"use strict";const s=e=>((null==e||!e[Symbol.iterator])&&i.illegalArgs(`value is not iterable: ${e}`),e),l=(e,r,n=t.equiv)=>{for(let t=e.length;--t>=0;)if(n(r,e[t]))return t;return-1};const h=(e,r)=>e===r,a=(e,r,t=1/0,n=h)=>{if(e===r)return 0;if(e.length>r.length){const t=e;e=r,r=t}let i=e.length,o=r.length;for(;i>0&&n(e[~-i],r[~-o]);)i--,o--;let u=0;for(;u<i&&n(e[u],r[u]);)u++;if(i-=u,o-=u,0===i||o<3)return o;let s,l,a,f,c,g,d,p,y,b,m,q,v,S=0;const k=(e,r,t,i,o)=>e<r||t<r?e>t?t+1:e+1:n(o,i)?r:r+1,w=[];for(s=0;s<i;s++)w.push(s+1,e[u+s]);const A=w.length-1,T=o-3;for(;S<T;){for(b=r[u+(a=S)],m=r[u+(f=S+1)],q=r[u+(c=S+2)],v=r[u+(g=S+3)],d=S+=4,l=1/0,s=0;s<A;s+=2)p=w[s],y=w[s+1],a=k(p,a,f,b,y),f=k(a,f,c,m,y),c=k(f,c,g,q,y),d=k(c,g,d,v,y),d<l&&(l=d),w[s]=d,g=c,c=f,f=a,a=p;if(l>t)return 1/0}for(;S<o;){for(b=r[u+(a=S)],d=++S,l=1/0,s=0;s<A;s+=2)p=w[s],w[s]=d=k(p,a,d,b,w[s+1]),d<l&&(l=d),a=p;if(l>t)return 1/0}return d},f=(e,r,t)=>{const n=e[r];e[r]=e[t],e[t]=n};const c=(e,r=0,t=e.length,n=u.SYSTEM)=>{o.assert(r>=0&&t>=r&&t<=e.length,`illegal range ${r}..${t}`);let i=t-r;const s=i;if(s>1)for(;--i>=0;){const t=r+n.float(s)|0,i=r+n.float(s)|0,o=e[t];e[t]=e[i],e[i]=o}return e};e.arrayIterator=function*(e,r=0,t){if(!e)return;r=r,void 0===t&&(t=e.length);const n=r<=t?1:-1;for(;r!==t;r+=n)yield e[r]},e.binarySearch=(e,t,n=(e=>e),i=r.compare,o=0,u=e.length-1)=>{const s=n(t);for(;o<=u;){const r=o+u>>>1,t=i(n(e[r]),s);if(t<0)o=r+1;else{if(!(t>0))return r;u=r-1}}return-o-1},e.binarySearch16=(e,r)=>{let t=e[8]<=r?8:0;return t|=e[t+4]<=r?4:0,t|=e[t+2]<=r?2:0,t|=e[t+1]<=r?1:0,e[t]===r?t:-t-1},e.binarySearch32=(e,r)=>{let t=e[16]<=r?16:0;return t|=e[t+4]<=r?8:0,t|=e[t+4]<=r?4:0,t|=e[t+2]<=r?2:0,t|=e[t+1]<=r?1:0,e[t]===r?t:-t-1},e.binarySearch4=(e,r)=>{let t=e[2]<=r?2:0;return t|=e[t+1]<=r?1:0,e[t]===r?t:-t-1},e.binarySearch8=(e,r)=>{let t=e[4]<=r?4:0;return t|=e[t+2]<=r?2:0,t|=e[t+1]<=r?1:0,e[t]===r?t:-t-1},e.binarySearchNumeric=(e,t,n=r.compareNumAsc,i=0,o=e.length-1)=>{for(;i<=o;){const r=i+o>>>1,u=n(e[r],t);if(u<0)i=r+1;else{if(!(u>0))return r;o=r-1}}return-i-1},e.bsEQ=e=>e<0?-1:e,e.bsGE=(e,r)=>(e=e<0?-e-1:e)<r?e:-1,e.bsGT=(e,r)=>(e=e<0?-e-1:e+1)<r?e:-1,e.bsLE=e=>e<0?-e-2:e,e.bsLT=e=>e<0?-e-2:e-1,e.endsWith=(e,r,n=t.equiv)=>{let i=e.length,o=r.length;if(i<o)return!1;for(;--i,--o>=0&&n(e[i],r[o]););return o<0},e.ensureArray=e=>n.isArray(e)?e:[...s(e)],e.ensureArrayLike=e=>n.isArrayLike(e)?e:[...s(e)],e.ensureIterable=s,e.fillRange=(e,r=0,t=0,n=e.length,i=(n>t?1:-1))=>{if(i>0)for(;t<n;t+=i)e[r++]=t;else for(;t>n;t+=i)e[r++]=t;return e},e.find=(e,r,n=t.equiv)=>{const i=l(e,r,n);return-1!==i?e[i]:void 0},e.findIndex=l,e.first=e=>e[0],e.fuzzyMatch=(e,r,n=t.equiv)=>{const i=e.length,o=r.length;if(o>i)return!1;if(o===i)return n(r,e);e:for(let t=0,u=0;t<o;t++){const o=r[t];for(;u<i;)if(n(e[u++],o))continue e;return!1}return!0},e.isSorted=(e,t=r.compare,n=0,i=e.length)=>{let o=e[n];for(;++n<i;){const r=e[n];if(t(o,r)>0)return!1;o=r}return!0},e.levenshtein=a,e.multiSwap=(...e)=>{const[r,t,n]=e,i=e.length;switch(i){case 0:return f;case 1:return(e,t,n)=>{f(e,t,n),f(r,t,n)};case 2:return(e,n,i)=>{f(e,n,i),f(r,n,i),f(t,n,i)};case 3:return(e,i,o)=>{f(e,i,o),f(r,i,o),f(t,i,o),f(n,i,o)};default:return(r,t,n)=>{f(r,t,n);for(let r=i;--r>=0;)f(e[r],t,n)}}},e.normalizedLevenshtein=(e,r,t=1/0,n=h)=>{const i=Math.max(e.length,r.length);return i>0?a(e,r,t,n)/i:0},e.peek=e=>e[e.length-1],e.quickSort=function e(t,n=r.compare,i=f,o=0,u=t.length-1){if(o<u){const r=t[o+(u-o>>1)];let s=o-1,l=u+1;for(;;){do{s++}while(n(t[s],r)<0);do{l--}while(n(t[l],r)>0);if(s>=l)break;i(t,s,l)}e(t,n,i,o,l),e(t,n,i,l+1,u)}return t},e.shuffle=(e,r=e.length,t=u.SYSTEM)=>c(e,0,r,t),e.shuffleRange=c,e.startsWith=(e,r,n=t.equiv)=>{let i=e.length,o=r.length;if(i<o)return!1;for(;-o>=0&&n(e[o],r[o]););return o<0},e.swap=f,e.swizzle=e=>{const[r,t,n,i,o,u,s,l]=e;switch(e.length){case 0:return()=>[];case 1:return e=>[e[r]];case 2:return e=>[e[r],e[t]];case 3:return e=>[e[r],e[t],e[n]];case 4:return e=>[e[r],e[t],e[n],e[i]];case 5:return e=>[e[r],e[t],e[n],e[i],e[o]];case 6:return e=>[e[r],e[t],e[n],e[i],e[o],e[u]];case 7:return e=>[e[r],e[t],e[n],e[i],e[o],e[u],e[s]];case 8:return e=>[e[r],e[t],e[n],e[i],e[o],e[u],e[s],e[l]];default:return r=>{const t=[];for(let n=e.length;--n>=0;)t[n]=r[e[n]];return t}}},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@thi.ng/compare"),require("@thi.ng/equiv"),require("@thi.ng/checks"),require("@thi.ng/errors"),require("@thi.ng/api"),require("@thi.ng/random")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/compare","@thi.ng/equiv","@thi.ng/checks","@thi.ng/errors","@thi.ng/api","@thi.ng/random"],r):r(((e="undefined"!=typeof globalThis?globalThis:e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.arrays={}),e.thi.ng.compare,e.thi.ng.equiv,e.thi.ng.checks,e.thi.ng.errors,e.thi.ng.api,e.thi.ng.random)}(this,(function(e,r,t,n,i,o,s){"use strict";const u=(e,r=e.length>>>1)=>[e.slice(0,r),e.slice(r)],l=e=>((null==e||!e[Symbol.iterator])&&i.illegalArgs(`value is not iterable: ${e}`),e),h=(e,r,n=t.equiv)=>{for(let t=e.length;--t>=0;)if(n(r,e[t]))return t;return-1};const c=(e,r)=>e===r,a=(e,r,t=1/0,n=c)=>{if(e===r)return 0;if(e.length>r.length){const t=e;e=r,r=t}let i=e.length,o=r.length;for(;i>0&&n(e[~-i],r[~-o]);)i--,o--;let s=0;for(;s<i&&n(e[s],r[s]);)s++;if(i-=s,o-=s,0===i||o<3)return o;let u,l,h,a,f,g,d,p,y,b,m,q,v,S=0;const k=(e,r,t,i,o)=>e<r||t<r?e>t?t+1:e+1:n(o,i)?r:r+1,w=[];for(u=0;u<i;u++)w.push(u+1,e[s+u]);const x=w.length-1,A=o-3;for(;S<A;){for(b=r[s+(h=S)],m=r[s+(a=S+1)],q=r[s+(f=S+2)],v=r[s+(g=S+3)],d=S+=4,l=1/0,u=0;u<x;u+=2)p=w[u],y=w[u+1],h=k(p,h,a,b,y),a=k(h,a,f,m,y),f=k(a,f,g,q,y),d=k(f,g,d,v,y),d<l&&(l=d),w[u]=d,g=f,f=a,a=h,h=p;if(l>t)return 1/0}for(;S<o;){for(b=r[s+(h=S)],d=++S,l=1/0,u=0;u<x;u+=2)p=w[u],w[u]=d=k(p,h,d,b,w[u+1]),d<l&&(l=d),h=p;if(l>t)return 1/0}return d},f=(e,r,t)=>{const n=e[r];e[r]=e[t],e[t]=n},g=(...e)=>{const[r,t,n]=e,i=e.length;switch(i){case 0:return f;case 1:return(e,t,n)=>{f(e,t,n),f(r,t,n)};case 2:return(e,n,i)=>{f(e,n,i),f(r,n,i),f(t,n,i)};case 3:return(e,i,o)=>{f(e,i,o),f(r,i,o),f(t,i,o),f(n,i,o)};default:return(r,t,n)=>{f(r,t,n);for(let r=i;--r>=0;)f(e[r],t,n)}}};function d(e,t=r.compare,n=f,i=0,o=e.length-1){if(i<o){const r=e[i+(o-i>>1)];let s=i-1,u=o+1;for(;;){do{s++}while(t(e[s],r)<0);do{u--}while(t(e[u],r)>0);if(s>=u)break;n(e,s,u)}d(e,t,n,i,u),d(e,t,n,u+1,o)}return e}const p=(e,r=0,t=e.length,n=s.SYSTEM)=>{o.assert(r>=0&&t>=r&&t<=e.length,`illegal range ${r}..${t}`);let i=t-r;const u=i;if(u>1)for(;--i>=0;){const t=r+n.float(u)|0,i=r+n.float(u)|0,o=e[t];e[t]=e[i],e[i]=o}return e};e.arrayIterator=function*(e,r=0,t){if(!e)return;r=r,void 0===t&&(t=e.length);const n=r<=t?1:-1;for(;r!==t;r+=n)yield e[r]},e.binarySearch=(e,t,n=(e=>e),i=r.compare,o=0,s=e.length-1)=>{const u=n(t);for(;o<=s;){const r=o+s>>>1,t=i(n(e[r]),u);if(t<0)o=r+1;else{if(!(t>0))return r;s=r-1}}return-o-1},e.binarySearch16=(e,r)=>{let t=e[8]<=r?8:0;return t|=e[t+4]<=r?4:0,t|=e[t+2]<=r?2:0,t|=e[t+1]<=r?1:0,e[t]===r?t:-t-1},e.binarySearch32=(e,r)=>{let t=e[16]<=r?16:0;return t|=e[t+4]<=r?8:0,t|=e[t+4]<=r?4:0,t|=e[t+2]<=r?2:0,t|=e[t+1]<=r?1:0,e[t]===r?t:-t-1},e.binarySearch4=(e,r)=>{let t=e[2]<=r?2:0;return t|=e[t+1]<=r?1:0,e[t]===r?t:-t-1},e.binarySearch8=(e,r)=>{let t=e[4]<=r?4:0;return t|=e[t+2]<=r?2:0,t|=e[t+1]<=r?1:0,e[t]===r?t:-t-1},e.binarySearchNumeric=(e,t,n=r.compareNumAsc,i=0,o=e.length-1)=>{for(;i<=o;){const r=i+o>>>1,s=n(e[r],t);if(s<0)i=r+1;else{if(!(s>0))return r;o=r-1}}return-i-1},e.bisect=u,e.bisectWith=(e,r)=>{const t=e.findIndex(r);return t>=0?u(e,t):[e,[]]},e.bsEQ=e=>e<0?-1:e,e.bsGE=(e,r)=>(e=e<0?-e-1:e)<r?e:-1,e.bsGT=(e,r)=>(e=e<0?-e-1:e+1)<r?e:-1,e.bsLE=e=>e<0?-e-2:e,e.bsLT=e=>e<0?-e-2:e-1,e.endsWith=(e,r,n=t.equiv)=>{let i=e.length,o=r.length;if(i<o)return!1;for(;--i,--o>=0&&n(e[i],r[o]););return o<0},e.ensureArray=e=>n.isArray(e)?e:[...l(e)],e.ensureArrayLike=e=>n.isArrayLike(e)?e:[...l(e)],e.ensureIterable=l,e.fillRange=(e,r=0,t=0,n=e.length,i=(n>t?1:-1))=>{if(i>0)for(;t<n;t+=i)e[r++]=t;else for(;t>n;t+=i)e[r++]=t;return e},e.find=(e,r,n=t.equiv)=>{const i=h(e,r,n);return-1!==i?e[i]:void 0},e.findIndex=h,e.first=e=>e[0],e.fuzzyMatch=(e,r,n=t.equiv)=>{const i=e.length,o=r.length;if(o>i)return!1;if(o===i)return n(r,e);e:for(let t=0,s=0;t<o;t++){const o=r[t];for(;s<i;)if(n(e[s++],o))continue e;return!1}return!0},e.into=(e,r,t=1/0)=>{for(let n of r){if(--t<0)break;e.push(n)}return e},e.isSorted=(e,t=r.compare,n=0,i=e.length)=>{let o=e[n];for(;++n<i;){const r=e[n];if(t(o,r)>0)return!1;o=r}return!0},e.levenshtein=a,e.multiSwap=g,e.normalizedLevenshtein=(e,r,t=1/0,n=c)=>{const i=Math.max(e.length,r.length);return i>0?a(e,r,t,n)/i:0},e.peek=e=>e[e.length-1],e.quickSort=d,e.shuffle=(e,r=e.length,t=s.SYSTEM)=>p(e,0,r,t),e.shuffleRange=p,e.sortByCachedKey=(e,t,i=r.compare)=>{const s=n.isFunction(t)?e.map(t):t;return o.assert(s.length===e.length,"keys.length != src.length"),d(s,i,g(e)),e},e.startsWith=(e,r,n=t.equiv)=>{let i=e.length,o=r.length;if(i<o)return!1;for(;-o>=0&&n(e[o],r[o]););return o<0},e.swap=f,e.swizzle=e=>{const[r,t,n,i,o,s,u,l]=e;switch(e.length){case 0:return()=>[];case 1:return e=>[e[r]];case 2:return e=>[e[r],e[t]];case 3:return e=>[e[r],e[t],e[n]];case 4:return e=>[e[r],e[t],e[n],e[i]];case 5:return e=>[e[r],e[t],e[n],e[i],e[o]];case 6:return e=>[e[r],e[t],e[n],e[i],e[o],e[s]];case 7:return e=>[e[r],e[t],e[n],e[i],e[o],e[s],e[u]];case 8:return e=>[e[r],e[t],e[n],e[i],e[o],e[s],e[u],e[l]];default:return r=>{const t=[];for(let n=e.length;--n>=0;)t[n]=r[e[n]];return t}}},Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "@thi.ng/arrays",
"version": "0.8.5",
"version": "0.9.0",
"description": "Array / Arraylike utilities",

@@ -36,3 +36,3 @@ "module": "./index.js",

"doc:readme": "ts-node -P ../../tools/tsconfig.json ../../tools/src/readme.ts",
"doc": "node_modules/.bin/typedoc --mode modules --out doc --theme ../../tools/doc/typedoc-theme src",
"doc": "node_modules/.bin/typedoc --excludePrivate --out doc --theme ../../tools/doc/typedoc-theme src/index.ts",
"doc:ae": "mkdir -p .ae/doc .ae/temp && node_modules/.bin/api-extractor run --local --verbose",

@@ -49,12 +49,12 @@ "pub": "yarn build:release && yarn publish --access public"

"ts-node": "^9.1.1",
"typedoc": "^0.19.2",
"typedoc": "^0.20.4",
"typescript": "^4.1.3"
},
"dependencies": {
"@thi.ng/api": "^6.13.5",
"@thi.ng/checks": "^2.7.12",
"@thi.ng/compare": "^1.3.21",
"@thi.ng/equiv": "^1.0.34",
"@thi.ng/errors": "^1.2.25",
"@thi.ng/random": "^2.1.3"
"@thi.ng/api": "^6.13.6",
"@thi.ng/checks": "^2.7.13",
"@thi.ng/compare": "^1.3.22",
"@thi.ng/equiv": "^1.0.35",
"@thi.ng/errors": "^1.2.26",
"@thi.ng/random": "^2.1.4"
},

@@ -83,3 +83,3 @@ "files": [

},
"gitHead": "8fed74edc94bfb65f84e8982e6724619bbfbd1d0"
"gitHead": "a2127bae6d16682027fd94190452b8404bf99a47"
}

@@ -45,3 +45,3 @@ <!-- This file is generated - DO NOT EDIT! -->

Package sizes (gzipped, pre-treeshake): ESM: 1.84 KB / CJS: 2.00 KB / UMD: 1.99 KB
Package sizes (gzipped, pre-treeshake): ESM: 2.00 KB / CJS: 2.18 KB / UMD: 2.15 KB

@@ -121,2 +121,2 @@ ## Dependencies

&copy; 2018 - 2020 Karsten Schmidt // Apache Software License 2.0
&copy; 2018 - 2021 Karsten Schmidt // Apache Software License 2.0

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc