
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
safe-object-path
Advanced tools
A lightweight TypeScript library for safe object path access with zero dependencies.
npm install safe-object-path
import { get, has } from 'safe-object-path';
const user = {
profile: {
name: 'John Doe',
settings: {
theme: 'dark'
}
},
posts: [
{ id: 1, title: 'Hello World' },
{ id: 2, title: 'TypeScript Tips' }
]
};
// Dot notation
const name = get(user, 'profile.name'); // 'John Doe'
const theme = get(user, 'profile.settings.theme'); // 'dark'
// Array access
const firstPost = get(user, 'posts[0].title'); // 'Hello World'
// With default values
const email = get(user, 'profile.email', 'no-email@example.com');
// Check if path exists
const hasName = has(user, 'profile.name'); // true
const hasEmail = has(user, 'profile.email'); // false
get(object, path, defaultValue?)Safely gets a value from an object using a path.
Parameters:
object - The object to get the value frompath - The path to the property (string or array)defaultValue - The value to return if the path doesn't existReturns: The value at the path or defaultValue/undefined
has(object, path)Checks if a path exists in an object.
Parameters:
object - The object to checkpath - The path to check (string or array)Returns: true if the path exists, false otherwise
// Dot notation
get(obj, 'user.profile.name')
// Bracket notation
get(obj, 'users[0].name')
// Mixed notation
get(obj, 'users[0].settings.theme')
// Array paths
get(obj, ['user', 'profile', 'name'])
?.)MIT
FAQs
A lightweight TypeScript library for safe object path access
The npm package safe-object-path receives a total of 8 weekly downloads. As such, safe-object-path popularity was classified as not popular.
We found that safe-object-path 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
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.