Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
flow-remove-types
Advanced tools
Removes Flow type annotations from JavaScript files with speed and simplicity.
The flow-remove-types npm package is a tool designed to strip Flow type annotations from JavaScript code. This is useful for projects that use Flow for type checking but need to remove the type annotations for production builds or for compatibility with environments that do not support Flow.
Remove Flow Types from JavaScript Code
This feature allows you to remove Flow type annotations from a string of JavaScript code. The input code contains Flow type annotations, and the output will be the same code without the type annotations.
const flowRemoveTypes = require('flow-remove-types');
const input = '/* @flow */\nfunction square(n: number): number {\n return n * n;\n}';
const output = flowRemoveTypes(input);
console.log(output.toString());
Remove Flow Types from Files
This feature allows you to remove Flow type annotations from a JavaScript file. The input file contains Flow type annotations, and the output file will be the same code without the type annotations.
const fs = require('fs');
const flowRemoveTypes = require('flow-remove-types');
const inputFilePath = 'path/to/input.js';
const outputFilePath = 'path/to/output.js';
const inputCode = fs.readFileSync(inputFilePath, 'utf8');
const output = flowRemoveTypes(inputCode);
fs.writeFileSync(outputFilePath, output.toString());
babel-plugin-transform-flow-strip-types is a Babel plugin that removes Flow type annotations from JavaScript code. It integrates with the Babel ecosystem, making it a good choice for projects that already use Babel for transpilation. Compared to flow-remove-types, this plugin is more suitable for projects that use Babel as part of their build process.
TypeScript is a superset of JavaScript that adds static types. While it is not a direct replacement for Flow, it provides similar type-checking capabilities. TypeScript has its own compiler that removes type annotations, similar to how flow-remove-types works for Flow. However, adopting TypeScript usually involves a more significant change to the codebase compared to using Flow.
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.
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);
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 all character offset remain the same. This removes the need
for sourcemaps, maintains legible output, and ensures its super easy to include
flow-remove-types
at any point in your build.
Built atop the excellent babylon
parser,
flow-remove-types
shares the same parse rules as the source of truth
Babel plugins. It also passes through other common non-standard syntax such as
JSX and experimental 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
}
}
FAQs
Removes Flow type annotations from JavaScript files with speed and simplicity.
The npm package flow-remove-types receives a total of 107,152 weekly downloads. As such, flow-remove-types popularity was classified as popular.
We found that flow-remove-types demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.