@kaciras/utilities
Advanced tools
Comparing version 0.10.3 to 0.10.4
@@ -5,4 +5,7 @@ const alwaysTrue = ()=>true; | ||
const noop = ()=>{}; | ||
const AsyncFunction = (async function() {}).constructor; | ||
/** | ||
* In JavaScript, every async function is actually an AsyncFunction object. | ||
* https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction | ||
*/ const AsyncFunction = (async function() {}).constructor; | ||
/** | ||
* Call a function silently. returns undefined if any error occurs. | ||
@@ -44,2 +47,10 @@ */ function silentCall(fn) { | ||
/** | ||
* Get the first item of the iterable object, or undefined it's empty. | ||
* | ||
* NOTE: Code after the first yield in Generator will not be executed. | ||
*/ function firstItem(iterable) { | ||
// noinspection LoopStatementThatDoesntLoopJS | ||
for (const item of iterable)return item; | ||
} | ||
/** | ||
* A Map which allows multiple values for the same Key. | ||
@@ -51,5 +62,5 @@ * | ||
* const map = new MultiMap<string, number>(); | ||
* map.set("A", [11, 22]); // A -> [11,22] | ||
* map.set("A", [11, 22]); // A -> [11, 22] | ||
* map.add("B", 11); // B -> [11] | ||
* map.add("B", 22); // B -> [11,22] | ||
* map.add("B", 22); // B -> [11, 22] | ||
* | ||
@@ -63,3 +74,3 @@ * map.size; // 2 | ||
* | ||
* map.deleteItem("B", 33); // false, B -> [11,22] | ||
* map.deleteItem("B", 33); // false, B -> [11, 22] | ||
* map.deleteItem("B", 22); // true, B -> [11] | ||
@@ -111,3 +122,3 @@ * map.delete("A"); // true, A no longer exists. | ||
} else { | ||
return !!list.splice(i, 1).length; | ||
return !!list.splice(i, 1); | ||
} | ||
@@ -1556,2 +1567,2 @@ } | ||
export { AESHelper, AsyncFunction, Composite, FetchClient, FetchClientError, LRUCache, MultiEventEmitter, MultiMap, NeverAbort, rpc as RPC, ResponseFacade, SingleEventEmitter, UnitConvertor, alwaysFalse, alwaysTrue, base64url, blobToBase64URL, cartesianArray, cartesianObject, compositor, createInstance, dataSizeIEC, dataSizeSI, dragSortContext, durationFmt, ellipsis, escapeHTML, fetchFile, identity, isPointerInside, noop, nthInChildren, pubSub2ReqRes, saveFile, selectFile, sha256, silencePromise, silentCall, sleep, svgToUrl, swapElements, syncScroll, uniqueId }; | ||
export { AESHelper, AsyncFunction, Composite, FetchClient, FetchClientError, LRUCache, MultiEventEmitter, MultiMap, NeverAbort, rpc as RPC, ResponseFacade, SingleEventEmitter, UnitConvertor, alwaysFalse, alwaysTrue, base64url, blobToBase64URL, cartesianArray, cartesianObject, compositor, createInstance, dataSizeIEC, dataSizeSI, dragSortContext, durationFmt, ellipsis, escapeHTML, fetchFile, firstItem, identity, isPointerInside, noop, nthInChildren, pubSub2ReqRes, saveFile, selectFile, sha256, silencePromise, silentCall, sleep, svgToUrl, swapElements, syncScroll, uniqueId }; |
import { ItemOfIterable } from "./lang.js"; | ||
/** | ||
* Get the first item of the iterable object, or undefined it's empty. | ||
* | ||
* NOTE: Code after the first yield in Generator will not be executed. | ||
*/ | ||
export declare function firstItem<T>(iterable: Iterable<T>): T | undefined; | ||
/** | ||
* A Map which allows multiple values for the same Key. | ||
@@ -9,5 +15,5 @@ * | ||
* const map = new MultiMap<string, number>(); | ||
* map.set("A", [11, 22]); // A -> [11,22] | ||
* map.set("A", [11, 22]); // A -> [11, 22] | ||
* map.add("B", 11); // B -> [11] | ||
* map.add("B", 22); // B -> [11,22] | ||
* map.add("B", 22); // B -> [11, 22] | ||
* | ||
@@ -21,3 +27,3 @@ * map.size; // 2 | ||
* | ||
* map.deleteItem("B", 33); // false, B -> [11,22] | ||
* map.deleteItem("B", 33); // false, B -> [11, 22] | ||
* map.deleteItem("B", 22); // true, B -> [11] | ||
@@ -42,3 +48,3 @@ * map.delete("A"); // true, A no longer exists. | ||
*/ | ||
distribute(keys: K[], ...values: V[]): void; | ||
distribute(keys: Iterable<K>, ...values: V[]): void; | ||
/** | ||
@@ -45,0 +51,0 @@ * Remove the value from array of the specified key. |
@@ -10,2 +10,6 @@ export type ItemOfIterable<T> = T extends Iterable<infer E> ? E : never; | ||
export declare const noop: (..._: unknown[]) => void; | ||
/** | ||
* In JavaScript, every async function is actually an AsyncFunction object. | ||
* https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction | ||
*/ | ||
export declare const AsyncFunction: FunctionConstructor; | ||
@@ -12,0 +16,0 @@ type ClassOf<T> = Function & { |
@@ -7,4 +7,7 @@ import process from 'process'; | ||
const noop = ()=>{}; | ||
const AsyncFunction = (async function() {}).constructor; | ||
/** | ||
* In JavaScript, every async function is actually an AsyncFunction object. | ||
* https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction | ||
*/ const AsyncFunction = (async function() {}).constructor; | ||
/** | ||
* Call a function silently. returns undefined if any error occurs. | ||
@@ -46,2 +49,10 @@ */ function silentCall(fn) { | ||
/** | ||
* Get the first item of the iterable object, or undefined it's empty. | ||
* | ||
* NOTE: Code after the first yield in Generator will not be executed. | ||
*/ function firstItem(iterable) { | ||
// noinspection LoopStatementThatDoesntLoopJS | ||
for (const item of iterable)return item; | ||
} | ||
/** | ||
* A Map which allows multiple values for the same Key. | ||
@@ -53,5 +64,5 @@ * | ||
* const map = new MultiMap<string, number>(); | ||
* map.set("A", [11, 22]); // A -> [11,22] | ||
* map.set("A", [11, 22]); // A -> [11, 22] | ||
* map.add("B", 11); // B -> [11] | ||
* map.add("B", 22); // B -> [11,22] | ||
* map.add("B", 22); // B -> [11, 22] | ||
* | ||
@@ -65,3 +76,3 @@ * map.size; // 2 | ||
* | ||
* map.deleteItem("B", 33); // false, B -> [11,22] | ||
* map.deleteItem("B", 33); // false, B -> [11, 22] | ||
* map.deleteItem("B", 22); // true, B -> [11] | ||
@@ -113,3 +124,3 @@ * map.delete("A"); // true, A no longer exists. | ||
} else { | ||
return !!list.splice(i, 1).length; | ||
return !!list.splice(i, 1); | ||
} | ||
@@ -1401,2 +1412,2 @@ } | ||
export { AESHelper, AsyncFunction, Composite, FetchClient, FetchClientError, LRUCache, MultiEventEmitter, MultiMap, NeverAbort, rpc as RPC, ResponseFacade, SingleEventEmitter, UnitConvertor, alwaysFalse, alwaysTrue, base64url, blobToBase64URL, cartesianArray, cartesianObject, compositor, createInstance, dataSizeIEC, dataSizeSI, durationFmt, ellipsis, escapeHTML, fetchFile, identity, noop, onExit, pubSub2ReqRes, sha256, silencePromise, silentCall, sleep, svgToUrl, uniqueId }; | ||
export { AESHelper, AsyncFunction, Composite, FetchClient, FetchClientError, LRUCache, MultiEventEmitter, MultiMap, NeverAbort, rpc as RPC, ResponseFacade, SingleEventEmitter, UnitConvertor, alwaysFalse, alwaysTrue, base64url, blobToBase64URL, cartesianArray, cartesianObject, compositor, createInstance, dataSizeIEC, dataSizeSI, durationFmt, ellipsis, escapeHTML, fetchFile, firstItem, identity, noop, onExit, pubSub2ReqRes, sha256, silencePromise, silentCall, sleep, svgToUrl, uniqueId }; |
{ | ||
"name": "@kaciras/utilities", | ||
"version": "0.10.3", | ||
"version": "0.10.4", | ||
"license": "MIT", | ||
@@ -30,15 +30,15 @@ "description": "A set of common JS functions for node and browser.", | ||
"@kaciras/eslint-config-typescript": "^2.6.2", | ||
"@playwright/test": "^1.40.0", | ||
"@playwright/test": "^1.40.1", | ||
"@rollup/plugin-replace": "^5.0.5", | ||
"@stryker-mutator/core": "^7.3.0", | ||
"@stryker-mutator/jest-runner": "^7.3.0", | ||
"@swc/core": "^1.3.99", | ||
"@stryker-mutator/core": "^8.0.0", | ||
"@stryker-mutator/jest-runner": "^8.0.0", | ||
"@swc/core": "^1.3.101", | ||
"@swc/jest": "^0.2.29", | ||
"@tsd/typescript": "^5.3.2", | ||
"@tsd/typescript": "^5.3.3", | ||
"@types/istanbul-lib-coverage": "^2.0.6", | ||
"@types/istanbul-lib-report": "^3.0.3", | ||
"@types/istanbul-reports": "^3.0.4", | ||
"@types/node": "^20.10.0", | ||
"@types/node": "^20.10.5", | ||
"es-module-lexer": "^1.4.1", | ||
"eslint": "^8.54.0", | ||
"eslint": "^8.56.0", | ||
"is-builtin-module": "^3.2.1", | ||
@@ -50,6 +50,6 @@ "istanbul-lib-coverage": "^3.2.2", | ||
"jest-runner-tsd": "^6.0.0", | ||
"mockttp": "^3.9.4", | ||
"rollup": "^4.6.0", | ||
"mockttp": "^3.10.0", | ||
"rollup": "^4.9.1", | ||
"tsd-lite": "^0.8.1", | ||
"typescript": "^5.3.2", | ||
"typescript": "^5.3.3", | ||
"v8-to-istanbul": "^9.2.0" | ||
@@ -56,0 +56,0 @@ }, |
129187
3916