
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
object-rover
Advanced tools
A package to get, read and modify nested javascript object properties.
A package to get, read and modify nested javascript object properties. List all nested leaf properties of object, optionally get their primitive types, then iterate over them and change what you need. Very useful for json validation. This package will be used for a complete rewrite of express-autosanitizer, a popular tool that cleans xss injections from express requests.
If this does help you, please consider making a tiny donation here, even small amounts help! 🤝
npm i object-rover
const rover = require('object-rover');
const testObj = {
foo: null,
bar: {
a: {
b: 'hello'
},
c: false
}
};
rover.getProperties(testObj)
// ['foo', 'bar.c', 'bar.a.b']
await rover.getPropertiesAsync(testObj)
// ['foo', 'bar.c', 'bar.a.b']
// for a list of types, read types section
rover.getPropertiesWithTypes(testObj)
// [{ path: 'foo', type: 'null' },
// { path: 'bar.c', type: 'boolean' },
// { path: 'bar.a.b', type: 'string' }]
await rover.getPropertiesWithTypesAsync(testObj)
// [{ path: 'foo', type: 'null' },
// { path: 'bar.c', type: 'boolean' },
// { path: 'bar.a.b', type: 'string' }]
rover.getProperty(testObj, 'foo') // null
rover.getProperty(testObj, 'bar.a.b') // 'hello'
rover.getProperty(testObj, 'bar.a')
// testObj.bar.a object will be returned
// set is mutating, so we clone testObj if we need to get a new object
rover.setProperty({ ...testObj }, 'bar.a.b', 44)
// returns an object like testObj except testObj.bar.a.b will be 44
Returned types are JavaScript Primitive types, with null and array. JavaScript recognizes null and arrays as objects, but you might need to filter them out or do something with them, so object-rover indicates that.
divider is a nonempty string that is used to parse/generate paths, by default it is a dot. if you pass '-' for example, you will get paths like bar-a-b
selector is the path string, e.g. 'bar.a.c'
getProperties(obj: object, divider?: string): string[]
getPropertiesAsync(obj: object, divider?: string): Promise<string[]>
getPropertiesWithTypes(obj: object,divider?: string): { path: string; type: PrimitiveType }[]
getPropertiesWithTypesAsync(obj: object,divider?: string): Promise<{ path: string; type: PrimitiveType }[]>
setProperty(obj: object,selector: string,value: any,divider?: string): object
getProperty(obj: object,selector: string,divider?: string): PrimitiveType | object
Distributed under the MIT License. See LICENSE
for more information.
A huge portion of this package is based on code written by coderaiser
Antonio Ramirez: sepehralizade@live.com
Project Link: Github
how to get all nested properties of object how to list all leaf properties of object list nested properties of object list nested primitive properties of object set nested property of object get nested property of object
FAQs
A package to get, read and modify nested javascript object properties.
The npm package object-rover receives a total of 5 weekly downloads. As such, object-rover popularity was classified as not popular.
We found that object-rover demonstrated a not healthy version release cadence and project activity because the last version was released 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
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.