@putout/plugin-apply-maybe
🐊Putout plugin applies Maybe monad
Last updated 3 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @putout/plugin-apply-maybe 
SYNC missed versions from official npm registry.

@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

Current Tags

  • 1.2.1                                ...           latest (3 years ago)

4 Versions

  • 1.2.1                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (0)
None
Dev Dependencies (9)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |