🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

namespace-constants

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

namespace-constants

Add namespace to Redux action type constants without name conflicts.

1.0.1
latest
Source
npm
Version published
Weekly downloads
295
-47.79%
Maintainers
1
Weekly downloads
 
Created
Source

namespace-constants build status Coverage Status

NPM

Namespacing Redux action type constant values.

image

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

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

Pass constant values as an array of mixed types

export const {
    ADD_TODO,
    REMOVE_TODO,
    TOGGLE_TODO,
    SHOW_ALL,
    SHOW_COMPLETED,
    SHOW_ACTIVE,
    FETCH,
    EXPORT
} = constants('ns', [
    'ADD_TODO',
    'REMOVE_TODO',
    'TOGGLE_TODO',
    ['SHOW_ALL', 'SHOW_COMPLETED', 'SHOW_ACTIVE'],
    {
      'FETCH': ['REQUEST', 'SUCCESS', 'FAILURE'],
      'EXPORT': 'EXPORT'
    }
]);
// {
//   'ADD_TODO': 'ns:ADD_TODO',
//   'REMOVE_TODO': 'ns:REMOVE_TODO',
//   'TOGGLE_TODO': 'ns:TOGGLE_TODO',
//   'SHOW_ALL': 'ns:SHOW_ALL',
//   'SHOW_COMPLETED': 'ns:SHOW_COMPLETED',
//   'SHOW_ACTIVE': 'ns:SHOW_ACTIVE',
//   'FETCH': {
//     'REQUEST': 'ns:FETCH.REQUEST',
//     'SUCCESS': 'ns:FETCH.SUCCESS',
//     'FAILURE': 'ns:FETCH.FAILURE'
//   },
//   'EXPORT': 'ns:EXPORT'
// }

Pass constant values as an object of mixed types

export const {
    ADD_TODO,
    REMOVE_TODO,
    TOGGLE_TODO,
    SHOW_ALL,
    SHOW_COMPLETED,
    SHOW_ACTIVE,
    FETCH,
    EXPORT
} = constants('ns', {
    'ADD_TODO': 'ADD_TODO',
    'REMOVE_TODO': 'REMOVE_TODO',
    'TOGGLE_TODO': 'TOGGLE_TODO',
    'SHOW_ALL': 'SHOW_ALL',
    'SHOW_COMPLETED': 'SHOW_COMPLETED',
    'SHOW_ACTIVE': 'SHOW_ACTIVE',
    'FETCH': ['REQUEST', 'SUCCESS', 'FAILURE'],
    'EXPORT': 'EXPORT'
});
// {
//   'ADD_TODO': 'ns:ADD_TODO',
//   'REMOVE_TODO': 'ns:REMOVE_TODO',
//   'TOGGLE_TODO': 'ns:TOGGLE_TODO',
//   'SHOW_ALL': 'ns:SHOW_ALL',
//   'SHOW_COMPLETED': 'ns:SHOW_COMPLETED',
//   'SHOW_ACTIVE': 'ns:SHOW_ACTIVE',
//   'FETCH': {
//     'REQUEST': 'ns:FETCH.REQUEST',
//     'SUCCESS': 'ns:FETCH.SUCCESS',
//     'FAILURE': 'ns:FETCH.FAILURE'
//   },
//   'EXPORT': 'ns:EXPORT'
// }

License

MIT

Keywords

redux

FAQs

Package last updated on 30 May 2019

Did you know?

Socket

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