1.2.1 β€’ Published 1 year ago

@putout/plugin-apply-maybe v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@putout/plugin-apply-maybe NPM version

🐊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

1.2.0

1 year ago

1.2.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago