
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
jsdoc2flow
Advanced tools
Convert JSDoc comments into Flow/Typescript annotations
This is a library and CLI tool that reads JSDoc comments and inserts the corresponding Flow annotations.
For example, it turns the following code
/**
* @typedef {object} Result
* @property {string} id
* @property {number} count
*/
/**
* @param {number} count
* @returns {Result}
*/
function getResult(count) {}
into:
type Result = {
id: string,
count: number,
}
/**
* @typedef {object} Result
* @property {string} id
* @property {number} count
*/
/**
* @param {number} count
* @returns {Result}
*/
function getResult(count: number): Result {}
Note that you still need to add // @flow
yourself to the top of the files to be checked by Flow.
Globally:
> npm install -g jsdoc2flow
Within a project:
> npm install --save-dev jsdoc2flow
Update the files in place:
> jsdoc2flow -i path/to/input/dir --overwrite
Convert a single file and output to stdout:
> jsdoc2flow -f path/to/file.js
Convert a directory of files and output to a new location:
> jsdoc2flow -i path/to/input/dir -o path/to/output/dir
All options:
Usage: cli [options]
Options:
-V, --version output the version number
-f, --file <file> The file to convert and output to stdout
-i, --input-directory <dir> Source directory for original files
-w, --overwrite Overwrite the original files
-o, --output-directory <dir> Destination directory for converted files
--ext [ext] File extension to convert. Can specify multiple extensions. Defaults to 'js' only.
(default: ["js"])
-v, --verbose Verbose output
-h, --help display help for command
After conversion to Flow, you can convert your code to TypeScript using @khanacademy/flow-to-ts
const Converter = require("jsdoc2flow")
const converter = new Converter(opts)
converter.convertSourceCode(code)
converter.convertFile(src, dst)
See the test
directory for detailed list of validated cases.
You can document @param
and @returns
for functions in any of the following style:
function test(a) {}
Something.prototype.test = function(a) {};
const test = function(a) {};
const obj = { test: function(a) {} };
const test = (a) => {};
const test = a => {};
class Test { test(a) {} }
You can document using @typedef
to define custom types:
/** @typedef {number} MyNumber */
/**
* @typedef {object} MyObject
* @property {string} str
* @property {number} num
*/
For callback and functions, you can use @callback
:
/**
* @callback MyCallback
* @param {number} arg1
* @returns {number}
*/
/** @type {number} */
const count = 1;
/** @type {MyObject} */
const obj;
This is inspired by flow-jsdoc, but is a totally separate implementation of the same idea. This uses the Espree parser instead and implements some of the things flow-jsdoc is missing.
FAQs
Convert JSDoc comments into Flow/Typescript annotations
The npm package jsdoc2flow receives a total of 2 weekly downloads. As such, jsdoc2flow popularity was classified as not popular.
We found that jsdoc2flow demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.