This commit is contained in:
6
node_modules/unist-util-is/convert.d.ts
generated
vendored
Normal file
6
node_modules/unist-util-is/convert.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import {Test, TestFunction} from '.'
|
||||
import {Node} from 'unist'
|
||||
|
||||
declare function convert<T extends Node>(test: Test<T>): TestFunction<T>
|
||||
|
||||
export = convert
|
||||
77
node_modules/unist-util-is/convert.js
generated
vendored
Normal file
77
node_modules/unist-util-is/convert.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = convert
|
||||
|
||||
function convert(test) {
|
||||
if (test == null) {
|
||||
return ok
|
||||
}
|
||||
|
||||
if (typeof test === 'string') {
|
||||
return typeFactory(test)
|
||||
}
|
||||
|
||||
if (typeof test === 'object') {
|
||||
return 'length' in test ? anyFactory(test) : allFactory(test)
|
||||
}
|
||||
|
||||
if (typeof test === 'function') {
|
||||
return test
|
||||
}
|
||||
|
||||
throw new Error('Expected function, string, or object as test')
|
||||
}
|
||||
|
||||
// Utility assert each property in `test` is represented in `node`, and each
|
||||
// values are strictly equal.
|
||||
function allFactory(test) {
|
||||
return all
|
||||
|
||||
function all(node) {
|
||||
var key
|
||||
|
||||
for (key in test) {
|
||||
if (node[key] !== test[key]) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
function anyFactory(tests) {
|
||||
var checks = []
|
||||
var index = -1
|
||||
|
||||
while (++index < tests.length) {
|
||||
checks[index] = convert(tests[index])
|
||||
}
|
||||
|
||||
return any
|
||||
|
||||
function any() {
|
||||
var index = -1
|
||||
|
||||
while (++index < checks.length) {
|
||||
if (checks[index].apply(this, arguments)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Utility to convert a string into a function which checks a given node’s type
|
||||
// for said string.
|
||||
function typeFactory(test) {
|
||||
return type
|
||||
|
||||
function type(node) {
|
||||
return Boolean(node && node.type === test)
|
||||
}
|
||||
}
|
||||
|
||||
// Utility to return true.
|
||||
function ok() {
|
||||
return true
|
||||
}
|
||||
71
node_modules/unist-util-is/index.d.ts
generated
vendored
Normal file
71
node_modules/unist-util-is/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
// TypeScript Version: 3.5
|
||||
|
||||
import {Node, Parent} from 'unist'
|
||||
|
||||
declare namespace unistUtilIs {
|
||||
/**
|
||||
* Check that type property matches expectation for a node
|
||||
*
|
||||
* @typeParam T type of node that passes test
|
||||
*/
|
||||
type TestType<T extends Node> = T['type']
|
||||
|
||||
/**
|
||||
* Check that some attributes on a node are matched
|
||||
*
|
||||
* @typeParam T type of node that passes test
|
||||
*/
|
||||
type TestObject<T extends Node> = Partial<T>
|
||||
|
||||
/**
|
||||
* Check if a node passes a test
|
||||
*
|
||||
* @param node node to check
|
||||
* @param index index of node in parent
|
||||
* @param parent parent of node
|
||||
* @typeParam T type of node that passes test
|
||||
* @returns true if type T is found, false otherwise
|
||||
*/
|
||||
type TestFunction<T extends Node> = (
|
||||
node: unknown,
|
||||
index?: number,
|
||||
parent?: Parent
|
||||
) => node is T
|
||||
|
||||
/**
|
||||
* Union of all the types of tests
|
||||
*
|
||||
* @typeParam T type of node that passes test
|
||||
*/
|
||||
type Test<T extends Node> =
|
||||
| TestType<T>
|
||||
| TestObject<T>
|
||||
| TestFunction<T>
|
||||
| null
|
||||
| undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Unist utility to check if a node passes a test.
|
||||
*
|
||||
* @param node Node to check.
|
||||
* @param test When nullish, checks if `node` is a `Node`.
|
||||
* When `string`, works like passing `function (node) {return 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 any one of the subtests pass.
|
||||
* @param index Position of `node` in `parent`
|
||||
* @param parent Parent of `node`
|
||||
* @param context Context object to invoke `test` with
|
||||
* @typeParam T type that node is compared with
|
||||
* @returns Whether test passed and `node` is a `Node` (object with `type` set to non-empty `string`).
|
||||
*/
|
||||
declare function unistUtilIs<T extends Node>(
|
||||
node: unknown,
|
||||
test?: unistUtilIs.Test<T> | Array<unistUtilIs.Test<any>>,
|
||||
index?: number,
|
||||
parent?: Parent,
|
||||
context?: any
|
||||
): node is T
|
||||
|
||||
export = unistUtilIs
|
||||
32
node_modules/unist-util-is/index.js
generated
vendored
Normal file
32
node_modules/unist-util-is/index.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict'
|
||||
|
||||
var convert = require('./convert')
|
||||
|
||||
module.exports = is
|
||||
|
||||
is.convert = convert
|
||||
|
||||
// Assert if `test` passes for `node`.
|
||||
// When a `parent` node is known the `index` of node should also be given.
|
||||
function is(node, test, index, parent, context) {
|
||||
var check = convert(test)
|
||||
|
||||
if (
|
||||
index != null &&
|
||||
(typeof index !== 'number' || index < 0 || index === Infinity)
|
||||
) {
|
||||
throw new Error('Expected positive finite index')
|
||||
}
|
||||
|
||||
if (parent != null && (!is(parent) || !parent.children)) {
|
||||
throw new Error('Expected parent node')
|
||||
}
|
||||
|
||||
if ((parent == null) !== (index == null)) {
|
||||
throw new Error('Expected both parent and index')
|
||||
}
|
||||
|
||||
return node && node.type && typeof node.type === 'string'
|
||||
? Boolean(check.call(context, node, index, parent))
|
||||
: false
|
||||
}
|
||||
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.
|
||||
105
node_modules/unist-util-is/package.json
generated
vendored
Normal file
105
node_modules/unist-util-is/package.json
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
{
|
||||
"name": "unist-util-is",
|
||||
"version": "4.1.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)"
|
||||
],
|
||||
"files": [
|
||||
"index.js",
|
||||
"convert.js",
|
||||
"index.d.ts",
|
||||
"convert.d.ts"
|
||||
],
|
||||
"types": "index.d.ts",
|
||||
"devDependencies": {
|
||||
"@types/mdast": "^3.0.0",
|
||||
"browserify": "^17.0.0",
|
||||
"dtslint": "^4.0.0",
|
||||
"fast-check": "^2.0.0",
|
||||
"lodash": "^4.0.0",
|
||||
"nyc": "^15.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^9.0.0",
|
||||
"remark-preset-wooorm": "^8.0.0",
|
||||
"tape": "^5.0.0",
|
||||
"tinyify": "^3.0.0",
|
||||
"unified": "^9.0.0",
|
||||
"xo": "^0.38.0"
|
||||
},
|
||||
"scripts": {
|
||||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
|
||||
"build-bundle": "browserify . -s unistUtilIs -o unist-util-is.js",
|
||||
"build-mangle": "browserify . -s unistUtilIs -o unist-util-is.min.js -p tinyify",
|
||||
"build": "npm run build-bundle && npm run build-mangle",
|
||||
"test-api": "node test",
|
||||
"test-coverage": "nyc --reporter lcov tape test",
|
||||
"test-types": "dtslint .",
|
||||
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"esnext": false,
|
||||
"rules": {
|
||||
"@typescript-eslint/no-unused-expressions": "off",
|
||||
"eqeqeq": [
|
||||
"error",
|
||||
"always",
|
||||
{
|
||||
"null": "ignore"
|
||||
}
|
||||
],
|
||||
"max-params": "off",
|
||||
"no-eq-null": "off",
|
||||
"unicorn/prefer-number-properties": "off",
|
||||
"unicorn/prefer-reflect-apply": "off",
|
||||
"unicorn/prefer-type-error": "off"
|
||||
},
|
||||
"ignore": [
|
||||
"*.ts",
|
||||
"unist-util-is.js"
|
||||
]
|
||||
},
|
||||
"nyc": {
|
||||
"check-coverage": true,
|
||||
"lines": 100,
|
||||
"functions": 100,
|
||||
"branches": 100
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"preset-wooorm"
|
||||
]
|
||||
}
|
||||
}
|
||||
203
node_modules/unist-util-is/readme.md
generated
vendored
Normal file
203
node_modules/unist-util-is/readme.md
generated
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
# 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**][unist] utility to check if a node passes a test.
|
||||
|
||||
## Install
|
||||
|
||||
[npm][]:
|
||||
|
||||
```sh
|
||||
npm install unist-util-is
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
var is = require('unist-util-is')
|
||||
|
||||
var node = {type: 'strong'}
|
||||
var parent = {type: 'paragraph', children: [node]}
|
||||
|
||||
function test(node, n) {
|
||||
return n === 5
|
||||
}
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `is(node[, test[, index, parent[, context]]])`
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `node` ([`Node`][node]) — Node to check.
|
||||
* `test` ([`Function`][test], `string`, `Object`, or `Array.<Test>`, optional)
|
||||
— When nullish, checks if `node` is a [`Node`][node].
|
||||
When `string`, works like passing `node => node.type === test`.
|
||||
When `array`, checks if any one of the subtests pass.
|
||||
When `object`, checks that all keys in `test` are in `node`,
|
||||
and that they have strictly equal values
|
||||
* `index` (`number`, optional) — [Index][] of `node` in `parent`
|
||||
* `parent` ([`Node`][node], optional) — [Parent][] of `node`
|
||||
* `context` (`*`, optional) — Context object to invoke `test` with
|
||||
|
||||
###### Returns
|
||||
|
||||
`boolean` — Whether `test` passed *and* `node` is a [`Node`][node] (object with
|
||||
`type` set to a non-empty `string`).
|
||||
|
||||
#### `function test(node[, index, parent])`
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `node` ([`Node`][node]) — Node to check
|
||||
* `index` (`number?`) — [Index][] of `node` in `parent`
|
||||
* `parent` ([`Node?`][node]) — [Parent][] of `node`
|
||||
|
||||
###### Context
|
||||
|
||||
`*` — The to `is` given `context`.
|
||||
|
||||
###### Returns
|
||||
|
||||
`boolean?` — Whether `node` matches.
|
||||
|
||||
### `is.convert(test)`
|
||||
|
||||
Create a test function from `test`, that can later be called with a `node`,
|
||||
`index`, and `parent`.
|
||||
Useful if you’re going to test many nodes, for example when creating a utility
|
||||
where something else passes an is-compatible test.
|
||||
|
||||
The created function is slightly faster because it expects valid input only.
|
||||
Therefore, passing invalid input, yields unexpected results.
|
||||
|
||||
Can also be accessed with `require('unist-util-is/convert')`.
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
var u = require('unist-builder')
|
||||
var convert = require('unist-util-is/convert')
|
||||
|
||||
var test = convert('leaf')
|
||||
|
||||
var tree = u('tree', [
|
||||
u('node', [u('leaf', '1')]),
|
||||
u('leaf', '2'),
|
||||
u('node', [u('leaf', '3'), u('leaf', '4')]),
|
||||
u('leaf', '5')
|
||||
])
|
||||
|
||||
var leafs = tree.children.filter((child, index) => test(child, index, tree))
|
||||
|
||||
console.log(leafs)
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```js
|
||||
[{type: 'leaf', value: '2'}, {type: 'leaf', value: '5'}]
|
||||
```
|
||||
|
||||
## 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` in `syntax-tree/.github`][contributing] 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
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
|
||||
|
||||
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
|
||||
|
||||
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
|
||||
|
||||
[unist]: https://github.com/syntax-tree/unist
|
||||
|
||||
[node]: https://github.com/syntax-tree/unist#node
|
||||
|
||||
[parent]: https://github.com/syntax-tree/unist#parent-1
|
||||
|
||||
[index]: https://github.com/syntax-tree/unist#index
|
||||
|
||||
[test]: #function-testnode-index-parent
|
||||
Reference in New Issue
Block a user