constant-factory
v1.2.1
Published
Stop rewriting the constant name in each entry use a factory for this job
Downloads
4
Maintainers
Readme
Constant Factory
Stop rewriting the constant name in each entry use a factory for this job
Install
npm
npm install constant-factory --save-dev
yarn
yarn add constant-factory --dev
Usage
// normal
constant(CONSTANT_NAME<STRING>, CONSTANT_ENTRIES<ARRAY>)
// advanced
constant(CONSTANT_COLLETION<ARRAY>)
Example
Before:
export const MY_CONSTANT = {
TODO: 'MY_CONSTANT_TODO',
ISSUES: 'MY_CONSTANT_ISSUES',
}
Now:
import c from 'constant-factory'
export const MY_CONSTANT = c('MY_CONSTANT', [
'TODO',
'ISSUES'
])
// returns
// {
// TODO: 'MY_CONSTANT_TODO',
// ISSUES: 'MY_CONSTANT_ISSUES'
// }
Advanced:
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
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: [
// 'MY_CONSTANT_STATUS_DONE',
// 'MY_CONSTANT_STATUS_OPEN'
// ]
// }
// }