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

rehype-minify-language

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-minify-language - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

index.d.ts

58

index.js

@@ -11,34 +11,40 @@ /**

'use strict'
/**
* @typedef {import('hast').Root} Root
*/
var normalize = require('bcp-47-normalize')
var visit = require('unist-util-visit')
var has = require('hast-util-has-property')
import {bcp47Normalize} from 'bcp-47-normalize'
import {visit} from 'unist-util-visit'
import {hasProperty} from 'hast-util-has-property'
module.exports = language
const fields = ['hrefLang', 'lang', 'srcLang', 'xmlLang']
var 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
function language() {
return transform
}
while (++index < fields.length) {
const prop = fields[index]
function transform(tree) {
visit(tree, 'element', visitor)
}
function visitor(node) {
var props = node.properties
var index = -1
var prop
while (++index < fields.length) {
prop = fields[index]
if (has(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] = (normalize(props[prop]) || props[prop]).toLowerCase()
}
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()
}
}
})
}
}
{
"name": "rehype-minify-language",
"version": "1.0.0",
"version": "2.0.0",
"description": "rehype plugin to minify language attributes",

@@ -27,13 +27,30 @@ "license": "MIT",

"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
"Titus Wormer <tituswormer@gmail.com>"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"bcp-47-normalize": "^1.1.0",
"hast-util-has-property": "^1.0.0",
"unist-util-visit": "^2.0.0"
"@types/hast": "^2.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"
},
"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,5 @@

This package exports no identifiers.
The default export is `rehypeMinifyLanguage`
## Use

@@ -30,6 +36,11 @@

```diff
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
+import rehypeMinifyLanguage from 'rehype-minify-language'
import rehypeStringify from 'rehype-stringify'
unified()
.use(require('rehype-parse'))
+ .use(require('rehype-minify-language'))
.use(require('rehype-stringify'))
.use(rehypeParse)
+ .use(rehypeMinifyLanguage)
.use(rehypeStringify)
.process('<span>some html</span>', function (err, file) {

@@ -44,3 +55,3 @@ console.error(report(err || file))

```sh
rehype input.html --use minify-language > output.html
rehype input.html --use minify-language --output output.html
```

@@ -82,5 +93,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

@@ -109,2 +120,4 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-minify.svg

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[npm]: https://docs.npmjs.com/cli/install

@@ -111,0 +124,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