@lcf.vs/io

1.1.2 • Public • Published

io

Simplify your function input destructuring

Install

`npm i @lcf.vs/io

API

/**
* @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)

Usage

Basic

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}

Using a constructor

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'}}}

License

MIT

Package Sidebar

Install

npm i @lcf.vs/io

Weekly Downloads

0

Version

1.1.2

License

MIT

Unpacked Size

3.02 kB

Total Files

4

Last publish

Collaborators

  • lcf.vs