JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 18
  • Score
    100M100P100Q45835F
  • License MIT

Assigns properties of source object(s) to a new object.

Package Exports

  • object-concat

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (object-concat) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

object-concat

Assigns properties of source object(s) to a new object.

Build Status Code Climate js-standard-style

npm install object-concat --save
npm stats

npm NPM downloads Dependency Status

Example

basic
var concat = require('object-concat')

var defaults = { level: 1 }
var restored = { player: 'isaac', level: 5 }
var gamedata = concat(defaults, restored)

assert.equal(gamedata.player, 'isaac')
//=> undefined

assert.equal(gamedata.level, 5)
//=> undefined

assert.notDeepEqual(gamedata, defaults)
//=> undefined

assert.notDeepEqual(gamedata, restored)
//=> undefined
transform
var concat = require('object-concat')

var defaults = { level: 1 }
var restored = { player: 'isaac', level: 5 }
var gamedata = concat(defaults, restored, function (key, sourceVal, targetVal) {
  return key === 'player' ? sourceVal.toUpperCase() : sourceVal
})

assert.equal(gamedata.player, 'ISAAC')
//=> undefined

Features

  • Return a new object instead of mutating a target object.
  • Subsequent source properties overwrite previous.
  • Supports optional iteratee function allowing transformation of target values.

Anti-Features

  • Will never make you seed your parameter list with an empty object:
    • No _.extend({}, source)
  • Will never mutate existing objects.
  • Will never overwrite native Object prototype methods (i.e. Object.assign polyfills).

API

concat([sources], [iteratee])

Arguments
  • [sources]: (…Object) The source objects.
  • [iteratee]: (Function) Function that produces desired target value (must be last parameter).
    • key: (String) Object key name.
    • sourceVal: (*) Object source value.
    • targetVal: (*) Object target value.
Returns
  • (Object) The new object.

Alternatives

Most, if not all of the alternatives listed have varying semantics so be careful which you choose for your own applications.

Licenses

GitHub license