{"id":13451948,"url":"https://github.com/aMarCruz/js-cleanup","last_synced_at":"2025-03-23T19:33:13.583Z","repository":{"id":44649960,"uuid":"163162307","full_name":"aMarCruz/js-cleanup","owner":"aMarCruz","description":"Smart comment and whitespace cleaner for JavaScript-like files","archived":false,"fork":false,"pushed_at":"2023-07-06T17:42:18.000Z","size":216,"stargazers_count":27,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T03:05:16.142Z","etag":null,"topics":["clean","cleanup","comments","es6","javascript","remove","source","typescript"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aMarCruz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-12-26T09:32:11.000Z","updated_at":"2024-09-10T05:41:06.000Z","dependencies_parsed_at":"2024-01-16T03:46:06.652Z","dependency_job_id":"bb3d640b-7619-4e65-806a-a87e1206b876","html_url":"https://github.com/aMarCruz/js-cleanup","commit_stats":{"total_commits":20,"total_committers":2,"mean_commits":10.0,"dds":"0.050000000000000044","last_synced_commit":"f4b7c364c4aba8415c22144a67617bbe9d6dade7"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aMarCruz%2Fjs-cleanup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aMarCruz%2Fjs-cleanup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aMarCruz%2Fjs-cleanup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aMarCruz%2Fjs-cleanup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aMarCruz","download_url":"https://codeload.github.com/aMarCruz/js-cleanup/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245158775,"owners_count":20570252,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clean","cleanup","comments","es6","javascript","remove","source","typescript"],"created_at":"2024-07-31T07:01:07.928Z","updated_at":"2025-03-23T19:33:13.253Z","avatar_url":"https://github.com/aMarCruz.png","language":"JavaScript","readme":"# js-cleanup\n\n[![License][license-badge]][license-url]\n[![npm Version][npm-badge]][npm-url]\n[![Travis][travis-badge]][travis-url]\n[![AppVeyor][appveyor-badge]][appveyor-url]\n[![Coverage][coverage-badge]][coverage-url]\n[![Code Quality][codacy-badge]][codacy-url]\n[![Maintainability][climate-badge]][climate-url]\n\nSmart comment and whitespace cleaner for JavaScript-like files.\n\nWith js-cleanup you have:\n\n- Compaction of empty lines within multiline comments and/or out of them.\n- Normalization of line endings to Unix, Mac, or Windows.\n- Removal of JavaScript comments through powerful, configurable filters.\n- Removal of trailing whitespace of each line.\n- TypeScript definitions.\n- Sourcemap support.\n\nAlthough 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.\n\njs-cleanup requires node v10.14.2 or above, but **avoid the buggy v11.x**\n\n**Why not Uglify?**\n\nUglify 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.\n\n## Support my Work\n\nI'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...\n\n[\u003cimg src=\"https://amarcruz.github.io/images/kofi_blue.png\" height=\"36\" title=\"Support Me on Ko-fi\" /\u003e][kofi-url]\n\nOf course, feedback, PRs, and stars are also welcome 🙃\n\nThanks!\n\n## Install\n\n```bash\n$ npm install js-cleanup -D\n# or\n$ yarn add js-cleanup -D\n```\n\n## Usage\n\n```typescript\njsCleanup(sourceCode: string, fileName?: string | null, options?: Options): Result;\n```\n\n### Result\n\nThe result is a plain JS object of this type:\n\n```typescript\ntype Result = {\n  code: string;\n  map?: object | null;\n};\n```\n\n| Name | Description                                                                                      |\n| ---- | ------------------------------------------------------------------------------------------------ |\n| code | The processed code.                                                                              |\n| map  | A raw sourcemap object, or `null` if the text did not change.\u003cbr\u003eUndefined if `sourcemap:false`. |\n\n### Options\n\nType definition:\n\n```typescript\ntype Options = {\n  comments?: string | RegExp;\n  compactComments?: boolean;\n  maxEmptyLines?: number; // use -1 to preserve all the lines\n  lineEndings?: string; // 'mac' | 'unix' | 'win'\n  sourcemap?: boolean;\n  sourcemapOptions: {\n    includeContent?: boolean;\n    inlineMap?: boolean;\n    hires?: boolean;\n  };\n};\n```\n\n| Name               | Default | Description                                                                                                                                      |\n| ------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |\n| comments           | 'some'  | Filter or array of filters that determinates which comments should be preserved.\u003cbr\u003eUse \"all\" to keep all, or \"none\" to remove all the comments. |\n| compactComments    | true    | Should js-cleanup also compact whitespace and blank lines in the preserved multiline comments?\u003cbr\u003eLine-ending normalization is always done.      |\n| maxEmptyLines      | 0       | Maximum successive empty lines to preserve in the output.\u003cbr\u003eUse a positive value, or -1 to preserve all the lines                               |\n| lineEndings        | 'unix'  | Type of Line-ending for normalization: \"unix\", \"mac\", \"win\".                                                                                     |\n| sourcemap          | true    | Should js-cleanup generate a sourcemap?                                                                                                          |\n| _sourcemapOptions_ | -       |\n| includeContent     | false   | Include the original source text in the sourcemap?                                                                                               |\n| inlineMap          | false   | Inline the sourcemap in the processed text?                                                                                                      |\n| hires              | true    | Should a hi-res sourcemap be generated?                                                                                                          |\n\n_**Note:**_\\\n_If you want to keep JSDoc comments, you should also set `compactComments: false`._\\\n_Since the JSDoc presentation depends on empty lines, these should be controlled by you._\n\n## Predefined Comment Filters\n\nInstead the special 'all' or 'none' keywords, you can use any combination of custom filters along with any of these predefined ones:\n\n| Name     | Will preserve...                                                                                                                                                                                                                                        |\n| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| some     | Comments containing \"@license\", \"@preserve\", or starting with \"!\".                                                                                                                                                                                      |\n| license  | Comments containing \"@license\".                                                                                                                                                                                                                         |\n| eslint   | [ESLint](http://eslint.org/docs/user-guide/configuring) directives.                                                                                                                                                                                     |\n| flow     | Facebook [Flow](https://flow.org/en/docs) directives, [comment types](https://flow.org/en/docs/types/comments/), and [flowlint](https://flow.org/en/docs/linting/flowlint-comments/) comments.                                                          |\n| istanbul | [istanbul](https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md) ignore comments.                                                                                                                                           |\n| jsdoc    | [JSDoc](http://usejsdoc.org/) comments.                                                                                                                                                                                                                 |\n| jshint   | [JSHint](http://jshint.com/docs/#inline-configuration) directives.                                                                                                                                                                                      |\n| jslint   | [JSLint](http://www.jslint.com/help.html) directives.                                                                                                                                                                                                   |\n| sources  | Sourcemap directives [sourceURL](https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl) and [sourceMappingURL](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.9ppdoan5f016). |\n| ts       | MS [TypeScript](http://www.typescriptlang.org/) Triple-Slash and @ts-\\* directives, plus the @jsx pragma.                                                                                                                                               |\n| ts3s     | TypeScript [Triple-Slash](http://www.typescriptlang.org/docs/handbook/triple-slash-directives.html) directives.                                                                                                                                         |\n\n_**Note:**_\\\n_Since none of this filters is really accurate (js-cleanup is not a parser), they are suitable for the job without introducing greater complexity._\n\nSee the regexes in [src/predef-filters.ts](https://github.com/aMarCruz/js-cleanup/blob/master/src/predef-filters.ts)\n\n### Custom Filters\n\nA custom filter is a regex that must match the content of the comments that you want to preserve.\n\nThe 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 (`/`).\n\nFor example, the following filters will preserve ESLint directives and _multiline_ comments starting with a dash:\n\n```js\nconst cleanedCode = jsCleanup(code, null, {\n  comments: [\"eslint\", /^\\*-/],\n});\n```\n\n## License\n\nThe [MIT][license-url] License\n\n\u0026copy; 2018-2020 Alberto Martínez\n\n[license-badge]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat\n[license-url]: https://github.com/aMarCruz/js-cleanup/blob/master/LICENSE\n[npm-badge]: https://img.shields.io/npm/v/js-cleanup.svg\n[npm-url]: https://www.npmjs.com/package/js-cleanup\n[appveyor-badge]: https://img.shields.io/appveyor/ci/aMarCruz/js-cleanup/master.svg?label=appveyor\n[appveyor-url]: https://ci.appveyor.com/project/aMarCruz/js-cleanup\n[travis-badge]: https://img.shields.io/travis/aMarCruz/js-cleanup/master.svg?label=travis\n[travis-url]: https://travis-ci.org/aMarCruz/js-cleanup\n[coverage-badge]: https://img.shields.io/codecov/c/github/aMarCruz/js-cleanup.svg\n[coverage-url]: https://codecov.io/gh/aMarCruz/js-cleanup\n[codacy-badge]: https://img.shields.io/codacy/grade/1534ad8a654346b78ccb827dabe0bfa8/master.svg\n[codacy-url]: https://www.codacy.com/app/aMarCruz/js-cleanup?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=aMarCruz/js-cleanup\u0026utm_campaign=Badge_Grade\n[climate-badge]: https://img.shields.io/codeclimate/maintainability/aMarCruz/js-cleanup.svg\n[climate-url]: https://codeclimate.com/github/aMarCruz/js-cleanup/maintainability\n[kofi-url]: https://ko-fi.com/C0C7LF7I\n","funding_links":["https://ko-fi.com/C0C7LF7I"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FaMarCruz%2Fjs-cleanup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FaMarCruz%2Fjs-cleanup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FaMarCruz%2Fjs-cleanup/lists"}