Skip to content

Allow only access to known object properties using ES2015 Proxy

License

Notifications You must be signed in to change notification settings

sindresorhus/known

Repository files navigation

known

Allow only access to known object properties using ES2015 Proxy

Install

$ npm install known

Usage

import known from 'known';

const object = {foo: true};

console.log(object.bar);
//=> undefined

const object2 = known(object);

// Throws a TypeError when you try to access an unknown property
console.log(object2.bar);
//=> [TypeError] Unknown property: bar

Note that known transparently wraps the given object, meaning prototype properties will also exist. So known(someObject).__proto__ does not throw. If you want non-own properties to throw, ensure your object is created with Object.create(null).

Related

  • on-change - Watch an object or array for changes (Uses Proxy too)
  • negative-array - Negative array index support (Uses Proxy too)

About

Allow only access to known object properties using ES2015 Proxy

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •