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

unist-util-is

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-is - npm Package Compare versions

Comparing version 5.1.0 to 5.1.1

52

index.d.ts

@@ -15,4 +15,4 @@ /**

* @param {Node} node
* @param {number} [index]
* @param {Parent} [parent]
* @param {number|null|undefined} [index]
* @param {Parent|null|undefined} [parent]
* @returns {boolean|void}

@@ -26,4 +26,4 @@ */

* @param {Node} node
* @param {number} [index]
* @param {Parent} [parent]
* @param {number|null|undefined} [index]
* @param {Parent|null|undefined} [parent]
* @returns {node is X}

@@ -34,4 +34,4 @@ */

* @param {unknown} [node]
* @param {number} [index]
* @param {Parent} [parent]
* @param {number|null|undefined} [index]
* @param {Parent|null|undefined} [parent]
* @returns {boolean}

@@ -45,7 +45,7 @@ */

* @param {unknown} [node]
* @param {number} [index]
* @param {Parent} [parent]
* @param {number|null|undefined} [index]
* @param {Parent|null|undefined} [parent]
* @returns {node is Y}
*/
export var is: (<T extends import('unist').Node>(
export const is: (<T extends import('unist').Node<import('unist').Data>>(
node: unknown,

@@ -57,4 +57,4 @@ test:

| (T['type'] | Partial<T> | TestFunctionPredicate<T>)[],
index?: number,
parent?: Parent,
index?: number | null | undefined,
parent?: Parent | null | undefined,
context?: unknown

@@ -65,7 +65,7 @@ ) => node is T) &

test?: Test,
index?: number,
parent?: Parent,
index?: number | null | undefined,
parent?: Parent | null | undefined,
context?: unknown
) => boolean)
export var convert: (<T extends import('unist').Node>(
export const convert: (<T extends import('unist').Node<import('unist').Data>>(
test: T['type'] | Partial<T> | TestFunctionPredicate<T>

@@ -92,4 +92,4 @@ ) => AssertPredicate<T>) &

node: Node,
index?: number,
parent?: Parent
index?: number | null | undefined,
parent?: Parent | null | undefined
) => boolean | void

@@ -99,11 +99,13 @@ /**

*/
export type TestFunctionPredicate<X extends import('unist').Node> = (
export type TestFunctionPredicate<
X extends import('unist').Node<import('unist').Data>
> = (
node: Node,
index?: number,
parent?: Parent
index?: number | null | undefined,
parent?: Parent | null | undefined
) => node is X
export type AssertAnything = (
node?: unknown,
index?: number,
parent?: Parent
index?: number | null | undefined,
parent?: Parent | null | undefined
) => boolean

@@ -113,6 +115,8 @@ /**

*/
export type AssertPredicate<Y extends import('unist').Node> = (
export type AssertPredicate<
Y extends import('unist').Node<import('unist').Data>
> = (
node?: unknown,
index?: number,
parent?: Parent
index?: number | null | undefined,
parent?: Parent | null | undefined
) => node is Y

@@ -16,4 +16,4 @@ /**

* @param {Node} node
* @param {number} [index]
* @param {Parent} [parent]
* @param {number|null|undefined} [index]
* @param {Parent|null|undefined} [parent]
* @returns {boolean|void}

@@ -28,4 +28,4 @@ */

* @param {Node} node
* @param {number} [index]
* @param {Parent} [parent]
* @param {number|null|undefined} [index]
* @param {Parent|null|undefined} [parent]
* @returns {node is X}

@@ -37,4 +37,4 @@ */

* @param {unknown} [node]
* @param {number} [index]
* @param {Parent} [parent]
* @param {number|null|undefined} [index]
* @param {Parent|null|undefined} [parent]
* @returns {boolean}

@@ -49,8 +49,8 @@ */

* @param {unknown} [node]
* @param {number} [index]
* @param {Parent} [parent]
* @param {number|null|undefined} [index]
* @param {Parent|null|undefined} [parent]
* @returns {node is Y}
*/
export var is =
export const is =
/**

@@ -61,4 +61,4 @@ * Check if a node passes a test.

* @type {(
* (<T extends Node>(node: unknown, test: T['type']|Partial<T>|TestFunctionPredicate<T>|Array.<T['type']|Partial<T>|TestFunctionPredicate<T>>, index?: number, parent?: Parent, context?: unknown) => node is T) &
* ((node?: unknown, test?: Test, index?: number, parent?: Parent, context?: unknown) => boolean)
* (<T extends Node>(node: unknown, test: T['type']|Partial<T>|TestFunctionPredicate<T>|Array.<T['type']|Partial<T>|TestFunctionPredicate<T>>, index?: number|null|undefined, parent?: Parent|null|undefined, context?: unknown) => node is T) &
* ((node?: unknown, test?: Test, index?: number|null|undefined, parent?: Parent|null|undefined, context?: unknown) => boolean)
* )}

@@ -78,4 +78,4 @@ */

* When `array`, checks any one of the subtests pass.
* @param {number} [index] Position of `node` in `parent`
* @param {Parent} [parent] Parent of `node`
* @param {number|null|undefined} [index] Position of `node` in `parent`
* @param {Parent|null|undefined} [parent] Parent of `node`
* @param {unknown} [context] Context object to invoke `test` with

@@ -86,3 +86,3 @@ * @returns {boolean} Whether test passed and `node` is a `Node` (object with `type` set to non-empty `string`).

function is(node, test, index, parent, context) {
var check = convert(test)
const check = convert(test)

@@ -114,3 +114,3 @@ if (

// @ts-ignore Looks like a node.
// @ts-expect-error Looks like a node.
return node && node.type && typeof node.type === 'string'

@@ -122,3 +122,3 @@ ? Boolean(check.call(context, node, index, parent))

export var convert =
export const convert =
/**

@@ -151,4 +151,3 @@ * @type {(

if (typeof test === 'object') {
// @ts-ignore looks like a list of tests / partial test object.
return 'length' in test ? anyFactory(test) : propsFactory(test)
return Array.isArray(test) ? anyFactory(test) : propsFactory(test)
}

@@ -169,4 +168,4 @@

/** @type {Array.<AssertAnything>} */
var checks = []
var index = -1
const checks = []
let index = -1

@@ -185,3 +184,3 @@ while (++index < tests.length) {

function any(...parameters) {
var index = -1
let index = -1

@@ -191,2 +190,4 @@ while (++index < checks.length) {

}
return false
}

@@ -211,6 +212,7 @@ }

/** @type {string} */
var key
let key
for (key in check) {
if (node[key] !== check[key]) return
// @ts-expect-error: hush, it sure works as an index.
if (node[key] !== check[key]) return false
}

@@ -255,2 +257,3 @@

function assertion(...parameters) {
// @ts-expect-error: spreading is fine.
return Boolean(check.call(this, ...parameters))

@@ -257,0 +260,0 @@ }

{
"name": "unist-util-is",
"version": "5.1.0",
"version": "5.1.1",
"description": "unist utility to check if a node passes a test",

@@ -55,3 +55,3 @@ "license": "MIT",

"unified": "^9.0.0",
"xo": "^0.39.0"
"xo": "^0.42.0"
},

@@ -75,8 +75,3 @@ "scripts": {

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

@@ -83,0 +78,0 @@ "remarkConfig": {

@@ -29,4 +29,4 @@ # unist-util-is

var node = {type: 'strong'}
var parent = {type: 'paragraph', children: [node]}
const node = {type: 'strong'}
const parent = {type: 'paragraph', children: [node]}

@@ -33,0 +33,0 @@ function test(node, n) {

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