πPutout plugin adds ability to declare variables
npm install @putout/plugin-declare[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-declare.svg?style=flat&longCache=true
[NPMURL]: https://npmjs.org/package/@putout/plugin-declare "npm"
πPutout plugin adds ability to declare variable that was not defined before, including:
- maybe: maybeArray, maybeFn, maybeEmptyArray;
- wrap: not,id, returns;
- fresh-import: freshImport, freshImportDefault;
- fixtures: readFixture;
- properties of Object;
- wraptile;
- fullstore;
- currify;
- pipe-io;
- pullout;
- wait;
- chalk;
- jessy;
- nessy;
- table;
```
npm i putout @putout/plugin-declare -D
Add .putout.json with:
`json`
{
"plugins": {
"declare": "on"
}
}
Use options:
- β
dismiss for variables you don't want to declare;declarations
- β
to declare variables;
`json`
{
"rules": {
"declare": ["on", {
"declarations": {
"hello": "import {hello} from 'world'"
},
"dismiss": [
"assert",
"entries",
"parse",
"stringify",
"defineProperty",
"noop",
"join",
"keys",
"values",
"stopAll",
"once",
"putout"
]
}]
}
}
`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`
noop();
`js`
const noop = () => {};
noop();
`js
const isFn = (a) => typeof a === 'function';
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);
`
`js`
entries([1, 2, 3]);
`js
const {entries} = Object;
entries([1, 2, 3]);
`
`js`
fromEntries(['hello', 'world']);
`js
const {fromEntries} = Object;
fromEntries(['hello', 'world']);
`
`js`
const encoded = new TextEncoder().encode(str);
fromCharCode(...encoded);
`js
const {fromCharCode} = String;
const encoded = new TextEncoder().encode(str);
fromCharCode(...encoded);
``
MIT