@blake.regalia/belt
Advanced tools
Comparing version 0.30.0 to 0.31.0
@@ -64,2 +64,9 @@ import type { Dict, JsonObject } from './types'; | ||
/** | ||
* Removes duplicates from an array, keeping only the first occurrence. | ||
* @param z_identify - if specified and a string, identifies the key of each item to use as an identifier | ||
* if specified and a function, used as a callback to produce the comparison key | ||
* if omitted, compares items using full equality `===` | ||
*/ | ||
export declare const deduplicate: <z_item extends unknown, s_key extends keyof z_item = keyof z_item>(a_items: z_item[], z_identify?: s_key | ((z_item: z_item) => any) | undefined) => z_item[]; | ||
/** | ||
* Escape all special regex characters to turn a string into a verbatim match pattern | ||
@@ -66,0 +73,0 @@ * @param s_input input string |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.die = exports.remove = exports.shuffle = exports.crypto_random_int = exports.random_int = exports.crypto_random = exports.defer_many = exports.defer = exports.microtask = exports.forever = exports.with_timeout = exports.timeout_exec = exports.timeout = exports.fodemtv = exports.oderom = exports.oderaf = exports.oderac = exports.oder = exports.odem = exports.ofe = exports.ode = exports.odv = exports.odk = exports.oda = exports.oc = exports.escape_regex = exports.interjoin = exports.fold = exports.is_dict_es = exports.is_dict = exports.is_array = exports.is_bytes = exports.pascal = exports.snake = exports.proper = exports.F_IDENTITY = exports.F_NOOP = exports.XG_32 = exports.XG_16 = exports.XG_8 = exports.__UNDEFINED = exports.ATU8_NIL = void 0; | ||
exports.die = exports.remove = exports.shuffle = exports.crypto_random_int = exports.random_int = exports.crypto_random = exports.defer_many = exports.defer = exports.microtask = exports.forever = exports.with_timeout = exports.timeout_exec = exports.timeout = exports.fodemtv = exports.oderom = exports.oderaf = exports.oderac = exports.oder = exports.odem = exports.ofe = exports.ode = exports.odv = exports.odk = exports.oda = exports.oc = exports.escape_regex = exports.deduplicate = exports.interjoin = exports.fold = exports.is_dict_es = exports.is_dict = exports.is_array = exports.is_bytes = exports.pascal = exports.snake = exports.proper = exports.F_IDENTITY = exports.F_NOOP = exports.XG_32 = exports.XG_16 = exports.XG_8 = exports.__UNDEFINED = exports.ATU8_NIL = void 0; | ||
/** | ||
@@ -100,50 +100,44 @@ * Utility nil buffer constant | ||
exports.interjoin = interjoin; | ||
// /** | ||
// * Removes duplicates from an array, keeping only the first occurrence. | ||
// * @param z_identify - if specified and a string, identifies the key of each item to use as an identifier | ||
// * if specified and a function, used as a callback to produce the comparison key | ||
// * if omitted, compares items using full equality `===` | ||
// */ | ||
// export const deduplicate = < | ||
// z_item extends any, | ||
// s_key extends keyof z_item=keyof z_item, | ||
// >(a_items: z_item[], z_identify?: s_key | ((z_item: z_item) => any)): typeof a_items => { | ||
// // compare items exactly by default | ||
// let a_keys: any[] = a_items; | ||
// // identify argument | ||
// if(z_identify) { | ||
// // use object property | ||
// if('string' === typeof z_identify) { | ||
// a_keys = a_items.map(w => w[z_identify]); | ||
// } | ||
// // use identity function | ||
// else if('function' === typeof z_identify) { | ||
// a_keys = a_items.map(z_identify); | ||
// } | ||
// else { | ||
// throw new TypeError(`Invalid identifier argument value: ${String(z_identify)}`); | ||
// } | ||
// } | ||
// // each item in list | ||
// for(let i_item=0, nl_items=a_items.length; i_item<nl_items; i_item++) { | ||
// const si_item = a_keys[i_item]; | ||
// // compare against all higher-indexed items | ||
// for(let i_test=i_item+1; i_test<nl_items; i_test++) { | ||
// // found duplicate | ||
// if(si_item === a_keys[i_test]) { | ||
// // remove duplicate | ||
// a_items.splice(i_test, 1); | ||
// a_keys.splice(i_test, 1); | ||
// // update length | ||
// nl_items -= 1; | ||
// // update test index | ||
// i_test -= 1; | ||
// // repeat | ||
// continue; | ||
// } | ||
// } | ||
// } | ||
// return a_items; | ||
// }; | ||
/** | ||
* Removes duplicates from an array, keeping only the first occurrence. | ||
* @param z_identify - if specified and a string, identifies the key of each item to use as an identifier | ||
* if specified and a function, used as a callback to produce the comparison key | ||
* if omitted, compares items using full equality `===` | ||
*/ | ||
const deduplicate = (a_items, z_identify) => { | ||
// compare items exactly by default | ||
let a_keys = a_items; | ||
// identify argument | ||
if (z_identify) { | ||
// use object property | ||
if ('string' === typeof z_identify) { | ||
a_keys = a_items.map(w => w[z_identify]); | ||
} | ||
// use identity function | ||
else if ('function' === typeof z_identify) { | ||
a_keys = a_items.map(z_identify); | ||
} | ||
else { | ||
throw new TypeError(`Invalid identifier argument value: ${String(z_identify)}`); | ||
} | ||
} | ||
// prep keys set | ||
const as_keys = new Set(); | ||
// prep output | ||
const a_unique = []; | ||
// each item in list | ||
for (let i_item = 0, nl_items = a_items.length; i_item < nl_items; i_item++) { | ||
const w_key = a_keys[i_item]; | ||
// already in set; skip | ||
if (as_keys.has(w_key)) | ||
continue; | ||
// add to keys set | ||
as_keys.add(w_key); | ||
// add to items | ||
a_unique.push(a_items[i_item]); | ||
} | ||
return a_unique; | ||
}; | ||
exports.deduplicate = deduplicate; | ||
/** | ||
* Escape all special regex characters to turn a string into a verbatim match pattern | ||
@@ -150,0 +144,0 @@ * @param s_input input string |
@@ -98,3 +98,3 @@ "use strict"; | ||
const atu8_encoded = (0, exports.concat)([ | ||
(0, exports.bytes)(2), | ||
(0, exports.bytes)(2), // 2 bytes for length prefix | ||
atu8_data, | ||
@@ -101,0 +101,0 @@ ]); |
@@ -64,2 +64,9 @@ import type { Dict, JsonObject } from './types'; | ||
/** | ||
* Removes duplicates from an array, keeping only the first occurrence. | ||
* @param z_identify - if specified and a string, identifies the key of each item to use as an identifier | ||
* if specified and a function, used as a callback to produce the comparison key | ||
* if omitted, compares items using full equality `===` | ||
*/ | ||
export declare const deduplicate: <z_item extends unknown, s_key extends keyof z_item = keyof z_item>(a_items: z_item[], z_identify?: s_key | ((z_item: z_item) => any) | undefined) => z_item[]; | ||
/** | ||
* Escape all special regex characters to turn a string into a verbatim match pattern | ||
@@ -66,0 +73,0 @@ * @param s_input input string |
@@ -87,50 +87,43 @@ import { ok } from 'assert'; | ||
}; | ||
// /** | ||
// * Removes duplicates from an array, keeping only the first occurrence. | ||
// * @param z_identify - if specified and a string, identifies the key of each item to use as an identifier | ||
// * if specified and a function, used as a callback to produce the comparison key | ||
// * if omitted, compares items using full equality `===` | ||
// */ | ||
// export const deduplicate = < | ||
// z_item extends any, | ||
// s_key extends keyof z_item=keyof z_item, | ||
// >(a_items: z_item[], z_identify?: s_key | ((z_item: z_item) => any)): typeof a_items => { | ||
// // compare items exactly by default | ||
// let a_keys: any[] = a_items; | ||
// // identify argument | ||
// if(z_identify) { | ||
// // use object property | ||
// if('string' === typeof z_identify) { | ||
// a_keys = a_items.map(w => w[z_identify]); | ||
// } | ||
// // use identity function | ||
// else if('function' === typeof z_identify) { | ||
// a_keys = a_items.map(z_identify); | ||
// } | ||
// else { | ||
// throw new TypeError(`Invalid identifier argument value: ${String(z_identify)}`); | ||
// } | ||
// } | ||
// // each item in list | ||
// for(let i_item=0, nl_items=a_items.length; i_item<nl_items; i_item++) { | ||
// const si_item = a_keys[i_item]; | ||
// // compare against all higher-indexed items | ||
// for(let i_test=i_item+1; i_test<nl_items; i_test++) { | ||
// // found duplicate | ||
// if(si_item === a_keys[i_test]) { | ||
// // remove duplicate | ||
// a_items.splice(i_test, 1); | ||
// a_keys.splice(i_test, 1); | ||
// // update length | ||
// nl_items -= 1; | ||
// // update test index | ||
// i_test -= 1; | ||
// // repeat | ||
// continue; | ||
// } | ||
// } | ||
// } | ||
// return a_items; | ||
// }; | ||
/** | ||
* Removes duplicates from an array, keeping only the first occurrence. | ||
* @param z_identify - if specified and a string, identifies the key of each item to use as an identifier | ||
* if specified and a function, used as a callback to produce the comparison key | ||
* if omitted, compares items using full equality `===` | ||
*/ | ||
export const deduplicate = (a_items, z_identify) => { | ||
// compare items exactly by default | ||
let a_keys = a_items; | ||
// identify argument | ||
if (z_identify) { | ||
// use object property | ||
if ('string' === typeof z_identify) { | ||
a_keys = a_items.map(w => w[z_identify]); | ||
} | ||
// use identity function | ||
else if ('function' === typeof z_identify) { | ||
a_keys = a_items.map(z_identify); | ||
} | ||
else { | ||
throw new TypeError(`Invalid identifier argument value: ${String(z_identify)}`); | ||
} | ||
} | ||
// prep keys set | ||
const as_keys = new Set(); | ||
// prep output | ||
const a_unique = []; | ||
// each item in list | ||
for (let i_item = 0, nl_items = a_items.length; i_item < nl_items; i_item++) { | ||
const w_key = a_keys[i_item]; | ||
// already in set; skip | ||
if (as_keys.has(w_key)) | ||
continue; | ||
// add to keys set | ||
as_keys.add(w_key); | ||
// add to items | ||
a_unique.push(a_items[i_item]); | ||
} | ||
return a_unique; | ||
}; | ||
/** | ||
* Escape all special regex characters to turn a string into a verbatim match pattern | ||
@@ -137,0 +130,0 @@ * @param s_input input string |
@@ -87,3 +87,3 @@ import { XG_8, is_array, is_dict_es, ode, ofe } from './belt.js'; | ||
const atu8_encoded = concat([ | ||
bytes(2), | ||
bytes(2), // 2 bytes for length prefix | ||
atu8_data, | ||
@@ -90,0 +90,0 @@ ]); |
{ | ||
"name": "@blake.regalia/belt", | ||
"version": "0.30.0", | ||
"version": "0.31.0", | ||
"repository": "github:blake-regalia/belt", | ||
@@ -5,0 +5,0 @@ "license": "ISC", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
212763
4103