All Projects → aMarCruz → js-cleanup

aMarCruz / js-cleanup

Licence: MIT License
Smart comment and whitespace cleaner for JavaScript-like files

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
Makefile
30231 projects

Projects that are alternatives of or similar to js-cleanup

Dropcss
An exceptionally fast, thorough and tiny unused-CSS cleaner
Stars: ✭ 2,102 (+9454.55%)
Mutual labels:  clean, remove
Modclean
Remove unwanted files and directories from your node_modules folder
Stars: ✭ 309 (+1304.55%)
Mutual labels:  clean, cleanup
strip-markdown
plugin remove Markdown formatting
Stars: ✭ 84 (+281.82%)
Mutual labels:  clean, remove
remove-files-webpack-plugin
A plugin for webpack that removes files and folders before and after compilation.
Stars: ✭ 48 (+118.18%)
Mutual labels:  clean, remove
laravel-queued-db-cleanup
https://flareapp.io/blog/7-how-to-safely-delete-records-in-massive-tables-on-aws-using-laravel
Stars: ✭ 64 (+190.91%)
Mutual labels:  cleanup
eliminate
Delete files and directories without all the bullshit.
Stars: ✭ 51 (+131.82%)
Mutual labels:  remove
pull-request-comment-branch
A GitHub Action to get the head ref and sha of a pull request comment
Stars: ✭ 21 (-4.55%)
Mutual labels:  comments
Fun
Small fun scripts
Stars: ✭ 22 (+0%)
Mutual labels:  source
riblet-sample
A sample to represent Uber Riblets design pattern using Swift.
Stars: ✭ 42 (+90.91%)
Mutual labels:  clean
larapos
Laravel Point of sale with invoice full source code free download pos apps.
Stars: ✭ 38 (+72.73%)
Mutual labels:  source
ultimatevocalremovergui
GUI for a Vocal Remover that uses Deep Neural Networks.
Stars: ✭ 370 (+1581.82%)
Mutual labels:  source
source-server-manager
Manage CSGO and other source dedicated servers
Stars: ✭ 44 (+100%)
Mutual labels:  source
neos-blog
A simple blog plugin for Neos CMS
Stars: ✭ 17 (-22.73%)
Mutual labels:  comments
lazy-load-for-comments
Lazy load WordPress default commenting system.
Stars: ✭ 17 (-22.73%)
Mutual labels:  comments
pmp
6️⃣本人2019年06月份PMP备考资料,包含第六版教材、教学视频和练习真题。如资料链接失效,可通过Issues提问或者个人主页邮箱联系。视频资料持续更新中……
Stars: ✭ 116 (+427.27%)
Mutual labels:  source
threaded-comments
Reddit styled threaded comments using Supabase and Next.js
Stars: ✭ 111 (+404.55%)
Mutual labels:  comments
typester
✒️ A WYSIWYG that gives you predictable and clean HTML
Stars: ✭ 29 (+31.82%)
Mutual labels:  clean
CFX-BYPASS
Bypass it, you won't be Banned when playing cheats 2022
Stars: ✭ 18 (-18.18%)
Mutual labels:  source
StrafeAnalyzer
A tool that analyzes player inputs and tells the player how to improve player movement through statistics, realtime graphs, etc! :)
Stars: ✭ 20 (-9.09%)
Mutual labels:  source
git-bonsai
Tend the branches of your git garden
Stars: ✭ 15 (-31.82%)
Mutual labels:  clean

js-cleanup

License npm Version Travis AppVeyor Coverage Code Quality Maintainability

Smart comment and whitespace cleaner for JavaScript-like files.

With js-cleanup you have:

  • Compaction of empty lines within multiline comments and/or out of them.
  • Normalization of line endings to Unix, Mac, or Windows.
  • Removal of JavaScript comments through powerful, configurable filters.
  • Removal of trailing whitespace of each line.
  • TypeScript definitions.
  • Sourcemap support.

Although js-cleanup is not locked to a particular JavaScript dialect and can handle any JS-like file: TypeScript, Flow, React, ES9, etc, it is mainly a postprocessor, so it should be runned in a later stage of your toolchain, after any preprocessor or transpiler.

js-cleanup requires node v10.14.2 or above, but avoid the buggy v11.x

Why not Uglify?

Uglify is a excelent minifier but you have little control over the results, while with js-cleanup your coding style remains intact and the removal of comments is strictly under your control.

Support my Work

I'm a full-stack developer with more than 20 year of experience and I try to share most of my work for free and help others, but this takes a significant amount of time and effort so, if you like my work, please consider...

Of course, feedback, PRs, and stars are also welcome 🙃

Thanks!

Install

$ npm install js-cleanup -D
# or
$ yarn add js-cleanup -D

Usage

jsCleanup(sourceCode: string, fileName?: string | null, options?: Options): Result;

Result

The result is a plain JS object of this type:

type Result = {
  code: string;
  map?: object | null;
};
Name Description
code The processed code.
map A raw sourcemap object, or null if the text did not change.
Undefined if sourcemap:false.

Options

Type definition:

type Options = {
  comments?: string | RegExp;
  compactComments?: boolean;
  maxEmptyLines?: number; // use -1 to preserve all the lines
  lineEndings?: string; // 'mac' | 'unix' | 'win'
  sourcemap?: boolean;
  sourcemapOptions: {
    includeContent?: boolean;
    inlineMap?: boolean;
    hires?: boolean;
  };
};
Name Default Description
comments 'some' Filter or array of filters that determinates which comments should be preserved.
Use "all" to keep all, or "none" to remove all the comments.
compactComments true Should js-cleanup also compact whitespace and blank lines in the preserved multiline comments?
Line-ending normalization is always done.
maxEmptyLines 0 Maximum successive empty lines to preserve in the output.
Use a positive value, or -1 to preserve all the lines
lineEndings 'unix' Type of Line-ending for normalization: "unix", "mac", "win".
sourcemap true Should js-cleanup generate a sourcemap?
sourcemapOptions -
includeContent false Include the original source text in the sourcemap?
inlineMap false Inline the sourcemap in the processed text?
hires true Should a hi-res sourcemap be generated?

Note:
If you want to keep JSDoc comments, you should also set compactComments: false.
Since the JSDoc presentation depends on empty lines, these should be controlled by you.

Predefined Comment Filters

Instead the special 'all' or 'none' keywords, you can use any combination of custom filters along with any of these predefined ones:

Name Will preserve...
some Comments containing "@license", "@preserve", or starting with "!".
license Comments containing "@license".
eslint ESLint directives.
flow Facebook Flow directives, comment types, and flowlint comments.
istanbul istanbul ignore comments.
jsdoc JSDoc comments.
jshint JSHint directives.
jslint JSLint directives.
sources Sourcemap directives sourceURL and sourceMappingURL.
ts MS TypeScript Triple-Slash and @ts-* directives, plus the @jsx pragma.
ts3s TypeScript Triple-Slash directives.

Note:
Since none of this filters is really accurate (js-cleanup is not a parser), they are suitable for the job without introducing greater complexity.

See the regexes in src/predef-filters.ts

Custom Filters

A custom filter is a regex that must match the content of the comments that you want to preserve.

The content of the comments tested by each filter does not includes the first slash, nor the */ terminator of the multiline comments, so the multiline comments begins with an asterisk (*) and single-line comments begins with a slash (/).

For example, the following filters will preserve ESLint directives and multiline comments starting with a dash:

const cleanedCode = jsCleanup(code, null, {
  comments: ["eslint", /^\*-/],
});

License

The MIT License

© 2018-2020 Alberto Martínez

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].