Socket
Socket
Sign inDemoInstall

rehype-remove-duplicate-attribute-values

Package Overview
Dependencies
15
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.2 to 3.0.0

index.d.ts

61

index.js

@@ -8,38 +8,39 @@ /**

'use strict'
/**
* @typedef {import('hast').Root} Root
*/
var uniq = require('uniq')
var array = require('x-is-array')
var visit = require('unist-util-visit')
var is = require('hast-util-is-element')
var attributes = require('./schema')
import {visit} from 'unist-util-visit'
import {isElement} from 'hast-util-is-element'
import {schema} from './schema.js'
module.exports = empty
const own = {}.hasOwnProperty
var own = {}.hasOwnProperty
/**
* Remove duplicates in attribute values with unique tokens.
*
* @type {import('unified').Plugin<[], Root>}
*/
export default function rehypeRemoveDuplicateAttributeValues() {
return (tree) => {
visit(tree, 'element', (node) => {
const props = node.properties || {}
/** @type {string} */
let prop
function empty() {
return transform
}
for (prop in props) {
if (own.call(props, prop)) {
const value = props[prop]
function transform(tree) {
visit(tree, 'element', visitor)
}
function visitor(node) {
var props = node.properties
var prop
var value
for (prop in props) {
value = props[prop]
if (
own.call(attributes, prop) &&
is(node, attributes[prop]) &&
array(value)
) {
uniq(value)
}
if (
own.call(schema, prop) &&
isElement(node, schema[prop]) &&
Array.isArray(value)
) {
props[prop] = [...new Set(value)]
}
}
}
})
}
}
{
"name": "rehype-remove-duplicate-attribute-values",
"version": "2.0.2",
"version": "3.0.0",
"description": "rehype plugin to remove duplicates in attribute values with unique tokens",

@@ -29,13 +29,29 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js",
"schema.json"
"schema.d.ts",
"schema.js"
],
"dependencies": {
"hast-util-is-element": "^1.0.0",
"uniq": "^1.0.1",
"unist-util-visit": "^2.0.0",
"x-is-array": "^0.1.0"
"@types/hast": "^2.0.0",
"hast-util-is-element": "^2.0.0",
"unified": "^10.0.0",
"unist-util-visit": "^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
}
}

@@ -17,2 +17,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][]:

@@ -24,2 +27,31 @@

This package exports no identifiers.
The default export is `rehypeRemoveDuplicateAttributeValues`
## Use
On the API:
```diff
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
+import rehypeRemoveDuplicateAttributeValues from 'rehype-remove-duplicate-attribute-values'
import rehypeStringify from 'rehype-stringify'
unified()
.use(rehypeParse)
+ .use(rehypeRemoveDuplicateAttributeValues)
.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-duplicate-attribute-values --output output.html
```
## Example

@@ -53,5 +85,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

@@ -76,6 +108,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

@@ -82,0 +116,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc