$ cnpm install @putout/plugin-apply-maybe
????Putout plugin helps with maybe monad. Depends on @putout/declare. Renamed to @putout/plugin-maybe.
npm i @putout/plugin-apply-maybe -D
{
"rules": {
"apply-maybe/array": "on",
"apply-maybe/empty-array": "on",
"apply-maybe/fn": "on"
}
}
const array = isArray(a) ? a : [a];
const maybeArray = (a) => isArray(a) ? a : [a];
const array = maybeArray(a);
const array = !a ? [] : a;
const maybeArray = (a) => !a ? [] : a;
const array = maybeEmptyArray(a);
const fn = isFn(a) ? a : () => {};
const noop = () => {};
const maybeFn = isFn(a) ? a : noop;
const fn = maybeFn(a);
const fn = f || (() => {});
const noop = () => {};
const fn = fn || noop;
MIT
Copyright 2013 - present © cnpmjs.org | Home |