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

rehype-minify-whitespace

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-minify-whitespace - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

31

index.js
/**
* @fileoverview
* Collapse whitespace.
*
* Normally, collapses to a single space. If `newlines: true`,
* collapses white-space containing newlines to `'\n'` instead
* of `' '`.
* @example

@@ -25,7 +29,11 @@ * <h1>Heading</h1>

function collapse() {
function collapse(proc, options) {
return transform;
function transform(tree) {
return minify(tree, options || {});
}
}
function transform(tree) {
function minify(tree, options) {
var whitespace = options.newlines ? collapseToNewLines : collapseWhiteSpace;
var modifier = modify(visitor);

@@ -51,11 +59,11 @@ var inside = false;

value = collapseWhiteSpace(node.value);
value = whitespace(node.value);
end = value.length;
start = 0;
if (value.charAt(0) === ' ' && viable(prev)) {
if (empty(value.charAt(0)) && viable(prev)) {
start++;
}
if (value.charAt(end - 1) === ' ' && viable(next)) {
if (empty(value.charAt(end - 1)) && viable(next)) {
end--;

@@ -102,1 +110,14 @@ }

}
/* Collapse to spaces, or newlines if they’re in a run. */
function collapseToNewLines(value) {
var result = String(value).replace(/\s+/g, function ($0) {
return $0.indexOf('\n') === -1 ? ' ' : '\n';
});
return result;
}
function empty(character) {
return character === ' ' || character === '\n';
}

2

package.json
{
"name": "rehype-minify-whitespace",
"version": "1.0.0",
"version": "1.1.0",
"description": "Collapse whitespace with rehype",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -7,2 +7,6 @@ <!--This file is generated by `build-packages.js`-->

Normally, collapses to a single space. If `newlines: true`,
collapses white-space containing newlines to `'\n'` instead
of `' '`.
## Install

@@ -9,0 +13,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