Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

undefsafe

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

undefsafe

Undefined safe way of extracting object properties

  • 2.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is undefsafe?

The undefsafe package is a utility for safely accessing deeply nested properties of an object. It allows developers to query properties without worrying about intermediate properties being undefined or null. This can be particularly useful in situations where the structure of an object might be unpredictable or when dealing with JSON objects returned from an API.

What are undefsafe's main functionalities?

Safe property access

This feature allows for the safe querying of nested properties. If any property in the path is undefined, undefsafe will return `undefined` instead of throwing an error.

const undefsafe = require('undefsafe');
const obj = { a: { b: { c: 'd' } } };
console.log(undefsafe(obj, 'a.b.c')); // 'd'
console.log(undefsafe(obj, 'a.x.c')); // undefined

Setting deeply nested values safely

Undefsafe can also be used to set a value at a deeply nested path within an object. If any part of the path does not exist, it will be created.

const undefsafe = require('undefsafe');
let obj = {};
undefsafe(obj, 'a.b.c', 'd');
console.log(obj.a.b.c); // 'd'

Other packages similar to undefsafe

Keywords

FAQs

Package last updated on 15 Feb 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc