🚀 Socket Launch Week 🚀 Day 4: Introducing Historical Analytics.Learn More
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

drier

eliminate repetition or stutter in assignments

1.0.3
latest
Version published
Maintainers
1
Created

David

Drier

Does repetition in code bother you to what others call an unreasonable degree?

Is DRY (Don't Repeat Yourself) such a governing rule when you write code that you regularly apply it to real life scenarios?

Do blocks of code with even this level of repetition offend you at a visceral level?

let thing = operator('thing')
let aThing = operator('aThing')
let thisThing = operator('thisThing')
let thatThing = operator('thatThing')
let theOtherThing = operator('theOtherThing')

Be offended no more: just make it drier!

let {thing, aThing, thisThing,
	thatThing, theOtherThing} = require('drier')(operator)

...and through the magic of destructuring and proxies, never stutter variables in code again!

How It Works

drier is a function which invokes its input function with a string of each variable name on the left of the destructuring assignment, removing the need to repeat them, and maybe encouraging more meaningful names.

Or you could describe it as an iterator across variable names.

More Examples

const drier = require('./drier.js')
const dryquire = drier(require)
const {fs, crypto, util, http, os, repl, express, "package.json":{scripts}} = dryquire
const {sqlA, sqlB, sqlC, sqlD} = drier(s => fs.readFileSync(`${__dirname}/${s}.sql`))

see also

FAQs

Package last updated on 21 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts