Socket
Socket
Sign inDemoInstall

rehype-minify-language

Package Overview
Dependencies
11
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 3.0.0

lib/index.d.ts

10

index.d.ts

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

/**
* Minify language attributes.
*
* @type {import('unified').Plugin<[], Root>}
*/
export default function rehypeMinifyLanguage():
| void
| import('unified').Transformer<import('hast').Root, import('hast').Root>
export type Root = import('hast').Root
export { default } from "./lib/index.js";
/**
* @fileoverview
* Minify language attributes.
* rehype plugin to minify language attributes.
*
* ## What is this?
*
* This package is a plugin that can minify the contents of language tags:
* [BCP 47 tags](https://github.com/wooorm/bcp-47).
*
* ## When should I use this?
*
* You can use this plugin when you want to improve the size of HTML documents.
*
* ## API
*
* ### `unified().use(rehypeMinifyLanguage)`
*
* Minify language attributes.
*
* ###### Returns
*
* Transform ([`Transformer`](https://github.com/unifiedjs/unified#transformer)).
*
* @example
* {}
* <span lang="en-US">Color</span>

@@ -11,40 +31,2 @@ * <a href="https://nl.wikipedia.org/wiki/HyperText_Markup_Language" hreflang="nld-NL">HTML</a>

/**
* @typedef {import('hast').Root} Root
*/
import {bcp47Normalize} from 'bcp-47-normalize'
import {visit} from 'unist-util-visit'
import {hasProperty} from 'hast-util-has-property'
const fields = ['hrefLang', 'lang', 'srcLang', 'xmlLang']
/**
* Minify language attributes.
*
* @type {import('unified').Plugin<[], Root>}
*/
export default function rehypeMinifyLanguage() {
return (tree) => {
visit(tree, 'element', (node) => {
const props = node.properties
let index = -1
while (++index < fields.length) {
const prop = fields[index]
if (
props &&
hasProperty(node, prop) &&
typeof props[prop] === 'string'
) {
// BCP 47 tags are case-insensitive, but in this project we prefer
// lowercase which *should* help GZIP.
props[prop] = String(
bcp47Normalize(String(props[prop])) || props[prop]
).toLowerCase()
}
}
})
}
}
export {default} from './lib/index.js'
{
"name": "rehype-minify-language",
"version": "2.0.0",
"version": "3.0.0",
"description": "rehype plugin to minify language attributes",
"license": "MIT",
"keywords": [
"unified",
"bcp",
"bcp47",
"html",
"lang",
"language",
"mangle",
"minify",
"plugin",
"rehype",
"rehype-plugin",
"plugin",
"html",
"minify",
"mangle",
"language",
"lang",
"bcp",
"bcp47"
"unified"
],

@@ -31,26 +31,21 @@ "repository": "https://github.com/rehypejs/rehype-minify/tree/main/packages/rehype-minify-language",

"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": "./index.js",
"files": [
"index.d.ts",
"index.js"
"index.js",
"lib/"
],
"dependencies": {
"@types/hast": "^2.0.0",
"@types/hast": "^3.0.0",
"bcp-47-normalize": "^2.0.0",
"hast-util-has-property": "^2.0.0",
"unified": "^10.0.0",
"unist-util-visit": "^4.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,39 @@ # rehype-minify-language

[![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]
Minify language attributes.
**[rehype][]** plugin to minify language attributes.
## 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(rehypeMinifyLanguage)`](#unifieduserehypeminifylanguage)
* [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 can minify the contents of language tags:
[BCP 47 tags](https://github.com/wooorm/bcp-47).
## When should I use this?
You can use this plugin when you want to improve the 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 +51,16 @@ npm install rehype-minify-language

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

@@ -35,16 +70,16 @@

```diff
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
+import rehypeMinifyLanguage from 'rehype-minify-language'
import rehypeStringify from 'rehype-stringify'
```js
import rehypeMinifyLanguage from 'rehype-minify-language'
import rehypeParse from 'rehype-parse'
import rehypeStringify from 'rehype-stringify'
import {read} from 'to-vfile'
import {unified} from 'unified'
unified()
.use(rehypeParse)
+ .use(rehypeMinifyLanguage)
.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(rehypeMinifyLanguage)
.use(rehypeStringify)
.process(await read('index.html'))
console.log(String(file))
```

@@ -55,8 +90,35 @@

```sh
rehype input.html --use minify-language --output output.html
rehype input.html --use rehype-minify-language --output output.html
```
On the CLI in a config file (here a `package.json`):
```diff
"rehype": {
"plugins": [
+ "rehype-minify-language",
]
}
```
## API
This package exports no identifiers.
The default export is `rehypeMinifyLanguage`.
### `unified().use(rehypeMinifyLanguage)`
Minify language attributes.
###### Returns
Transform ([`Transformer`](https://github.com/unifiedjs/unified#transformer)).
## Example
##### In
###### In

@@ -70,3 +132,3 @@ ```html

##### Out
###### Out

@@ -80,2 +142,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-minify-language@^3`,
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

@@ -95,42 +187,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-minify-language.svg
[coverage-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-minify.svg
[downloads]: https://www.npmjs.com/package/rehype-minify-language
[size-badge]: https://img.shields.io/bundlephobia/minzip/rehype-minify-language.svg
[downloads-badge]: https://img.shields.io/npm/dm/rehype-minify-language.svg
[size]: https://bundlephobia.com/result?p=rehype-minify-language
[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-minify-language
[size-badge]: https://img.shields.io/bundlejs/size/rehype-minify-language
[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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc