Socket
Socket
Sign inDemoInstall

namespace-constants

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    namespace-constants

Add namespace to Redux action type constants without name conflicts.


Version published
Weekly downloads
785
decreased by-44.91%
Maintainers
1
Install size
5.58 kB
Created
Weekly downloads
 

Readme

Source

namespace-constants build status Coverage Status

NPM

Add namespace to Redux action type constants without name conflicts.

Installation

npm install --save namespace-constants

Examples

Global Constants
import constants from 'namespace-constants';

module.exports = constants([
    'ADD_TODO',
    'REMOVE_TODO',
    'TOGGLE_TODO'
]);
// {
//   'ADD_TODO': 'ADD_TODO',
//   'REMOVE_TODO': 'REMOVE_TODO'
//   'TOGGLE_TODO': 'TOGGLE_TODO'
// }
Namespace Constants
import constants from 'namespace-constants';

module.exports = constants('todos', [
    'ADD_TODO',
    'REMOVE_TODO',
    'TOGGLE_TODO'
]);
// {
//   'ADD_TODO': 'todos:ADD_TODO',
//   'REMOVE_TODO': 'todos:REMOVE_TODO'
//   'TOGGLE_TODO': 'todos:TOGGLE_TODO'
// }

You can pass custom separator as below:

module.exports = constants('todos', [
    'ADD_TODO',
    'REMOVE_TODO',
    'TOGGLE_TODO'
], { separator: '/' });
// {
//   'ADD_TODO': 'todos/ADD_TODO',
//   'REMOVE_TODO': 'todos/REMOVE_TODO'
//   'TOGGLE_TODO': 'todos/TOGGLE_TODO'
// }
Transform constants

You can pass a custom transform function as well:

module.exports = constants('todos', [
    'add todo',
    'remove todo',
    'toggle todo'
], {
    separator: '/',
    transform: function (v) {
        return v.replace(/\ /g, '_').toUpperCase();
    }
});
// {
//   'ADD_TODO': 'todos/ADD_TODO',
//   'REMOVE_TODO': 'todos/REMOVE_TODO'
//   'TOGGLE_TODO': 'todos/TOGGLE_TODO'
// }

License

MIT

Keywords

FAQs

Last updated on 27 Dec 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc