Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cheton/namespace-constants
Namespacing Redux action type constant values.
https://github.com/cheton/namespace-constants
Last synced: about 1 month ago
JSON representation
Namespacing Redux action type constant values.
- Host: GitHub
- URL: https://github.com/cheton/namespace-constants
- Owner: cheton
- License: mit
- Created: 2016-05-31T03:39:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-08-27T11:45:06.000Z (about 5 years ago)
- Last Synced: 2024-05-21T17:09:46.882Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# namespace-constants [![build status](https://travis-ci.org/cheton/namespace-constants.svg?branch=master)](https://travis-ci.org/cheton/namespace-constants) [![Coverage Status](https://coveralls.io/repos/github/cheton/namespace-constants/badge.svg?branch=master)](https://coveralls.io/github/cheton/namespace-constants?branch=master)
[![NPM](https://nodei.co/npm/namespace-constants.png?downloads=true&stars=true)](https://www.npmjs.com/package/namespace-constants)
Namespacing Redux action type constant values.
![image](https://user-images.githubusercontent.com/447801/58611444-acced780-82e1-11e9-9772-69cfaebcd679.png)
## Installation
```bash
npm install --save namespace-constants
```## Examples
### Global Constants
```js
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
```js
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
```js
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
```js
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
```js
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