0.1.3 • Published 7 years ago

babel-plugin-define-undefined-type v0.1.3

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

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