@plandek-utils/safe-compact
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

@plandek-utils/safe-compact

npm version Github Actions Maintainability Test Coverage

TypeDoc generated docs in here

Github repo 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") // => true

safeIsTruthy

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

Readme

Keywords

none

Package Sidebar

Install

npm i @plandek-utils/safe-compact

Weekly Downloads

1,193

Version

2.0.3

License

MIT

Unpacked Size

19.8 kB

Total Files

12

Last publish

Collaborators

  • eturino
  • plandek-dev