diff --git a/Object.js b/Object.js index f9fcbc7..7fba618 100644 --- a/Object.js +++ b/Object.js @@ -2,6 +2,14 @@ * * * +* XXX shoule we add these from object to Object? +* - .parent(..) +* - .parentProperty(..) +* - .parentCall(..) +* - .parentOf(..) +* - .childOf(..) +* - .related(..) +* **********************************************/ /* c8 ignore next 2 */ ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) (function(require){ var module={} // make module AMD/node compatible... @@ -14,20 +22,34 @@ var object = require('ig-object') /*********************************************************************/ +// import stuff from object.js to Object... -Object.deepKeys = - Object.deepKeys - || object.deepKeys +var toObject = function(...keys){ + keys.forEach(function(key){ + Object[key] + || (Object[key] = object[key]) }) } + +toObject( + 'deepKeys', + + // XXX these should be called logically relative to Array.js and diff.js... + 'match', + 'matchPartial', + + /* XXX not yet sure about these... + // XXX EXPERIMENTAL... + 'parent', + 'parentProperty', + 'parentCall', + + 'parentOf', + 'childOf', + 'related', + //*/ +) -// XXX unify this with ./Array.js (.match(..)) and diff.js -Object.match = - Object.match - || object.match -Object.matchPartial = - Object.matchPartial - || object.matchPartil - +//--------------------------------------------------------------------- // Make a full key set copy of an object... // @@ -39,6 +61,11 @@ Object.flatCopy = function(obj){ return res }, {}) } +// XXX for some reason neumric keys do not respect order... +// to reproduce: +// Object.keys({a:0, x:1, 10:2, 0:3, z:4, ' 1 ':5}) +// // -> ["0", "10", "a", "x", "z", " 1 "] +// ...this is the same across Chrome and Firefox... Object.sort = function(obj, keys){ keys = (typeof(keys) == 'function' || keys === undefined) ? @@ -47,13 +74,16 @@ Object.sort = function(obj, keys){ new Set([...keys, ...Object.keys(obj)]) .forEach(function(k){ if(k in obj){ - var v = obj[k] + var v = Object.getOwnPropertyDescriptor(obj, k) delete obj[k] - obj[k] = v } }) + Object.defineProperty(obj, k, v) } }) return obj } -// keep the null prototype clean... -//Object.prototype.sort = function(keys){ -// return Object.sort(this, keys) } +Object.prototype.sort + || Object.defineProperty(Object.prototype, 'sort', { + enumerable: false, + value: function(keys){ + return Object.sort(this, keys) }, }) + diff --git a/package.json b/package.json index 4bbcdeb..30d235d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-types", - "version": "2.0.14", + "version": "2.0.15", "description": "Generic JavaScript types and type extensions...", "main": "main.js", "scripts": { diff --git a/test.js b/test.js index 167235d..d192ce7 100755 --- a/test.js +++ b/test.js @@ -34,7 +34,6 @@ var tests = test.Tests({ var cases = test.Cases({ // Object.js // - // XXX need to test sort with cmp function... Object: function(assert){ var o = Object.assign( Object.create({ @@ -63,14 +62,12 @@ var cases = test.Cases({ }, // Array.js - // - flat - // - includes + // - flat (???) + // - includes (???) // - first // - last // - compact // - len - // - toKeys - // - toMap // - unique // - tailUnique // - cmp @@ -79,6 +76,8 @@ var cases = test.Cases({ // - mapChunks // - filterChunks // - reduceChunks + // - toKeys + // - toMap Array: function(assert){ },