underscore.object.plus

1.0.0 • Public • Published

#underscore.object.plus

Some extra object functions for underscore.js. Such as deep extend, nested pick and nested omit.

Please note that extend, isWindow and isPlainObject functions are ported from jQuery 2.1.0 (Source)

##Table of Contents

##Requirements

Underscore.js 1.6.0

##Installation ``` bash $ npm install underscore.object.plus ``` ##Downloads Version | Description ------- | ----------- [Production (1.0.0)](https://rawgithub.com/lamgavin/underscore.object.plus/master/release/1_0_0/underscore.object.plus.min.js) | _1.14KB, Minified and Gzipped ([Source Map](https://rawgithub.com/lamgavin/underscore.object.plus/master/release/1_0_0/underscore.object.plus.min.map))_ [Development (1.0.0)](https://rawgithub.com/lamgavin/underscore.object.plus/master/release/1_0_0/underscore.object.plus.js) | _6.2KB, Uncompressed ([Source Map](https://rawgithub.com/lamgavin/underscore.object.plus/master/release/1_0_0/underscore.object.plus.map))_ [CoffeeScript (1.0.0)](https://rawgithub.com/lamgavin/underscore.object.plus/master/release/1_0_0/underscore.object.plus.coffee) | _5.9KB (Uncompress and with comments)_ ##Usage ``` html <script src="http://underscorejs.org/underscore-min.js"></script> <script src="underscore.object.plus.min.js"></script> ``` Node.js through require.js ``` javascript _ = require('underscore'); _ = require('underscore.object.plus'); ``` ## List of Functions ***extend*** \_.extend([deep], target, sources...) _Ported from jQuery 2.1.0 ([API Doc](http://api.jquery.com/jQuery.extend/))_ > ***_extend_*** function ported from jQuery 2.1.0 > > Deep clone using ***_.extend({}, sources...);*** ***pick*** \_.pick(object, keys) _Aliases: ***pickNested, pickRecursive***_ _([Example](#examples-pick))_

pick function with nested functionality added.

Invoked if type of keys is strictly object (not array or function).

pick _.pick(object, keys...) Delegates to Underscore.js 1.6.0 (API Doc)

Original pick function preserved from Underscore.js

***omit*** \_.omit(object, keys) _Aliases: ***omitNested, omitRecursive***_ _([Example](#examples-omit))_

omit function with nested functionality added.

Invoked if type of keys is strictly object (not array or function).

omit _.omit(object, keys...) Delegates to Underscore.js 1.6.0 (API Doc)

Original omit function preserved from Underscore.js

***isObject*** \_.isObject(object, strict) _([Example](#examples-isObject))_

Returns true if object is strictly object (not array or function)

Invoked if strict is true

isObject _.isObject(object) Delegates to Underscore.js 1.6.0 (API Doc)

Original isObject function preserved from Underscore.js

***isTypes*** \_.isTypes(object, types...) _([Example](#examples-isTypes))_

Returns true if object is of one of the types specified by types

types can be a string, strings, array of strings or mixed

isWindow _.isWindow(object) Ported from jQuery 2.1.0 (API Doc)

isWindow function ported from jQuery 2.1.0

Ported to facilitate the porting of extend function from jQuery 2.1.0

isPlainObject _.isPlainObject(object) Ported from jQuery 2.1.0 (API Doc)

isPlainObject function ported from jQuery 2.1.0

Ported to facilitate the porting of extend function from jQuery 2.1.0

***objects*** \_.objects(object, [strict]) _([Example](#examples-objects))_

Returns a sorted list of the names of every objects (including array and function) in object, or strictly objects (not array or function) if strict is true

In another words, returns the name of every object property of object

***arrays*** \_.arrays(object) _([Example](#examples-arrays))_

Returns a sorted list of the names of every arrays in object

In another words, returns the name of every array property of object

***types*** \_.types(object, types...) _([Example](#examples-types))_

Returns a sorted list of the names of every property in object that is of one of the types specified by types

In another words, returns the name of every property of object satisfying isTypes(object, types)

## Examples ***pick*** \_.pick(object, keys) _Aliases: ***pickNested, pickRecursive***_ _([Back to list of functions](#list-pick))_
var stock = {
  popsicle: {
    chocolate:  15,
    fruits: {
      orange:   13,
      mango:    27
    }
  },
  "ice cream": {
    chocolate:  16,
    vanilla:    27,
    fruits: {
      orange:   21,
      mango:    16
    }
  }
};
var keys = {
  popsicle: {
    chocolate:  1,
    fruits: {
      mango:    1
    }
  },
  "ice cream": {
    fruits: ['orange', 'mango']
  }
};

_.pick(stock, keys);

{ popsicle: { chocolate: 15, fruits: { mango: 27 } }, "ice cream": { fruits: { orange: 21, mango: 16 } } };


_([Back to list of functions](#list-pick))_

<a name="examples-isObject" />
***isObject*** \_.isObject(object, strict)
_([Back to list of functions](#list-isObject))_

``` javascript
_.isObject({}, true);
// => true

_.isObject([], true);
// => false

_.isObject(function() {}, true);
// => false

(Back to list of functions)

***omit*** \_.omit(object, keys) _Aliases: ***omitNested, omitRecursive***_ _([Back to list of functions](#list-omit))_
var stock = {
  popsicle: {
    chocolate:  15,
    fruits: {
      orange:   13,
      mango:    27
    }
  },
  "ice cream": {
    chocolate:  16,
    vanilla:    27,
    fruits: {
      orange:   21,
      mango:    16
    }
  }
};
var keys = {
  popsicle: {
    fruits: {
      orange:   1
    }
  },
  "ice cream": {
    fruits: ['orange', 'mango']
  }
};

_.omit(stock, keys);

{ popsicle: { chocolate: 15, fruits: { mango: 27 } }, "ice cream": { chocolate: 16, vanilla: 27 } };


_([Back to list of functions](#list-omit))_

<a name="tests" />
## Tests
Version | URL
------- | ---
master  | https://rawgithub.com/lamgavin/underscore.object.plus/master/test/index.html
1.0.0   | https://rawgithub.com/lamgavin/underscore.object.plus/master/test/release/1_0_0/index.html

<a name="license" />
## License
The MIT License (MIT)

Copyright (c) 2014 Gavin Lam and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

<a name="changes" />
##Change Log
***1.0.0***
- First release
- Test report: https://rawgithub.com/lamgavin/underscore.object.plus/master/test/release/1_0_0/index.html

Package Sidebar

Install

npm i underscore.object.plus

Weekly Downloads

1

Version

1.0.0

License

none

Last publish

Collaborators

  • lamgavin