known
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

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)

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 4.0.0
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 4.0.0
    2
  • 3.0.0
    0
  • 2.0.0
    117
  • 1.0.0
    0

Package Sidebar

Install

npm i known

Weekly Downloads

91

Version

4.0.0

License

MIT

Unpacked Size

3.58 kB

Total Files

5

Last publish

Collaborators

  • sindresorhus