mirror of
https://github.com/flynx/types.js.git
synced 2025-10-29 02:20:07 +00:00
tweaking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
d569ad185c
commit
72018510ea
34
Object.js
34
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 }, {}) }
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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": {
|
||||
|
||||
16
test.js
16
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user