# strip-literal

> Strip comments and string literals from JavaScript code

Latest version **4.0.0** (published 2026-07-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install strip-literal
pnpm add strip-literal
yarn add strip-literal
bun add strip-literal
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2026-07-30 |
| First published | 2022-05-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 88 |
| Author | Anthony Fu <anthonyfu117@hotmail.com> |
| Maintainers | antfu |

## Links

- npm: https://www.npmjs.com/package/strip-literal
- Repository: https://github.com/antfu/strip-literal
- Homepage: https://github.com/antfu/strip-literal#readme
- Issues: https://github.com/antfu/strip-literal/issues
- Funding: https://github.com/sponsors/antfu
- npm.io page: https://npm.io/package/strip-literal

## Dependencies (1)

- [js-tokens](https://npm.io/package/js-tokens.md) ^10.0.0

## Recent versions

- 4.0.0 (latest) — 2026-07-30
- 3.1.0 — 2025-09-27
- 3.0.0 — 2025-01-15
- 2.1.1 — 2024-11-23
- 2.1.0 — 2024-03-29
- 2.0.0 — 2023-12-29
- 1.3.0 — 2023-08-03
- 1.2.0 — 2023-08-02
- 1.1.0 — 2023-08-02
- 1.0.1 — 2023-02-03
- 1.0.0 — 2022-11-14
- 0.4.2 — 2022-09-18
- 0.4.1 — 2022-09-12
- 0.4.0 — 2022-06-14
- 0.3.0 — 2022-05-07
- … 2 more at https://npm.io/package/strip-literal/versions

## README

# strip-literal

[![NPM version](https://img.shields.io/npm/v/strip-literal?color=a1b858&label=)](https://www.npmjs.com/package/strip-literal)

Strip comments and string literals from JavaScript code. Powered by [`js-tokens`](https://github.com/lydell/js-tokens).

## Usage

> [!NOTE]
> Since v4.0.0, this package is ESM-only. Use v3.x if you need CommonJS.


```ts
import { stripLiteral } from 'strip-literal'

stripLiteral('const foo = `//foo ${bar}`') // 'const foo = `       ${bar}`'
```

Comments, string literals will be replaced by spaces with the same length to keep the source map untouched.

## Sponsors

<p align="center">
  <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
    <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg' alt="Sponsors"/>
  </a>
</p>

## License

[MIT](./LICENSE) License © 2022 [Anthony Fu](https://github.com/antfu)

---
_Source: https://npm.io/package/strip-literal · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
