vfile-find-down
Advanced tools
Comparing version 6.1.0 to 7.0.0
export type Assert = import('./lib/index.js').Assert | ||
export type Callback = import('./lib/index.js').Callback | ||
export type CallbackOne = import('./lib/index.js').CallbackOne | ||
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 {BREAK, INCLUDE, SKIP, findDown, findDownOne} from './lib/index.js' | ||
export {findDown, findDownAll} from './lib/index.js' |
/** | ||
* @typedef {import('./lib/index.js').Assert} Assert | ||
* @typedef {import('./lib/index.js').Callback} Callback | ||
* @typedef {import('./lib/index.js').CallbackOne} CallbackOne | ||
* @typedef {import('./lib/index.js').CallbackAll} CallbackAll | ||
* @typedef {import('./lib/index.js').Result} Result | ||
* @typedef {import('./lib/index.js').Test} Test | ||
*/ | ||
export {BREAK, INCLUDE, SKIP, findDown, findDownOne} from './lib/index.js' | ||
export {findDown, findDownAll} from './lib/index.js' |
/// <reference types="node" resolution-mode="require"/> | ||
/** | ||
* Include this file. | ||
*/ | ||
export const INCLUDE: 1 | ||
/** | ||
* Skip this folder. | ||
*/ | ||
export const SKIP: 4 | ||
/** | ||
* Stop searching. | ||
*/ | ||
export const BREAK: 8 | ||
/** | ||
* Find files or folders downwards. | ||
* | ||
* > 👉 **Note**: files are not read (their `value` is not populated). | ||
* | ||
* @param test | ||
* Things to search for. | ||
* @param paths | ||
* Places to search from. | ||
* @param callback | ||
* Callback called when done. | ||
* @returns | ||
* Nothing when `callback` is given, otherwise a promise that resolves to | ||
* files. | ||
*/ | ||
export const findDown: (( | ||
export function findDown( | ||
test: Test, | ||
paths: Array<string> | string | null | undefined, | ||
callback: Callback | ||
) => void) & | ||
((test: Test, callback: Callback) => void) & | ||
(( | ||
test: Test, | ||
paths?: Array<string> | null | undefined | ||
) => Promise<Array<VFile>>) | ||
/** | ||
* Find the first file or folder downwards. | ||
* | ||
* > 👉 **Note**: files are not read (their `value` is not populated). | ||
* | ||
* @param test | ||
* Things to search for. | ||
* @param paths | ||
* Places to search from. | ||
* @param callback | ||
* Callback called when done. | ||
* @returns | ||
* Nothing when `callback` is given, otherwise a promise that resolves to | ||
* a file or `null`. | ||
*/ | ||
export const findDownOne: (( | ||
): 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: CallbackOne | ||
) => void) & | ||
((test: Test, callback: CallbackOne) => void) & | ||
(( | ||
test: Test, | ||
paths?: Array<string> | null | undefined | ||
) => Promise<VFile | null>) | ||
export type VFile = import('vfile').VFile | ||
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>> | ||
/** | ||
* Handle a file. | ||
*/ | ||
export type Assert = ( | ||
file: VFile, | ||
stats: fs.Stats | ||
) => boolean | null | number | undefined | void | ||
export type Assert = (file: VFile, stats: fs.Stats) => Result | undefined | ||
/** | ||
* Callback called when done. | ||
*/ | ||
export type Callback = (error: Error | null, files: Array<VFile>) => void | ||
export type CallbackAll = ( | ||
error: Error | undefined, | ||
files?: Array<VFile> | undefined | ||
) => undefined | ||
/** | ||
* Callback called when done finding one file. | ||
*/ | ||
export type CallbackOne = (error: Error | null, file: VFile | null) => void | ||
export type Callback = ( | ||
error: Error | undefined, | ||
file?: VFile | undefined | ||
) => undefined | ||
/** | ||
@@ -89,2 +49,19 @@ * Things to search for. | ||
/** | ||
* 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 | ||
} | ||
/** | ||
* State. | ||
@@ -94,2 +71,6 @@ */ | ||
/** | ||
* Whether we stopped searching. | ||
*/ | ||
broken: boolean | ||
/** | ||
* Files that have been checked already. | ||
@@ -99,10 +80,11 @@ */ | ||
/** | ||
* Whether we’re looking for one file. | ||
*/ | ||
one: boolean | ||
/** | ||
* File test. | ||
*/ | ||
test: Assert | ||
/** | ||
* Whether we stopped searching. | ||
*/ | ||
broken: boolean | ||
} | ||
import {VFile} from 'vfile' | ||
import fs from 'node:fs' |
449
lib/index.js
/** | ||
* @typedef {import('vfile').VFile} VFile | ||
*/ | ||
/** | ||
* @callback Assert | ||
@@ -12,3 +8,3 @@ * Handle a file. | ||
* Stats from `fs.stat`. | ||
* @returns {boolean | null | number | undefined | void} | ||
* @returns {Result | undefined} | ||
* How to handle this file. | ||
@@ -21,22 +17,22 @@ * | ||
* | ||
* @callback Callback | ||
* @callback CallbackAll | ||
* Callback called when done. | ||
* @param {Error | null} error | ||
* @param {Error | undefined} error | ||
* Error. | ||
* | ||
* > 👉 **Note**: Errors are currently never passed. | ||
* @param {Array<VFile>} files | ||
* @param {Array<VFile> | undefined} [files] | ||
* Files. | ||
* @returns {void} | ||
* @returns {undefined} | ||
* Nothing. | ||
* | ||
* @callback CallbackOne | ||
* @callback Callback | ||
* Callback called when done finding one file. | ||
* @param {Error | null} error | ||
* @param {Error | undefined} error | ||
* Error. | ||
* | ||
* > 👉 **Note**: Errors are currently never passed | ||
* @param {VFile | null} file | ||
* @param {VFile | undefined} [file] | ||
* File. | ||
* @returns {void} | ||
* @returns {undefined} | ||
* Nothing. | ||
@@ -51,10 +47,21 @@ * | ||
* | ||
* @typedef Result | ||
* What to do when collecting a file or folder. | ||
* @property {boolean | null | undefined} [break] | ||
* Stop searching after this file or folder. | ||
* @property {boolean | null | undefined} [include] | ||
* Include this file or folder. | ||
* @property {boolean | null | undefined} [skip] | ||
* Do not search inside this folder. | ||
* | ||
* @typedef State | ||
* State. | ||
* @property {boolean} broken | ||
* Whether we stopped searching. | ||
* @property {Set<string>} checked | ||
* Files that have been checked already. | ||
* @property {boolean} one | ||
* Whether we’re looking for one file. | ||
* @property {Assert} test | ||
* File test. | ||
* @property {boolean} broken | ||
* Whether we stopped searching. | ||
*/ | ||
@@ -67,22 +74,63 @@ | ||
import process from 'node:process' | ||
import {toVFile} from 'to-vfile' | ||
import {VFile} from 'vfile' | ||
// To do: use `URL`? | ||
// To do: next major: rename to `findDownAll`? | ||
// To do: next next major: use `URL`s instead of paths? | ||
/** | ||
* Include this file. | ||
* 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<string> | string | null | undefined} paths | ||
* @param {Callback} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Callback} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<string> | string | null | undefined} [paths] | ||
* @returns {Promise<VFile | undefined>} | ||
* | ||
* @param {Test} test | ||
* Things to search for. | ||
* @param {Array<string> | Callback | 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 const INCLUDE = 1 | ||
export function findDown(test, paths, callback) { | ||
/** @type {Callback | null | undefined} */ | ||
let callbackOne | ||
/** @type {Promise<Array<VFile>>} */ | ||
let promise | ||
/** | ||
* Skip this folder. | ||
*/ | ||
export const SKIP = 4 | ||
if (typeof paths === 'function') { | ||
callbackOne = paths | ||
promise = find(test, undefined, true) | ||
} else { | ||
callbackOne = callback | ||
promise = find(test, paths || undefined, true) | ||
} | ||
/** | ||
* Stop searching. | ||
*/ | ||
export const BREAK = 8 | ||
if (!callbackOne) { | ||
return promise.then(pickFirst) | ||
} | ||
promise.then(function (files) { | ||
// @ts-expect-error: `callbackOne` is defined. | ||
callbackOne(undefined, pickFirst(files)) | ||
return files | ||
}, callback) | ||
} | ||
/** | ||
@@ -92,109 +140,131 @@ * Find files or folders downwards. | ||
* > 👉 **Note**: files are not read (their `value` is not populated). | ||
* > use `to-vfile` for that. | ||
* | ||
* @param test | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<string> | string | null | undefined} paths | ||
* @param {CallbackAll} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {CallbackAll} callback | ||
* @returns {undefined} | ||
* | ||
* @overload | ||
* @param {Test} test | ||
* @param {Array<string> | string | null | undefined} [paths] | ||
* @returns {Promise<Array<VFile>>} | ||
* | ||
* @param {Test} test | ||
* Things to search for. | ||
* @param paths | ||
* @param {Array<string> | CallbackAll | string | null | undefined} [paths] | ||
* Places to search from. | ||
* @param callback | ||
* @param {CallbackAll | null | undefined} [callback] | ||
* Callback called when done. | ||
* @returns | ||
* @returns {Promise<Array<VFile>> | undefined} | ||
* Nothing when `callback` is given, otherwise a promise that resolves to | ||
* files. | ||
*/ | ||
export const findDown = | ||
/** | ||
* @type {( | ||
* ((test: Test, paths: Array<string> | string | null | undefined, callback: Callback) => void) & | ||
* ((test: Test, callback: Callback) => void) & | ||
* ((test: Test, paths?: Array<string> | null | undefined) => Promise<Array<VFile>>) | ||
* )} | ||
*/ | ||
( | ||
/** | ||
* @param {Test} test | ||
* @param {Array<string> | Callback | string | null | undefined} [paths] | ||
* @param {Callback | null | undefined} [callback] | ||
* @returns {Promise<Array<VFile>> | undefined} | ||
*/ | ||
function (test, paths, callback) { | ||
/** @type {Callback | null | undefined} */ | ||
let callbackAll | ||
/** @type {Promise<Array<VFile>>} */ | ||
let promise | ||
export function findDownAll(test, paths, callback) { | ||
/** @type {CallbackAll | null | undefined} */ | ||
let callbackAll | ||
/** @type {Promise<Array<VFile>>} */ | ||
let promise | ||
if (typeof paths === 'function') { | ||
callbackAll = paths | ||
promise = find(test, undefined, false) | ||
} else { | ||
callbackAll = callback | ||
promise = find(test, paths || undefined, false) | ||
} | ||
if (typeof paths === 'function') { | ||
callbackAll = paths | ||
promise = find(test, undefined, false) | ||
} else { | ||
callbackAll = callback | ||
promise = find(test, paths || undefined, false) | ||
} | ||
if (!callbackAll) { | ||
return promise | ||
} | ||
if (!callbackAll) { | ||
return promise | ||
} | ||
promise.then( | ||
// @ts-expect-error: `callbackAll` is defined. | ||
(files) => callbackAll(null, files), | ||
callbackAll | ||
) | ||
} | ||
) | ||
promise.then(function (files) { | ||
// @ts-expect-error: `callbackAll` is defined. | ||
callbackAll(undefined, files) | ||
return files | ||
}, callbackAll) | ||
} | ||
/** | ||
* Find the first file or folder downwards. | ||
* Convert `test` | ||
* | ||
* > 👉 **Note**: files are not read (their `value` is not populated). | ||
* @param {Test} test | ||
* @returns {Assert} | ||
*/ | ||
function convert(test) { | ||
return typeof test === 'function' | ||
? test | ||
: typeof test === 'string' | ||
? convertString(test) | ||
: convertTests(test) | ||
} | ||
/** | ||
* Convert a string test. | ||
* | ||
* @param test | ||
* Things to search for. | ||
* @param paths | ||
* Places to search from. | ||
* @param callback | ||
* Callback called when done. | ||
* @returns | ||
* Nothing when `callback` is given, otherwise a promise that resolves to | ||
* a file or `null`. | ||
* @param {string} test | ||
* @returns {Assert} | ||
*/ | ||
export const findDownOne = | ||
function convertString(test) { | ||
return assertString | ||
/** | ||
* @type {( | ||
* ((test: Test, paths: Array<string> | string | null | undefined, callback: CallbackOne) => void) & | ||
* ((test: Test, callback: CallbackOne) => void) & | ||
* ((test: Test, paths?: Array<string> | null | undefined) => Promise<VFile | null>) | ||
* )} | ||
* Check whether the given `file` matches the bound value. | ||
* | ||
* @type {Assert} | ||
*/ | ||
( | ||
/** | ||
* @param {Test} test | ||
* @param {Array<string> | CallbackOne | string | null | undefined} [paths] | ||
* @param {CallbackOne | null | undefined} [callback] | ||
* @returns {Promise<VFile | null> | undefined} | ||
*/ | ||
function (test, paths, callback) { | ||
/** @type {CallbackOne | null | undefined} */ | ||
let callbackOne | ||
/** @type {Promise<Array<VFile>>} */ | ||
let promise | ||
function assertString(file) { | ||
// File matches the given value as the basename or extname. | ||
if (test === file.basename || test === file.extname) { | ||
return {include: true} | ||
} | ||
if (typeof paths === 'function') { | ||
callbackOne = paths | ||
promise = find(test, undefined, true) | ||
} else { | ||
callbackOne = callback | ||
promise = find(test, paths || undefined, true) | ||
} | ||
// Ignore dotfiles and `node_modules` normally. | ||
if ( | ||
file.basename && | ||
(file.basename.charAt(0) === '.' || file.basename === 'node_modules') | ||
) { | ||
return {skip: true} | ||
} | ||
} | ||
} | ||
if (!callbackOne) { | ||
return promise.then(one) | ||
/** | ||
* Convert multiple tests. | ||
* | ||
* @param {Array<Assert | string>} test | ||
* Tests. | ||
* @returns {Assert} | ||
* Assertion. | ||
*/ | ||
function convertTests(test) { | ||
/** @type {Array<Assert>} */ | ||
const tests = [] | ||
let index = -1 | ||
while (++index < test.length) { | ||
tests[index] = convert(test[index]) | ||
} | ||
return assert | ||
/** @type {Assert} */ | ||
function assert(file, stats) { | ||
let index = -1 | ||
while (++index < tests.length) { | ||
const result = tests[index](file, stats) | ||
if (result) { | ||
return result | ||
} | ||
promise.then( | ||
// @ts-expect-error: `callbackOne` is defined. | ||
(files) => callbackOne(null, one(files)), | ||
callbackOne | ||
) | ||
} | ||
) | ||
} | ||
} | ||
@@ -215,3 +285,3 @@ /** | ||
/** @type {State} */ | ||
const state = {checked: new Set(), test: convert(test), broken: false} | ||
const state = {broken: false, checked: new Set(), one, test: convert(test)} | ||
/** @type {Array<string>} */ | ||
@@ -229,3 +299,4 @@ let cleanPaths | ||
return new Promise(function (resolve) { | ||
visitAll(state, cleanPaths, undefined, one, resolve) | ||
// @ts-expect-error: `resolve` is fine. | ||
visitAll(state, cleanPaths, undefined, resolve) | ||
}) | ||
@@ -235,2 +306,16 @@ } | ||
/** | ||
* Get the first item. | ||
* | ||
* @template {unknown} T | ||
* Kind. | ||
* @param {Array<T>} values | ||
* List. | ||
* @returns {T | undefined} | ||
* Head. | ||
*/ | ||
function pickFirst(values) { | ||
return values[0] | ||
} | ||
/** | ||
* Find files in `filePath`. | ||
@@ -242,8 +327,8 @@ * | ||
* Base. | ||
* @param {boolean} one | ||
* Stop at one file. | ||
* @param {(files: Array<VFile>) => void} done | ||
* @param {(files: Array<VFile>) => undefined} done | ||
* Callback called when done. | ||
* @returns {undefined} | ||
* Nothing. | ||
*/ | ||
function visit(state, filePath, one, done) { | ||
function visit(state, filePath, done) { | ||
// Don’t walk into places multiple times. | ||
@@ -265,9 +350,9 @@ if (state.checked.has(filePath)) { | ||
} else { | ||
const file = toVFile(filePath) | ||
const result = Number(state.test(file, stats)) | ||
const file = new VFile({path: filePath}) | ||
const result = state.test(file, stats) | ||
if ((result & INCLUDE) === INCLUDE /* Include. */) { | ||
if (result && result.include) { | ||
results.push(file) | ||
if (one) { | ||
if (state.one) { | ||
state.broken = true | ||
@@ -278,11 +363,7 @@ return done(results) | ||
if ((result & BREAK) === BREAK /* Break. */) { | ||
if (result && result.break) { | ||
state.broken = true | ||
} | ||
if ( | ||
state.broken || | ||
!stats.isDirectory() || | ||
(result & SKIP) === SKIP /* Skip. */ | ||
) { | ||
if (state.broken || !stats.isDirectory() || (result && result.skip)) { | ||
return done(results) | ||
@@ -292,3 +373,3 @@ } | ||
fs.readdir(filePath, function (_, entries) { | ||
visitAll(state, entries, filePath, one, onvisit) | ||
visitAll(state, entries, filePath, onvisit) | ||
}) | ||
@@ -299,2 +380,5 @@ } | ||
* @param {Array<VFile>} files | ||
* Files. | ||
* @returns {undefined} | ||
* Nothing. | ||
*/ | ||
@@ -316,9 +400,8 @@ function onvisit(files) { | ||
* Base. | ||
* @param {boolean} one | ||
* Stop at one file. | ||
* @param {(files: Array<VFile>) => void} done | ||
* @param {(files: Array<VFile>) => undefined} done | ||
* Callback called when done. | ||
* @returns {undefined} | ||
* Nothing. | ||
*/ | ||
// eslint-disable-next-line max-params | ||
function visitAll(state, paths, cwd, one, done) { | ||
function visitAll(state, paths, cwd, done) { | ||
let actual = -1 | ||
@@ -330,3 +413,3 @@ let expected = -1 | ||
while (++expected < paths.length) { | ||
visit(state, path.join(cwd || '', paths[expected]), one, onvisit) | ||
visit(state, path.join(cwd || '', paths[expected]), onvisit) | ||
} | ||
@@ -338,2 +421,5 @@ | ||
* @param {Array<VFile>} files | ||
* Files. | ||
* @returns {undefined} | ||
* Nothing. | ||
*/ | ||
@@ -345,2 +431,6 @@ function onvisit(files) { | ||
/** | ||
* @returns {undefined} | ||
* Nothing. | ||
*/ | ||
function next() { | ||
@@ -352,86 +442,1 @@ if (++actual === expected) { | ||
} | ||
/** | ||
* Convert `test` | ||
* | ||
* @param {Test} test | ||
* @returns {Assert} | ||
*/ | ||
function convert(test) { | ||
return typeof test === 'function' | ||
? test | ||
: typeof test === 'string' | ||
? testString(test) | ||
: multiple(test) | ||
} | ||
/** | ||
* Wrap a string given as a test. | ||
* | ||
* @param {string} test | ||
* @returns {Assert} | ||
*/ | ||
function testString(test) { | ||
return check | ||
/** | ||
* Check whether the given `file` matches the bound value. | ||
* | ||
* @type {Assert} | ||
*/ | ||
function check(file) { | ||
// File matches the given value as the basename or extname. | ||
if (test === file.basename || test === file.extname) { | ||
return INCLUDE | ||
} | ||
// Ignore dotfiles and `node_modules` normally. | ||
if ( | ||
file.basename && | ||
(file.basename.charAt(0) === '.' || file.basename === 'node_modules') | ||
) { | ||
return SKIP | ||
} | ||
} | ||
} | ||
/** | ||
* Check multiple tests. | ||
* | ||
* @param {Array<Assert | string>} test | ||
* @returns {Assert} | ||
*/ | ||
function multiple(test) { | ||
/** @type {Array<Assert>} */ | ||
const tests = [] | ||
let index = -1 | ||
while (++index < test.length) { | ||
tests[index] = convert(test[index]) | ||
} | ||
return check | ||
/** @type {Assert} */ | ||
function check(file, stats) { | ||
let index = -1 | ||
while (++index < tests.length) { | ||
const result = tests[index](file, stats) | ||
if (result) { | ||
return result | ||
} | ||
} | ||
return false | ||
} | ||
} | ||
/** | ||
* @param {Array<VFile>} files | ||
* @returns {VFile | null} | ||
*/ | ||
function one(files) { | ||
return files[0] || null | ||
} |
{ | ||
"name": "vfile-find-down", | ||
"version": "6.1.0", | ||
"version": "7.0.0", | ||
"description": "vfile utility to find one or more files by searching the file system downwards", | ||
@@ -30,4 +30,3 @@ "license": "MIT", | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"exports": "./index.js", | ||
"files": [ | ||
@@ -39,8 +38,7 @@ "lib/", | ||
"dependencies": { | ||
"to-vfile": "^7.0.0", | ||
"vfile": "^5.0.0" | ||
"vfile": "^6.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.0.0", | ||
"c8": "^7.0.0", | ||
"@types/node": "^20.0.0", | ||
"c8": "^8.0.0", | ||
"prettier": "^2.0.0", | ||
@@ -50,4 +48,4 @@ "remark-cli": "^11.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.53.0" | ||
"typescript": "^5.0.0", | ||
"xo": "^0.54.0" | ||
}, | ||
@@ -59,22 +57,16 @@ "scripts": { | ||
"test-api": "node --conditions development test/index.js", | ||
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", | ||
"test-coverage": "c8 --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" | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "none", | ||
"useTabs": false | ||
}, | ||
"xo": { | ||
"prettier": true, | ||
"rules": { | ||
"no-bitwise": "off" | ||
} | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-wooorm" | ||
"remark-preset-wooorm" | ||
] | ||
@@ -85,4 +77,8 @@ }, | ||
"detail": true, | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"xo": { | ||
"prettier": true | ||
} | ||
} |
136
readme.md
@@ -20,9 +20,7 @@ # vfile-find-down | ||
* [`findDown(test[, paths][, callback])`](#finddowntest-paths-callback) | ||
* [`findDownOne(test[, paths][, callback])`](#finddownonetest-paths-callback) | ||
* [`BREAK`](#break) | ||
* [`INCLUDE`](#include) | ||
* [`SKIP`](#skip) | ||
* [`findDownAll(test[, paths][, callback])`](#finddownalltest-paths-callback) | ||
* [`Assert`](#assert) | ||
* [`Callback`](#callback) | ||
* [`CallbackOne`](#callbackone) | ||
* [`CallbackAll`](#callbackall) | ||
* [`Result`](#result) | ||
* [`Test`](#test) | ||
@@ -48,3 +46,3 @@ * [Types](#types) | ||
This package is [ESM only][esm]. | ||
In Node.js (version 14.14+ and 16.0+), install with [npm][]: | ||
In Node.js (version 16), install with [npm][]: | ||
@@ -66,7 +64,8 @@ ```sh | ||
```js | ||
[ VFile { | ||
VFile { | ||
cwd: '/Users/tilde/Projects/oss/vfile-find-down', | ||
data: {}, | ||
messages: [], | ||
history: [ '/Users/tilde/projects/oss/vfile-find-down/readme.md' ], | ||
cwd: '/Users/tilde/projects/oss/vfile-find-down' } ] | ||
history: [ '/Users/tilde/Projects/oss/vfile-find-down/readme.md' ], | ||
messages: [] | ||
} | ||
``` | ||
@@ -77,7 +76,4 @@ | ||
This package exports the identifiers | ||
[`BREAK`][api-break], | ||
[`INCLUDE`][api-include], | ||
[`SKIP`][api-skip], | ||
[`findDown`][api-find-down], and | ||
[`findDownOne`][api-find-down-one]. | ||
[`findDown`][api-find-down] and | ||
[`findDownAll`][api-find-down-all]. | ||
There is no default export. | ||
@@ -87,10 +83,11 @@ | ||
Find files or folders downwards. | ||
Find the first file or folder downwards. | ||
> 👉 **Note**: files are not read (their `value` is not populated). | ||
> use [`to-vfile`][to-vfile] for that. | ||
###### Signatures | ||
* `(test[, paths], callback) => void` | ||
* `(test[, paths]) => Promise<Array<VFile>>` | ||
* `(test[, paths], callback) => undefined` | ||
* `(test[, paths]) => Promise<VFile>` | ||
@@ -101,3 +98,3 @@ ###### Parameters | ||
— things to search for | ||
* `paths` (`Array<string> | string`, default: `process.cwd()`) | ||
* `paths` (`Array<string>` or `string`, default: `process.cwd()`) | ||
— places to search from | ||
@@ -109,15 +106,16 @@ * `callback` ([`Callback`][api-callback], optional) | ||
Nothing when `callback` is given (`void`), otherwise a promise that resolves to | ||
files ([`Array<VFile>`][vfile]). | ||
Nothing when `callback` is given (`undefined`), otherwise a promise that | ||
resolves to a file ([`VFile`][vfile] or `undefined`). | ||
### `findDownOne(test[, paths][, callback])` | ||
### `findDownAll(test[, paths][, callback])` | ||
Find the first file or folder downwards. | ||
Find files or folders downwards. | ||
> 👉 **Note**: files are not read (their `value` is not populated). | ||
> use [`to-vfile`][to-vfile] for that. | ||
###### Signatures | ||
* `(test[, paths], callback) => void` | ||
* `(test[, paths]) => Promise<VFile>` | ||
* `(test[, paths], callback) => undefined` | ||
* `(test[, paths]) => Promise<Array<VFile>>` | ||
@@ -128,5 +126,5 @@ ###### Parameters | ||
— things to search for | ||
* `paths` (`Array<string> | string`, default: `process.cwd()`) | ||
* `paths` (`Array<string>` or `string`, default: `process.cwd()`) | ||
— places to search from | ||
* `callback` ([`CallbackOne`][api-callback-one], optional) | ||
* `callback` ([`CallbackAll`][api-callback-all], optional) | ||
— callback called when done | ||
@@ -136,17 +134,5 @@ | ||
Nothing when `callback` is given (`void`), otherwise a promise that resolves to | ||
a file ([`VFile | null`][vfile]). | ||
Nothing when `callback` is given (`undefined`), otherwise a promise that | ||
resolves to files ([`Array<VFile>`][vfile]). | ||
### `BREAK` | ||
Stop searching (`number`). | ||
### `INCLUDE` | ||
Include this file (`number`). | ||
### `SKIP` | ||
Skip this folder (`number`). | ||
### `Assert` | ||
@@ -165,39 +151,47 @@ | ||
How to handle this file (`boolean | number`, optional). | ||
How to handle this file ([`Result`][api-result], optional). | ||
Booleans are treated as `INCLUDE` (when `true`) or `SKIP` (when `false`). | ||
No result is treated as `SKIP`. | ||
The different flags can be combined by using the pipe operator: | ||
`INCLUDE | SKIP`. | ||
### `Callback` | ||
Callback called when done (TypeScript type). | ||
Callback called when done finding one file (TypeScript type). | ||
###### Parameters | ||
* `error` (`Error | null`) | ||
* `error` (`Error` or `undefined`) | ||
— error; errors are currently never passed | ||
* `files` ([`Array<VFile>`][vfile]) | ||
— files | ||
* `file` ([`VFile`][vfile] or `undefined`) | ||
— file | ||
###### Returns | ||
Nothing (`void`). | ||
Nothing (`undefined`). | ||
### `CallbackOne` | ||
### `CallbackAll` | ||
Callback called when done finding one file (TypeScript type). | ||
Callback called when done (TypeScript type). | ||
###### Parameters | ||
* `error` (`Error | null`) | ||
* `error` (`Error` or `undefined`) | ||
— error; errors are currently never passed | ||
* `file` ([`VFile | null`][vfile]) | ||
— file | ||
* `files` ([`Array<VFile>`][vfile]) | ||
— files | ||
###### Returns | ||
Nothing (`void`). | ||
Nothing (`undefined`). | ||
### `Result` | ||
What to do when collecting a file or folder (TypeScript type). | ||
###### Fields | ||
* `break` (`boolean`, default: `false`) | ||
— stop searching after this file or folder | ||
* `include` (`boolean`, default: `false`) | ||
— include this file or folder | ||
* `skip` (`boolean`, default: `false`) | ||
— do not search inside this folder | ||
### `Test` | ||
@@ -223,3 +217,4 @@ | ||
[`Callback`][api-callback], | ||
[`CallbackOne`][api-callback-one], and | ||
[`CallbackAll`][api-callback-all], | ||
[`Result`][api-result], and | ||
[`Test`][api-test]. | ||
@@ -229,7 +224,10 @@ | ||
Projects maintained by the unified collective are compatible with all maintained | ||
Projects maintained by the unified collective are compatible with 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. | ||
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, `vfile-find-down@^7`, | ||
compatible with Node.js 16. | ||
## Contribute | ||
@@ -293,2 +291,4 @@ | ||
[to-vfile]: https://github.com/vfile/to-vfile | ||
[vfile-find-up]: https://github.com/vfile/vfile-find-up | ||
@@ -298,12 +298,6 @@ | ||
[api-break]: #break | ||
[api-find-down-all]: #finddownalltest-paths-callback | ||
[api-include]: #include | ||
[api-skip]: #skip | ||
[api-find-down]: #finddowntest-paths-callback | ||
[api-find-down-one]: #finddownonetest-paths-callback | ||
[api-assert]: #assert | ||
@@ -313,4 +307,6 @@ | ||
[api-callback-one]: #callbackone | ||
[api-callback-all]: #callbackall | ||
[api-result]: #result | ||
[api-test]: #test |
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
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
22726
1
486
298
+ Added@types/unist@3.0.2(transitive)
+ Addedunist-util-stringify-position@4.0.0(transitive)
+ Addedvfile@6.0.1(transitive)
+ Addedvfile-message@4.0.2(transitive)
- Removedto-vfile@^7.0.0
- Removed@types/unist@2.0.10(transitive)
- Removedis-buffer@2.0.5(transitive)
- Removedto-vfile@7.2.4(transitive)
- Removedunist-util-stringify-position@3.0.3(transitive)
- Removedvfile@5.3.7(transitive)
- Removedvfile-message@3.1.4(transitive)
Updatedvfile@^6.0.0