Socket
Socket
Sign inDemoInstall

find-key

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.1 to 2.1.3

2

changelog.md
###find-key changelog
v2.1.3 - merged upstream changes to codebase and updated devDeps, also increased test coverage to node 10
v2.0.0 - updated devDependencies lab and code, added use strict and ES6 features and added basic-utils for type checking

@@ -4,0 +6,0 @@

35

lib/index.js

@@ -5,33 +5,20 @@ 'use strict';

module.exports = exports = internals.findKey = (obj, key, results) => {
module.exports = exports = internals.findKey = (jsObject, requiredKey, results = []) => {
results = results || [];
if (obj === null || typeof obj === 'undefined') {
return;
if (((typeof jsObject) !== 'object') || ((typeof requiredKey) !== 'string')) {
return undefined;
}
if (typeof key !== 'string') {
return;
}
for (const key in jsObject) {
const value = jsObject[key];
if (key === requiredKey && !results.includes(value)) {
results.push(value);
}
const keys = Object.keys(obj);
for (let i = 0; i < keys.length; ++i) {
const name = keys[i];
const subkeys = obj[name];
if (typeof subkeys === 'object') {
if (name === key) {
results.push(subkeys);
}
internals.findKey(subkeys, key, results);
if ((typeof value) === 'object') {
results = internals.findKey(value, requiredKey, results);
}
else {
if (name === key) {
if (results.indexOf(subkeys) === -1) {
results.push(subkeys);
}
}
}
}
return results;
};
{
"name": "find-key",
"version": "2.1.1",
"version": "2.1.3",
"description": "find value inside nested object from key name",

@@ -16,5 +16,5 @@ "main": "lib/index.js",

"devDependencies": {
"code": "^5.2.0",
"coveralls": "^3.0.0",
"lab": "^15.4.1"
"code": "^5.2.1",
"coveralls": "^3.0.2",
"lab": "^17.0.1"
},

@@ -21,0 +21,0 @@ "engines": {

@@ -40,3 +40,15 @@ 'use strict';

const expectedArrayResultOnPassingValidParameters = [
{
type: 'string',
format: 'lookup'
},
'lookup',
{
test: 'dbRef'
},
'dbRef'
];
describe('Find', () => {

@@ -67,4 +79,5 @@

expect(result).to.have.length(4);
expect(result).to.equal(expectedArrayResultOnPassingValidParameters);
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc