Skip to content

Commit

Permalink
Refactor to externalize hast-util-minify-whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 17, 2024
1 parent aeddee2 commit 29fd94a
Show file tree
Hide file tree
Showing 14 changed files with 1,577 additions and 364 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"packages/hast-util-is-css-style/",
"packages/hast-util-is-event-handler/",
"packages/hast-util-is-javascript/",
"packages/hast-util-minify-whitespace/",
"packages/hast-util-to-string/",
"packages/rehype-concat-css-style/",
"packages/rehype-concat-javascript/",
Expand Down
2 changes: 2 additions & 0 deletions packages/hast-util-minify-whitespace/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore-scripts=true
package-lock=false
69 changes: 69 additions & 0 deletions packages/hast-util-minify-whitespace/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* hast utility to minify whitespace between elements.
*
* ## What is this?
*
* This package is a utility that can minify the whitespace between elements.
*
* ## When should I use this?
*
* You can use this package when you want to improve the size of HTML fragments.
*
* ## Use
*
* ```js
* import {h} from 'hastscript'
* import {minifyWhitespace} from 'hast-util-minify-whitespace'
*
* const tree = h('p', [
* ' ',
* h('strong', 'foo'),
* ' ',
* h('em', 'bar'),
* ' ',
* h('meta', {itemProp: true}),
* ' '
* ])
*
* minifyWhitespace(tree)
*
* console.log(tree)
* //=> h('p', [h('strong', 'foo'), ' ', h('em', 'bar'), h('meta', {itemProp: true})])
* ```
*
* ## API
*
* ### `Options`
*
* Configuration (TypeScript type).
*
* ###### Fields
*
* * `newlines` (`boolean`, default: `false`)
* — collapse whitespace containing newlines to `'\n'` instead of `' '`
* (default: `false`);
* the default is to collapse to a single space
*
* ###### Returns
*
* Nothing (`undefined`).
*
* ### `minifywhitespace(tree[, options])`
*
* Minify whitespace.
*
* ###### Parameters
*
* * `tree` (`Node`) — tree
* * `options` (`Options`, optional) — configuration
*
* ###### Returns
*
* Nothing (`undefined`).
*/

/**
* @typedef {import('./lib/index.js').Options} Options
*/

export {minifyWhitespace} from './lib/index.js'
Loading

0 comments on commit 29fd94a

Please sign in to comment.