@ephetic/checked-constants

0.0.1 • Public • Published

checked-constants

Grepable typo-resistant namespaced constants

Example

//// constants.js
const cc = require('checked-constants')

// define single
cc`my/namespace/pi ${3}`

// define multiple
cc`my/namespace/
                foo       ${'Fooooooo!'}
                frobulate ${123}`

//// file1.js
const cc = require('checked-constants')

const msg = { type: cc`my/namespace/foo` } // reference shared constant

Purpose

String constants are easily mistyped. Aggregating constants in objects makes constants harder to grep and can still be mistyped. This libary is meant to provide a minimal syntax to define and reference constants in a safer and more consistent way.

Downsides

  • Users could still use names other than cc and format the template in hard to grep ways.
  • Constant is only checked if called. Better would be if this were a Babel transform to at least get compile-time errors if not editor feedback.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.1
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.1
    1

Package Sidebar

Install

npm i @ephetic/checked-constants

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • ephetic