diff --git a/Object.js b/Object.js index 1c9c665..b400f3f 100644 --- a/Object.js +++ b/Object.js @@ -9,33 +9,33 @@ require('object-run') +var object = require('ig-object') + /*********************************************************************/ -// Get all the accessible keys... -// -// This is different to Object.keys(..) in that this will return keys -// from all the prototypes in the inheritance chain while .keys(..) will -// only return the keys defined in the current object only. -Object.deepKeys = function(obj){ - var res = [] - while(obj != null){ - res = res.concat(Object.keys(obj)) - obj = obj.__proto__ - } - return res.unique() } +Object.deepKeys = + Object.deepKeys + || object.deepKeys + + +Object.match = + Object.match + || object.match +Object.matchPartial = + Object.matchPartial + || object.matchPartil // Make a full key set copy of an object... // // NOTE: this will not deep-copy the values... Object.flatCopy = function(obj){ - var res = {} - Object.deepKeys(obj).forEach(function(key){ - res[key] = obj[key] - }) - return res } + return Object.deepKeys(obj) + .reduce(function(res, key){ + res[key] = obj[key] + return res }, {}) } diff --git a/package.json b/package.json index daf95c2..b281c6e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-types", - "version": "2.0.6", + "version": "2.0.7", "description": "Generic JavaScript types and type extensions...", "main": "main.js", "scripts": { diff --git a/test.js b/test.js index 8840537..e903adf 100755 --- a/test.js +++ b/test.js @@ -10,6 +10,7 @@ var colors = require('colors') var test = require('ig-test') +var object = require('ig-object') var types = require('./main') var containers = require('./containers') @@ -29,6 +30,21 @@ var tests = test.Tests({ var cases = test.Cases({ + // Object.js + // - flatCopy + Object: function(assert){ + var o = Object.assign( + Object.create({ + x: 111, + y: 222, + }), { + y: 333, + z: 444, + }) + var oo = Object.flatCopy(o) + + assert(Object.match(oo, {x: 111, y: 333, z: 444}), '') + }, // Array.js // - flat // - includes