1.0.0 • Published 10 years ago

underscore.object.plus v1.0.0

Weekly downloads
6
License
-
Repository
github
Last release
10 years ago

#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

Underscore.js 1.6.0

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

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

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

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

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

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

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)

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)

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

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

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

(Back to list of functions)

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)

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.