New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

objob

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

objob - npm Package Compare versions

Comparing version 2.7.5 to 2.7.6

274

lib/objob.js

@@ -89,75 +89,51 @@ 'use strict';

* @param {object|any[]} subject The object or array to perform the omit operation on.
* @param {string|string[]} keys The keys of the object or nested object that you would like to omit.
* @param {string|string[]} input The keys or key of the object or nested object that you would like to omit.
* @returns {object|any[]} The object or array of objects without the omited keys
*/
omit: function omit(subject) {
var keys = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
var input = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
subject = ob.clone(subject);
var subjectKeys = ob.keys(ob.flatten(subject));
var keysToKeep = [];
var flattened = ob.flatten(subject);
var updatedFlattened = {};
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
for (var key in flattened) {
if ((0, _typeOf2.default)(input) === 'array') {
var matchFound = false;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = subjectKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var subjectKey = _step.value;
try {
for (var _iterator = input[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var inputKey = _step.value;
var keepKey = true;
if ((0, _typeOf2.default)(keys) === 'array') {
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
if (key.startsWith(inputKey)) {
matchFound = true;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
for (var _iterator2 = keys[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var keyToRemove = _step2.value;
if (subjectKey === keyToRemove) {
keepKey = false;
}
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
if (_didIteratorError) {
throw _iteratorError;
}
}
} else if ((0, _typeOf2.default)(keys) === 'string') {
if (subjectKey === keys) {
keepKey = false;
}
}
if (keepKey) {
keysToKeep.push(subjectKey);
if (matchFound === false) {
updatedFlattened[key] = flattened[key];
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
} else {
if (key.startsWith(input) === false) {
updatedFlattened[key] = flattened[key];
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return ob.pick(subject, keysToKeep);
return ob.expand(updatedFlattened);
},

@@ -265,9 +241,9 @@ /**

if (true) {
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator3 = keyChains[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var i = _step3.value;
for (var _iterator2 = keyChains[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var i = _step2.value;

@@ -279,12 +255,12 @@ if (i.startsWith('[]')) {

} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
if (_didIteratorError2) {
throw _iteratorError2;
}

@@ -298,9 +274,9 @@ }

res = [];
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator4 = keyChains[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var keyChain = _step4.value;
for (var _iterator3 = keyChains[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var keyChain = _step3.value;

@@ -334,12 +310,12 @@ // This converts something like []0.name.name or []0[].name.name to 0

} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
if (_didIteratorError3) {
throw _iteratorError3;
}

@@ -359,9 +335,9 @@ }

var keys = keyChain.split('.');
var _iteratorNormalCompletion5 = true;
var _didIteratorError5 = false;
var _iteratorError5 = undefined;
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator5 = keys[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
var key = _step5.value;
for (var _iterator4 = keys[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var key = _step4.value;

@@ -384,12 +360,12 @@ if (count === keys.length) {

} catch (err) {
_didIteratorError5 = true;
_iteratorError5 = err;
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion5 && _iterator5.return) {
_iterator5.return();
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
} finally {
if (_didIteratorError5) {
throw _iteratorError5;
if (_didIteratorError4) {
throw _iteratorError4;
}

@@ -520,9 +496,9 @@ }

if ((0, _typeOf2.default)(subject) === 'array') {
var _iteratorNormalCompletion6 = true;
var _didIteratorError6 = false;
var _iteratorError6 = undefined;
var _iteratorNormalCompletion5 = true;
var _didIteratorError5 = false;
var _iteratorError5 = undefined;
try {
for (var _iterator6 = subject[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
var i = _step6.value;
for (var _iterator5 = subject[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
var i = _step5.value;

@@ -532,12 +508,12 @@ keys = keys.concat(ob.keys(i));

} catch (err) {
_didIteratorError6 = true;
_iteratorError6 = err;
_didIteratorError5 = true;
_iteratorError5 = err;
} finally {
try {
if (!_iteratorNormalCompletion6 && _iterator6.return) {
_iterator6.return();
if (!_iteratorNormalCompletion5 && _iterator5.return) {
_iterator5.return();
}
} finally {
if (_didIteratorError6) {
throw _iteratorError6;
if (_didIteratorError5) {
throw _iteratorError5;
}

@@ -632,9 +608,9 @@ }

var _iteratorNormalCompletion7 = true;
var _didIteratorError7 = false;
var _iteratorError7 = undefined;
var _iteratorNormalCompletion6 = true;
var _didIteratorError6 = false;
var _iteratorError6 = undefined;
try {
for (var _iterator7 = Object.keys(shallowSubject)[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
var key = _step7.value;
for (var _iterator6 = Object.keys(shallowSubject)[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
var key = _step6.value;

@@ -646,12 +622,12 @@ if ((0, _typeOf2.default)(shallowSubject[key]) !== 'object' && (0, _typeOf2.default)(shallowSubject[key]) !== 'array') {

} catch (err) {
_didIteratorError7 = true;
_iteratorError7 = err;
_didIteratorError6 = true;
_iteratorError6 = err;
} finally {
try {
if (!_iteratorNormalCompletion7 && _iterator7.return) {
_iterator7.return();
if (!_iteratorNormalCompletion6 && _iterator6.return) {
_iterator6.return();
}
} finally {
if (_didIteratorError7) {
throw _iteratorError7;
if (_didIteratorError6) {
throw _iteratorError6;
}

@@ -735,51 +711,51 @@ }

* @param {object|any[]} subject The object or array of objects to perform the pick operation on
* @param {string|string[]} keys The keys you would like to pick
* @param {string|string[]} input The keys or key you would like to pick
* @returns {object|any[]} The object or array of objects with only the picked keys.
*/
pick: function pick(subject) {
var keys = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
var input = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
subject = ob.clone(subject);
var resp = undefined;
var flattened = ob.flatten(subject);
var updatedFlattened = {};
resp = {};
for (var key in flattened) {
if ((0, _typeOf2.default)(input) === 'array') {
var matchFound = false;
var _iteratorNormalCompletion7 = true;
var _didIteratorError7 = false;
var _iteratorError7 = undefined;
var flat = ob.flatten(subject);
for (var actualKey in flat) {
if ((0, _typeOf2.default)(keys) === 'array') {
var _iteratorNormalCompletion8 = true;
var _didIteratorError8 = false;
var _iteratorError8 = undefined;
try {
for (var _iterator8 = keys[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
var desiredKey = _step8.value;
for (var _iterator7 = input[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
var inputKey = _step7.value;
if (actualKey === desiredKey) {
resp[actualKey] = flat[actualKey];
if (key.startsWith(inputKey)) {
matchFound = true;
}
}
} catch (err) {
_didIteratorError8 = true;
_iteratorError8 = err;
_didIteratorError7 = true;
_iteratorError7 = err;
} finally {
try {
if (!_iteratorNormalCompletion8 && _iterator8.return) {
_iterator8.return();
if (!_iteratorNormalCompletion7 && _iterator7.return) {
_iterator7.return();
}
} finally {
if (_didIteratorError8) {
throw _iteratorError8;
if (_didIteratorError7) {
throw _iteratorError7;
}
}
}
} else if ((0, _typeOf2.default)(keys) === 'string') {
if (actualKey === keys) {
resp[actualKey] = flat[actualKey];
if (matchFound === true) {
updatedFlattened[key] = flattened[key];
}
} else {
if (key.startsWith(input) === true) {
updatedFlattened[key] = flattened[key];
}
}
}
return ob.expand(resp);
return ob.expand(updatedFlattened);
},

@@ -820,9 +796,9 @@ /**

if ((0, _typeOf2.default)(subject) === 'array') {
var _iteratorNormalCompletion9 = true;
var _didIteratorError9 = false;
var _iteratorError9 = undefined;
var _iteratorNormalCompletion8 = true;
var _didIteratorError8 = false;
var _iteratorError8 = undefined;
try {
for (var _iterator9 = subject[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
var i = _step9.value;
for (var _iterator8 = subject[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
var i = _step8.value;

@@ -832,12 +808,12 @@ values = values.concat(ob.values(i));

} catch (err) {
_didIteratorError9 = true;
_iteratorError9 = err;
_didIteratorError8 = true;
_iteratorError8 = err;
} finally {
try {
if (!_iteratorNormalCompletion9 && _iterator9.return) {
_iterator9.return();
if (!_iteratorNormalCompletion8 && _iterator8.return) {
_iterator8.return();
}
} finally {
if (_didIteratorError9) {
throw _iteratorError9;
if (_didIteratorError8) {
throw _iteratorError8;
}

@@ -844,0 +820,0 @@ }

{
"name": "objob",
"version": "2.7.5",
"version": "2.7.6",
"description": "A tool for controlling and manipulating javascript object fields and output.",

@@ -5,0 +5,0 @@ "main": "lib/objob.js",

@@ -76,32 +76,28 @@ 'use strict';

* @param {object|any[]} subject The object or array to perform the omit operation on.
* @param {string|string[]} keys The keys of the object or nested object that you would like to omit.
* @param {string|string[]} input The keys or key of the object or nested object that you would like to omit.
* @returns {object|any[]} The object or array of objects without the omited keys
*/
omit: function(subject, keys = []){
subject = ob.clone(subject);
let subjectKeys = ob.keys(ob.flatten(subject));
let keysToKeep = [];
omit: function(subject, input = []){
let flattened = ob.flatten(subject);
let updatedFlattened = {};
for( let subjectKey of subjectKeys ) {
let keepKey = true;
if(type(keys) === 'array') {
for( let keyToRemove of keys ){
if(subjectKey === keyToRemove){
keepKey = false;
for(let key in flattened) {
if(type(input) === 'array') {
let matchFound = false;
for(let inputKey of input) {
if(key.startsWith(inputKey)) {
matchFound = true;
}
}
} else if(type(keys) === 'string') {
if(subjectKey === keys){
keepKey = false;
if(matchFound === false) {
updatedFlattened[key] = flattened[key];
}
} else {
if(key.startsWith(input) === false) {
updatedFlattened[key] = flattened[key];
}
}
if(keepKey){
keysToKeep.push(subjectKey);
}
}
return ob.pick(subject, keysToKeep);
return ob.expand(updatedFlattened);
},

@@ -560,28 +556,28 @@ /**

* @param {object|any[]} subject The object or array of objects to perform the pick operation on
* @param {string|string[]} keys The keys you would like to pick
* @param {string|string[]} input The keys or key you would like to pick
* @returns {object|any[]} The object or array of objects with only the picked keys.
*/
pick: (subject, keys = []) => {
subject = ob.clone(subject);
let resp;
pick: (subject, input = []) => {
let flattened = ob.flatten(subject);
let updatedFlattened = {};
resp = {};
let flat = ob.flatten(subject);
for (let actualKey in flat){
if(type(keys) === 'array') {
for (let desiredKey of keys){
if(actualKey === desiredKey) {
resp[actualKey] = flat[actualKey];
for(let key in flattened) {
if(type(input) === 'array') {
let matchFound = false;
for(let inputKey of input) {
if(key.startsWith(inputKey)) {
matchFound = true;
}
}
} else if(type(keys) === 'string') {
if(actualKey === keys) {
resp[actualKey] = flat[actualKey];
if(matchFound === true) {
updatedFlattened[key] = flattened[key];
}
} else {
if(key.startsWith(input) === true) {
updatedFlattened[key] = flattened[key];
}
}
}
return ob.expand(resp);
return ob.expand(updatedFlattened);
},

@@ -588,0 +584,0 @@ /**

@@ -7,3 +7,3 @@ /* eslint max-nested-callbacks: 0*/

describe('omit', () => {
let ob1, ob2, ob3;
let ob1, ob2, ob3, ob4;
let arr2;

@@ -36,2 +36,17 @@

ob4 = {
'id': { description: 'The id', example: '5634d4760066be016bf10c09'},
'name': { description: 'The name', example: 'Jane Doe'},
'email':{
description:'Email address',
example: () => {
return faker.internet.email();
},
},
'username': { description: 'The username', example: 'janedoe'},
'password': { description: 'The password', example: 'testtest'},
'date_created': { description: 'Date created', example: '2015-10-31T14:47:18.000Z'},
'date_modified': { description: 'Date modified', example: '2015-10-31T14:47:18.000Z'},
};
arr2 = [ob1, ob2];

@@ -45,2 +60,4 @@

expect(ob.omit(ob2, ['name', 'age'])).to.deep.equal({weight: ob2.weight, feet: ob2.feet});
expect(Object.keys(ob.omit(ob4, ['date_modified', 'date_created'])))
.to.deep.equal(['id','name','email','username','password']);

@@ -47,0 +64,0 @@ expect(ob.omit(ob3, ['eyes[].0.location'])).to.deep.equal({

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