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
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';

export const {
    ADD_TODO,
    REMOVE_TODO,
    TOGGLE_TODO
} = 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';

export const {
    ADD_TODO,
    REMOVE_TODO,
    TOGGLE_TODO
} = constants('ns', [
    'ADD_TODO',
    'REMOVE_TODO',
    'TOGGLE_TODO'
]);
// {
//   'ADD_TODO': 'ns:ADD_TODO',
//   'REMOVE_TODO': 'ns:REMOVE_TODO'
//   'TOGGLE_TODO': 'ns:TOGGLE_TODO'
// }
Mixing with string and object types
const result = constants('ns', [
    'ADD_TODO',
    'REMOVE_TODO',
    'TOGGLE_TODO',
    {
	FETCH: ['REQUEST', 'SUCCESS', 'FAILURE'],
	EXPORT: 'REQUEST'
    }
]);
// {
//   'ADD_TODO': 'ns:ADD_TODO',
//   'REMOVE_TODO': 'ns:REMOVE_TODO',
//   'TOGGLE_TODO': 'ns:TOGGLE_TODO',
//   'FETCH': {
//     'REQUEST': 'ns:FETCH.REQUEST',
//     'SUCCESS': 'ns:FETCH.SUCCESS',
//     'FAILURE': 'ns:FETCH.FAILURE'
//   },
//   'EXPORT': 'ns:EXPORT.REQUEST'
// }
Use a custom separator
export const {
    ADD_TODO,
    REMOVE_TODO,
    TOGGLE_TODO
} = constants('ns', [
    'ADD_TODO',
    'REMOVE_TODO',
    'TOGGLE_TODO'
], { separator: '/' });
// {
//   'ADD_TODO': 'ns/ADD_TODO',
//   'REMOVE_TODO': 'ns/REMOVE_TODO'
//   'TOGGLE_TODO': 'ns/TOGGLE_TODO'
// }

License

MIT

Keywords

FAQs

Last updated on 29 May 2019

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