Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.
This commit is contained in:
4
node_modules/unist-util-is/index.d.ts
generated
vendored
Normal file
4
node_modules/unist-util-is/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export type Check = import('./lib/index.js').Check
|
||||
export type Test = import('./lib/index.js').Test
|
||||
export type TestFunction = import('./lib/index.js').TestFunction
|
||||
export {is, convert} from './lib/index.js'
|
7
node_modules/unist-util-is/index.js
generated
vendored
Normal file
7
node_modules/unist-util-is/index.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @typedef {import('./lib/index.js').Check} Check
|
||||
* @typedef {import('./lib/index.js').Test} Test
|
||||
* @typedef {import('./lib/index.js').TestFunction} TestFunction
|
||||
*/
|
||||
|
||||
export {is, convert} from './lib/index.js'
|
196
node_modules/unist-util-is/lib/index.d.ts
generated
vendored
Normal file
196
node_modules/unist-util-is/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,196 @@
|
||||
/**
|
||||
* @typedef {import('unist').Node} Node
|
||||
* @typedef {import('unist').Parent} Parent
|
||||
*/
|
||||
/**
|
||||
* @template Fn
|
||||
* @template Fallback
|
||||
* @typedef {Fn extends (value: any) => value is infer Thing ? Thing : Fallback} Predicate
|
||||
*/
|
||||
/**
|
||||
* @callback Check
|
||||
* Check that an arbitrary value is a node.
|
||||
* @param {unknown} this
|
||||
* The given context.
|
||||
* @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.
|
||||
*
|
||||
* @typedef {Record<string, unknown> | Node} Props
|
||||
* Object to check for equivalence.
|
||||
*
|
||||
* Note: `Node` is included as it is common but is not indexable.
|
||||
*
|
||||
* @typedef {Array<Props | TestFunction | string> | Props | TestFunction | string | null | undefined} Test
|
||||
* Check for an arbitrary node.
|
||||
*
|
||||
* @callback TestFunction
|
||||
* Check if a node passes a test.
|
||||
* @param {unknown} this
|
||||
* The given context.
|
||||
* @param {Node} node
|
||||
* A node.
|
||||
* @param {number | undefined} [index]
|
||||
* The node’s position in its parent.
|
||||
* @param {Parent | undefined} [parent]
|
||||
* The node’s parent.
|
||||
* @returns {boolean | undefined | void}
|
||||
* Whether this node passes the test.
|
||||
*
|
||||
* Note: `void` is included until TS sees no return as `undefined`.
|
||||
*/
|
||||
/**
|
||||
* Check if `node` is a `Node` and whether it passes the given test.
|
||||
*
|
||||
* @param {unknown} node
|
||||
* Thing to check, typically `Node`.
|
||||
* @param {Test} test
|
||||
* A check for a specific node.
|
||||
* @param {number | null | undefined} index
|
||||
* The node’s position in its parent.
|
||||
* @param {Parent | null | undefined} parent
|
||||
* The node’s parent.
|
||||
* @param {unknown} context
|
||||
* Context object (`this`) to pass to `test` functions.
|
||||
* @returns {boolean}
|
||||
* Whether `node` is a node and passes a test.
|
||||
*/
|
||||
export const is: (<Condition extends string>(
|
||||
node: unknown,
|
||||
test: Condition,
|
||||
index?: number | null | undefined,
|
||||
parent?: Parent | null | undefined,
|
||||
context?: unknown
|
||||
) => node is import('unist').Node & {
|
||||
type: Condition
|
||||
}) &
|
||||
(<Condition_1 extends Props>(
|
||||
node: unknown,
|
||||
test: Condition_1,
|
||||
index?: number | null | undefined,
|
||||
parent?: Parent | null | undefined,
|
||||
context?: unknown
|
||||
) => node is import('unist').Node & Condition_1) &
|
||||
(<Condition_2 extends TestFunction>(
|
||||
node: unknown,
|
||||
test: Condition_2,
|
||||
index?: number | null | undefined,
|
||||
parent?: Parent | null | undefined,
|
||||
context?: unknown
|
||||
) => node is import('unist').Node &
|
||||
Predicate<Condition_2, import('unist').Node>) &
|
||||
((node?: null | undefined) => false) &
|
||||
((
|
||||
node: unknown,
|
||||
test?: null | undefined,
|
||||
index?: number | null | undefined,
|
||||
parent?: Parent | null | undefined,
|
||||
context?: unknown
|
||||
) => node is import('unist').Node) &
|
||||
((
|
||||
node: unknown,
|
||||
test?: Test,
|
||||
index?: number | null | undefined,
|
||||
parent?: 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} 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 {Check}
|
||||
* An assertion.
|
||||
*/
|
||||
export const convert: (<Condition extends string>(
|
||||
test: Condition
|
||||
) => (
|
||||
node: unknown,
|
||||
index?: number | null | undefined,
|
||||
parent?: Parent | null | undefined,
|
||||
context?: unknown
|
||||
) => node is import('unist').Node & {
|
||||
type: Condition
|
||||
}) &
|
||||
(<Condition_1 extends Props>(
|
||||
test: Condition_1
|
||||
) => (
|
||||
node: unknown,
|
||||
index?: number | null | undefined,
|
||||
parent?: Parent | null | undefined,
|
||||
context?: unknown
|
||||
) => node is import('unist').Node & Condition_1) &
|
||||
(<Condition_2 extends TestFunction>(
|
||||
test: Condition_2
|
||||
) => (
|
||||
node: unknown,
|
||||
index?: number | null | undefined,
|
||||
parent?: Parent | null | undefined,
|
||||
context?: unknown
|
||||
) => node is import('unist').Node &
|
||||
Predicate<Condition_2, import('unist').Node>) &
|
||||
((
|
||||
test?: null | undefined
|
||||
) => (
|
||||
node?: unknown,
|
||||
index?: number | null | undefined,
|
||||
parent?: Parent | null | undefined,
|
||||
context?: unknown
|
||||
) => node is import('unist').Node) &
|
||||
((test?: Test) => Check)
|
||||
export type Node = import('unist').Node
|
||||
export type Parent = import('unist').Parent
|
||||
export type Predicate<Fn, Fallback> = Fn extends (
|
||||
value: any
|
||||
) => value is infer Thing
|
||||
? Thing
|
||||
: Fallback
|
||||
/**
|
||||
* Check that an arbitrary value is a node.
|
||||
*/
|
||||
export type Check = (
|
||||
this: unknown,
|
||||
node?: unknown,
|
||||
index?: number | null | undefined,
|
||||
parent?: Parent | null | undefined
|
||||
) => boolean
|
||||
/**
|
||||
* Object to check for equivalence.
|
||||
*
|
||||
* Note: `Node` is included as it is common but is not indexable.
|
||||
*/
|
||||
export type Props = Record<string, unknown> | Node
|
||||
/**
|
||||
* Check for an arbitrary node.
|
||||
*/
|
||||
export type Test =
|
||||
| Array<Props | TestFunction | string>
|
||||
| Props
|
||||
| TestFunction
|
||||
| string
|
||||
| null
|
||||
| undefined
|
||||
/**
|
||||
* Check if a node passes a test.
|
||||
*/
|
||||
export type TestFunction = (
|
||||
this: unknown,
|
||||
node: Node,
|
||||
index?: number | undefined,
|
||||
parent?: Parent | undefined
|
||||
) => boolean | undefined | void
|
291
node_modules/unist-util-is/lib/index.js
generated
vendored
Normal file
291
node_modules/unist-util-is/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,291 @@
|
||||
/**
|
||||
* @typedef {import('unist').Node} Node
|
||||
* @typedef {import('unist').Parent} Parent
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template Fn
|
||||
* @template Fallback
|
||||
* @typedef {Fn extends (value: any) => value is infer Thing ? Thing : Fallback} Predicate
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback Check
|
||||
* Check that an arbitrary value is a node.
|
||||
* @param {unknown} this
|
||||
* The given context.
|
||||
* @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.
|
||||
*
|
||||
* @typedef {Record<string, unknown> | Node} Props
|
||||
* Object to check for equivalence.
|
||||
*
|
||||
* Note: `Node` is included as it is common but is not indexable.
|
||||
*
|
||||
* @typedef {Array<Props | TestFunction | string> | Props | TestFunction | string | null | undefined} Test
|
||||
* Check for an arbitrary node.
|
||||
*
|
||||
* @callback TestFunction
|
||||
* Check if a node passes a test.
|
||||
* @param {unknown} this
|
||||
* The given context.
|
||||
* @param {Node} node
|
||||
* A node.
|
||||
* @param {number | undefined} [index]
|
||||
* The node’s position in its parent.
|
||||
* @param {Parent | undefined} [parent]
|
||||
* The node’s parent.
|
||||
* @returns {boolean | undefined | void}
|
||||
* Whether this node passes the test.
|
||||
*
|
||||
* Note: `void` is included until TS sees no return as `undefined`.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check if `node` is a `Node` and whether it passes the given test.
|
||||
*
|
||||
* @param {unknown} node
|
||||
* Thing to check, typically `Node`.
|
||||
* @param {Test} test
|
||||
* A check for a specific node.
|
||||
* @param {number | null | undefined} index
|
||||
* The node’s position in its parent.
|
||||
* @param {Parent | null | undefined} parent
|
||||
* The node’s parent.
|
||||
* @param {unknown} context
|
||||
* Context object (`this`) to pass to `test` functions.
|
||||
* @returns {boolean}
|
||||
* Whether `node` is a node and passes a test.
|
||||
*/
|
||||
export const is =
|
||||
// Note: overloads in JSDoc can’t yet use different `@template`s.
|
||||
/**
|
||||
* @type {(
|
||||
* (<Condition extends string>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
|
||||
* (<Condition extends Props>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
|
||||
* (<Condition extends TestFunction>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
|
||||
* ((node?: null | undefined) => false) &
|
||||
* ((node: unknown, test?: null | undefined, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
|
||||
* ((node: unknown, test?: Test, index?: number | null | undefined, parent?: 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 (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')
|
||||
}
|
||||
|
||||
return looksLikeANode(node)
|
||||
? 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} 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 {Check}
|
||||
* An assertion.
|
||||
*/
|
||||
export const convert =
|
||||
// Note: overloads in JSDoc can’t yet use different `@template`s.
|
||||
/**
|
||||
* @type {(
|
||||
* (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
|
||||
* (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
|
||||
* (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
|
||||
* ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
|
||||
* ((test?: Test) => Check)
|
||||
* )}
|
||||
*/
|
||||
(
|
||||
/**
|
||||
* @param {Test} [test]
|
||||
* @returns {Check}
|
||||
*/
|
||||
function (test) {
|
||||
if (test === null || test === undefined) {
|
||||
return ok
|
||||
}
|
||||
|
||||
if (typeof test === 'function') {
|
||||
return castFactory(test)
|
||||
}
|
||||
|
||||
if (typeof test === 'object') {
|
||||
return Array.isArray(test) ? anyFactory(test) : propsFactory(test)
|
||||
}
|
||||
|
||||
if (typeof test === 'string') {
|
||||
return typeFactory(test)
|
||||
}
|
||||
|
||||
throw new Error('Expected function, string, or object as test')
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* @param {Array<Props | TestFunction | string>} tests
|
||||
* @returns {Check}
|
||||
*/
|
||||
function anyFactory(tests) {
|
||||
/** @type {Array<Check>} */
|
||||
const checks = []
|
||||
let index = -1
|
||||
|
||||
while (++index < tests.length) {
|
||||
checks[index] = convert(tests[index])
|
||||
}
|
||||
|
||||
return castFactory(any)
|
||||
|
||||
/**
|
||||
* @this {unknown}
|
||||
* @type {TestFunction}
|
||||
*/
|
||||
function any(...parameters) {
|
||||
let index = -1
|
||||
|
||||
while (++index < checks.length) {
|
||||
if (checks[index].apply(this, parameters)) return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn an object into a test for a node with a certain fields.
|
||||
*
|
||||
* @param {Props} check
|
||||
* @returns {Check}
|
||||
*/
|
||||
function propsFactory(check) {
|
||||
const checkAsRecord = /** @type {Record<string, unknown>} */ (check)
|
||||
|
||||
return castFactory(all)
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function all(node) {
|
||||
const nodeAsRecord = /** @type {Record<string, unknown>} */ (
|
||||
/** @type {unknown} */ (node)
|
||||
)
|
||||
|
||||
/** @type {string} */
|
||||
let key
|
||||
|
||||
for (key in check) {
|
||||
if (nodeAsRecord[key] !== checkAsRecord[key]) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a string into a test for a node with a certain type.
|
||||
*
|
||||
* @param {string} check
|
||||
* @returns {Check}
|
||||
*/
|
||||
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 {TestFunction} testFunction
|
||||
* @returns {Check}
|
||||
*/
|
||||
function castFactory(testFunction) {
|
||||
return check
|
||||
|
||||
/**
|
||||
* @this {unknown}
|
||||
* @type {Check}
|
||||
*/
|
||||
function check(value, index, parent) {
|
||||
return Boolean(
|
||||
looksLikeANode(value) &&
|
||||
testFunction.call(
|
||||
this,
|
||||
value,
|
||||
typeof index === 'number' ? index : undefined,
|
||||
parent || undefined
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function ok() {
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
* @returns {value is Node}
|
||||
*/
|
||||
function looksLikeANode(value) {
|
||||
return value !== null && typeof value === 'object' && 'type' in value
|
||||
}
|
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.
|
100
node_modules/unist-util-is/package.json
generated
vendored
Normal file
100
node_modules/unist-util-is/package.json
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
{
|
||||
"name": "unist-util-is",
|
||||
"version": "6.0.0",
|
||||
"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",
|
||||
"exports": "./index.js",
|
||||
"files": [
|
||||
"lib/",
|
||||
"index.d.ts",
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@types/unist": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mdast": "^4.0.0",
|
||||
"@types/node": "^20.0.0",
|
||||
"c8": "^8.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^11.0.0",
|
||||
"remark-preset-wooorm": "^9.0.0",
|
||||
"tsd": "^0.28.0",
|
||||
"type-coverage": "^2.0.0",
|
||||
"typescript": "^5.0.0",
|
||||
"xo": "^0.54.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 --100 --reporter lcov npm run test-api",
|
||||
"test": "npm run build && npm run format && npm run test-coverage"
|
||||
},
|
||||
"prettier": {
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"tabWidth": 2,
|
||||
"trailingComma": "none",
|
||||
"useTabs": false
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"remark-preset-wooorm"
|
||||
]
|
||||
},
|
||||
"typeCoverage": {
|
||||
"atLeast": 100,
|
||||
"detail": true,
|
||||
"#": "needed `any`s",
|
||||
"ignoreFiles": [
|
||||
"lib/index.d.ts"
|
||||
],
|
||||
"ignoreCatch": true,
|
||||
"strict": true
|
||||
},
|
||||
"xo": {
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"**/*.ts"
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/consistent-type-definitions": "off",
|
||||
"@typescript-eslint/no-unnecessary-type-arguments": "off",
|
||||
"import/no-extraneous-dependencies": "off"
|
||||
}
|
||||
}
|
||||
],
|
||||
"prettier": true
|
||||
}
|
||||
}
|
351
node_modules/unist-util-is/readme.md
generated
vendored
Normal file
351
node_modules/unist-util-is/readme.md
generated
vendored
Normal file
@@ -0,0 +1,351 @@
|
||||
# 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)
|
||||
* [`Check`](#check)
|
||||
* [`Test`](#test)
|
||||
* [`TestFunction`](#testfunction)
|
||||
* [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 16+), 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@6'
|
||||
```
|
||||
|
||||
In browsers with [`esm.sh`][esmsh]:
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import {is} from 'https://esm.sh/unist-util-is@6?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`][api-convert] and
|
||||
[`is`][api-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`, optional)
|
||||
— thing to check, typically [`Node`][node]
|
||||
* `test` ([`Test`][api-test], optional)
|
||||
— a test for a specific element
|
||||
* `index` (`number`, optional)
|
||||
— the node’s position in its parent
|
||||
* `parent` ([`Node`][node], optional)
|
||||
— the node’s parent
|
||||
* `context` (`unknown`, 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`][api-test], optional)
|
||||
— a test for a specific node
|
||||
|
||||
###### Returns
|
||||
|
||||
A check ([`Check`][api-check]).
|
||||
|
||||
### `Check`
|
||||
|
||||
Check that an arbitrary value is a node (TypeScript type).
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `this` (`unknown`, optional)
|
||||
— context object (`this`) to call `test` with
|
||||
* `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`).
|
||||
|
||||
### `Test`
|
||||
|
||||
Check for an arbitrary node (TypeScript type).
|
||||
|
||||
###### Type
|
||||
|
||||
```ts
|
||||
type Test =
|
||||
| Array<Record<string, unknown> | TestFunction | string>
|
||||
| Record<string, unknown>
|
||||
| TestFunction
|
||||
| string
|
||||
| null
|
||||
| undefined
|
||||
```
|
||||
|
||||
Checks that the given thing is a node, and then:
|
||||
|
||||
* when `string`, checks that the node has that tag name
|
||||
* when `function`, see [`TestFunction`][api-test-function]
|
||||
* 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
|
||||
|
||||
### `TestFunction`
|
||||
|
||||
Check if a node passes a test (TypeScript type).
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `node` ([`Node`][node])
|
||||
— a node
|
||||
* `index` (`number` or `undefined`)
|
||||
— the node’s position in its parent
|
||||
* `parent` ([`Node`][node] or `undefined`)
|
||||
— the node’s parent
|
||||
|
||||
###### Returns
|
||||
|
||||
Whether this node passes the test (`boolean`, optional).
|
||||
|
||||
## 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(function (child, index) {
|
||||
return 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 [`Check`][api-check],
|
||||
[`Test`][api-test],
|
||||
[`TestFunction`][api-test-function].
|
||||
|
||||
## Compatibility
|
||||
|
||||
Projects maintained by the unified collective are compatible with maintained
|
||||
versions of Node.js.
|
||||
|
||||
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, `unist-util-is@^6`,
|
||||
compatible with Node.js 16.
|
||||
|
||||
## 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/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=unist-util-is
|
||||
|
||||
[size]: https://bundlejs.com/?q=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
|
||||
|
||||
[api-convert]: #converttest
|
||||
|
||||
[api-is]: #isnode-test-index-parent-context
|
||||
|
||||
[api-check]: #check
|
||||
|
||||
[api-test]: #test
|
||||
|
||||
[api-test-function]: #testfunction
|
Reference in New Issue
Block a user