Skip to content

10xly/safe-property-access

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

safe-property-access

Access properties on a JS object reliably, throwing an error if the property does not exist. Does not support symbol keys (silently returns undefined). Notice: Does not keep bound-this properties. Throws if the

Installation

npm install safe-property-access

Usage

var access = require("safe-property-access")

console.log(access({ a: 1 }, "a")) // 1
console.log(access({ foo: "bar" }, "nonExistentProperty")) // Error: expects something with nonExistentProperty property

console.log(access({ undefinedValue: undefined }, "undefinedValue")) // Error: expects something with undefinedValue property
// length has its own special one
console.log(access.length("hi")) // 2
console.log(access.length(access)(access) === access.length) // true

About

get a property on something if it exists, otherwise throw an error

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors