dts-minify
v0.3.3
Published
Minifier for TypeScript declaration files (.d.ts).
Downloads
3,429
Readme
dts-minify
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;}