🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
13
node_modules/unist-util-is/index.d.ts
generated
vendored
Normal file
13
node_modules/unist-util-is/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
export type Test = import('./lib/index.js').Test
|
||||
export type TestFunctionAnything = import('./lib/index.js').TestFunctionAnything
|
||||
export type AssertAnything = import('./lib/index.js').AssertAnything
|
||||
export type PredicateTest<
|
||||
Kind extends import('unist').Node<import('unist').Data>
|
||||
> = import('./lib/index.js').PredicateTest<Kind>
|
||||
export type TestFunctionPredicate<
|
||||
Kind extends import('unist').Node<import('unist').Data>
|
||||
> = import('./lib/index.js').TestFunctionPredicate<Kind>
|
||||
export type AssertPredicate<
|
||||
Kind extends import('unist').Node<import('unist').Data>
|
||||
> = import('./lib/index.js').AssertPredicate<Kind>
|
||||
export {is, convert} from './lib/index.js'
|
||||
22
node_modules/unist-util-is/index.js
generated
vendored
Normal file
22
node_modules/unist-util-is/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* @typedef {import('./lib/index.js').Test} Test
|
||||
* @typedef {import('./lib/index.js').TestFunctionAnything} TestFunctionAnything
|
||||
* @typedef {import('./lib/index.js').AssertAnything} AssertAnything
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template {import('unist').Node} Kind
|
||||
* @typedef {import('./lib/index.js').PredicateTest<Kind>} PredicateTest
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template {import('unist').Node} Kind
|
||||
* @typedef {import('./lib/index.js').TestFunctionPredicate<Kind>} TestFunctionPredicate
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template {import('unist').Node} Kind
|
||||
* @typedef {import('./lib/index.js').AssertPredicate<Kind>} AssertPredicate
|
||||
*/
|
||||
|
||||
export {is, convert} from './lib/index.js'
|
||||
207
node_modules/unist-util-is/lib/index.d.ts
generated
vendored
Normal file
207
node_modules/unist-util-is/lib/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
/**
|
||||
* @typedef {import('unist').Node} Node
|
||||
* @typedef {import('unist').Parent} Parent
|
||||
*/
|
||||
/**
|
||||
* @typedef {Record<string, unknown>} Props
|
||||
* @typedef {null | undefined | string | Props | TestFunctionAnything | Array<string | Props | TestFunctionAnything>} Test
|
||||
* Check for an arbitrary node, unaware of TypeScript inferral.
|
||||
*
|
||||
* @callback TestFunctionAnything
|
||||
* Check if a node passes a test, unaware of TypeScript inferral.
|
||||
* @param {unknown} this
|
||||
* The given context.
|
||||
* @param {Node} node
|
||||
* A node.
|
||||
* @param {number | null | undefined} [index]
|
||||
* The node’s position in its parent.
|
||||
* @param {Parent | null | undefined} [parent]
|
||||
* The node’s parent.
|
||||
* @returns {boolean | void}
|
||||
* Whether this node passes the test.
|
||||
*/
|
||||
/**
|
||||
* @template {Node} Kind
|
||||
* Node type.
|
||||
* @typedef {Kind['type'] | Partial<Kind> | TestFunctionPredicate<Kind> | Array<Kind['type'] | Partial<Kind> | TestFunctionPredicate<Kind>>} PredicateTest
|
||||
* Check for a node that can be inferred by TypeScript.
|
||||
*/
|
||||
/**
|
||||
* Check if a node passes a certain test.
|
||||
*
|
||||
* @template {Node} Kind
|
||||
* Node type.
|
||||
* @callback TestFunctionPredicate
|
||||
* Complex test function for a node that can be inferred by TypeScript.
|
||||
* @param {Node} node
|
||||
* A node.
|
||||
* @param {number | null | undefined} [index]
|
||||
* The node’s position in its parent.
|
||||
* @param {Parent | null | undefined} [parent]
|
||||
* The node’s parent.
|
||||
* @returns {node is Kind}
|
||||
* Whether this node passes the test.
|
||||
*/
|
||||
/**
|
||||
* @callback AssertAnything
|
||||
* Check that an arbitrary value is a node, unaware of TypeScript inferral.
|
||||
* @param {unknown} [node]
|
||||
* Anything (typically a node).
|
||||
* @param {number | null | undefined} [index]
|
||||
* The node’s position in its parent.
|
||||
* @param {Parent | null | undefined} [parent]
|
||||
* The node’s parent.
|
||||
* @returns {boolean}
|
||||
* Whether this is a node and passes a test.
|
||||
*/
|
||||
/**
|
||||
* Check if a node is a node and passes a certain node test.
|
||||
*
|
||||
* @template {Node} Kind
|
||||
* Node type.
|
||||
* @callback AssertPredicate
|
||||
* Check that an arbitrary value is a specific node, aware of TypeScript.
|
||||
* @param {unknown} [node]
|
||||
* Anything (typically a node).
|
||||
* @param {number | null | undefined} [index]
|
||||
* The node’s position in its parent.
|
||||
* @param {Parent | null | undefined} [parent]
|
||||
* The node’s parent.
|
||||
* @returns {node is Kind}
|
||||
* Whether this is a node and passes a test.
|
||||
*/
|
||||
/**
|
||||
* Check if `node` is a `Node` and whether it passes the given test.
|
||||
*
|
||||
* @param node
|
||||
* Thing to check, typically `Node`.
|
||||
* @param test
|
||||
* A check for a specific node.
|
||||
* @param index
|
||||
* The node’s position in its parent.
|
||||
* @param parent
|
||||
* The node’s parent.
|
||||
* @returns
|
||||
* Whether `node` is a node and passes a test.
|
||||
*/
|
||||
export const is: (() => false) &
|
||||
(<
|
||||
Kind extends import('unist').Node<
|
||||
import('unist').Data
|
||||
> = import('unist').Node<import('unist').Data>
|
||||
>(
|
||||
node: unknown,
|
||||
test: PredicateTest<Kind>,
|
||||
index: number,
|
||||
parent: Parent,
|
||||
context?: unknown
|
||||
) => node is Kind) &
|
||||
(<
|
||||
Kind_1 extends import('unist').Node<
|
||||
import('unist').Data
|
||||
> = import('unist').Node<import('unist').Data>
|
||||
>(
|
||||
node: unknown,
|
||||
test: PredicateTest<Kind_1>,
|
||||
index?: null | undefined,
|
||||
parent?: null | undefined,
|
||||
context?: unknown
|
||||
) => node is Kind_1) &
|
||||
((
|
||||
node: unknown,
|
||||
test: Test,
|
||||
index: number,
|
||||
parent: Parent,
|
||||
context?: unknown
|
||||
) => boolean) &
|
||||
((
|
||||
node: unknown,
|
||||
test?: Test,
|
||||
index?: null | undefined,
|
||||
parent?: null | undefined,
|
||||
context?: unknown
|
||||
) => boolean)
|
||||
/**
|
||||
* Generate an assertion from a test.
|
||||
*
|
||||
* Useful if you’re going to test many nodes, for example when creating a
|
||||
* utility where something else passes a compatible test.
|
||||
*
|
||||
* The created function is a bit faster because it expects valid input only:
|
||||
* a `node`, `index`, and `parent`.
|
||||
*
|
||||
* @param test
|
||||
* * when nullish, checks if `node` is a `Node`.
|
||||
* * when `string`, works like passing `(node) => node.type === test`.
|
||||
* * when `function` checks if function passed the node is true.
|
||||
* * when `object`, checks that all keys in test are in node, and that they have (strictly) equal values.
|
||||
* * when `array`, checks if any one of the subtests pass.
|
||||
* @returns
|
||||
* An assertion.
|
||||
*/
|
||||
export const convert: (<
|
||||
Kind extends import('unist').Node<import('unist').Data>
|
||||
>(
|
||||
test: PredicateTest<Kind>
|
||||
) => AssertPredicate<Kind>) &
|
||||
((test?: Test) => AssertAnything)
|
||||
export type Node = import('unist').Node
|
||||
export type Parent = import('unist').Parent
|
||||
export type Props = Record<string, unknown>
|
||||
/**
|
||||
* Check for an arbitrary node, unaware of TypeScript inferral.
|
||||
*/
|
||||
export type Test =
|
||||
| null
|
||||
| undefined
|
||||
| string
|
||||
| Props
|
||||
| TestFunctionAnything
|
||||
| Array<string | Props | TestFunctionAnything>
|
||||
/**
|
||||
* Check if a node passes a test, unaware of TypeScript inferral.
|
||||
*/
|
||||
export type TestFunctionAnything = (
|
||||
this: unknown,
|
||||
node: Node,
|
||||
index?: number | null | undefined,
|
||||
parent?: Parent | null | undefined
|
||||
) => boolean | void
|
||||
/**
|
||||
* Check for a node that can be inferred by TypeScript.
|
||||
*/
|
||||
export type PredicateTest<
|
||||
Kind extends import('unist').Node<import('unist').Data>
|
||||
> =
|
||||
| Kind['type']
|
||||
| Partial<Kind>
|
||||
| TestFunctionPredicate<Kind>
|
||||
| Array<Kind['type'] | Partial<Kind> | TestFunctionPredicate<Kind>>
|
||||
/**
|
||||
* Complex test function for a node that can be inferred by TypeScript.
|
||||
*/
|
||||
export type TestFunctionPredicate<
|
||||
Kind extends import('unist').Node<import('unist').Data>
|
||||
> = (
|
||||
node: Node,
|
||||
index?: number | null | undefined,
|
||||
parent?: Parent | null | undefined
|
||||
) => node is Kind
|
||||
/**
|
||||
* Check that an arbitrary value is a node, unaware of TypeScript inferral.
|
||||
*/
|
||||
export type AssertAnything = (
|
||||
node?: unknown,
|
||||
index?: number | null | undefined,
|
||||
parent?: Parent | null | undefined
|
||||
) => boolean
|
||||
/**
|
||||
* Check that an arbitrary value is a specific node, aware of TypeScript.
|
||||
*/
|
||||
export type AssertPredicate<
|
||||
Kind extends import('unist').Node<import('unist').Data>
|
||||
> = (
|
||||
node?: unknown,
|
||||
index?: number | null | undefined,
|
||||
parent?: Parent | null | undefined
|
||||
) => node is Kind
|
||||
301
node_modules/unist-util-is/lib/index.js
generated
vendored
Normal file
301
node_modules/unist-util-is/lib/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,301 @@
|
|||
/**
|
||||
* @typedef {import('unist').Node} Node
|
||||
* @typedef {import('unist').Parent} Parent
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Record<string, unknown>} Props
|
||||
* @typedef {null | undefined | string | Props | TestFunctionAnything | Array<string | Props | TestFunctionAnything>} Test
|
||||
* Check for an arbitrary node, unaware of TypeScript inferral.
|
||||
*
|
||||
* @callback TestFunctionAnything
|
||||
* Check if a node passes a test, unaware of TypeScript inferral.
|
||||
* @param {unknown} this
|
||||
* The given context.
|
||||
* @param {Node} node
|
||||
* A node.
|
||||
* @param {number | null | undefined} [index]
|
||||
* The node’s position in its parent.
|
||||
* @param {Parent | null | undefined} [parent]
|
||||
* The node’s parent.
|
||||
* @returns {boolean | void}
|
||||
* Whether this node passes the test.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template {Node} Kind
|
||||
* Node type.
|
||||
* @typedef {Kind['type'] | Partial<Kind> | TestFunctionPredicate<Kind> | Array<Kind['type'] | Partial<Kind> | TestFunctionPredicate<Kind>>} PredicateTest
|
||||
* Check for a node that can be inferred by TypeScript.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check if a node passes a certain test.
|
||||
*
|
||||
* @template {Node} Kind
|
||||
* Node type.
|
||||
* @callback TestFunctionPredicate
|
||||
* Complex test function for a node that can be inferred by TypeScript.
|
||||
* @param {Node} node
|
||||
* A node.
|
||||
* @param {number | null | undefined} [index]
|
||||
* The node’s position in its parent.
|
||||
* @param {Parent | null | undefined} [parent]
|
||||
* The node’s parent.
|
||||
* @returns {node is Kind}
|
||||
* Whether this node passes the test.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback AssertAnything
|
||||
* Check that an arbitrary value is a node, unaware of TypeScript inferral.
|
||||
* @param {unknown} [node]
|
||||
* Anything (typically a node).
|
||||
* @param {number | null | undefined} [index]
|
||||
* The node’s position in its parent.
|
||||
* @param {Parent | null | undefined} [parent]
|
||||
* The node’s parent.
|
||||
* @returns {boolean}
|
||||
* Whether this is a node and passes a test.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check if a node is a node and passes a certain node test.
|
||||
*
|
||||
* @template {Node} Kind
|
||||
* Node type.
|
||||
* @callback AssertPredicate
|
||||
* Check that an arbitrary value is a specific node, aware of TypeScript.
|
||||
* @param {unknown} [node]
|
||||
* Anything (typically a node).
|
||||
* @param {number | null | undefined} [index]
|
||||
* The node’s position in its parent.
|
||||
* @param {Parent | null | undefined} [parent]
|
||||
* The node’s parent.
|
||||
* @returns {node is Kind}
|
||||
* Whether this is a node and passes a test.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check if `node` is a `Node` and whether it passes the given test.
|
||||
*
|
||||
* @param node
|
||||
* Thing to check, typically `Node`.
|
||||
* @param test
|
||||
* A check for a specific node.
|
||||
* @param index
|
||||
* The node’s position in its parent.
|
||||
* @param parent
|
||||
* The node’s parent.
|
||||
* @returns
|
||||
* Whether `node` is a node and passes a test.
|
||||
*/
|
||||
export const is =
|
||||
/**
|
||||
* @type {(
|
||||
* (() => false) &
|
||||
* (<Kind extends Node = Node>(node: unknown, test: PredicateTest<Kind>, index: number, parent: Parent, context?: unknown) => node is Kind) &
|
||||
* (<Kind extends Node = Node>(node: unknown, test: PredicateTest<Kind>, index?: null | undefined, parent?: null | undefined, context?: unknown) => node is Kind) &
|
||||
* ((node: unknown, test: Test, index: number, parent: Parent, context?: unknown) => boolean) &
|
||||
* ((node: unknown, test?: Test, index?: null | undefined, parent?: null | undefined, context?: unknown) => boolean)
|
||||
* )}
|
||||
*/
|
||||
(
|
||||
/**
|
||||
* @param {unknown} [node]
|
||||
* @param {Test} [test]
|
||||
* @param {number | null | undefined} [index]
|
||||
* @param {Parent | null | undefined} [parent]
|
||||
* @param {unknown} [context]
|
||||
* @returns {boolean}
|
||||
*/
|
||||
// eslint-disable-next-line max-params
|
||||
function is(node, test, index, parent, context) {
|
||||
const check = convert(test)
|
||||
|
||||
if (
|
||||
index !== undefined &&
|
||||
index !== null &&
|
||||
(typeof index !== 'number' ||
|
||||
index < 0 ||
|
||||
index === Number.POSITIVE_INFINITY)
|
||||
) {
|
||||
throw new Error('Expected positive finite index')
|
||||
}
|
||||
|
||||
if (
|
||||
parent !== undefined &&
|
||||
parent !== null &&
|
||||
(!is(parent) || !parent.children)
|
||||
) {
|
||||
throw new Error('Expected parent node')
|
||||
}
|
||||
|
||||
if (
|
||||
(parent === undefined || parent === null) !==
|
||||
(index === undefined || index === null)
|
||||
) {
|
||||
throw new Error('Expected both parent and index')
|
||||
}
|
||||
|
||||
// @ts-expect-error Looks like a node.
|
||||
return node && node.type && typeof node.type === 'string'
|
||||
? Boolean(check.call(context, node, index, parent))
|
||||
: false
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Generate an assertion from a test.
|
||||
*
|
||||
* Useful if you’re going to test many nodes, for example when creating a
|
||||
* utility where something else passes a compatible test.
|
||||
*
|
||||
* The created function is a bit faster because it expects valid input only:
|
||||
* a `node`, `index`, and `parent`.
|
||||
*
|
||||
* @param test
|
||||
* * when nullish, checks if `node` is a `Node`.
|
||||
* * when `string`, works like passing `(node) => node.type === test`.
|
||||
* * when `function` checks if function passed the node is true.
|
||||
* * when `object`, checks that all keys in test are in node, and that they have (strictly) equal values.
|
||||
* * when `array`, checks if any one of the subtests pass.
|
||||
* @returns
|
||||
* An assertion.
|
||||
*/
|
||||
export const convert =
|
||||
/**
|
||||
* @type {(
|
||||
* (<Kind extends Node>(test: PredicateTest<Kind>) => AssertPredicate<Kind>) &
|
||||
* ((test?: Test) => AssertAnything)
|
||||
* )}
|
||||
*/
|
||||
(
|
||||
/**
|
||||
* @param {Test} [test]
|
||||
* @returns {AssertAnything}
|
||||
*/
|
||||
function (test) {
|
||||
if (test === undefined || test === null) {
|
||||
return ok
|
||||
}
|
||||
|
||||
if (typeof test === 'string') {
|
||||
return typeFactory(test)
|
||||
}
|
||||
|
||||
if (typeof test === 'object') {
|
||||
return Array.isArray(test) ? anyFactory(test) : propsFactory(test)
|
||||
}
|
||||
|
||||
if (typeof test === 'function') {
|
||||
return castFactory(test)
|
||||
}
|
||||
|
||||
throw new Error('Expected function, string, or object as test')
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* @param {Array<string | Props | TestFunctionAnything>} tests
|
||||
* @returns {AssertAnything}
|
||||
*/
|
||||
function anyFactory(tests) {
|
||||
/** @type {Array<AssertAnything>} */
|
||||
const checks = []
|
||||
let index = -1
|
||||
|
||||
while (++index < tests.length) {
|
||||
checks[index] = convert(tests[index])
|
||||
}
|
||||
|
||||
return castFactory(any)
|
||||
|
||||
/**
|
||||
* @this {unknown}
|
||||
* @param {Array<unknown>} parameters
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function any(...parameters) {
|
||||
let index = -1
|
||||
|
||||
while (++index < checks.length) {
|
||||
if (checks[index].call(this, ...parameters)) return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn an object into a test for a node with a certain fields.
|
||||
*
|
||||
* @param {Props} check
|
||||
* @returns {AssertAnything}
|
||||
*/
|
||||
function propsFactory(check) {
|
||||
return castFactory(all)
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function all(node) {
|
||||
/** @type {string} */
|
||||
let key
|
||||
|
||||
for (key in check) {
|
||||
// @ts-expect-error: hush, it sure works as an index.
|
||||
if (node[key] !== check[key]) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a string into a test for a node with a certain type.
|
||||
*
|
||||
* @param {string} check
|
||||
* @returns {AssertAnything}
|
||||
*/
|
||||
function typeFactory(check) {
|
||||
return castFactory(type)
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
*/
|
||||
function type(node) {
|
||||
return node && node.type === check
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a custom test into a test for a node that passes that test.
|
||||
*
|
||||
* @param {TestFunctionAnything} check
|
||||
* @returns {AssertAnything}
|
||||
*/
|
||||
function castFactory(check) {
|
||||
return assertion
|
||||
|
||||
/**
|
||||
* @this {unknown}
|
||||
* @param {unknown} node
|
||||
* @param {Array<unknown>} parameters
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function assertion(node, ...parameters) {
|
||||
return Boolean(
|
||||
node &&
|
||||
typeof node === 'object' &&
|
||||
'type' in node &&
|
||||
// @ts-expect-error: fine.
|
||||
Boolean(check.call(this, node, ...parameters))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function ok() {
|
||||
return true
|
||||
}
|
||||
22
node_modules/unist-util-is/license
generated
vendored
Normal file
22
node_modules/unist-util-is/license
generated
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(The MIT license)
|
||||
|
||||
Copyright (c) 2015 Titus Wormer <tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
88
node_modules/unist-util-is/package.json
generated
vendored
Normal file
88
node_modules/unist-util-is/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
{
|
||||
"name": "unist-util-is",
|
||||
"version": "5.2.1",
|
||||
"description": "unist utility to check if a node passes a test",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"unist",
|
||||
"unist-util",
|
||||
"util",
|
||||
"utility",
|
||||
"tree",
|
||||
"node",
|
||||
"is",
|
||||
"equal",
|
||||
"check",
|
||||
"test",
|
||||
"type"
|
||||
],
|
||||
"repository": "syntax-tree/unist-util-is",
|
||||
"bugs": "https://github.com/syntax-tree/unist-util-is/issues",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
},
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"Christian Murphy <christian.murphy.42@gmail.com>",
|
||||
"Lucas Brandstaetter <lucas@brandstaetter.tech> (https://github.com/Roang-zero1)"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"files": [
|
||||
"lib/",
|
||||
"index.d.ts",
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@types/unist": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.0.0",
|
||||
"@types/mdast": "^3.0.0",
|
||||
"@types/node": "^18.0.0",
|
||||
"c8": "^7.0.0",
|
||||
"fast-check": "^3.0.0",
|
||||
"lodash": "^4.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^11.0.0",
|
||||
"remark-preset-wooorm": "^9.0.0",
|
||||
"tsd": "^0.25.0",
|
||||
"type-coverage": "^2.0.0",
|
||||
"typescript": "^4.0.0",
|
||||
"unified": "^10.0.0",
|
||||
"xo": "^0.53.0"
|
||||
},
|
||||
"scripts": {
|
||||
"prepack": "npm run build && npm run format",
|
||||
"build": "tsc --build --clean && tsc --build && tsd && type-coverage",
|
||||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
|
||||
"test-api": "node --conditions development test/index.js",
|
||||
"test-coverage": "c8 --check-coverage --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"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"remark-preset-wooorm"
|
||||
]
|
||||
},
|
||||
"typeCoverage": {
|
||||
"atLeast": 100,
|
||||
"detail": true,
|
||||
"strict": true
|
||||
}
|
||||
}
|
||||
419
node_modules/unist-util-is/readme.md
generated
vendored
Normal file
419
node_modules/unist-util-is/readme.md
generated
vendored
Normal file
|
|
@ -0,0 +1,419 @@
|
|||
# unist-util-is
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
[![Sponsors][sponsors-badge]][collective]
|
||||
[![Backers][backers-badge]][collective]
|
||||
[![Chat][chat-badge]][chat]
|
||||
|
||||
[unist][] utility to check if nodes pass a test.
|
||||
|
||||
## Contents
|
||||
|
||||
* [What is this?](#what-is-this)
|
||||
* [When should I use this?](#when-should-i-use-this)
|
||||
* [Install](#install)
|
||||
* [Use](#use)
|
||||
* [API](#api)
|
||||
* [`is(node[, test[, index, parent[, context]]])`](#isnode-test-index-parent-context)
|
||||
* [`convert(test)`](#converttest)
|
||||
* [`AssertAnything`](#assertanything)
|
||||
* [`AssertPredicate`](#assertpredicate)
|
||||
* [`Test`](#test)
|
||||
* [`TestFunctionAnything`](#testfunctionanything)
|
||||
* [`PredicateTest`](#predicatetest)
|
||||
* [`TestFunctionPredicate`](#testfunctionpredicate)
|
||||
* [Examples](#examples)
|
||||
* [Example of `convert`](#example-of-convert)
|
||||
* [Types](#types)
|
||||
* [Compatibility](#compatibility)
|
||||
* [Related](#related)
|
||||
* [Contribute](#contribute)
|
||||
* [License](#license)
|
||||
|
||||
## What is this?
|
||||
|
||||
This package is a small utility that checks that a node is a certain node.
|
||||
|
||||
## When should I use this?
|
||||
|
||||
Use this small utility if you find yourself repeating code for checking what
|
||||
nodes are.
|
||||
|
||||
A similar package, [`hast-util-is-element`][hast-util-is-element], works on hast
|
||||
elements.
|
||||
|
||||
For more advanced tests, [`unist-util-select`][unist-util-select] can be used
|
||||
to match against CSS selectors.
|
||||
|
||||
## Install
|
||||
|
||||
This package is [ESM only][esm].
|
||||
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
|
||||
|
||||
```sh
|
||||
npm install unist-util-is
|
||||
```
|
||||
|
||||
In Deno with [`esm.sh`][esmsh]:
|
||||
|
||||
```js
|
||||
import {is} from 'https://esm.sh/unist-util-is@5'
|
||||
```
|
||||
|
||||
In browsers with [`esm.sh`][esmsh]:
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import {is} from 'https://esm.sh/unist-util-is@5?bundle'
|
||||
</script>
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
import {is} from 'unist-util-is'
|
||||
|
||||
const node = {type: 'strong'}
|
||||
const parent = {type: 'paragraph', children: [node]}
|
||||
|
||||
is() // => false
|
||||
is({children: []}) // => false
|
||||
is(node) // => true
|
||||
is(node, 'strong') // => true
|
||||
is(node, 'emphasis') // => false
|
||||
|
||||
is(node, node) // => true
|
||||
is(parent, {type: 'paragraph'}) // => true
|
||||
is(parent, {type: 'strong'}) // => false
|
||||
|
||||
is(node, test) // => false
|
||||
is(node, test, 4, parent) // => false
|
||||
is(node, test, 5, parent) // => true
|
||||
|
||||
function test(node, n) {
|
||||
return n === 5
|
||||
}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
This package exports the identifiers [`convert`][convert] and [`is`][is].
|
||||
There is no default export.
|
||||
|
||||
### `is(node[, test[, index, parent[, context]]])`
|
||||
|
||||
Check if `node` is a `Node` and whether it passes the given test.
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `node` (`unknown`)
|
||||
— thing to check, typically [`Node`][node]
|
||||
* `test` ([`Test`][test] or [`PredicateTest`][predicatetest], optional)
|
||||
— a check for a specific element
|
||||
* `index` (`number`, optional)
|
||||
— the node’s position in its parent
|
||||
* `parent` ([`Node`][node], optional)
|
||||
— the node’s parent
|
||||
* `context` (`any`, optional)
|
||||
— context object (`this`) to call `test` with
|
||||
|
||||
###### Returns
|
||||
|
||||
Whether `node` is a [`Node`][node] and passes a test (`boolean`).
|
||||
|
||||
###### Throws
|
||||
|
||||
When an incorrect `test`, `index`, or `parent` is given.
|
||||
There is no error thrown when `node` is not a node.
|
||||
|
||||
### `convert(test)`
|
||||
|
||||
Generate a check from a test.
|
||||
|
||||
Useful if you’re going to test many nodes, for example when creating a
|
||||
utility where something else passes a compatible test.
|
||||
|
||||
The created function is a bit faster because it expects valid input only:
|
||||
a `node`, `index`, and `parent`.
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `test` ([`Test`][test] or [`PredicateTest`][predicatetest], optional)
|
||||
— a check for a specific node
|
||||
|
||||
###### Returns
|
||||
|
||||
An assertion ([`AssertAnything`][assertanything] or
|
||||
[`AssertPredicate`][assertpredicate]).
|
||||
|
||||
### `AssertAnything`
|
||||
|
||||
Check that an arbitrary value is a node, unaware of TypeScript inferral
|
||||
(TypeScript type).
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `node` (`unknown`)
|
||||
— anything (typically a node)
|
||||
* `index` (`number`, optional)
|
||||
— the node’s position in its parent
|
||||
* `parent` ([`Node`][node], optional)
|
||||
— the node’s parent
|
||||
|
||||
###### Returns
|
||||
|
||||
Whether this is a node and passes a test (`boolean`).
|
||||
|
||||
### `AssertPredicate`
|
||||
|
||||
Check that an arbitrary value is a specific node, aware of TypeScript
|
||||
(TypeScript type).
|
||||
|
||||
###### Type parameters
|
||||
|
||||
* `Kind` ([`Node`][node])
|
||||
— node type
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `node` (`unknown`)
|
||||
— anything (typically a node)
|
||||
* `index` (`number`, optional)
|
||||
— the node’s position in its parent
|
||||
* `parent` ([`Node`][node], optional)
|
||||
— the node’s parent
|
||||
|
||||
###### Returns
|
||||
|
||||
Whether this is a node and passes a test (`node is Kind`).
|
||||
|
||||
### `Test`
|
||||
|
||||
Check for an arbitrary node, unaware of TypeScript inferral (TypeScript
|
||||
type).
|
||||
|
||||
###### Type
|
||||
|
||||
```ts
|
||||
type Test =
|
||||
| null
|
||||
| undefined
|
||||
| string
|
||||
| Record<string, unknown>
|
||||
| TestFunctionAnything
|
||||
| Array<string | Record<string, unknown> | TestFunctionAnything>
|
||||
```
|
||||
|
||||
Checks that the given thing is a node, and then:
|
||||
|
||||
* when `string`, checks that the node has that tag name
|
||||
* when `function`, see [`TestFunctionAnything`][testfunctionanything]
|
||||
* when `object`, checks that all keys in test are in node, and that they have
|
||||
(strictly) equal values
|
||||
* when `Array`, checks if one of the subtests pass
|
||||
|
||||
### `TestFunctionAnything`
|
||||
|
||||
Check if a node passes a test, unaware of TypeScript inferral (TypeScript
|
||||
type).
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `node` ([`Node`][node])
|
||||
— a node
|
||||
* `index` (`number`, optional)
|
||||
— the node’s position in its parent
|
||||
* `parent` ([`Node`][node], optional)
|
||||
— the node’s parent
|
||||
|
||||
###### Returns
|
||||
|
||||
Whether this node passes the test (`boolean`).
|
||||
|
||||
### `PredicateTest`
|
||||
|
||||
Check for a node that can be inferred by TypeScript (TypeScript type).
|
||||
|
||||
###### Type
|
||||
|
||||
```ts
|
||||
type PredicateTest<Kind extends Node> =
|
||||
| Kind['type']
|
||||
| Partial<Kind>
|
||||
| TestFunctionPredicate<Kind>
|
||||
| Array<Kind['type'] | Partial<Kind> | TestFunctionPredicate<Kind>>
|
||||
```
|
||||
|
||||
See [`TestFunctionPredicate`][testfunctionpredicate].
|
||||
|
||||
### `TestFunctionPredicate`
|
||||
|
||||
Check if a node passes a certain node test (TypeScript type).
|
||||
|
||||
###### Type parameters
|
||||
|
||||
* `Kind` ([`Node`][node])
|
||||
— node type
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `node` ([`Node`][node])
|
||||
— a node
|
||||
* `index` (`number`, optional)
|
||||
— the node’s position in its parent
|
||||
* `parent` ([`Node`][node], optional)
|
||||
— the node’s parent
|
||||
|
||||
###### Returns
|
||||
|
||||
Whether this node passes the test (`node is Kind`).
|
||||
|
||||
## Examples
|
||||
|
||||
### Example of `convert`
|
||||
|
||||
```js
|
||||
import {u} from 'unist-builder'
|
||||
import {convert} from 'unist-util-is'
|
||||
|
||||
const test = convert('leaf')
|
||||
|
||||
const tree = u('tree', [
|
||||
u('node', [u('leaf', '1')]),
|
||||
u('leaf', '2'),
|
||||
u('node', [u('leaf', '3'), u('leaf', '4')]),
|
||||
u('leaf', '5')
|
||||
])
|
||||
|
||||
const leafs = tree.children.filter((child, index) => test(child, index, tree))
|
||||
|
||||
console.log(leafs)
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```js
|
||||
[{type: 'leaf', value: '2'}, {type: 'leaf', value: '5'}]
|
||||
```
|
||||
|
||||
## Types
|
||||
|
||||
This package is fully typed with [TypeScript][].
|
||||
It exports the additional types [`AssertAnything`][assertanything],
|
||||
[`AssertPredicate`][assertpredicate], [`Test`][test],
|
||||
[`TestFunctionAnything`][testfunctionanything],
|
||||
[`TestFunctionPredicate`][testfunctionpredicate], and
|
||||
[`PredicateTest`][predicatetest].
|
||||
|
||||
## 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.
|
||||
|
||||
## Related
|
||||
|
||||
* [`unist-util-find-after`](https://github.com/syntax-tree/unist-util-find-after)
|
||||
— find a node after another node
|
||||
* [`unist-util-find-before`](https://github.com/syntax-tree/unist-util-find-before)
|
||||
— find a node before another node
|
||||
* [`unist-util-find-all-after`](https://github.com/syntax-tree/unist-util-find-all-after)
|
||||
— find all nodes after another node
|
||||
* [`unist-util-find-all-before`](https://github.com/syntax-tree/unist-util-find-all-before)
|
||||
— find all nodes before another node
|
||||
* [`unist-util-find-all-between`](https://github.com/mrzmmr/unist-util-find-all-between)
|
||||
— find all nodes between two nodes
|
||||
* [`unist-util-filter`](https://github.com/syntax-tree/unist-util-filter)
|
||||
— create a new tree with nodes that pass a check
|
||||
* [`unist-util-remove`](https://github.com/syntax-tree/unist-util-remove)
|
||||
— remove nodes from tree
|
||||
|
||||
## Contribute
|
||||
|
||||
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
|
||||
ways to get started.
|
||||
See [`support.md`][support] for ways to get help.
|
||||
|
||||
This project has a [code of conduct][coc].
|
||||
By interacting with this repository, organization, or community you agree to
|
||||
abide by its terms.
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
<!-- Definitions -->
|
||||
|
||||
[build-badge]: https://github.com/syntax-tree/unist-util-is/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/syntax-tree/unist-util-is/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-is.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/syntax-tree/unist-util-is
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/unist-util-is.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/unist-util-is
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/unist-util-is.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=unist-util-is
|
||||
|
||||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
|
||||
|
||||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
|
||||
|
||||
[collective]: https://opencollective.com/unified
|
||||
|
||||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
|
||||
|
||||
[chat]: https://github.com/syntax-tree/unist/discussions
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
||||
|
||||
[esmsh]: https://esm.sh
|
||||
|
||||
[typescript]: https://www.typescriptlang.org
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[health]: https://github.com/syntax-tree/.github
|
||||
|
||||
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.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
|
||||
|
||||
[unist]: https://github.com/syntax-tree/unist
|
||||
|
||||
[node]: https://github.com/syntax-tree/unist#node
|
||||
|
||||
[hast-util-is-element]: https://github.com/syntax-tree/hast-util-is-element
|
||||
|
||||
[unist-util-select]: https://github.com/syntax-tree/unist-util-select
|
||||
|
||||
[is]: #isnode-test-index-parent-context
|
||||
|
||||
[convert]: #converttest
|
||||
|
||||
[assertanything]: #assertanything
|
||||
|
||||
[assertpredicate]: #assertpredicate
|
||||
|
||||
[test]: #test
|
||||
|
||||
[testfunctionanything]: #testfunctionanything
|
||||
|
||||
[testfunctionpredicate]: #testfunctionpredicate
|
||||
|
||||
[predicatetest]: #predicatetest
|
||||
Loading…
Add table
Add a link
Reference in a new issue