
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@ezzylabs/object-path
Advanced tools
@ezzylabs/object-pathAccess nested object properties using paths.
npm i @ezzylabs/object-path
// Import the module.
import objectPath from '@ezzylabs/object-path'
// Define an object with some properties.
const obj = { a: { b: 'x' } }
// Check if the property at the specified path is defined.
objectPath.has(obj, 'a.b')
// Get the property at the specified path.
objectPath.get(obj, 'a.b')
// Set the property at the specified path.
objectPath.set(obj, 'a.b', 'y')
has(obj, path)Checks if the property at the given path is defined in the obj.
// Object with properties.
const obj = { a: { b: 'x', c: [{ d: 'y' }] } }
// Named properties.
objectPath.has(obj, 'a') // returns true
objectPath.has(obj, 'a.b') // returns true
objectPath.has(obj, 'a.b.x') // returns false; 'x' is not defined
// Array elements.
objectPath.has(obj, 'a.b.c.0') // returns true
objectPath.has(obj, 'a.b.c.0.d') // returns true
objectPath.has(obj, 'a.b.c.1') // returns false; '1' is out of bounds
objectPath.has(obj, 'a.b.c.1.d') // returns false; '1' is out of bounds
// Invalid paths.
objectPath.has(obj) // throws TypeError
objectPath.has(obj, null) // throws TypeError
get(obj, path, fallback)Gets a property of the obj at the given path, or returns the fallback value if the property is not defined.
// Object with properties.
const obj = { a: { b: 'x', c: [{ d: 'y' }] } }
// Named properties.
objectPath.get(obj, 'a.b') // returns 'x'
objectPath.get(obj, 'a.x') // throws; 'x' is not defined
objectPath.get(obj, 'a.x', 'z') // returns 'z'; 'x' is not defined
// Array elements.
objectPath.get(obj, 'a.c.0.d') // returns 'y'
objectPath.get(obj, 'a.c.1.d') // throws; '1' is out of bounds
objectPath.get(obj, 'a.c.1.d', 'z') // returns 'z'; '1' is out of bounds
// Invalid paths.
objectPath.get(obj) // throws TypeError
objectPath.get(obj, null) // throws TypeError
set(obj, path, value)Sets a property at the given path.
// Object with properties.
const obj = { a: { b: 'x', c: [{ d: 'y' }] } }
// Named properties.
objectPath.set(obj, 'a.b', 'z') // modifies 'a.b' to 'z'
objectPath.set(obj, 'a.d.f', 'x') // adds 'd.f' properties to obj
// Array elements.
objectPath.set(obj, 'a.c.0', 'x') // modifies 'a.c.0' to 'x'
objectPath.set(obj, 'a.c.1', 'y') // adds 'y' to the array
objectPath.set(obj, 'a.c.3', 'w') // adds 'w' to the array; 'a.c.2' will be undefined
// Invalid paths.
objectPath.set(obj) // throws TypeError; path is not provided
objectPath.set(obj, null) // thorws TypeError; path is not valid
join(...segments)Joins multiple path segments into a single path.
// Single segment.
objectPath.join('x') // returns 'x'
objectPath.join(0) // returns '0'
objectPath.join('x.y.z') // returns 'x.y.z'
// Multiple segments.
objectPath.join('x', 'y', 'z') // Returns 'x.y.z'
objectPath.join('x', 0, 'z') // Returns 'x.0.z'
objectPath.join('x.y', 'z') // Returns 'x.y.z'
// Invalid segments.
objectPath.join('x', 'y', null) // throws TypeError; null is not a valid path segment
objectPath.join('x', 7.5, 'z') // throws; '7.5' is not a valid path segment
split(path)Splits the given path into individual segments.
// Without separators.
objectPath.split('x') // returns ['x']
// With seprators.
objectPath.split('x.y.z') // returns ['x', 'y', 'z']
objectPath.split('x.0.z') // returns ['x', '0', 'z']
// Invalid paths.
objectPath.split() // throws TypeError; undefined cannot be split
objectPath.split(null) // throws TypeError; null cannot be split
FAQs
Access nested object properties using paths
We found that @ezzylabs/object-path 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.