Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→arrayiffy-if-stringnext

arrayiffy-if-string5.2.1

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

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • PURPOSE
  • API — ARRAYIFFY()
  • API — TYPES
  • COMPETITION
  • Changelog

Installation

Quick Take

Examples

  • Turn an empty string into an empty array
  • Pass non-string values through untouched

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’ arrifyopens 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.

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab