Skip to content

Commit 2843272

Browse files
committed
Add improved docs
1 parent 5d0d014 commit 2843272

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

lib/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010
const own = {}.hasOwnProperty
1111

1212
/**
13-
* Check if `node` has a `field` property.
13+
* Check if `node`is an element and has a `field` property.
1414
*
1515
* @param {unknown} node
16-
* @param {string | null | undefined} field
16+
* Thing to check (typically `Element`).
17+
* @param {unknown} field
18+
* Field name to check (typically `string`).
1719
* @returns {boolean}
20+
* Whether `node` is an element that has a `field` property.
1821
*/
1922
export function hasProperty(node, field) {
2023
const value =
21-
field &&
24+
typeof field === 'string' &&
2225
isNode(node) &&
2326
node.type === 'element' &&
2427
node.properties &&

readme.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`hasProperty(node, name)`](#haspropertynode-name)
20+
* [`hasProperty(node, field)`](#haspropertynode-field)
2121
* [Types](#types)
2222
* [Compatibility](#compatibility)
2323
* [Security](#security)
@@ -38,7 +38,7 @@ looking for!
3838
## Install
3939

4040
This package is [ESM only][esm].
41-
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]:
41+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
4242

4343
```sh
4444
npm install hast-util-has-property
@@ -88,22 +88,21 @@ hasProperty(
8888

8989
## API
9090

91-
This package exports the identifier `hasProperty`.
91+
This package exports the identifier [`hasProperty`][hasproperty].
9292
There is no default export.
9393

94-
### `hasProperty(node, name)`
94+
### `hasProperty(node, field)`
9595

96-
Check if `node` is an [*element*][element] that has a `name`
97-
[*property name*][property].
96+
Check if `node`is an element and has a `field` property.
9897

9998
###### Parameters
10099

101-
* `node` ([`Node`][node], optional) — [*Node*][node] to check, likely element
102-
* `name` (`string`) - [*Property name*][property]
100+
* `node` (`unknown`) — thing to check (typically [`Element`][element])
101+
* `name` (`unknown`) - field name to check (typically `string`)
103102

104103
###### Returns
105104

106-
Whether `node` is has property `name` (`boolean`).
105+
Whether `node` is an element that has a `field` property (`boolean`).
107106

108107
## Types
109108

@@ -114,7 +113,7 @@ It exports no additional types.
114113

115114
Projects maintained by the unified collective are compatible with all maintained
116115
versions of Node.js.
117-
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
116+
As of now, that is Node.js 14.14+ and 16.0+.
118117
Our projects sometimes work with older versions, but this is not guaranteed.
119118

120119
## Security
@@ -219,10 +218,8 @@ abide by its terms.
219218

220219
[hast]: https://github.com/syntax-tree/hast
221220

222-
[node]: https://github.com/syntax-tree/hast#nodes
223-
224221
[element]: https://github.com/syntax-tree/hast#element
225222

226-
[property]: https://github.com/syntax-tree/hast#property-names
227-
228223
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
224+
225+
[hasproperty]: #haspropertynode-field

0 commit comments

Comments
 (0)