babel-plugin-define-undefined-type

0.1.3 • Public • Published

babel-plugin-define-undefined-type

Build Status styled with prettier

Define string literal type when you write undefined type.

Install

$ npm install --save-dev babel-plugin-define-undefined-type

Usage

{
  "plugins": ["define-undefined-type"]
}

Examples

General

In:

type X = A;

Out:

type A = "A";
type X = A;

Union

In:

type Action = { type: ADD | INCREMENT };

Out:

type ADD = "ADD";
type INCREMENT = "INCREMENT";
type Action = { type: ADD | INCREMENT };

In:

type Action = { type: ADD } | { type: INCREMENT }

Out:

type ADD = "ADD";
type INCREMENT = "INCREMENT";
type Action = { type: ADD } | { type: INCREMENT };

Options

usePrefix

type: boolean
Default: false

Prefix of the file path.

Example

.babelrc

{
  "plugins": ["define-undefined-type", {"usePrefix": true}]
}

In:

type Action = { type: ADD } | { type: INCREMENT }

Out:

type ADD = "app/counter/ADD";
type INCREMENT = "app/counter/INCREMENT";
type Action = { type: ADD } | { type: INCREMENT };

removePrefix

type: string
Default: ''

Example

.babelrc

{
  "plugins": [
    "define-undefined-type",
    {
      "usePrefix": true,
      "removePrefix": "app"
    }
  ]
}

In:

type Action = { type: ADD } | { type: INCREMENT }

Out:

type ADD = "counter/ADD";
type INCREMENT = "counter/INCREMENT";
type Action = { type: ADD } | { type: INCREMENT };

License

MIT © akameco

Package Sidebar

Install

npm i babel-plugin-define-undefined-type

Weekly Downloads

2

Version

0.1.3

License

MIT

Last publish

Collaborators

  • akameco