constant-factory

1.2.1 • Public • Published

Constant Factory

Stop rewriting the constant name in each entry use a factory for this job

Zero Dependencies Coverage Status Build Status greenkeeper badge

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'
//     ]
//   }
// }

Package Sidebar

Install

npm i constant-factory

Weekly Downloads

0

Version

1.2.1

License

MIT

Last publish

Collaborators

  • michaelzoidl