checked-constants
Grepable typo-resistant namespaced constants
Example
//// constants.jsconst cc = // define singlecc`my/namespace/pi ` // define multiplecc`my/namespace/ foo frobulate ` //// file1.jsconst cc = 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.