Skip to content

Generate namespaced strings for Flux standard actions

Notifications You must be signed in to change notification settings

slovyagin/actiontypes

Repository files navigation

actiontypes

A simple utility to generate namespaced strings for Flux standard actions.

Usage

actionTypes(namespace, type1, [type2, ...] [, options])

actionTypes(namespace, typesArray, [, options])

Basic

import actionTypes from "actiontypes";

const actions = actionTypes("namespace", "HELLO", "THERE");

You’ll got:

console.log(actions);
{
  HELLO: "namespace/HELLO",
  THERE: "namespace/THERE"
}

More:

const actions = actionTypes(
  "namespace", // Mandatory
  "OPEN", // At least one string must be provided
  "CLOSE",
  "close", // Skips duplicates
  "tYPO", // Forces uppercase
);
console.log(actions);
{
  OPEN: "namespace/OPEN",
  CLOSE: "namespace/CLOSE",
  TYPO: "namespace/TYPO"
}

Array of types

Also an array of types strings as a second argument can be passed:

const actions = actionTypes("simple", ["HELLO", "THERE"]);

Configuration

import actionTypes from "actiontypes";

const actions = actionTypes("namespace", "INIT", {
    prefix: "@@", // Optional. Prepends to all strings. Default is `""`, an empty string.
    delimeter: "--", // Optional. Separator between namespace and short form. Default is `/`, a slash.
  }
);

And you’ll got:

console.log(actions);
{
  INIT: "@@namespace--INIT"
}

About

Generate namespaced strings for Flux standard actions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published