Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rehype-remove-duplicate-attribute-values

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-remove-duplicate-attribute-values - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

lib/index.d.ts

10

index.d.ts

@@ -1,9 +0,1 @@

/**
* Remove duplicates in attribute values with unique tokens.
*
* @type {import('unified').Plugin<[], Root>}
*/
export default function rehypeRemoveDuplicateAttributeValues():
| void
| import('unified').Transformer<import('hast').Root, import('hast').Root>
export type Root = import('hast').Root
export { default } from "./lib/index.js";
/**
* @fileoverview
* Remove duplicates in attribute values with unique tokens.
* rehype plugin to remove duplicates in attributes values.
*
* ## What is this?
*
* This package is a plugin that removes duplicates amongst attribute values of
* unique tokens (such as `class`).
*
* ## When should I use this?
*
* You can use this plugin when you want to improve the transfer size of HTML
* documents.
*
* ## API
*
* ### `unified().use(rehypeRemoveDuplicateAttributeValues)`
*
* Remove duplicates in attributes values.
*
* ###### Returns
*
* Transform ([`Transformer`](https://github.com/unifiedjs/unified#transformer)).
*
* @example
* <div class="foo foo"></label>
* {}
* <div class="foo foo"></div>
*/
/**
* @typedef {import('hast').Root} Root
*/
import {visit} from 'unist-util-visit'
import {isElement} from 'hast-util-is-element'
import {schema} from './schema.js'
const 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
for (prop in props) {
if (own.call(props, prop)) {
const value = props[prop]
if (
own.call(schema, prop) &&
isElement(node, schema[prop]) &&
Array.isArray(value)
) {
props[prop] = [...new Set(value)]
}
}
}
})
}
}
export {default} from './lib/index.js'
{
"name": "rehype-remove-duplicate-attribute-values",
"version": "3.0.0",
"version": "4.0.0",
"description": "rehype plugin to remove duplicates in attribute values with unique tokens",
"license": "MIT",
"keywords": [
"unified",
"attribute",
"duplicate",
"html",
"mangle",
"minify",
"plugin",
"rehype",
"rehype-plugin",
"plugin",
"html",
"minify",
"mangle",
"remove",
"duplicate",
"attribute",
"unified",
"value"

@@ -31,27 +31,21 @@ ],

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

@@ -1,2 +0,2 @@

<!--This file is generated by `build-packages.js`-->
<!--This file is generated-->

@@ -9,15 +9,40 @@ # rehype-remove-duplicate-attribute-values

[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Sponsors][funding-sponsors-badge]][funding]
[![Backers][funding-backers-badge]][funding]
[![Chat][chat-badge]][chat]
Remove duplicates in attribute values with unique tokens.
**[rehype][]** plugin to remove duplicates in attributes values.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`unified().use(rehypeRemoveDuplicateAttributeValues)`](#unifieduserehyperemoveduplicateattributevalues)
* [Example](#example)
* [Syntax](#syntax)
* [Syntax tree](#syntax-tree)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a plugin that removes duplicates amongst attribute values of
unique tokens (such as `class`).
## When should I use this?
You can use this plugin when you want to improve the transfer size of HTML
documents.
## Install
This package is [ESM only][esm]:
Node 12+ is needed to use it and it must be `imported`ed instead of `required`d.
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
[npm][]:
```sh

@@ -27,5 +52,16 @@ npm install rehype-remove-duplicate-attribute-values

This package exports no identifiers.
The default export is `rehypeRemoveDuplicateAttributeValues`
In Deno with [`esm.sh`][esm-sh]:
```js
import rehypeRemoveDuplicateAttributeValues from 'https://esm.sh/rehype-remove-duplicate-attribute-values@4'
```
In browsers with [`esm.sh`][esm-sh]:
```html
<script type="module">
import rehypeRemoveDuplicateAttributeValues from 'https://esm.sh/rehype-remove-duplicate-attribute-values@4?bundle'
</script>
```
## Use

@@ -35,16 +71,16 @@

```diff
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
+import rehypeRemoveDuplicateAttributeValues from 'rehype-remove-duplicate-attribute-values'
import rehypeStringify from 'rehype-stringify'
```js
import rehypeParse from 'rehype-parse'
import rehypeRemoveDuplicateAttributeValues from 'rehype-remove-duplicate-attribute-values'
import rehypeStringify from 'rehype-stringify'
import {read} from 'to-vfile'
import {unified} from 'unified'
unified()
.use(rehypeParse)
+ .use(rehypeRemoveDuplicateAttributeValues)
.use(rehypeStringify)
.process('<span>some html</span>', function (err, file) {
console.error(report(err || file))
console.log(String(file))
})
const file = await unified()
.use(rehypeParse)
.use(rehypeRemoveDuplicateAttributeValues)
.use(rehypeStringify)
.process(await read('index.html'))
console.log(String(file))
```

@@ -55,14 +91,41 @@

```sh
rehype input.html --use remove-duplicate-attribute-values --output output.html
rehype input.html --use rehype-remove-duplicate-attribute-values --output output.html
```
On the CLI in a config file (here a `package.json`):
```diff
"rehype": {
"plugins": [
+ "rehype-remove-duplicate-attribute-values",
]
}
```
## API
This package exports no identifiers.
The default export is `rehypeRemoveDuplicateAttributeValues`.
### `unified().use(rehypeRemoveDuplicateAttributeValues)`
Remove duplicates in attributes values.
###### Returns
Transform ([`Transformer`](https://github.com/unifiedjs/unified#transformer)).
## Example
##### In
###### In
```html
<div class="foo foo"></label>
<div class="foo foo"></div>
```
##### Out
###### Out

@@ -73,2 +136,32 @@ ```html

## Syntax
HTML is parsed according to WHATWG HTML (the living standard), which is also
followed by all browsers.
## Syntax tree
The syntax tree used is [hast][].
## Types
This package is fully typed with [TypeScript][].
## Compatibility
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`rehype-remove-duplicate-attribute-values@^4`,
compatible with Node.js 16.
## Security
As **rehype** works on HTML and improper use of HTML can open you up to a
[cross-site scripting (XSS)][xss] attack, use of rehype can also be unsafe.
Use [`rehype-sanitize`][rehype-sanitize] to make the tree safe.
## Contribute

@@ -88,42 +181,54 @@

[build-badge]: https://github.com/rehypejs/rehype-minify/workflows/main/badge.svg
[author]: https://wooorm.com
[build]: https://github.com/rehypejs/rehype-minify/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-minify.svg
[build-badge]: https://github.com/rehypejs/rehype-minify/workflows/main/badge.svg
[chat]: https://github.com/rehypejs/rehype/discussions
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[coc]: https://github.com/rehypejs/.github/blob/main/code-of-conduct.md
[contributing]: https://github.com/rehypejs/.github/blob/main/contributing.md
[coverage]: https://codecov.io/github/rehypejs/rehype-minify
[downloads-badge]: https://img.shields.io/npm/dm/rehype-remove-duplicate-attribute-values.svg
[coverage-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-minify.svg
[downloads]: https://www.npmjs.com/package/rehype-remove-duplicate-attribute-values
[size-badge]: https://img.shields.io/bundlephobia/minzip/rehype-remove-duplicate-attribute-values.svg
[downloads-badge]: https://img.shields.io/npm/dm/rehype-remove-duplicate-attribute-values.svg
[size]: https://bundlephobia.com/result?p=rehype-remove-duplicate-attribute-values
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[esm-sh]: https://esm.sh
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[funding]: https://opencollective.com/unified
[collective]: https://opencollective.com/unified
[funding-backers-badge]: https://opencollective.com/unified/backers/badge.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[funding-sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[chat]: https://github.com/rehypejs/rehype/discussions
[hast]: https://github.com/syntax-tree/hast
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[health]: https://github.com/rehypejs/.github
[license]: https://github.com/rehypejs/rehype-minify/blob/main/license
[npm]: https://docs.npmjs.com/cli/install
[health]: https://github.com/rehypejs/.github
[rehype]: https://github.com/rehypejs/rehype
[contributing]: https://github.com/rehypejs/.github/blob/main/contributing.md
[rehype-sanitize]: https://github.com/rehypejs/rehype-sanitize
[size]: https://bundlejs.com/?q=rehype-remove-duplicate-attribute-values
[size-badge]: https://img.shields.io/bundlejs/size/rehype-remove-duplicate-attribute-values
[support]: https://github.com/rehypejs/.github/blob/main/support.md
[coc]: https://github.com/rehypejs/.github/blob/main/code-of-conduct.md
[typescript]: https://www.typescriptlang.org
[license]: https://github.com/rehypejs/rehype-minify/blob/main/license
[author]: https://wooorm.com
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
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