Skip to main content

@david/dts-minify@0.3.3

Minifier for TypeScript declaration files (.d.ts)

Works with
This package works with Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
100%
Published
2 months ago

dts-minify

JSR npm version CI

Minifies TypeScript declaration files (.d.ts files).

Strips:

  • Non-essential whitespace and newlines.
  • Comments, but keeps triple-slash directives.

Use Case

This library is useful for minifying declaration files that won't be read by humans.

Setup

Deno:

deno add @david/dts-minify

Node:

npm install dts-minify

Example

import { createMinifier } from "@david/dts-minify"; // dts-minify on npm
import * as ts from "typescript";

// setup (provide a TS Compiler API object)
const minifier = createMinifier(ts);

// minify
const inputText = `declare class MyClass {
    /**
     * Some description.
     */
    doSomething(value: number): number;
}`;
const minifiedText = minifier.minify(inputText);

console.log(minifiedText);

Outputs:

declare class MyClass{doSomething(value:number):number;}

Options

keepJsDocs

When true, it won't remove the JS docs.

const minifiedText = minifier.minify(inputText, {
  keepJsDocs: true, // false by default
});

Outputs:

declare class MyClass{/**
 * Some description.
 */doSomething(value:number):number;}
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @david/dts-minify

Import symbol

import * as mod from "@david/dts-minify";

Add Package

npx jsr add @david/dts-minify

Import symbol

import * as mod from "@david/dts-minify";

Add Package

yarn dlx jsr add @david/dts-minify

Import symbol

import * as mod from "@david/dts-minify";

Add Package

pnpm dlx jsr add @david/dts-minify

Import symbol

import * as mod from "@david/dts-minify";

Add Package

bunx jsr add @david/dts-minify

Import symbol

import * as mod from "@david/dts-minify";