Socket
Socket
Sign inDemoInstall

hast-util-whitespace

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hast-util-whitespace - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

8

index.d.ts
/**
* Check if the given value is *inter-element whitespace*.
*
* @param {unknown} thing
* Thing to check (typically `Node` or `string`).
* @returns {boolean}
* Whether the `value` is inter-element whitespace (`boolean`): consisting of
* zero or more of space, tab (`\t`), line feed (`\n`), carriage return
* (`\r`), or form feed (`\f`).
* If a node is passed it must be a `Text` node, whose `value` field is
* checked.
*/
export function whitespace(thing: unknown): boolean

16

index.js
/**
* Check if the given value is *inter-element whitespace*.
*
* @param {unknown} thing
* Thing to check (typically `Node` or `string`).
* @returns {boolean}
* Whether the `value` is inter-element whitespace (`boolean`): consisting of
* zero or more of space, tab (`\t`), line feed (`\n`), carriage return
* (`\r`), or form feed (`\f`).
* If a node is passed it must be a `Text` node, whose `value` field is
* checked.
*/
export function whitespace(thing) {
/** @type {string} */
var value =
// @ts-ignore looks like a node.
const value =
// @ts-expect-error looks like a node.
thing && typeof thing === 'object' && thing.type === 'text'
? // @ts-ignore looks like a text.
? // @ts-expect-error looks like a text.
thing.value || ''

@@ -15,4 +23,4 @@ : thing

// HTML whitespace expression.
// See <https://html.spec.whatwg.org/#space-character>.
// See <https://infra.spec.whatwg.org/#ascii-whitespace>.
return typeof value === 'string' && value.replace(/[ \t\n\f\r]/g, '') === ''
}
{
"name": "hast-util-whitespace",
"version": "2.0.0",
"version": "2.0.1",
"description": "hast utility to check if a node is inter-element whitespace",

@@ -38,19 +38,17 @@ "license": "MIT",

"devDependencies": {
"@types/tape": "^4.0.0",
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.39.0"
"xo": "^0.53.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"

@@ -67,7 +65,3 @@ },

"xo": {
"prettier": true,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
"prettier": true
},

@@ -74,0 +68,0 @@ "remarkConfig": {

@@ -11,12 +11,34 @@ # hast-util-whitespace

[**hast**][hast] utility to check if a `node` is [*inter-element
whitespace*][spec].
[hast][] utility to check if a node is [*inter-element whitespace*][spec].
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`whitespace(thing)`](#whitespacething)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a small utility that checks if a node is whitespace according to
HTML.
## When should I use this?
This utility is super niche, if you’re here you probably know what you’re
looking for!
## Install
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
[npm][]:
```sh

@@ -26,2 +48,16 @@ npm install hast-util-whitespace

In Deno with [`esm.sh`][esmsh]:
```js
import {whitespace} from 'https://esm.sh/hast-util-whitespace@2'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {whitespace} from 'https://esm.sh/hast-util-whitespace@2?bundle'
</script>
```
## Use

@@ -51,6 +87,6 @@

This package exports the following identifiers: `whitespace`.
This package exports the identifier [`whitespace`][whitespace].
There is no default export.
### `whitespace(node|value)`
### `whitespace(thing)`

@@ -61,12 +97,25 @@ Check if the given value is [*inter-element whitespace*][spec].

* `node` ([`Node`][node], optional) — Node to check
* `value` (`string`, optional) — Value to check
* `thing` (`unknown`, optional)
— thing to check (typically [`Node`][node] or `string`)
###### Returns
`boolean` — Whether the `value` is inter-element white-space: consisting of zero
Whether the `value` is inter-element whitespace (`boolean`): consisting of zero
or more of space, tab (`\t`), line feed (`\n`), carriage return (`\r`), or form
feed (`\f`).
If `node` is passed it must be a [*text*][text] node.
If a node is passed it must be a [`Text`][text] node, whose `value` field is
checked.
## Types
This package is fully typed with [TypeScript][].
It exports no additional types.
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
## Security

@@ -99,11 +148,11 @@

— check if a node is a script-supporting element
* [`hast-util-is-body-ok-link`](https://github.com/rehypejs/rehype-minify/tree/HEAD/packages/hast-util-is-body-ok-link)
* [`hast-util-is-body-ok-link`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-is-body-ok-link)
— check if a node is “Body OK” link element
* [`hast-util-is-conditional-comment`](https://github.com/rehypejs/rehype-minify/tree/HEAD/packages/hast-util-is-conditional-comment)
— check if a node is a conditional comment
* [`hast-util-is-css-link`](https://github.com/rehypejs/rehype-minify/tree/HEAD/packages/hast-util-is-css-link)
* [`hast-util-is-css-link`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-is-css-link)
— check if a node is a CSS link element
* [`hast-util-is-css-style`](https://github.com/rehypejs/rehype-minify/tree/HEAD/packages/hast-util-is-css-style)
* [`hast-util-is-css-style`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-is-css-style)
— check if a node is a CSS style element
* [`hast-util-is-javascript`](https://github.com/rehypejs/rehype-minify/tree/HEAD/packages/hast-util-is-javascript)
* [`hast-util-is-javascript`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-is-javascript)
— check if a node is a JavaScript script element

@@ -113,4 +162,4 @@

See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
started.
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
ways to get started.
See [`support.md`][support] for ways to get help.

@@ -156,2 +205,8 @@

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[typescript]: https://www.typescriptlang.org
[license]: license

@@ -161,11 +216,13 @@

[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
[health]: https://github.com/syntax-tree/.github
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
[hast]: https://github.com/syntax-tree/hast
[spec]: https://html.spec.whatwg.org/#inter-element-whitespace
[spec]: https://html.spec.whatwg.org/multipage/dom.html#inter-element-whitespace

@@ -177,1 +234,3 @@ [node]: https://github.com/syntax-tree/hast#nodes

[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[whitespace]: #whitespacething
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