New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

filter-clone

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filter-clone

cloning of objects and arrays by set some filters

latest
npmnpm
Version
0.0.12
Version published
Maintainers
1
Created
Source

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

Keywords

js

FAQs

Package last updated on 31 Dec 2019

Related posts