flow-typestrip
v0.1.3
Published
A Recast based transform to remove Flow type annotations.
Readme
flow-typestrip 
flow-typestrip is a recast based transform to remove Flow type annotations from typed JavaScript code, so that the code can be executed in JavaScript environments.
Alternatives: react-tools also strips type annotations. You should use it if you are also using React / JSX.
Install
$ npm install [-D] flow-typestripUsage
As a CLI
flow-typstrip comes with a command-line interface that can be used when installed globally. Here is how to convert a single file and print to stdout:
$ flow-typestrip source.jsTo compile many files at once, specify an output directory:
$ flow-typestrip -o dist src/**/*.jsTo enable source maps for this files, add the --source-maps flag.
As a library
var flowStrip = require('flow-typestrip');
var result = flowStrip.compile(source, {
sourceFileName: 'example.js',
sourceMapName: 'example.js.map'
});
fs.writeFileSync('result.js', result.code);
fs.writeFileSync('result.js.map', JSON.stringify(result.map));With browserify
flow-typestrip can directly be used with browserify:
$ browserify -t flow-typestrip script.jsDevelopment
If you look at the main transform function, it is very simple. To ensure that the types are stripped correctly, I'm using the unit tests from jstransform.
Acknowledgments
- Facebook for building Flow (and jstransform).
- Ben Newman for building recast and ast-types.
