πPutout plugin adds ability to declare undefined variables
npm install @putout/plugin-declare-undefined-variables[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-declare-undefined-variables.svg?style=flat&longCache=true
[NPMURL]: https://npmjs.org/package/@putout/plugin-declare-undefined-variables"npm"
πPutout plugin adds ability to declare variable that was not defined before, including:
- is types: isFn, isString, isNumber, isObject, isBool, isUndefined, isSymbol and isNull;
- maybe: maybeArray, maybeFn, maybeEmptyArray;
- wrap: not,id, returns;
- fresh-import: freshImport, freshImportDefault;
- fixtures: readFixture(name);
- properties of Object;
- wraptile;
- fullstore;
- currify;
- pipe-io;
- pullout;
- simport;
- chalk;
- table;
Renamed to @putout/plugin-declare.
```
npm i putout @putout/plugin-declare-undefined-variables -D
Add .putout.json with:
`json`
{
"plugins": {
"declare-undefined-variables": "on"
}
}
Use options:
- β
dismiss for variables you don't want to declare;declarations
- β
to declare variables;
`json`
{
"rules": {
"declare-undefined-variables": ["on", {
"declarations": {
"hello": "import {hello} from 'world'"
},
"dismiss": [
"assert",
"entries",
"parse",
"stringify",
"defineProperty",
"isArray",
"noop",
"join",
"keys",
"values",
"stopAll",
"once",
"putout",
"simport"
]
}]
}
}
`js
const hello = 'world';
const object = {};
assign(object, {
hello,
});
`
`js
const hello = 'world';
const object = {};
const {assign} = Object;
assign(object, {
hello,
});
`
`js
const hello = 'world';
const object = {};
const allKeys = keys(object);
`
`js
const hello = 'world';
const object = {};
const {keys} = Object;
const allKeys = keys(object);
`
`js`
const object = {};
const allValues = values(object);
`js
const {values} = Object;
const object = {};
const allValues = values(object);
`
`js`
isArray(array);
`js`
const {isArray} = Array;
isArray(array);
`js`
noop();
`js`
const noop = () => {};
noop();
`js`
if (isFn(fn))
fn();
`js
const isFn = (a) => typeof a === 'function';
if (isFn(fn))
fn();
`
`js`
const a = [
...maybeArray(b),
];
`js
const {isArray} = Array;
const maybeArray = (a) => isArray(a) ? a : [a];
const a = [
...maybeArray(b),
];
``
MIT