2.0.2 • Published 10 months ago

@plandek-utils/safe-compact v2.0.2

Weekly downloads
70
License
MIT
Repository
github
Last release
10 months ago

@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
2.0.3

10 months ago

2.0.2

10 months ago

2.0.1

1 year ago

2.0.0

10 months ago

1.1.3

5 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago