strip-comments-js
v1.0.11
Published
Strip comments from JavaScript and TypeScript code
Maintainers
Readme
strip-comments-js
Strip comments from JavaScript and TypeScript code.
Install
npm install strip-comments-jsUsage
CLI
strip-comments-js file-1.js file-2.jsstrip-comments-js --pattern eslint-disable file-1.js file-2.jsAPI
import { stripComments } from "strip-comments-js";
stripComments("var unicorns = false; // Only horses");
//=> "var unicorns = false;"
stripComments("var unicorns = false; // Only horses", { pattern: /unicorn/ });
//=> "var unicorns = false; // Only horses"
stripComments("var unicorns = false; // Only horses", { pattern: /horses/ });
//=> "var unicorns = false;"
stripComments("var unicorns = false; // Only horses", { line: false });
//=> "var unicorns = false; // Only horses"Options
stripComments(code, [options])
pattern: The pattern of comments to strip. By default all comments are stripped.line: Whether to strip line comments. By default line comments are stripped.block: Whether to strip block comments. By default block comments are stripped.jsdoc: Whether to strip JSDoc comments (comments like/** ... */). By default JSDoc comments are stripped.protected: Whether to strip protected comments (comments like//! ...or/*! ... */). By default protected comments are stripped.spdx: Whether to strip SPDX short-form identifiers (comments like// SPDX-License-Identifier: ...). By default SPDX short-form identifiers are NOT stripped.
Related
License
The source code is licensed under the Apache-2.0 license, see LICENSE for
the full license text.
