Skip to content
/ io Public

Simplify your function input destructuring

License

Notifications You must be signed in to change notification settings

Lcfvs/io

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simplify your function input destructuring

`npm i @lcf.vs/io

/**
* @param {Function} fn - the function to call
* @param {*} input - the function input (duplicated and sent as array)
* @param {...*} args - the extra arguments
*/
io(fn, input, ...args)
import io from '@lcf.vs/io'

function defineC([{a, b}, input], c) {
  input.c = c
}

function defineD([{a, b, c}, input]) {
  input.d = a + b + c
}

function log([input]) {
  console.log(input)
}

const obj = {a: 1, b: 2}

io(defineC, obj, 3) // obj = {a: 1, b: 2, c: 3}
io(defineD, obj) // obj = {a: 1, b: 2, c: 3, d: 6}
io(log, obj) // {a: 1, b: 2, c: 3, d: 6}
import io from '@lcf.vs/io'

function Member([{members}], name) {
  this.name = name
  members[name] = this
}

const team = {
  members: {}
}

new io(Member, team, 'Lcf.vs')
console.log(team) // {members: {'Lcf.vs': {name: 'Lcf.vs'}}}

MIT

About

Simplify your function input destructuring

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages