1.2.1 β’ Published 1 year ago
@putout/plugin-apply-maybe v1.2.1
@putout/plugin-apply-maybe
πPutout plugin helps with maybe
monad. Depends on @putout/declare
. Renamed to @putout/plugin-maybe
.
Install
npm i @putout/plugin-apply-maybe -D
Rules
{
"rules": {
"apply-maybe/array": "on",
"apply-maybe/empty-array": "on",
"apply-maybe/fn": "on"
}
}
array
β Example of incorrect code
const array = isArray(a) ? a : [a];
β Example of correct code
const maybeArray = (a) => isArray(a) ? a : [a];
const array = maybeArray(a);
empty-array
β Example of incorrect code
const array = !a ? [] : a;
β Example of correct code
const maybeArray = (a) => !a ? [] : a;
const array = maybeEmptyArray(a);
fn
β Example of incorrect code
const fn = isFn(a) ? a : () => {};
β Example of correct code
const noop = () => {};
const maybeFn = isFn(a) ? a : noop;
const fn = maybeFn(a);
noop
β Example of incorrect code
const fn = f || (() => {});
β Example of correct code
const noop = () => {};
const fn = fn || noop;
License
MIT