flow-remove-types
Removes Flow type annotations from JavaScript files with speed and simplicity.
Last updated 10 days ago by flowtype .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install flow-remove-types 
SYNC missed versions from official npm registry.

flow-remove-types

npm Build Status

Turn your JavaScript with Flow type annotations into standard JavaScript in an instant with no configuration and minimal setup.

Flow provides static type checking to JavaScript which can both help find and detect bugs long before code is deployed and can make code easier to read and more self-documenting. The Flow tool itself only reads and analyzes code. Running code with Flow type annotations requires first removing the annotations which are non-standard JavaScript. Typically this is done via adding a plugin to your Babel configuration, however Babel may be overkill if you're only targeting modern versions of Node.js or just not using the modern ES2015 features that may not be in every browser.

flow-remove-types is a faster, simpler, zero-configuration alternative with minimal dependencies for super-fast npm install time.

Get Started!

Use the command line:

npm install --global flow-remove-types
flow-remove-types --help
flow-remove-types input.js > output.js

Or the JavaScript API:

npm install flow-remove-types
var flowRemoveTypes = require('flow-remove-types');
var fs = require('fs');

var input = fs.readFileSync('input.js', 'utf8');
var output = flowRemoveTypes(input);
fs.writeFileSync('output.js', output.toString());

When using the flow-remove-types script, be sure not to direct the output to itself!

Use in Build Systems:

Rollup: rollup-plugin-flow

Browserify: unflowify

Webpack: remove-flow-types-loader

Gulp: gulp-flow-remove-types

Use with existing development tools

Use flow-node

Wherever you use node you can substitute flow-node and have a super fast flow-types aware evaluator or REPL.

$ flow-node
> var x: number = 42
undefined
> x
42

Note: This package is also available under the alias flow-node since it's often looked for at that location due to the popularity of this script. Both scripts are available no matter which package you install.

Use the require hook

Using the require hook allows you to automatically compile files on the fly when requiring in node, useful during development:

require('flow-remove-types/register')
require('./some-module-with-flow-type-syntax')

You can also provide options to the require hook:

// Transforms all files, not just those with a "@flow" comment.
require('flow-remove-types/register')({ all: true })

Use options to define exactly which files to includes or excludes with regular expressions. All files are included by default except those found in the node_modules folder, which is excluded by default.

require('flow-remove-types/register')({ includes: /\/custom_path\// })

Don't use the require hook in packages distributed on NPM

As always, don't forget to use flow-remove-types to compile files before distributing your code on npm, as using the require hook affects the whole runtime and not just your module and may hurt the runtime performance of code that includes it.

Dead-Simple Transforms

When flow-remove-types removes Flow types, it replaces them with whitespace. This ensures that the transformed output has exactly the same number of lines and characters and that all character offsets remain the same. This removes the need for sourcemaps, maintains legible output, and ensures that it is super easy to include flow-remove-types at any point in your existing build tools.

Built atop the official Flow parser, flow-remove-types is designed to operate on the same syntax Flow itself understands. It also passes through other common non-standard syntax such as JSX and experimental ECMAScript proposals that Flow supports.

Before:

import SomeClass from 'some-module'
import type { SomeInterface } from 'some-module'

export class MyClass<T> extends SomeClass implements SomeInterface {

  value: T

  constructor(value: T) {
    this.value = value
  }

  get(): T {
    return this.value
  }

}

After:

import SomeClass from 'some-module'


export class MyClass    extends SomeClass                          {



  constructor(value   ) {
    this.value = value
  }

  get()    {
    return this.value
  }

}

Pretty Transform

Rather not have the whitespace? Pass the --pretty flag to remove the whitespace.

flow-remove-types --pretty --sourcemaps source.js

Or using the JS API:

var flowRemoveTypes = require('flow-remove-types');
var fs = require('fs');

var input = fs.readFileSync('input.js', 'utf8');
var output = flowRemoveTypes(input, { pretty: true });
fs.writeFileSync('output.js', output.toString());
var sourceMap = output.generateMap();
fs.writeFileSync('output.js.map', JSON.stringify(sourceMap));

Performance

NOTE: These timings are for flow-remove-types v1.

Install:

Installing via npm from an empty project:

flow-remove-types:

time npm install flow-remove-types

real  0m3.193s
user  0m1.643s
sys   0m0.775s

Babel:

time npm install babel-cli babel-plugin-transform-flow-strip-types

real  0m23.200s
user  0m10.395s
sys   0m4.238s

Transform:

Transforming a directory of 20 files of 100 lines each:

flow-remove-types:

time flow-remove-types src/ --out-dir dest/

real  0m0.431s
user  0m0.436s
sys   0m0.068s

Babel:

time babel src/ --out-dir dest/

real  0m1.074s
user  0m1.092s
sys   0m0.149s

Current Tags

  • 2.128.0                                ...           latest (10 days ago)

56 Versions

  • 2.128.0                                ...           10 days ago
  • 2.127.0                                ...           25 days ago
  • 2.126.1                                ...           a month ago
  • 2.126.0                                ...           a month ago
  • 2.125.1                                ...           2 months ago
  • 2.125.0                                ...           2 months ago
  • 2.124.0                                ...           2 months ago
  • 2.123.0                                ...           3 months ago
  • 2.122.0                                ...           3 months ago
  • 2.121.0                                ...           4 months ago
  • 2.120.1                                ...           4 months ago
  • 2.119.1                                ...           4 months ago
  • 2.119.0                                ...           5 months ago
  • 2.118.0                                ...           5 months ago
  • 2.117.1                                ...           5 months ago
  • 2.117.0                                ...           5 months ago
  • 2.116.1                                ...           6 months ago
  • 2.116.0                                ...           6 months ago
  • 2.115.0                                ...           6 months ago
  • 2.114.0                                ...           7 months ago
  • 2.113.0                                ...           7 months ago
  • 2.112.0                                ...           8 months ago
  • 2.111.3                                ...           8 months ago
  • 2.111.1                                ...           8 months ago
  • 2.111.0                                ...           8 months ago
  • 2.110.1                                ...           8 months ago
  • 2.110.0                                ...           9 months ago
  • 2.109.0                                ...           9 months ago
  • 2.108.0                                ...           10 months ago
  • 2.107.0                                ...           10 months ago
  • 2.106.3                                ...           10 months ago
  • 2.106.2                                ...           10 months ago
  • 2.106.1                                ...           10 months ago
  • 2.106.0                                ...           10 months ago
  • 2.105.2                                ...           a year ago
  • 2.105.0                                ...           a year ago
  • 2.104.0                                ...           a year ago
  • 2.103.0                                ...           a year ago
  • 2.102.0-rc                                ...           a year ago
  • 2.101.0                                ...           a year ago
  • 2.100.0                                ...           a year ago
  • 2.99.1                                ...           a year ago
  • 2.99.0                                ...           a year ago
  • 1.2.3                                ...           3 years ago
  • 1.2.2                                ...           3 years ago
  • 1.2.1                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.2                                ...           4 years ago
  • 1.1.1                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.5                                ...           4 years ago
  • 1.0.4                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 173
This Week 256
This Month 676
Last Day 83
Last Week 632
Last Month 4,099
Dependencies (3)
Dev Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |