arrayiffy-if-string3.11.38

Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.

§ Quick Take

import { strict as assert } from "assert";
import arrayiffy from "arrayiffy-if-string";

assert.deepEqual(arrayiffy("aaa"), ["aaa"]);

assert.deepEqual(arrayiffy(""), []);

assert.equal(arrayiffy(true), true);

assert.equal(arrayiffy(), undefined);

§ Purpose

  • If it's a non-empty string, put it into an array and return it.
  • If it's empty string, return an empty array.
  • If it's anything else, just return it.

It's main purpose is to prepare the input argument options' objects.

Also, check out check-types-mini.

§ API

arrayiffy(something)

In other words, it's a function which takes one input argument.

§ Competition

Mr. Sorhus' arrify opens in a new tab API is slightly different, it casts everything to array (null into empty array, for example). arrayiffy-if-string on other hand, wraps only strings into arrays, bypassing the rest (null into null, for example).

It depends what you need.

§ Licence

MIT opens in a new tab

Copyright © 2010–2020 Roy Revelt and other contributors

Related packages:

📦 array-of-arrays-into-ast 1.9.50
turns an array of arrays of data into a nested tree of plain objects
📦 array-of-arrays-sort-by-col 2.12.13
sort array of arrays by column, rippling the sorting outwards from that column
📦 array-pull-all-with-glob 4.12.72
pullAllWithGlob - like _.pullAll but pulling stronger, with globs
📦 arrayiffy-if-string 3.11.38
Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
📦 all-named-html-entities 1.3.7
List of all named HTML entities
📦 array-includes-with-glob 2.12.42
like _.includes but with wildcards
📦 array-group-str-omit-num-char 2.1.48
Groups array of strings by omitting number characters