js-cleanup
raw JSON → 1.2.0 verified Fri May 01 auth: no javascript maintenance
js-cleanup is a smart comment and whitespace cleaner for JavaScript-like files (JS, TS, Flow, React, ES9+). Current stable version is 1.2.0, released September 2020. It provides configurable comment filtering (preserve 'all'/'some'/'none'), blank line compaction, trailing whitespace removal, line ending normalization, TypeScript definitions, and sourcemap support. Unlike minifiers like Uglify, it preserves code style while giving fine-grained control over comments. Requires Node >=10.14.2 (<11.x). Release cadence is low; repository appears in maintenance mode.
Common errors
error Uncaught ReferenceError: jsCleanup is not defined ↓
cause Using default import instead of named import.
fix
Use import { jsCleanup } from 'js-cleanup'.
error Cannot find module 'js-cleanup' ↓
cause Package not installed or incorrect import path.
fix
Run 'npm install js-cleanup --save-dev' and ensure the import path is correct.
error TypeError: jsCleanup is not a function ↓
cause Attempting to call default export or require result incorrectly.
fix
Ensure you use import { jsCleanup } from 'js-cleanup' and then call jsCleanup() with correct arguments.
Warnings
breaking Node.js v11 is buggy and unsupported. Avoid using it with js-cleanup. ↓
fix Upgrade to Node.js v10.14.2, v12.0.0, or later (excluding v11).
gotcha The default export is not available; use named import { jsCleanup }. ↓
fix Use import { jsCleanup } from 'js-cleanup' instead of default import.
deprecated Type definitions require manual installation of @types/js-cleanup if not using TypeScript >=2.2? ↓
fix Ensure TypeScript version is >=2.2 to consume bundled types.
breaking Minimum Node.js version increased to 10.14.2 or 12.0.0 in v1.2.0. ↓
fix Upgrade Node.js to >=10.14.2 (v11 excluded) or >=12.0.0.
gotcha The 'comments' option accepts string or RegExp. Using 'none' removes all comments, but triple-slash directives may also be removed unless 'ts3s' filter is used. ↓
fix Use comments: 'ts3s' to preserve TypeScript triple-slash directives while removing other comments.
Install
npm install js-cleanup yarn add js-cleanup pnpm add js-cleanup Imports
- jsCleanup wrong
const jsCleanup = require('js-cleanup')correctimport { jsCleanup } from 'js-cleanup' - Result
import { Result } from 'js-cleanup' - Options wrong
import { Options } from 'js-cleanup' (casing mismatch, Options vs options)correctimport { Options } from 'js-cleanup'
Quickstart
import { jsCleanup } from 'js-cleanup';
const sourceCode = `function hello() {
// this is a comment
console.log('Hello, world!');
}`;
const result = jsCleanup(sourceCode, 'hello.js', {
comments: 'some',
compactComments: true,
maxEmptyLines: 0,
lineEndings: 'unix',
sourcemap: false
});
console.log(result.code);
// function hello() {
// console.log('Hello, world!');
// }