@nothing-but/utils
Advanced tools
Comparing version 0.8.0 to 0.9.0
@@ -7,2 +7,8 @@ /** | ||
/** | ||
* Map an array, but only keep non-nullish values. | ||
* | ||
* Useful for combining `map` and `filter` into one operation. | ||
*/ | ||
export declare function map_non_nullable<T, U>(array: readonly T[], fn: (item: T) => U): NonNullable<U>[]; | ||
/** | ||
* Checks if both arrays contain the same values. | ||
@@ -9,0 +15,0 @@ * Order doesn't matter. |
@@ -12,2 +12,20 @@ import { Num } from './index.js'; | ||
/** | ||
* Map an array, but only keep non-nullish values. | ||
* | ||
* Useful for combining `map` and `filter` into one operation. | ||
*/ | ||
export function map_non_nullable(array, fn) { | ||
const result = Array(array.length); | ||
let i = 0; | ||
for (const item of array) { | ||
const mapped = fn(item); | ||
if (mapped != null) { | ||
result[i] = mapped; | ||
i += 1; | ||
} | ||
} | ||
result.length = i; | ||
return result; | ||
} | ||
/** | ||
* Checks if both arrays contain the same values. | ||
@@ -45,2 +63,3 @@ * Order doesn't matter. | ||
array.length = 0; | ||
// eslint-disable-next-line @nothing-but/no-ignored-return | ||
array.push.apply(array, temp); | ||
@@ -47,0 +66,0 @@ } |
@@ -19,2 +19,6 @@ import { AnyClass, Noop } from './types.js'; | ||
/** | ||
* Converts any value to an Error. | ||
*/ | ||
export declare const toError: (e: unknown) => Error; | ||
/** | ||
* Check if a value is a PlainObject. A PlainObject is an object with no prototype. | ||
@@ -21,0 +25,0 @@ */ |
@@ -18,2 +18,6 @@ /** no operation */ | ||
/** | ||
* Converts any value to an Error. | ||
*/ | ||
export const toError = (e) => (e instanceof Error ? e : new Error(String(e))); | ||
/** | ||
* Check if a value is a PlainObject. A PlainObject is an object with no prototype. | ||
@@ -20,0 +24,0 @@ */ |
{ | ||
"name": "@nothing-but/utils", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"license": "MIT", | ||
@@ -20,2 +20,5 @@ "author": "Damian Tarnawski <gthetarnav@gmail.com>", | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"type": "module", | ||
@@ -22,0 +25,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
72296
27
1655