npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

redux-create-actiontype

v1.0.0

Published

Micro library for easy Action Types generation in Redux/React.

Readme

redux-create-actiontype Build Status

Micro library for easy Action Types generation in Redux/React.

Install

$ npm install redux-create-actiontype --save

Usage

Basic Usage

Create a basic object with Action Types:

import createActionTypes from 'redux-create-actiontype';

const types = createActionTypes()(
  'LOGIN',
  'LOGOUT',
  'IS_FETCHING',
  'CREATE_ACTION',
  { 'USER': { api: true } }
);

/* it is going to generate
const types = {
  LOGIN: 'LOGIN',
  LOGOUT: 'LOGOUT',
  IS_FETCHING: 'IS_FETCHING',
  CREATE_ACTION: 'CREATE_ACTION',
  USER_FETCHING: 'USER_FETCHING',
  USER_SUCCESS: 'USER_SUCCESS',
  USER_ERROR: 'USER_ERROR'
};
*/

A nested example which is closer to a real world project:

const types = createActionTypes('my app')(
  'login',
  'logout',
  createActionTypes('users')(
    { 'fetch': { api: true } },
    { 'dialog': { postfixes: ['open', 'close' ]}},
    'send email',
    'eat borscht'
  )
);

/* it is going to generate
const types = {
  MY_APP_LOGIN: 'MY_APP_LOGIN',
  MY_APP_LOGOUT: 'MY_APP_LOGOUT',
  MY_APP_USERS_FETCH_FETCHING: 'MY_APP_USERS_FETCH_FETCHING',
  MY_APP_USERS_FETCH_SUCCESS: 'MY_APP_USERS_FETCH_SUCCESS',
  MY_APP_USERS_FETCH_ERROR: 'MY_APP_USERS_FETCH_ERROR',
  MY_APP_USERS_DIALOG_OPEN: 'MY_APP_USERS_DIALOG_OPEN',
  MY_APP_USERS_DIALOG_CLOSE: 'MY_APP_USERS_DIALOG_CLOSE',
  MY_APP_USERS_SEND_EMAIL: 'MY_APP_USERS_SEND_EMAIL',
  MY_APP_USERS_EAT_BORSCHT: 'MY_APP_USERS_EAT_BORSCHT'
};
*/

Advanced Usage:

Generating API Action Types

const types = createActionTypes('my app')(
  'login',
  'logout',
  { 'user': { api: true } }
);

/* it is going to generate
const types = {
  MY_APP_LOGIN: 'MY_APP_LOGIN',
  MY_APP_LOGOUT: 'MY_APP_LOGOUT',
  MY_APP_USER_FETCHING: 'MY_APP_USER_FETCHING',
  MY_APP_USER_SUCCESS: 'MY_APP_USER_SUCCESS',
  MY_APP_USER_ERROR: 'MY_APP_USER_ERROR',
};
*/

Pre-define custom API postfixes

const types = createActionTypes({
  prefix: 'my app',
  apiPostfixes: ['OK', 'BAD']
})(
  'login',
  'logout',
  { 'user': { api: true } },
  { 'items': { api: true } }
);

/* it is going to generate
const types = {
  MY_APP_LOGIN: 'MY_APP_LOGIN',
  MY_APP_LOGOUT: 'MY_APP_LOGOUT',
  MY_APP_USER_OK: 'MY_APP_USER_OK',
  MY_APP_USER_BAD: 'MY_APP_USER_BAD',
  MY_APP_ITEMS_OK: 'MY_APP_ITEMS_OK',
  MY_APP_ITEMS_BAD: 'MY_APP_ITEMS_BAD'
};
*/

Custom postfixes for a custom Action Type

const types = createActionTypes('my app')(
  'login',
  'logout',
  { 'dialog': { postfixes: ['open', 'close'] } }
);

/* it is going to generate
const types = {
  MY_APP_LOGIN: 'MY_APP_LOGIN',
  MY_APP_LOGOUT: 'MY_APP_LOGOUT',
  MY_APP_DIALOG_OPEN: 'MY_APP_DIALOG_OPEN',
  MY_APP_DIALOG_CLOSE: 'MY_APP_DIALOG_CLOSE'
};
*/

// OR
// the following code yields the same results
const types = createActionTypes('my app')(
  'login',
  'logout',
  createActionTypes('dialog')(
    'open',
    'close'
  )
);

(support for another style) Set a lower-case prefix with / as a separator

const types = createActionTypes({
  prefix: 'my app',
  prefixUpperCase: false,
  separator: '/'
})(
  'login',
  'logout'
);

/* it is going to generate
const types = {
  'my_app/LOGIN': 'my_app/LOGIN',
  'my_app/LOGOUT': 'my_app/LOGOUT'
};
*/

deep structured actions

const types = createActionTypes('my app')(
  'login',
  'logout',
  createActionTypes('dialog')(
    'open',
    'close',
    createActionTypes('input')(
      'change',
      'on focus'
    )
  )
);

/* it is going to generate
const types = {
  MY_APP_LOGIN: 'MY_APP_LOGIN',
  MY_APP_LOGOUT: 'MY_APP_LOGOUT',
  MY_APP_DIALOG_OPEN: 'MY_APP_DIALOG_OPEN',
  MY_APP_DIALOG_CLOSE: 'MY_APP_DIALOG_CLOSE',
  MY_APP_DIALOG_INPUT_CHANGE: 'MY_APP_DIALOG_INPUT_CHANGE',
  MY_APP_DIALOG_INPUT_ON_FOCUS: 'MY_APP_DIALOG_INPUT_ON_FOCUS'
};
*/

Options

const types = createActionTypes({
  prefix,     // string prefix for all elements in array of types. default is ''
  separator,  // string character which is separates prefix and each element type. default is '_'
  upperCase,  // bool. it will set to upper case each key if set to true. default is true
  prefixUpperCase // bool. it will set to upper case the prefix if set to true. default is true
})(arrayOfTypes);

Default API Postfixes

const defaultAPIPostfixes = [
  'FETCHING',
  'ERROR',
  'SUCCESS'
];

Full list of examples

You can find more examples in my test file.

Feedback

For any ideas, suggestion or bugs feel free to ping me or create a ticket right here.

License

MIT license; see LICENSE.