https://github.com/entwicklerstube/constant-factory
🏭 Stop rewriting the constant name in each entry use a factory for this job
https://github.com/entwicklerstube/constant-factory
constant generator react redux
Last synced: about 2 months ago
JSON representation
🏭 Stop rewriting the constant name in each entry use a factory for this job
- Host: GitHub
- URL: https://github.com/entwicklerstube/constant-factory
- Owner: entwicklerstube
- License: mit
- Created: 2017-03-21T09:06:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-06-01T01:22:16.000Z (about 6 years ago)
- Last Synced: 2025-02-24T05:18:07.637Z (over 1 year ago)
- Topics: constant, generator, react, redux
- Language: JavaScript
- Homepage: https://npmjs.com/constant-factory
- Size: 1.59 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Constant Factory
> Stop rewriting the constant name in each entry use a factory for this job
[]()
[](https://coveralls.io/github/entwicklerstube/constant-factory?branch=master)
[](https://travis-ci.org/entwicklerstube/constant-factory)
[](https://greenkeeper.io/)
### Install
**npm**
```
npm install constant-factory --save-dev
```
**yarn**
```
yarn add constant-factory --dev
```
### Usage
```js
// normal
constant(CONSTANT_NAME, CONSTANT_ENTRIES)
// advanced
constant(CONSTANT_COLLETION)
```
### Example
Before:
```js
export const MY_CONSTANT = {
TODO: 'MY_CONSTANT_TODO',
ISSUES: 'MY_CONSTANT_ISSUES',
}
```
Now:
```js
import c from 'constant-factory'
export const MY_CONSTANT = c('MY_CONSTANT', [
'TODO',
'ISSUES'
])
// returns
// {
// TODO: 'MY_CONSTANT_TODO',
// ISSUES: 'MY_CONSTANT_ISSUES'
// }
```
Advanced:
```js
import c from 'constant-factory'
export const { MY_CONSTANT, ANOTHER_CONSTANT } = c({
'MY_CONSTANT': [
'TODO', 'ISSUES'
],
'ANOTHER_CONSTANT': [
'DATES'
]
})
// returns
// {
// MY_CONSTANT: {
// TODO: 'MY_CONSTANT_TODO',
// ISSUES: 'MY_CONSTANT_ISSUES'
// },
// ANOTHER_CONSTANT: {
// DATES: 'ANOTHER_CONSTANT_DATES'
// }
// }
```
Expert:
> Add additional subs in subs
```js
import c from 'constant-factory'
export const { MY_CONSTANT, ANOTHER_CONSTANT } = c({
'MY_CONSTANT': [
'TODO',
{
'STATUS': [
'DONE',
'OPEN',
]
}
],
})
// returns
// {
// MY_CONSTANT: {
// TODO: 'MY_CONSTANT_TODO',
// STATUS: {
// DONE: 'MY_CONSTANT_STATUS_DONE',
// OPEN: 'MY_CONSTANT_STATUS_OPEN'
// }
// }
// }
```