filter-clone
v0.0.12
Published
cloning of objects and arrays by set some filters
Downloads
5
Readme
you can easy copy a js object
use like this:
npm install filter-clone --save
import filterClone from 'filter-clone'
// some code
filterClone(object, include, exclude)
if include and exclude are all exist, exclude will be ignored
object
can be a array
or object
include
can be a array
, regexp
or function
exclude
can be a array
or regexp
or function
/**
* key array
***/
var obj = { a: 1, b: 2, c: 3 }
var b = filterClone(obj, ['a', 'b'])
// b = {a:1,b:2}
var b1 = filterClone(obj, [], ['a'])
// b1 = {b:2,c:3}
/**
* key reg
***/
var obj2 = { a: 1, b: 2, c: 3 }
var b2 = filterClone(obj, /a/)
// b2 = {a:1}
var b3 = filterClone(obj, null, /a/)
// b3 = {b:2,c:3}
/**
* key,value function
***/
var obj = { a: 123, b: 234, c: [1, 2, 3] }
var b4 = filterClone(obj, function(key, value) {
return value > 1
})
//{a: 123, b: 234}
var b5 = filterClone(obj, null, function(key, value) {
return value > 1
})
//{c: Array(3)}