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);


  • 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.



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


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.


See it in the monorepo opens in a new tab, on GitHub.


To report bugs or request features or assistance, raise an issue on GitHub opens in a new tab.

Any code contributions welcome! All Pull Requests will be dealt promptly.


MIT opens in a new tab

Copyright © 2010–2021 Roy Revelt and other contributors

Related packages:

📦 arrify opens in a new tab
Convert a value to an array
📦 check-types-mini 7.0.1
Validate options object