strip-literal is a JavaScript utility library designed to remove comments and string literals from code while preserving character positions. This is achieved by replacing the stripped content with an equivalent number of spaces, which is crucial for maintaining source map integrity. The library is currently on version 3.1.0 and is actively maintained, with a recent focus on performance improvements. Key differentiators include its reliance on `js-tokens` for robust parsing and its commitment to preserving code structure for tools like linters or code transformers. The project has undergone significant breaking changes, notably transitioning to an ESM-only module in v3.0.0 and switching its internal parsing engine from `acorn` to `js-tokens` in v2.0.0. Releases are fairly regular, addressing bugs and introducing optimizations.
npm install strip-literalVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and use `stripLiteral` to process JavaScript code, showcasing its behavior with various string and comment types while preserving whitespace for source map compatibility.
Update your import statements from `const { stripLiteral } = require('strip-literal')` to `import { stripLiteral } from 'strip-literal'` and ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).Thoroughly re-test your code transformation pipelines if upgrading from v1.x to v2.x to ensure the new parser behaves as expected for all your input scenarios.
Be aware that the output code will contain whitespace where comments/literals once were. If you require truly 'removed' content (e.g., for minification), `strip-literal` might need to be part of a larger processing pipeline or a different tool might be more suitable.
Change your import statement from `const { stripLiteral } = require('strip-literal')` to `import { stripLiteral } from 'strip-literal'`.Use named import syntax: `import { stripLiteral } from 'strip-literal'`.No dependency data recorded yet.