Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

assign.js

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assign.js - npm Package Compare versions

Comparing version 2.5.6 to 2.6.0

57

lib/assign.js

@@ -134,2 +134,59 @@ 'use strict'

assigner.mask = function (source, mask) {
var self = this
if (!source || !mask) return source
if (_.isPlainObject( source ) ) {
var object = { }
var index = -1, props = Object.keys( mask ), length = props.length
while (++index < length) {
var key = props[index]
if ( !mask[key] ) continue
object[ key ] = _.isPlainObject( mask[key] ) ? self.mask( source[key], mask[key] ) : source[key]
}
return object
}
else if (_.isArray( source ) ) {
var array = []
source.forEach( function ( element ) {
array.push( self.mask( element, mask ) )
} )
return array
}
return source
}
assigner.purify = function (source, mask) {
var self = this
if (!source || !mask) return source
if (_.isPlainObject( source ) ) {
var object = { }
var index = -1, props = Object.keys( source ), length = props.length
while (++index < length) {
var key = props[index]
if ( !mask[key] ) object[ key ] = source[key]
else if ( _.isPlainObject(mask[key]) ) object[ key ] = self.purify( source[key], mask[key] )
}
return object
}
else if (_.isArray( source ) ) {
var array = []
source.forEach( function ( element ) {
array.push( self.purify( element, mask ) )
} )
return array
}
return source
}
assigner.pick = function (object, properties) {

@@ -136,0 +193,0 @@ var obj = { }

2

package.json
{
"name": "assign.js",
"version": "2.5.6",
"version": "2.6.0",
"description": "Tiny libary to assign objects",

@@ -5,0 +5,0 @@ "keywords": [

@@ -71,4 +71,12 @@ Assign.js - dependency-free very minimal assign function

assigner.cloneObject( source )
assigner.cloneObject( source )
This created a cloned object from the source copied recursively.
assigner.mask( source, mask )
This created an object with the references only allowed by the mask object.
assigner.purify( source, mask )
This created an object with the references only not denifed by the mask object.

@@ -24,2 +24,40 @@ 'use strict'

}
let entity = {
name: 'Peter',
id: 10,
address: {
street: 'Nowhere 1',
country: 'UK'
},
social: {
twitter: '',
facebook: ''
}
}
// keep
let mask = {
name: true,
address: {
country: true
},
social: {
twitter: true,
facebook: false
}
}
// remove
let purify = {
id: 10,
address: {
street: true
},
social: {
twitter: true,
facebook: false
}
}
before(function (done) {

@@ -64,2 +102,13 @@ done()

})
it('Masking', function (done) {
let res = assigner.mask( entity, mask )
console.log( res )
done()
})
it('Purifying', function (done) {
let res = assigner.purify( entity, purify )
console.log( res )
done()
})
})

@@ -66,0 +115,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc