vfile-find-down
Advanced tools
Comparing version 7.0.0 to 7.1.0
@@ -1,6 +0,6 @@ | ||
export type Assert = import('./lib/index.js').Assert | ||
export type Callback = import('./lib/index.js').Callback | ||
export type CallbackAll = import('./lib/index.js').CallbackAll | ||
export type Result = import('./lib/index.js').Result | ||
export type Test = import('./lib/index.js').Test | ||
export {findDown, findDownAll} from './lib/index.js' | ||
export type Assert = import('./lib/index.js').Assert; | ||
export type Callback = import('./lib/index.js').Callback; | ||
export type CallbackAll = import('./lib/index.js').CallbackAll; | ||
export type Result = import('./lib/index.js').Result; | ||
export type Test = import('./lib/index.js').Test; | ||
export { findDown, findDownAll } from "./lib/index.js"; |
/// <reference types="node" resolution-mode="require"/> | ||
export function findDown( | ||
test: Test, | ||
paths: Array<string> | string | null | undefined, | ||
callback: Callback | ||
): undefined | ||
export function findDown(test: Test, callback: Callback): undefined | ||
export function findDown( | ||
test: Test, | ||
paths?: Array<string> | string | null | undefined | ||
): Promise<VFile | undefined> | ||
export function findDownAll( | ||
test: Test, | ||
paths: Array<string> | string | null | undefined, | ||
callback: CallbackAll | ||
): undefined | ||
export function findDownAll(test: Test, callback: CallbackAll): undefined | ||
export function findDownAll( | ||
test: Test, | ||
paths?: Array<string> | string | null | undefined | ||
): Promise<Array<VFile>> | ||
/** | ||
* Find the first file or folder downwards. | ||
* | ||
* > π **Note**: files are not read (their `value` is not populated). | ||
* > use `to-vfile` for that. | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<URL | string> | URL | string | null | undefined} paths | ||
* @param {Callback} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Callback} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<URL | string> | URL | string | null | undefined} [paths] | ||
* @returns {Promise<VFile | undefined>} | ||
* | ||
* @param {Test} test | ||
* Things to search for. | ||
* @param {Array<URL | string> | Callback | URL | string | null | undefined} [paths] | ||
* Places to search from. | ||
* @param {Callback | null | undefined} [callback] | ||
* Callback called when done. | ||
* @returns {Promise<VFile | undefined> | undefined} | ||
* Nothing when `callback` is given, otherwise a promise that resolves to | ||
* a file or `undefined`. | ||
*/ | ||
export function findDown(test: Test, paths: Array<URL | string> | URL | string | null | undefined, callback: Callback): undefined; | ||
/** | ||
* Find the first file or folder downwards. | ||
* | ||
* > π **Note**: files are not read (their `value` is not populated). | ||
* > use `to-vfile` for that. | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<URL | string> | URL | string | null | undefined} paths | ||
* @param {Callback} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Callback} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<URL | string> | URL | string | null | undefined} [paths] | ||
* @returns {Promise<VFile | undefined>} | ||
* | ||
* @param {Test} test | ||
* Things to search for. | ||
* @param {Array<URL | string> | Callback | URL | string | null | undefined} [paths] | ||
* Places to search from. | ||
* @param {Callback | null | undefined} [callback] | ||
* Callback called when done. | ||
* @returns {Promise<VFile | undefined> | undefined} | ||
* Nothing when `callback` is given, otherwise a promise that resolves to | ||
* a file or `undefined`. | ||
*/ | ||
export function findDown(test: Test, callback: Callback): undefined; | ||
/** | ||
* Find the first file or folder downwards. | ||
* | ||
* > π **Note**: files are not read (their `value` is not populated). | ||
* > use `to-vfile` for that. | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<URL | string> | URL | string | null | undefined} paths | ||
* @param {Callback} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Callback} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<URL | string> | URL | string | null | undefined} [paths] | ||
* @returns {Promise<VFile | undefined>} | ||
* | ||
* @param {Test} test | ||
* Things to search for. | ||
* @param {Array<URL | string> | Callback | URL | string | null | undefined} [paths] | ||
* Places to search from. | ||
* @param {Callback | null | undefined} [callback] | ||
* Callback called when done. | ||
* @returns {Promise<VFile | undefined> | undefined} | ||
* Nothing when `callback` is given, otherwise a promise that resolves to | ||
* a file or `undefined`. | ||
*/ | ||
export function findDown(test: Test, paths?: Array<URL | string> | URL | string | null | undefined): Promise<VFile | undefined>; | ||
/** | ||
* Find files or folders downwards. | ||
* | ||
* > π **Note**: files are not read (their `value` is not populated). | ||
* > use `to-vfile` for that. | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<URL | string> | URL | string | null | undefined} paths | ||
* @param {CallbackAll} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {CallbackAll} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<URL | string> | URL | string | null | undefined} [paths] | ||
* @returns {Promise<Array<VFile>>} | ||
* | ||
* @param {Test} test | ||
* Things to search for. | ||
* @param {Array<URL | string> | CallbackAll | URL | string | null | undefined} [paths] | ||
* Places to search from. | ||
* @param {CallbackAll | null | undefined} [callback] | ||
* Callback called when done. | ||
* @returns {Promise<Array<VFile>> | undefined} | ||
* Nothing when `callback` is given, otherwise a promise that resolves to | ||
* files. | ||
*/ | ||
export function findDownAll(test: Test, paths: Array<URL | string> | URL | string | null | undefined, callback: CallbackAll): undefined; | ||
/** | ||
* Find files or folders downwards. | ||
* | ||
* > π **Note**: files are not read (their `value` is not populated). | ||
* > use `to-vfile` for that. | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<URL | string> | URL | string | null | undefined} paths | ||
* @param {CallbackAll} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {CallbackAll} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<URL | string> | URL | string | null | undefined} [paths] | ||
* @returns {Promise<Array<VFile>>} | ||
* | ||
* @param {Test} test | ||
* Things to search for. | ||
* @param {Array<URL | string> | CallbackAll | URL | string | null | undefined} [paths] | ||
* Places to search from. | ||
* @param {CallbackAll | null | undefined} [callback] | ||
* Callback called when done. | ||
* @returns {Promise<Array<VFile>> | undefined} | ||
* Nothing when `callback` is given, otherwise a promise that resolves to | ||
* files. | ||
*/ | ||
export function findDownAll(test: Test, callback: CallbackAll): undefined; | ||
/** | ||
* Find files or folders downwards. | ||
* | ||
* > π **Note**: files are not read (their `value` is not populated). | ||
* > use `to-vfile` for that. | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<URL | string> | URL | string | null | undefined} paths | ||
* @param {CallbackAll} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {CallbackAll} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<URL | string> | URL | string | null | undefined} [paths] | ||
* @returns {Promise<Array<VFile>>} | ||
* | ||
* @param {Test} test | ||
* Things to search for. | ||
* @param {Array<URL | string> | CallbackAll | URL | string | null | undefined} [paths] | ||
* Places to search from. | ||
* @param {CallbackAll | null | undefined} [callback] | ||
* Callback called when done. | ||
* @returns {Promise<Array<VFile>> | undefined} | ||
* Nothing when `callback` is given, otherwise a promise that resolves to | ||
* files. | ||
*/ | ||
export function findDownAll(test: Test, paths?: Array<URL | string> | URL | string | null | undefined): Promise<Array<VFile>>; | ||
/** | ||
* Handle a file. | ||
*/ | ||
export type Assert = (file: VFile, stats: fs.Stats) => Result | undefined | ||
export type Assert = (file: VFile, stats: fs.Stats) => Result | undefined; | ||
/** | ||
* Callback called when done. | ||
*/ | ||
export type CallbackAll = ( | ||
error: Error | undefined, | ||
files?: Array<VFile> | undefined | ||
) => undefined | ||
export type CallbackAll = (error: Error | undefined, files?: Array<VFile> | undefined) => undefined; | ||
/** | ||
* Callback called when done finding one file. | ||
*/ | ||
export type Callback = ( | ||
error: Error | undefined, | ||
file?: VFile | undefined | ||
) => undefined | ||
export type Callback = (error: Error | undefined, file?: VFile | undefined) => undefined; | ||
/** | ||
@@ -47,3 +219,3 @@ * Things to search for. | ||
*/ | ||
export type Test = Array<Assert | string> | Assert | string | ||
export type Test = Array<Assert | string> | Assert | string; | ||
/** | ||
@@ -53,15 +225,15 @@ * What to do when collecting a file or folder. | ||
export type Result = { | ||
/** | ||
* Stop searching after this file or folder. | ||
*/ | ||
break?: boolean | null | undefined | ||
/** | ||
* Include this file or folder. | ||
*/ | ||
include?: boolean | null | undefined | ||
/** | ||
* Do not search inside this folder. | ||
*/ | ||
skip?: boolean | null | undefined | ||
} | ||
/** | ||
* Stop searching after this file or folder. | ||
*/ | ||
break?: boolean | null | undefined; | ||
/** | ||
* Include this file or folder. | ||
*/ | ||
include?: boolean | null | undefined; | ||
/** | ||
* Do not search inside this folder. | ||
*/ | ||
skip?: boolean | null | undefined; | ||
}; | ||
/** | ||
@@ -71,20 +243,20 @@ * State. | ||
export type State = { | ||
/** | ||
* Whether we stopped searching. | ||
*/ | ||
broken: boolean | ||
/** | ||
* Files that have been checked already. | ||
*/ | ||
checked: Set<string> | ||
/** | ||
* Whether weβre looking for one file. | ||
*/ | ||
one: boolean | ||
/** | ||
* File test. | ||
*/ | ||
test: Assert | ||
} | ||
import {VFile} from 'vfile' | ||
import fs from 'node:fs' | ||
/** | ||
* Whether we stopped searching. | ||
*/ | ||
broken: boolean; | ||
/** | ||
* Files that have been checked already. | ||
*/ | ||
checked: Set<string>; | ||
/** | ||
* Whether weβre looking for one file. | ||
*/ | ||
one: boolean; | ||
/** | ||
* File test. | ||
*/ | ||
test: Assert; | ||
}; | ||
import { VFile } from 'vfile'; | ||
import fs from 'node:fs'; |
@@ -71,2 +71,3 @@ /** | ||
import process from 'node:process' | ||
import {fileURLToPath} from 'node:url' | ||
import {VFile} from 'vfile' | ||
@@ -84,3 +85,3 @@ | ||
* @param {Test} test | ||
* @param {Array<string> | string | null | undefined} paths | ||
* @param {Array<URL | string> | URL | string | null | undefined} paths | ||
* @param {Callback} callback | ||
@@ -96,3 +97,3 @@ * @returns {undefined} | ||
* @param {Test} test | ||
* @param {Array<string> | string | null | undefined} [paths] | ||
* @param {Array<URL | string> | URL | string | null | undefined} [paths] | ||
* @returns {Promise<VFile | undefined>} | ||
@@ -102,3 +103,3 @@ * | ||
* Things to search for. | ||
* @param {Array<string> | Callback | string | null | undefined} [paths] | ||
* @param {Array<URL | string> | Callback | URL | string | null | undefined} [paths] | ||
* Places to search from. | ||
@@ -144,3 +145,3 @@ * @param {Callback | null | undefined} [callback] | ||
* @param {Test} test | ||
* @param {Array<string> | string | null | undefined} paths | ||
* @param {Array<URL | string> | URL | string | null | undefined} paths | ||
* @param {CallbackAll} callback | ||
@@ -156,3 +157,3 @@ * @returns {undefined} | ||
* @param {Test} test | ||
* @param {Array<string> | string | null | undefined} [paths] | ||
* @param {Array<URL | string> | URL | string | null | undefined} [paths] | ||
* @returns {Promise<Array<VFile>>} | ||
@@ -162,3 +163,3 @@ * | ||
* Things to search for. | ||
* @param {Array<string> | CallbackAll | string | null | undefined} [paths] | ||
* @param {Array<URL | string> | CallbackAll | URL | string | null | undefined} [paths] | ||
* Places to search from. | ||
@@ -278,3 +279,3 @@ * @param {CallbackAll | null | undefined} [callback] | ||
* Things to search for. | ||
* @param {Array<string> | string | undefined} paths | ||
* @param {Array<URL | string> | URL | string | undefined} paths | ||
* Places to search from. | ||
@@ -289,9 +290,9 @@ * @param {boolean} one | ||
const state = {broken: false, checked: new Set(), one, test: convert(test)} | ||
/** @type {Array<string>} */ | ||
/** @type {Array<URL | string>} */ | ||
let cleanPaths | ||
if (typeof paths === 'string') { | ||
if (Array.isArray(paths)) { | ||
cleanPaths = paths | ||
} else if (paths) { | ||
cleanPaths = [paths] | ||
} else if (Array.isArray(paths)) { | ||
cleanPaths = paths | ||
} else { | ||
@@ -322,3 +323,3 @@ cleanPaths = [process.cwd()] | ||
/** | ||
* Find files in `filePath`. | ||
* Find files in `base`. | ||
* | ||
@@ -393,3 +394,3 @@ * @param {State} state | ||
* Info passed around. | ||
* @param {Array<string>} paths | ||
* @param {Array<URL | string>} paths | ||
* Paths. | ||
@@ -410,3 +411,10 @@ * @param {string | undefined} cwd | ||
while (++expected < paths.length) { | ||
visit(state, path.join(cwd || '', paths[expected]), onvisit) | ||
const filePath = paths[expected] | ||
visit( | ||
state, | ||
typeof filePath === 'object' | ||
? fileURLToPath(filePath) | ||
: path.join(cwd || '', filePath), | ||
onvisit | ||
) | ||
} | ||
@@ -413,0 +421,0 @@ |
{ | ||
"name": "vfile-find-down", | ||
"version": "7.0.0", | ||
"version": "7.1.0", | ||
"description": "vfile utility to find one or more files by searching the file system downwards", | ||
@@ -42,3 +42,3 @@ "license": "MIT", | ||
"c8": "^8.0.0", | ||
"prettier": "^2.0.0", | ||
"prettier": "^3.0.0", | ||
"remark-cli": "^11.0.0", | ||
@@ -48,3 +48,3 @@ "remark-preset-wooorm": "^9.0.0", | ||
"typescript": "^5.0.0", | ||
"xo": "^0.54.0" | ||
"xo": "^0.56.0" | ||
}, | ||
@@ -54,3 +54,3 @@ "scripts": { | ||
"build": "tsc --build --clean && tsc --build && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix", | ||
"test-api": "node --conditions development test/index.js", | ||
@@ -57,0 +57,0 @@ "test-coverage": "c8 --100 --reporter lcov npm run test-api", |
@@ -93,3 +93,3 @@ # vfile-find-down | ||
β things to search for | ||
* `paths` (`Array<string>` or `string`, default: `process.cwd()`) | ||
* `paths` (`Array<URL | string> | URL | string`, default: `process.cwd()`) | ||
β places to search from | ||
@@ -120,3 +120,3 @@ * `callback` ([`Callback`][api-callback], optional) | ||
β things to search for | ||
* `paths` (`Array<string>` or `string`, default: `process.cwd()`) | ||
* `paths` (`Array<URL | string> | URL | string`, default: `process.cwd()`) | ||
β places to search from | ||
@@ -123,0 +123,0 @@ * `callback` ([`CallbackAll`][api-callback-all], optional) |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
28844
666
0