unist-util-find-all-after
Advanced tools
Comparing version 3.0.2 to 4.0.0
@@ -1,19 +0,29 @@ | ||
// TypeScript Version: 3.5 | ||
import {Node, Parent} from 'unist' | ||
import {Test} from 'unist-util-is' | ||
export = findAllAfter | ||
/** | ||
* Unist utility to get all children of a parent after a node or index | ||
* | ||
* @param parent Parent to search in | ||
* @param index or Node to start from | ||
* @param test that Nodes must pass to be included | ||
* @returns Array of found Nodes | ||
*/ | ||
declare function findAllAfter<T extends Node>( | ||
parent: Parent, | ||
index: number | Node, | ||
test?: Test<T> | Array<Test<T>> | ||
): Node[] | ||
export const findAllAfter: (<T extends import('unist').Node>( | ||
node: Parent, | ||
index: Node | number, | ||
test: | ||
| T['type'] | ||
| Partial<T> | ||
| import('unist-util-is').TestFunctionPredicate<T> | ||
| ( | ||
| T['type'] | ||
| Partial<T> | ||
| import('unist-util-is').TestFunctionPredicate<T> | ||
)[] | ||
) => T[]) & | ||
(( | ||
node: Parent, | ||
index: Node | number, | ||
test?: | ||
| null | ||
| undefined | ||
| Type | ||
| Props | ||
| TestFunctionAnything | ||
| Array<Type | Props | TestFunctionAnything> | ||
) => Array<Node>) | ||
export type Node = import('unist').Node | ||
export type Parent = import('unist').Parent | ||
export type Type = import('unist-util-is').Type | ||
export type Props = import('unist-util-is').Props | ||
export type TestFunctionAnything = import('unist-util-is').TestFunctionAnything |
75
index.js
@@ -1,34 +0,57 @@ | ||
'use strict' | ||
/** | ||
* @typedef {import('unist').Node} Node | ||
* @typedef {import('unist').Parent} Parent | ||
* | ||
* @typedef {import('unist-util-is').Type} Type | ||
* @typedef {import('unist-util-is').Props} Props | ||
* @typedef {import('unist-util-is').TestFunctionAnything} TestFunctionAnything | ||
*/ | ||
var convert = require('unist-util-is/convert') | ||
import {convert} from 'unist-util-is' | ||
module.exports = findAllAfter | ||
export const findAllAfter = | ||
/** | ||
* @type {( | ||
* (<T extends Node>(node: Parent, index: Node|number, test: T['type']|Partial<T>|import('unist-util-is').TestFunctionPredicate<T>|Array.<T['type']|Partial<T>|import('unist-util-is').TestFunctionPredicate<T>>) => Array.<T>) & | ||
* ((node: Parent, index: Node|number, test?: null|undefined|Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything>) => Array.<Node>) | ||
* )} | ||
*/ | ||
( | ||
/** | ||
* Utility to get all children of a parent after a node or index | ||
* | ||
* @param {Parent} parent Parent node | ||
* @param {Node|number} index Child of `parent`, or it’s index | ||
* @param {null|undefined|Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything>} [test] is-compatible test (such as a type) | ||
* @returns {Array.<Node>} | ||
*/ | ||
function (parent, index, test) { | ||
var is = convert(test) | ||
/** @type {Array.<Node>} */ | ||
var results = [] | ||
function findAllAfter(parent, index, test) { | ||
var is = convert(test) | ||
var results = [] | ||
if (!parent || !parent.type || !parent.children) { | ||
throw new Error('Expected parent node') | ||
} | ||
if (!parent || !parent.type || !parent.children) { | ||
throw new Error('Expected parent node') | ||
} | ||
if (typeof index === 'number') { | ||
if (index < 0 || index === Number.POSITIVE_INFINITY) { | ||
throw new Error('Expected positive finite number as index') | ||
} | ||
} else { | ||
index = parent.children.indexOf(index) | ||
if (typeof index === 'number') { | ||
if (index < 0 || index === Infinity) { | ||
throw new Error('Expected positive finite number as index') | ||
} | ||
} else { | ||
index = parent.children.indexOf(index) | ||
if (index < 0) { | ||
throw new Error('Expected child node or index') | ||
} | ||
} | ||
if (index < 0) { | ||
throw new Error('Expected child node or index') | ||
} | ||
} | ||
while (++index < parent.children.length) { | ||
if (is(parent.children[index], index, parent)) { | ||
results.push(parent.children[index]) | ||
} | ||
} | ||
while (++index < parent.children.length) { | ||
if (is(parent.children[index], index, parent)) { | ||
results.push(parent.children[index]) | ||
return results | ||
} | ||
} | ||
return results | ||
} | ||
) |
{ | ||
"name": "unist-util-find-all-after", | ||
"version": "3.0.2", | ||
"version": "4.0.0", | ||
"description": "unist utility to find nodes after another node", | ||
@@ -27,15 +27,17 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"types": "index.d.ts", | ||
"dependencies": { | ||
"unist-util-is": "^4.0.0" | ||
"@types/unist": "^2.0.0", | ||
"unist-util-is": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/tape": "^4.0.0", | ||
"browserify": "^17.0.0", | ||
"dtslint": "^4.0.0", | ||
"nyc": "^15.0.0", | ||
"c8": "^7.0.0", | ||
"prettier": "^2.0.0", | ||
@@ -45,23 +47,16 @@ "remark": "^13.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"tinyify": "^3.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.34.0" | ||
"xo": "^0.38.0" | ||
}, | ||
"scripts": { | ||
"prepack": "npm run build && npm run format", | ||
"build": "rimraf \"*.d.ts\" && tsc && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"build-bundle": "browserify . -s unistUtilFindAllAfter -o unist-util-find-all-after.js", | ||
"build-mangle": "browserify . -s unistUtilFindAllAfter -p tinyify -o unist-util-find-all-after.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test-types": "dtslint .", | ||
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types" | ||
"test-api": "node test.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
@@ -77,18 +72,6 @@ "tabWidth": 2, | ||
"prettier": true, | ||
"esnext": false, | ||
"rules": { | ||
"eqeqeq": [ | ||
"error", | ||
"always", | ||
{ | ||
"null": "ignore" | ||
} | ||
], | ||
"guard-for-in": "off", | ||
"no-eq-null": "off" | ||
}, | ||
"ignore": [ | ||
"unist-util-find-all-after.js", | ||
"*.ts" | ||
] | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off" | ||
} | ||
}, | ||
@@ -99,3 +82,8 @@ "remarkConfig": { | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true | ||
} | ||
} |
@@ -15,2 +15,5 @@ # unist-util-find-all-after | ||
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): | ||
Node 12+ is needed to use it and it must be `import`ed instead of `require`d. | ||
[npm][]: | ||
@@ -25,4 +28,4 @@ | ||
```js | ||
var u = require('unist-builder') | ||
var findAllAfter = require('unist-util-find-all-after') | ||
import {u} from 'unist-builder' | ||
import {findAllAfter} from 'unist-util-find-all-after' | ||
@@ -54,2 +57,5 @@ var tree = u('tree', [ | ||
This package exports the following identifiers: `findAllAfter`. | ||
There is no default export. | ||
### `findAllAfter(parent, node|index[, test])` | ||
@@ -115,5 +121,5 @@ | ||
[build-badge]: https://img.shields.io/travis/syntax-tree/unist-util-find-all-after.svg | ||
[build-badge]: https://github.com/syntax-tree/unist-util-find-all-after/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/syntax-tree/unist-util-find-all-after | ||
[build]: https://github.com/syntax-tree/unist-util-find-all-after/actions | ||
@@ -120,0 +126,0 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-find-all-after.svg |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11283
11
79
167
Yes
2
+ Added@types/unist@^2.0.0
+ Added@types/unist@2.0.11(transitive)
+ Addedunist-util-is@5.2.1(transitive)
- Removedunist-util-is@4.1.0(transitive)
Updatedunist-util-is@^5.0.0