Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
find-object-paths
Advanced tools
Find paths in objects to given key('s), value('s) or key/value combinations
Easy to use zero dependency get or find paths in objects to given key('s), value('s) or key/value combinations. It is meant to interact nicely with lodash to quickly access or test values in objects, but can be used standalone as well.
Despite other projects you also can specify values to be searched for.
Install via npm
npm install find-object-paths
acmeInc.json
{
"company": {
"name": "ACME INC",
"address": "1st Street, Toontown, TT",
"founded": "December 31st 1969",
"hasStocks": true,
"numberOfEmployees": 2,
"numberOfActors": 3
}
// see full content on github
}
import { has, findObjectPaths } from 'find-object-paths';
class TestMe {
static async main() {
let acmeInc = {};
rawFileContent = fs.readFileSync(p.resolve(__dirname, 'acmeInc.json'), 'utf-8');
acmeInc = JSON.parse(rawFileContent);
let path = findObjectPaths(acmeInc, {key: 'founded'});
// company.founded
path = findObjectPaths(acmeInc, {value: 'December 31st 1969'});
// company.founded
const allPaths: string[] = findObjectPaths(acmeInc, {key: 'actorId'}) as string[];
/* [ 'actors[0].actorId',
'actors[1].actorId',
'actors[2].actorId',
'actors[3].actorId' ]
*/
const ceoPath = findObjectPaths(acmeInc, {key: 'isCEO', value: true});
// employees[0].isCEO
has(acmeInc, 'name', 'Hugo Boss');
// true
has(acmeInc, {value: 'Hugo Boss'});
// true
}
}
TestMe.main();
See more examples implemented in tests-findObjectPaths.
findObjectPaths can be used as a lodash mixin.
import _ from '../lib/FindObjectPathsMixin';
.
.
.
const path = _.findObjectPaths(acmeInc, {key: 'numberOfActors'});
// company.numberOfActors
path = _.findObjectPaths(acmeInc, {value: 'DVD'});
// distributionChannels[1][2]
if (_.has(acmeInc, _.findObjectPaths(acmeInc, {value: 'DVD'}))) {
const dvd = _.get(acmeInc, _.findObjectPaths(acmeInc, {value: 'DVD'}));
// do something
}
Tests can be found in /test
and run by jest. To run the tests call npm test
.
has
function to check availability of keys / values in objects or arraysFAQs
Find paths in objects to given key('s), value('s) or key/value combinations
We found that find-object-paths demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.