iif-ts
Version:
A tiny utility function to conditionally insert elements into arrays or objects using the spread operator. Supports both eager and deferred evaluation.
11 lines • 416 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.iifArray = iifArray;
exports.iifObject = iifObject;
function iifArray(condition, ...values) {
return condition ? values.map((v) => (typeof v === 'function' ? v() : v)) : [];
}
function iifObject(condition, value) {
return condition ? (typeof value === 'function' ? value() : value) : {};
}
//# sourceMappingURL=index.js.map