New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rehype-remove-comments

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-remove-comments - npm Package Compare versions

Comparing version 4.0.2 to 5.0.0

index.d.ts

54

index.js

@@ -12,25 +12,51 @@ /**

'use strict'
/**
* @typedef {import('hast').Root} Root
* @typedef {import('unist').Node} Node
* @typedef {Root|Root['children'][number]} HastNode
*
* @typedef Options
* Configuration.
* @property {boolean} [removeConditional=false]
* Conditional comments are also removed when configured with `force: true`
* The default is to leave them.
*/
var filter = require('unist-util-filter')
var conditional = require('hast-util-is-conditional-comment')
import {filter} from 'unist-util-filter'
import {isConditionalComment} from 'hast-util-is-conditional-comment'
module.exports = comments
/**
* Remove comments (except conditional comments).
*
* When configured with `force: true` (default: `false`), conditional comments
* are also removed.
*
* @type {import('unified').Plugin<[Options?] | void[], Root>}
*/
export default function rehypeRemoveComments(options = {}) {
const force = options.removeConditional
function comments(options) {
var force = (options || {}).removeConditional
return transform
function transform(tree) {
return filter(tree, {cascade: false}, force ? hard : soft)
}
return (tree) =>
// `undefined` is never returned because we don’t remove nodes (but TS
// doesn’t know it.)
/* c8 ignore next */
filter(tree, {cascade: false}, force ? hard : soft) || undefined
}
/**
* @param {Node} node
* @returns {boolean}
*/
function soft(node) {
return hard(node) || conditional(node)
const x = /** @type {HastNode} */ (node)
return hard(x) || isConditionalComment(x)
}
/**
* @param {Node} node
* @returns {boolean}
*/
function hard(node) {
return node.type !== 'comment'
const x = /** @type {HastNode} */ (node)
return x.type !== 'comment'
}
{
"name": "rehype-remove-comments",
"version": "4.0.2",
"version": "5.0.0",
"description": "rehype plugin to remove comments (except conditional comments)",

@@ -26,10 +26,27 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"unist-util-filter": "^2.0.0",
"hast-util-is-conditional-comment": "^1.0.0"
"@types/hast": "^2.0.0",
"hast-util-is-conditional-comment": "^2.0.0",
"unified": "^10.0.0",
"unist-util-filter": "^4.0.0"
},
"xo": false
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"test": "node --conditions development test.js"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}

@@ -20,2 +20,5 @@ <!--This file is generated by `build-packages.js`-->

This package is [ESM only][esm]:
Node 12+ is needed to use it and it must be `imported`ed instead of `required`d.
[npm][]:

@@ -27,2 +30,31 @@

This package exports no identifiers.
The default export is `rehypeRemoveComments`
## Use
On the API:
```diff
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
+import rehypeRemoveComments from 'rehype-remove-comments'
import rehypeStringify from 'rehype-stringify'
unified()
.use(rehypeParse)
+ .use(rehypeRemoveComments)
.use(rehypeStringify)
.process('<span>some html</span>', function (err, file) {
console.error(report(err || file))
console.log(String(file))
})
```
On the CLI:
```sh
rehype input.html --use remove-comments --output output.html
```
## Example

@@ -57,5 +89,5 @@

[build-badge]: https://img.shields.io/travis/rehypejs/rehype-minify.svg
[build-badge]: https://github.com/rehypejs/rehype-minify/workflows/main/badge.svg
[build]: https://travis-ci.org/rehypejs/rehype-minify
[build]: https://github.com/rehypejs/rehype-minify/actions

@@ -80,6 +112,8 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-minify.svg

[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://spectrum.chat/unified/rehype
[chat]: https://github.com/rehypejs/rehype/discussions
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[npm]: https://docs.npmjs.com/cli/install

@@ -86,0 +120,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc