defined-object
v1.0.3
Published
Objects which enforce reading only defined properties
Downloads
8
Readme
Defined Object
Usage
const definedObject = require('defined-object')
const CONSTANTS = definedObject({
IMPORTANT_IMMUTABLE_CONST: 'bar',
API_KEY: 'sh',
POOL_AMT: 5,
});
CONSTANTS.IMPORTANT_IMMUTABLE_CONST
// 'bar'
CONSTANTS.what_the_f_are_you_doing
// Error: Undefined property what_the_4_are_you_doing on { IMPORTANT_IMMUTABLE_CONST: 'bar', API_KEY: 'sh', POOL_AMT: 5 }
CONSTANTS.IMPORTANT_IMMUTABLE_CONST = "oops"
// Error: Cannot set properties on read only object
Why?
This came out of multiple production breakages related to
CONSTANT.Property === Something
and no error was being thrown because
CONSTANT.Property
was undefined
and silently failing
while CONSTANT.property
was the actual value.
Crash early.