Skip to content

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

License

Notifications You must be signed in to change notification settings

entwicklerstube/constant-factory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: {
//       DONE: 'MY_CONSTANT_STATUS_DONE',
//       OPEN: 'MY_CONSTANT_STATUS_OPEN'
//     }
//   }
// }

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published