https://github.com/chee/exceptional-objects
create strict objects that will throw an exception if you try to get a property from them that they don't have
https://github.com/chee/exceptional-objects
Last synced: about 1 year ago
JSON representation
create strict objects that will throw an exception if you try to get a property from them that they don't have
- Host: GitHub
- URL: https://github.com/chee/exceptional-objects
- Owner: chee
- License: gpl-3.0
- Created: 2022-02-03T20:44:09.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-08-05T01:18:26.000Z (almost 4 years ago)
- Last Synced: 2025-03-15T15:40:46.682Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# exceptional objects
create strict objects that will throw an exception if you try to get a property
from them that they don't have.
uses Proxy.
here's some typed up:
```js
const exceptional = require('exceptional-objects')
const dog = exceptional({bark: 'woof', color: 'tan'})
dog.bark
//-> 'woof'
dog.color
//-> 'tan'
dog.name
//-> throws "Error: Object does not contain name"
```
you can still set things like normal:
```js
const lol = exceptional({})
console.log(lol.dog) //-> throws "Error: Object does not contain dog"
lol.dog = 'henry'
console.log(lol.dog) //-> henry
```