A run-time guard to require a value to be an array; it will throw a ZeroDepError
if the guard fails.
Full documentation is available at the zerodep.app page.
All @zerodep packages support both ESM and CJS.
import { guardArray } from '@zerodep/guard-array';
// or
const { guardArray } = require('@zerodep/guard-array');
guardArray([]); // void
guardArray(['a', 'b', 'c']); // void
guardArray(1000n); // throws ZeroDepError: Value is not an array
guardArray(true); // throws ZeroDepError: Value is not an array
guardArray(new Date()); // throws ZeroDepError: Value is not an array
guardArray(''); // throws ZeroDepError: Value is not an array
guardArray(new Error('message')); // throws ZeroDepError: Value is not an array
guardArray(3.14); // throws ZeroDepError: Value is not an array
guardArray(() => 'function'); // throws ZeroDepError: Value is not an array
guardArray(42); // throws ZeroDepError: Value is not an array
guardArray(
new Map([
['a', 1],
['b', 2],
])
); // throws ZeroDepError: Value is not an array
guardArray(null); // throws ZeroDepError: Value is not an array
guardArray({ an: 'object' }); // throws ZeroDepError: Value is not an array
guardArray(new Promise(() => {})); // throws ZeroDepError: Value is not an array
guardArray(/[regex]+/gi); // throws ZeroDepError: Value is not an array
guardArray(new Set([1, 2, 3])); // throws ZeroDepError: Value is not an array
guardArray('a string'); // throws ZeroDepError: Value is not an array
guardArray(Symbol()); // throws ZeroDepError: Value is not an array
guardArray(new Int32Array(2)); // throws ZeroDepError: Value is not an array
guardArray(undefined); // throws ZeroDepError: Value is not an array