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

rehype-minify-meta-content

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-minify-meta-content - npm Package Compare versions

Comparing version 2.0.2 to 3.0.0

index.d.ts

88

index.js

@@ -12,52 +12,54 @@ /**

'use strict'
/**
* @typedef {import('hast').Root} Root
*/
var comma = require('comma-separated-tokens')
var visit = require('unist-util-visit')
var is = require('hast-util-is-element')
var has = require('hast-util-has-property')
import {parse, stringify} from 'comma-separated-tokens'
import {visit} from 'unist-util-visit'
import {isElement} from 'hast-util-is-element'
import {hasProperty} from 'hast-util-has-property'
module.exports = content
const lists = new Set([
'viewport',
'keywords',
'robots',
'apple-itunes-app',
'apple-media-service-subscription'
])
var own = {}.hasOwnProperty
/**
* Minify `content` on `meta` elements.
*
* Note: `meta[name=theme-color]` and `meta[name=msapplication-TileColor]`
* are handled by `rehype-minify-meta-color`.
*
* @type {import('unified').Plugin<[], Root>}
*/
export default function rehypeMinifyMetaContent() {
return (tree) => {
visit(tree, 'element', (node) => {
const props = node.properties || {}
const name = String(props.name || '')
let value = props.content
var handlers = {}
if (
isElement(node, 'meta') &&
hasProperty(node, 'content') &&
typeof value === 'string'
) {
if (name === 'viewport') {
value = value
.replace(/(\d+\.\d+)/, (d) => String(Number(d)))
.replace(/user-scalable=\s*yes/, '')
// Fall through.
}
handlers.viewport = viewport
handlers.keywords = collapse
handlers.robots = collapse
handlers['apple-itunes-app'] = collapse
handlers['apple-media-service-subscription'] = collapse
if (lists.has(name)) {
value = stringify(parse(value), {padLeft: false})
}
function content() {
return transform
}
function transform(tree) {
visit(tree, 'element', visitor)
}
function visitor(node) {
var props = node.properties
var name = props.name
if (is(node, 'meta') && has(node, 'content') && own.call(handlers, name)) {
if (typeof props.content === 'string') {
props.content = handlers[name](props.content)
}
props.content = value
}
})
}
}
function viewport(value) {
return collapse(
value.replace(/(\d+\.\d+)/, toNumber).replace(/user-scalable=\s*yes/, '')
)
}
function collapse(value) {
return comma.stringify(comma.parse(value), {padLeft: false})
}
function toNumber(value) {
return Number(value)
}
{
"name": "rehype-minify-meta-content",
"version": "2.0.2",
"version": "3.0.0",
"description": "rehype plugin to minify `content` on `meta` elements",

@@ -27,12 +27,29 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"comma-separated-tokens": "^1.0.2",
"hast-util-has-property": "^1.0.0",
"hast-util-is-element": "^1.0.0",
"unist-util-visit": "^2.0.0"
"@types/hast": "^2.0.0",
"comma-separated-tokens": "^2.0.0",
"hast-util-has-property": "^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
}
}

@@ -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 `rehypeMinifyMetaContent`
## Use
On the API:
```diff
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
+import rehypeMinifyMetaContent from 'rehype-minify-meta-content'
import rehypeStringify from 'rehype-stringify'
unified()
.use(rehypeParse)
+ .use(rehypeMinifyMetaContent)
.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 minify-meta-content --output output.html
```
## Example

@@ -58,5 +90,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

@@ -81,6 +113,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

@@ -87,0 +121,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