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.1 to 3.0.0

2

index.d.ts

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

export {hasProperty} from './lib/index.js'
export { hasProperty } from "./lib/index.js";
/**
* Check if `node`is an element and has a `field` property.
* Check if `node` is an element and has a `name` property.
*
* @param {unknown} node
* Thing to check (typically `Element`).
* @param {unknown} field
* Field name to check (typically `string`).
* @returns {boolean}
* Whether `node` is an element that has a `field` property.
* @template {string} Key
* Type of key.
* @param {Nodes} node
* Node to check (typically `Element`).
* @param {Key} name
* Property name to check.
* @returns {node is Element & {properties: Record<Key, Array<number | string> | number | string | true>}}}
* Whether `node` is an element that has a `name` property.
*
* Note: see <https://github.com/DefinitelyTyped/DefinitelyTyped/blob/27c9274/types/hast/index.d.ts#L37C29-L37C98>.
*/
export function hasProperty(node: unknown, field: unknown): boolean
export type Root = import('hast').Root
export type Content = import('hast').Content
export type Node = Root | Content
export function hasProperty<Key extends string>(node: Nodes, name: Key): node is import("hast").Element & {
properties: Record<Key, string | number | true | (string | number)[]>;
};
export type Element = import('hast').Element;
export type Nodes = import('hast').Nodes;
/**
* @typedef {import('hast').Root} Root
* @typedef {import('hast').Content} Content
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Nodes} Nodes
*/
/**
* @typedef {Root | Content} Node
*/
const own = {}.hasOwnProperty
/**
* Check if `node`is an element and has a `field` property.
* Check if `node` is an element and has a `name` property.
*
* @param {unknown} node
* Thing to check (typically `Element`).
* @param {unknown} field
* Field name to check (typically `string`).
* @returns {boolean}
* Whether `node` is an element that has a `field` property.
* @template {string} Key
* Type of key.
* @param {Nodes} node
* Node to check (typically `Element`).
* @param {Key} name
* Property name to check.
* @returns {node is Element & {properties: Record<Key, Array<number | string> | number | string | true>}}}
* Whether `node` is an element that has a `name` property.
*
* Note: see <https://github.com/DefinitelyTyped/DefinitelyTyped/blob/27c9274/types/hast/index.d.ts#L37C29-L37C98>.
*/
export function hasProperty(node, field) {
export function hasProperty(node, name) {
const value =
typeof field === 'string' &&
isNode(node) &&
node.type === 'element' &&
node.properties &&
own.call(node.properties, field) &&
node.properties[field]
own.call(node.properties, name) &&
node.properties[name]
return value !== null && value !== undefined && value !== false
}
/**
* @param {unknown} value
* @returns {value is Node}
*/
function isNode(value) {
return Boolean(value && typeof value === 'object' && 'type' in value)
}
{
"name": "hast-util-has-property",
"version": "2.0.1",
"version": "3.0.0",
"description": "hast utility to check if a node has a property",

@@ -29,4 +29,3 @@ "license": "MIT",

"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": "./index.js",
"files": [

@@ -37,34 +36,35 @@ "lib/",

],
"dependencies": {
"@types/hast": "^3.0.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"tsd": "^0.28.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.53.0"
"typescript": "^5.0.0",
"xo": "^0.55.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"build": "tsc --build --clean && tsc --build && type-coverage && tsd",
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"xo": {
"prettier": true
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
"remark-preset-wooorm"
]

@@ -75,4 +75,8 @@ },

"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true
}
}

@@ -41,3 +41,3 @@ # hast-util-has-property

This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
In Node.js (version 16+), install with [npm][]:

@@ -51,3 +51,3 @@ ```sh

```js
import {hasProperty} from 'https://esm.sh/hast-util-has-property@2'
import {hasProperty} from 'https://esm.sh/hast-util-has-property@3'
```

@@ -59,3 +59,3 @@

<script type="module">
import {hasProperty} from 'https://esm.sh/hast-util-has-property@2?bundle'
import {hasProperty} from 'https://esm.sh/hast-util-has-property@3?bundle'
</script>

@@ -94,3 +94,3 @@ ```

This package exports the identifier [`hasProperty`][hasproperty].
This package exports the identifier [`hasProperty`][api-has-property].
There is no default export.

@@ -100,12 +100,12 @@

Check if `node`is an element and has a `field` property.
Check if `node`is an element and has a `name` property.
###### Parameters
* `node` (`unknown`) — thing to check (typically [`Element`][element])
* `name` (`unknown`) - field name to check (typically `string`)
* `node` (`Node`) — node to check (typically [`Element`][element])
* `name` (`string`) - property name to check
###### Returns
Whether `node` is an element that has a `field` property (`boolean`).
Whether `node` is an element that has a `name` property (`boolean`).

@@ -119,7 +119,10 @@ ## Types

Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with 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.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`hast-util-has-property@^3`, compatible with Node.js 16.
## Security

@@ -191,5 +194,5 @@

[size-badge]: https://img.shields.io/bundlephobia/minzip/hast-util-has-property.svg
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-has-property
[size]: https://bundlephobia.com/result?p=hast-util-has-property
[size]: https://bundlejs.com/?q=hast-util-has-property

@@ -232,2 +235,2 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[hasproperty]: #haspropertynode-field
[api-has-property]: #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