eachvar
v1.0.1
Published
let {each,varName,be,iterable} = eachVar(x => /* do thing */ )
Downloads
17
Maintainers
Readme
eachVar
Instead of this:
let thing = some.operator('thing')
let aThing = some.operator('aThing')
let thisThing = some.operator('thisThing')
let thatThing = some.operator('thatThing')
let theOtherThing = some.operator('theOtherThing')
//...and so on!
Do this:
const eachVar = require('eachvar')
let {thing, aThing, thisThing,
thatThing, theOtherThing} = eachVar(some.operator)
...and through the magic of destructuring and proxies, never stutter variables in code again!
More signal, less noise.
How It Works
eachVar(iterateeFunction)
is a function which invokes its input function with a string of each variable name on the left of the destructuring assignment in order,
removing the need to repeat them on each side of the equal sign, and maybe encouraging more meaningful names.
Or you could describe it as an iterator across variable names.
More Examples
const eachVar = require('eachvar')
const dryquire = eachVar(require)
const {fs, crypto, util, http, os, repl, express, "package.json":{scripts}} = dryquire
const {sqlA, sqlB, sqlC, sqlD} = eachVar(s => fs.readFileSync(`${__dirname}/${s}.sql`))