https://github.com/andrejewski/constance
Constants with prefix and postfix options
https://github.com/andrejewski/constance
Last synced: 10 months ago
JSON representation
Constants with prefix and postfix options
- Host: GitHub
- URL: https://github.com/andrejewski/constance
- Owner: andrejewski
- License: isc
- Created: 2014-11-16T16:53:45.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-07-10T21:14:55.000Z (over 10 years ago)
- Last Synced: 2025-04-05T00:02:37.922Z (10 months ago)
- Language: JavaScript
- Size: 137 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Constance
Create constants with ease. Inspired by React's `keyMirror` module, Constance accepts an object and mirrors the keys onto their values. Constance also allows you to prefix and postfix constants, either to provide proper namespacing or cut down on the verbosity of writing out constants. Constance works with arrays too.
```sh
npm install constance
```
```js
var constance = require('constance');
var methods = ['save', 'update', 'validate'];
// normal
var events = constance(methods);
/* => {
save: 'save',
update: 'update',
validate: 'validate'
} */
// prefixing
var hooks = constance('pre_', methods);
/* => {
save: 'pre_save',
update: 'pre_update',
validate: 'pre_validate'
} */
// postfixing
var actions = constance(methods, '_action');
/* => {
save: 'save_action',
update: 'update_action',
validate: 'validate_action'
} */
```
## Contributing
We can always have more tests: if you find a bug, create an issue or be **fabulous** and fix the problem and write the tests up yourself in a coherent pull request.
Run tests with the `npm test` command.
Follow me on [Twitter](http://chrisandrejewski.com/twitter) for updates or just for the lolz and please check out my other [repositories](https://github.com/andrejewski) if I have earned it. I thank you for reading.