Lodash compact without removing 0, without `lodash`
npm install @plandek-utils/safe-compact@plandek-utils/safe-compact
!Github Actions


TypeDoc generated docs in here
utils similar to compact, to remove certain "falsy" values.
yarn add @plandek-utils/safe-compact or npm install @plandek-utils/safe-compact.
returns a list with the "safe truthy" elements of the given list
``typescript
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]
`
returns a list with the null and undefined elements removed
`typescript
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]
`
returns true if the value is not null nor undefined
`typescript
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") // => true
`
returns true if the value is truthy or if it is 0.
`typescript
import { safeIsTruthy } from "@plandek-utils/safe-compact";
safeIsTruthy(1) // => true
safeIsTruthy(0) // => true
safeIsTruthy("") // => false
safeIsTruthy(null) // => false
safeIsTruthy(undefined) // => false
safeIsTruthy(NaN) // => false
``