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

jm-ts-to-js-jsdoc

v1.0.2

Published

Transpiles TypeScript to JavaScript, adding JSDoc comments for type documentation

Downloads

5

Readme

TypeScript to JavaScript transpiler

Transpiles TypeScript to JavaScript, adding JSDoc comments for type documentation.

Functional description

  • preserves blank lines.
  • preserves type-only imports.

Object types

  • documents an intersection type.
  • removes any comments from a type alias (this becomes problematic when transpiled to JSDoc).
  • removes any comments from object properties (this becomes problematic when transpiled to JSDoc).

Interfaces

  • documents an interface.
  • documents an interface's optional properties.
  • documents an interface's readonly properties.
  • documents a generic interface.

Type aliases

  • documents a type alias
  • preserves property comments
  • treats object literal union and intersection as regular aliases

Functions

  • documents a function declaration.
  • documents an optional parameter.
  • documents a parameter's default value.
  • documents rest parameters.
  • documents an inferred return type.
  • documents a generic function.
  • references the return type.

Handling of existing JSDoc

  • replaces a tag's name synonym with the common name.
  • corrects the order of existing tags.
  • corrects the type for an existing @param tag when necessary.
  • corrects the type for an existing @returns tag when necessary.
  • removes tags for non-existing parameters.
  • removes optional parameter indicators for a parameter that is not optional.
  • removes comments from type arguments.

Variable declarations

  • documents the correct type for let and var declarations.
  • only adds type documentation to const declarations when a type is specified.
  • documents variables containing a function expression.
  • documents variables containing an arrow function expression.

Classes

  • documents a generic class.
  • documents a class that implements an interface.

class members

  • documents a class's constructor.
  • documents a class's methods.
  • documents properties that have initializers.
  • should NOT document properties that have initializers where the type is inferred.

property modifier

  • documents a readonly member.
  • documents a public member.
  • documents a protected member.
  • documents a private member.

Caveats

Documenting an object method's generic type is not supported.

example:

interface IProtocolMainService {
	createIPCObjectUrl<T>(): IIPCObjectUrl<T>;
}

transpiles to:

/**
 * @typedef {object} IProtocolMainService
 * @property {() => IIPCObjectUrl<T>} createIPCObjectUrl
 */

The generic type T for createIPCObjectUrl is lost.

leading- and trailing comments are removed.

They are removed because they are problematic within JSDoc comments.

Installation

npm i -g @jm/ts-to-js-jsdoc

# OR

yarn global add @jm/ts-to-js-jsdoc

The package manager will then link the binary for you, and you can access it with:

$ jm-ts-to-js-jsdoc

Usage

The following will transpile all TypeScript files in the given directory and subdirectories and writes all transpiled files to the same directory, including subdirectories. Any JavaScript files that exist in the directory will be overwritten.

jm-ts-to-js-jsdoc /path/to/folder/with/typescript/files/

The following will transpile the given TypeScript file to JavaScript and writes this into the same directory. If the file exist it will be overwritten.

jm-ts-to-js-jsdoc /path/to/folder/with/typescript/files/typescript.ts

The following will transpile all TypeScript files in the given directory and subdirectories and writes all transpiled files to the supplied directory, including subdirectories.

jm-ts-to-js-jsdoc /path/to/folder/with/typescript/files/ /path/to/folder/with/javascript/files/

The following will transpile the given TypeScript file to JavaScript and writes this into the supplied directory. If the file exist it will be overwritten.

jm-ts-to-js-jsdoc /path/to/folder/with/typescript/files/typescript.ts /path/to/folder/with/javascript/files/

For getting help information, type:

jm-ts-to-js-jsdoc --help

| Option | Description | | -------------------------------- | ----------------------------------------------- | | -l, --log-level | the level of logging to use (default: 'warn') | | --add-type-documentation | Add type documentation as JSDoc (default: true) | | -p, --ts-config-file-path | The path to a tsconfig.json file | | -h, --help | Print help information | | -v, --version | Print version information |

Command Line

$ jm-ts-to-js-jsdoc

Usage:
jm-ts-to-js-jsdoc [options] <input> [output]

Arguments:
  input          Input file or directory
  output         Output file or directory, (optional if it can be inferred)

Options:
  -v, --version                     display the version number
  -l, --log-level <level>           the level of logging to use (choices: "error", "warn", "info", "debug", "trace", default: "warn")
  --add-type-documentation          Add type documentation as JSDoc (default: true)
  -p, --ts-config-file-path <path>  The path to a tsconfig.json file
  -h, --help                        display help for command

License

Copyright (c) Johan Meester

Licensed under MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Licenses of all dependencies are listed in THIRD-PARTY-LICENSES

Credits

This project is heavily inspired by: TypeScript to JSDoc Published under the MIT License