Détail du package

existential-assign

kikobeats33MIT1.3.1

Check for the existential value of a variable/object. Assign one if the value doesn't exist.

assign, default, existence, existential

readme

existential-assign

Last version Build Status Dependency status Dev Dependencies Status NPM Status Donate

Check for the existential value of a variable/object. Assign one if the value doesn't exist.

Very useful to setup a object with default values if the user preferences are empty. Works fine with deep objects:

var defaults = {
  timeout: 3000,
  cb: function() {},
  user: {
    name: 'someone'
    url: 'github.com'
  }
}

var objt = {
  user: {
    name: 'Kiko Beats'
    url: 'github.com'
  }
}

existsAssign(defaults, objt)
// {
//   timeout: 3000,
//   cb: function() {},
//   user: {
//     name: 'Kiko Beats'
//     url: 'github.com'
//   }
// }

Notes that is slightly different than Object.assign.

Install

npm install existential-assign

If you want to use in the browser (powered by Browserify):

bower install existential-assign --save

and later link in your HTML:

<script src="bower_components/existential-assign/dist/existential-assign.js"></script>

Usage

First load the library:

var existsAssign = require('existential-assign');

Working with something that is not a Object:

existsAssign('hello world', null); // => 'hello world'
existsAssign('world', 'hello'); // => 'hello'

Working with Object:

existsAssign({hello: 'world'}, null) // => {hello: 'world'}
existsAssign({hello: 'Aloha'}, {hello: 'world'}) // => {hello: 'world'}

You can provide more than one source:

existsAssign({hello: 'world'}, null, undefined) // => {hello: 'world'}

It's equivalent to:

existsAssign(existsAssign({hello: 'world'}, null), undefined) // => {hello: 'world'}

License

MIT © Kiko Beats

changelog

1.3.1 (2016-04-27)

1.3.0 (2016-04-27)

  • Add pretest command (d59d57a)
  • Extend testing build (84b21f1)
  • Remove unnecessary dependency (7f41311)
  • Update test command (2ac4633)
  • chore(package): update lodash.clonedeep to version 4.3.1 (70ca4a2)
  • chore(package): update lodash.merge to version 4.3.0 (ee100f4)

1.2.5 (2016-02-16)

chore

  • chore(package): update lodash.clonedeep to version 4.1.0 (cbc5749)
  • chore(package): update lodash.clonedeep to version 4.2.0 (8d78513)

  • Merge pull request #2 from Kikobeats/greenkeeper-lodash.clonedeep-4.1.0 (de60285)

  • Merge pull request #4 from Kikobeats/greenkeeper-lodash.clonedeep-4.2.0 (95e924d)
  • update lodash.merge dependency (f193195)

1.2.4 (2016-02-01)

1.2.3 (2016-02-01)

  • Fix bug related with undefined values (84aa1b8)
  • Release 1.2.3 (3a65df2)
  • update bumped settings (ea048cd)

1.2.2 (2015-12-25)

1.2.1 (2015-12-09)

1.2.0 (2015-12-05)

1.1.1 (2015-12-04)

  • 1.1.1 releases (2e1e375)
  • added inmutable test (c670adc)
  • change merge dependency to reduce build size (9ab51a7)
  • deleted unnecessary dependency (f2c7f08)

1.1.0 (2015-12-02)

1.0.0 (2015-12-02)