eachvar

1.0.1 • Public • Published

David

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`))

see also

Package Sidebar

Install

npm i eachvar

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

2.64 kB

Total Files

3

Last publish

Collaborators

  • jnvm