npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flow-remove-types-no-whitespace

v1.0.5

Published

Removes Flow type annotations from JavaScript files with speed and simplicity.

Downloads

18,734

Readme

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 targetting 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);

Use in Build Systems:

Rollup: rollup-plugin-flow

Browserify: unflowify

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

Use the require hook

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

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

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 excellent babylon parser, flow-remove-types shares the same parse rules as the source of truth as Flow Babel plugins. It also passes through other common non-standard syntax such as JSX and experimental ECMAScript proposals.

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
  }

}

Performance

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