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

hast-util-has-property

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-has-property - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

lib/index.d.ts

9

index.d.ts

@@ -1,8 +0,1 @@

/**
* Check if `node` has a set `name` property.
*
* @param {unknown} node
* @param {string} name
* @returns {boolean}
*/
export function hasProperty(node: unknown, name: string): boolean
export {hasProperty} from './lib/index.js'

@@ -1,26 +0,1 @@

var own = {}.hasOwnProperty
/**
* Check if `node` has a set `name` property.
*
* @param {unknown} node
* @param {string} name
* @returns {boolean}
*/
export function hasProperty(node, name) {
/** @type {unknown} */
var value =
name &&
node &&
typeof node === 'object' &&
// @ts-ignore Looks like a node.
node.type === 'element' &&
// @ts-ignore Looks like an element.
node.properties &&
// @ts-ignore Looks like an element.
own.call(node.properties, name) &&
// @ts-ignore Looks like an element.
node.properties[name]
return value !== null && value !== undefined && value !== false
}
export {hasProperty} from './lib/index.js'
{
"name": "hast-util-has-property",
"version": "2.0.0",
"version": "2.0.1",
"description": "hast utility to check if a node has a property",

@@ -32,2 +32,3 @@ "license": "MIT",

"files": [
"lib/",
"index.d.ts",

@@ -37,19 +38,17 @@ "index.js"

"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"

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

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

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

@@ -11,12 +11,34 @@ # hast-util-has-property

[**hast**][hast] utility to check if an [*element*][element] has a
[*property*][property].
[hast][] utility to check if an element has a certain property.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`hasProperty(node, field)`](#haspropertynode-field)
* [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 an element that has
a given property.
## 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-has-property

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

@@ -57,20 +93,30 @@

This package exports the following identifiers: `hasProperty`.
This package exports the identifier [`hasProperty`][hasproperty].
There is no default export.
### `hasProperty(node, name)`
### `hasProperty(node, field)`
Check if `node` is an [*element*][element] that has a `name`
[*property name*][property].
Check if `node`is an element and has a `field` property.
###### Parameters
* `node` ([`Node`][node], optional) — [*Node*][node] to check
* `name` (`string`) - [*Property name*][property]
* `node` (`unknown`) — thing to check (typically [`Element`][element])
* `name` (`unknown`) - field name to check (typically `string`)
###### Returns
`boolean` — Whether `node` is an [*element*][element] that has a `name`
[*property name*][property].
Whether `node` is an element that has a `field` property (`boolean`).
## 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

@@ -85,9 +131,9 @@

— check if a node is a (certain) 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)
* [`hast-util-is-conditional-comment`](https://github.com/rehypejs/rehype-minify/tree/main/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

@@ -100,3 +146,3 @@ * [`hast-util-embedded`](https://github.com/syntax-tree/hast-util-embedded)

— check if a node is interactive
* [`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

@@ -118,4 +164,4 @@ * [`hast-util-labelable`](https://github.com/syntax-tree/hast-util-labelable)

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.

@@ -161,2 +207,8 @@

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

@@ -166,16 +218,16 @@

[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
[node]: https://github.com/syntax-tree/hast#nodes
[element]: https://github.com/syntax-tree/hast#element
[property]: https://github.com/syntax-tree/hast#property-names
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[hasproperty]: #haspropertynode-field
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