defined-object

1.0.3 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i defined-object

Weekly Downloads

0

Version

1.0.3

License

MIT

Last publish

Collaborators

  • tomzer0