softkave-js-utils
Version:
JavaScript & Typescript utility functions, types, and classes
25 lines • 743 B
JavaScript
import { toCompactArray } from './toCompactArray.js';
/**
* Returns 2nd argument if 1st argument is `null` or `undefined` or
* `arguments[0].length === 0`
*
* ```typescript
* const otherArr = ['other'];
*
* const arr01 = defaultToArray(undefined, other);
* arr01 === otherArr;
*
* const arr02 = defaultToArray(null, other);
* arr02 === otherArr;
*
* const arr03 = defaultToArray([], other);
* arr03 === otherArr;
*
* const willNotEqualOtherArr = defaultToArray(['non-empty'], other);
* willNotEqualOtherArr !== otherArr;
* ```
*/
export function defaultArrayTo(array, data) {
return (array === null || array === void 0 ? void 0 : array.length) ? array : toCompactArray(data);
}
//# sourceMappingURL=defaultArrayTo.js.map