Installation
Quick Take
Examples
Purpose
- If it’s a non-empty string, put it into an array and return it.
- If it’s an empty string, return an empty array.
- If it’s anything else, just return it.
...including proper typings.
It’s main purpose is to prepare the input argument options’ objects.
API — arrayiffy()
The main function arrayiffy() is imported like this:
It is a function which takes one input argument:
API — types
This package is written in TypeScript and exports the type StringInABox — the generic which computes the return type: an empty string yields [], any other string yields a one-element tuple, and a non-string is passed through unchanged.
import type { StringInABox } from "arrayiffy-if-string";
Competition
Mr. Sorhus’ arrify 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.