Socket
Book a DemoInstallSign in
Socket

array-of-truths

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-of-truths

Ensure your input becomes an Array, and keep only the truthy values.

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

array-of-truths

Ensure your input becomes an Array, and keep only the truthy values.

API

This module exports one function that holds another function:

arrayOfTruths(x)

If x is not an array, it will be treated as an array with x as the only item. Return a new Array that contains the truthy items from x.

.ifAny(x)

Like arrayOfTruths(x) but if there are no truthy items, instead of an empty array, return number 0.

.ifAnyMap(x, m)

Map a list x through one or more mapper functions m (function or array of functions), except initially and also after each step, false-y items are removed from the list. If the list would be empty, return number 0 instead.

.listAdd(o, k, v)

Replace o[k] with an array that contains:

  • The truthy old value(s), if o had an "own" property named k. See usage test for caveats.
  • v if it is truthy.

Returns that new array.

Usage

see test/usage.mjs.

Known issues

  • I find the package name tricky to pronounce.

 

License

ISC

FAQs

Package last updated on 14 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts