1.1.3 • Published 5 years ago
@plandek-utils/safe-compact v1.1.3
@plandek-utils/safe-compact
TypeDoc generated docs in here
utils similar to compact, to remove certain "falsy" values.
Installation
yarn add @plandek-utils/safe-compact or npm install @plandek-utils/safe-compact.
Usage
safeCompact
returns a list with the "safe truthy" elements of the given list
import { safeCompact } from "@plandek-utils/safe-compact";
safeCompact(null) // => []
safeCompact(undefined) // => []
safeCompact([1, 0, NaN, Infinity, 1, null, 2, [], "", undefined, -1])
// => [1, 0, Infinity, 1, 2, [], -1]filterNones
returns a list with the null and undefined elements removed
import { filterNones } from "@plandek-utils/safe-compact";
filterNones(null) // => []
filterNones(undefined) // => []
filterNones([0, NaN, Infinity, 1, null, 2, [], "", false, undefined, -1])
// => [0, NaN, Infinity, 1, 2, [], "", false, -1]isNotNone
returns true if the value is not null nor undefined
import { isNotNone } from "@plandek-utils/safe-compact";
isNotNone(null) // => false
isNotNone(undefined) // => false
isNotNone([]) // => true
isNotNone(false) // => true
isNotNone(0) // => true
isNotNone("") // => true
isNotNone("aaa") // => truesafeIsTruthy
returns true if the value is truthy or if it is 0.
import { safeIsTruthy } from "@plandek-utils/safe-compact";
safeIsTruthy(1) // => true
safeIsTruthy(0) // => true
safeIsTruthy("") // => false
safeIsTruthy(null) // => false
safeIsTruthy(undefined) // => false
safeIsTruthy(NaN) // => false