rehype-minify-whitespace
Advanced tools
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'; | ||
} |
{ | ||
"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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4571
134
35