amend-object

Update an object from an iterable of key/value-pairs.

Usage no npm install needed!

<script type="module">
  import amendObject from 'https://cdn.skypack.dev/amend-object';
</script>

README

Amend Object

Update an object from an iterable of key/value-pairs.

Installation

npm install --save amend-object

Usage

import amendObject from 'amend-object'

const me = {
  firstName: 'Linus',
  lastName: 'Unneb├Ąck'
}

amendObject(me, [
  ['firstName', 'Steve'],
  ['lastName', 'Jobs']
])

console.log(me)
// => { firstName: 'Steve', lastName: 'Jobs' }

API

amendObject(target, items) => object

Update object target with items.

items should be an iterable (e.g. an array) where each item is a key/value pair.

If the same key is specified twice, the latter will take precedence.

A TypeError will be thrown in the following conditions:

  • items is not an iterable
  • any element in items is not an object (usually an array, but can be object with the keys 0 and 1)
  • any key is not a string, a number, or a symbol