{"id":15044794,"url":"https://github.com/jonschlinkert/strip-comments","last_synced_at":"2025-05-16T04:03:42.757Z","repository":{"id":13992592,"uuid":"16693693","full_name":"jonschlinkert/strip-comments","owner":"jonschlinkert","description":"Strip block comments or line comments from JavaScript code. ","archived":false,"fork":false,"pushed_at":"2023-10-16T23:46:47.000Z","size":134,"stargazers_count":117,"open_issues_count":31,"forks_count":43,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-08T01:38:22.381Z","etag":null,"topics":["babel","babylon","code","code-comments","comments","javascript","jonschlinkert","node","nodejs","parse","remove","string","strip","strip-comments"],"latest_commit_sha":null,"homepage":"https://github.com/jonschlinkert","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/jonschlinkert.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-02-10T11:46:35.000Z","updated_at":"2025-05-04T07:30:23.000Z","dependencies_parsed_at":"2024-06-18T12:27:50.772Z","dependency_job_id":"2dca6b08-138e-4ed0-9336-c183dffa44de","html_url":"https://github.com/jonschlinkert/strip-comments","commit_stats":{"total_commits":82,"total_committers":13,"mean_commits":"6.3076923076923075","dds":"0.36585365853658536","last_synced_commit":"d225101be939ed9fbda3f3869855fc67f0309f85"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fstrip-comments","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fstrip-comments/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fstrip-comments/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fstrip-comments/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/strip-comments/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254384988,"owners_count":22062422,"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":["babel","babylon","code","code-comments","comments","javascript","jonschlinkert","node","nodejs","parse","remove","string","strip","strip-comments"],"created_at":"2024-09-24T20:51:03.113Z","updated_at":"2025-05-16T04:03:42.722Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","readme":"# strip-comments [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/strip-comments.svg?style=flat)](https://www.npmjs.com/package/strip-comments) [![NPM monthly downloads](https://img.shields.io/npm/dm/strip-comments.svg?style=flat)](https://npmjs.org/package/strip-comments) [![NPM total downloads](https://img.shields.io/npm/dt/strip-comments.svg?style=flat)](https://npmjs.org/package/strip-comments) [![Build Status](https://travis-ci.org/jonschlinkert/strip-comments.svg?branch=master)](https://travis-ci.org/jonschlinkert/strip-comments)\n\n\u003e Strip line and/or block comments from a string. Blazing fast, and works with JavaScript, Sass, CSS, Less.js, and a number of other languages.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n- [Install](#install)\n- [What does this do?](#what-does-this-do)\n- [Usage](#usage)\n- [API](#api)\n- [About](#about)\n\n_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/) (requires [Node.js](https://nodejs.org/en/) \u003e=10):\n\n```sh\n$ npm install --save strip-comments\n```\n\n## What does this do?\n\nTakes a string and returns a new string with comments removed. Works with line comments and/or block comments. Optionally removes the first comment only or ignores protected comments.\n\nWorks with:\n\n* ada\n* apl\n* applescript\n* c\n* csharp\n* css\n* hashbang\n* haskell\n* html\n* java\n* javascript\n* less\n* lua\n* matlab\n* ocaml\n* pascal\n* perl\n* php\n* python\n* ruby\n* sass\n* shebang\n* sql\n* swift\n* typscript\n* xml\n\n## Usage\n\nBy default all comments are stripped.\n\n```js\nconst strip = require('strip-comments');\nconst str = strip('const foo = \"bar\";// this is a comment\\n /* me too *\\/');\nconsole.log(str);\n// =\u003e 'const foo = \"bar\";\\n'\n```\n\nFor more use-cases see the [tests](./test)\n\n## API\n\n### [strip](index.js#L33)\n\nStrip all code comments from the given `input`, including protected comments that start with `!`, unless disabled by setting `options.keepProtected` to true.\n\n**Params**\n\n* `input` **{String}**: string from which to strip comments\n* `options` **{Object}**: optional options, passed to [extract-comments](https://github.com/jonschlinkert/extract-comments)  \n\n- `line` **{Boolean}**: if `false` strip only block comments, default `true`\n- `block` **{Boolean}**: if `false` strip only line comments, default `true`\n- `keepProtected` **{Boolean}**: Keep ignored comments (e.g. `/*!` and `//!`)\n- `preserveNewlines` **{Boolean}**: Preserve newlines after comments are stripped\n* `returns` **{String}**: modified input\n\n**Example**\n\n```js\nconst str = strip('const foo = \"bar\";// this is a comment\\n /* me too */');\nconsole.log(str);\n// =\u003e 'const foo = \"bar\";'\n```\n\n### [.block](index.js#L54)\n\nStrip only block comments.\n\n**Params**\n\n* `input` **{String}**: string from which to strip comments\n* `options` **{Object}**: pass `opts.keepProtected: true` to keep ignored comments (e.g. `/*!`)\n* `returns` **{String}**: modified string\n\n**Example**\n\n```js\nconst strip = require('..');\nconst str = strip.block('const foo = \"bar\";// this is a comment\\n /* me too */');\nconsole.log(str);\n// =\u003e 'const foo = \"bar\";// this is a comment'\n```\n\n### [.line](index.js#L74)\n\nStrip only line comments.\n\n**Params**\n\n* `input` **{String}**: string from which to strip comments\n* `options` **{Object}**: pass `opts.keepProtected: true` to keep ignored comments (e.g. `//!`)\n* `returns` **{String}**: modified string\n\n**Example**\n\n```js\nconst str = strip.line('const foo = \"bar\";// this is a comment\\n /* me too */');\nconsole.log(str);\n// =\u003e 'const foo = \"bar\";\\n/* me too */'\n```\n\n### [.first](index.js#L95)\n\nStrip the first comment from the given `input`. Or, if `opts.keepProtected` is true, the first non-protected comment will be stripped.\n\n**Params**\n\n* `input` **{String}**\n* `options` **{Object}**: pass `opts.keepProtected: true` to keep comments with `!`\n* `returns` **{String}**\n\n**Example**\n\n```js\nconst output = strip.first(input, { keepProtected: true });\nconsole.log(output);\n// =\u003e '//! first comment\\nfoo; '\n```\n\n### [.block](index.js#L116)\n\nParses a string and returns a basic CST (Concrete Syntax Tree).\n\n**Params**\n\n* `input` **{String}**: string from which to strip comments\n* `options` **{Object}**: pass `opts.keepProtected: true` to keep ignored comments (e.g. `/*!`)\n* `returns` **{String}**: modified string\n\n**Example**\n\n```js\nconst strip = require('..');\nconst str = strip.block('const foo = \"bar\";// this is a comment\\n /* me too */');\nconsole.log(str);\n// =\u003e 'const foo = \"bar\";// this is a comment'\n```\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [code-context](https://www.npmjs.com/package/code-context): Parse a string of javascript to determine the context for functions, variables and comments based… [more](https://github.com/jonschlinkert/code-context) | [homepage](https://github.com/jonschlinkert/code-context \"Parse a string of javascript to determine the context for functions, variables and comments based on the code that follows.\")\n* [extract-comments](https://www.npmjs.com/package/extract-comments): Uses esprima to extract line and block comments from a string of JavaScript. Also optionally… [more](https://github.com/jonschlinkert/extract-comments) | [homepage](https://github.com/jonschlinkert/extract-comments \"Uses esprima to extract line and block comments from a string of JavaScript. Also optionally parses code context (the next line of code after a comment).\")\n* [parse-code-context](https://www.npmjs.com/package/parse-code-context): Fast and simple way to parse code context for use with documentation from code comments… [more](https://github.com/jonschlinkert/parse-code-context) | [homepage](https://github.com/jonschlinkert/parse-code-context \"Fast and simple way to parse code context for use with documentation from code comments. Parses context from a single line of JavaScript, for functions, variable declarations, methods, prototype properties, prototype methods etc.\")\n* [parse-comments](https://www.npmjs.com/package/parse-comments): Parse code comments from JavaScript or any language that uses the same format. | [homepage](https://github.com/jonschlinkert/parse-comments \"Parse code comments from JavaScript or any language that uses the same format.\")\n\n### Contributors\n\n| **Commits** | **Contributor** |  \n| --- | --- |  \n| 82 | [jonschlinkert](https://github.com/jonschlinkert) |  \n| 4  | [tunnckoCore](https://github.com/tunnckoCore) |  \n| 2  | [mk-pmb](https://github.com/mk-pmb) |  \n| 1  | [kgryte](https://github.com/kgryte) |  \n| 1  | [briandipalma](https://github.com/briandipalma) |  \n| 1  | [epicoxymoron](https://github.com/epicoxymoron) |  \n| 1  | [XuluWarrior](https://github.com/XuluWarrior) |  \n\n### Author\n\n**Jon Schlinkert**\n\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n\n### License\n\nCopyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on November 13, 2019._\n","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=W8YFZ425KND68"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fstrip-comments","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fstrip-comments","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fstrip-comments/lists"}