@alttiri/util-node-js
Advanced tools
Comparing version
{ | ||
"name": "@alttiri/util-node-js", | ||
"version": "2.0.8", | ||
"version": "2.0.9", | ||
"description": "Some Node.js util functions for personal use", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -10,3 +10,62 @@ import { FileListingSetting, FileListingSettingInit } from "./settings.js"; | ||
}): AsyncGenerator<ListEntryStatsBigInt>; | ||
/** | ||
Returns an object: | ||
```ts | ||
{ | ||
path: string, | ||
dirent: Dirent, | ||
stats?: Stats | BigIntStats, | ||
link?: LinkInfo, | ||
errors?: { | ||
[name in "readdir" | "stats" | "readlink"]?: IOError | ||
}, | ||
} | ||
``` | ||
The return object's keys info: | ||
``` | ||
- path — `string`. | ||
The full path with the filename. | ||
- dirent — `Dirent`. | ||
A `Dirent` from `fs.readdir`. | ||
For the root folder a "fake" `Dirent` is used: | ||
- "DirentLike" — created based on `Stats` | ||
- "DirentDummy" — if there were errors (`errors: {stats, readdir}`) | ||
- stats? — `Stats | BigIntStats`. | ||
Optional, exists only when the scan option `stats` is `true`. | ||
Type depends on `bigint` option. | ||
Is missed if there is `errors.stats` error. | ||
- link? — `LinkInfo`. | ||
Optional, exists only for symlinks. | ||
`LinkInfo` is an alias for `{ | ||
pathTo: string, | ||
content: string, | ||
}`. | ||
Is missed if there is `errors.readlink` error. | ||
- errors? — an `object` with `IOError`s. | ||
Optional, exists only one or more errors occurred. | ||
Possible errors: | ||
- "readdir" | ||
- "stats" | ||
- "readlink" | ||
``` | ||
@note `listFiles` does not follow symlinks. | ||
@options | ||
```js | ||
- filepath: string = process.cwd(), // filepath of a (root) directory to list | ||
- recursively: boolean = true, | ||
- yieldDir: boolean = false, | ||
- yieldRoot: boolean = true, // (is used only if `yieldDir` is `true`) | ||
- depthFirst: boolean = true, // travel strategy | ||
- breadthFirstRoot: boolean = false, // breadth first strategy for the root folder (if `depthFirst` is `true`) | ||
- stats: boolean = true, | ||
- bigint: boolean = false, // (use only if `stats` is `true`) | ||
- parallels: number = 4, // count of `fs.stats` executed in parallel | ||
``` | ||
*/ | ||
export declare function listFiles(initSettings: FileListingSettingInit): AsyncGenerator<ListEntryStats>; | ||
export declare function _listFilesWithStat(settings: FileListingSetting, listEntries: ListEntryDirent): AsyncGenerator<ListEntryStatsAny>; |
@@ -5,3 +5,2 @@ import fs from "node:fs/promises"; | ||
import { getDefaultSettings } from "./settings.js"; | ||
/** Not follows symlinks. */ | ||
export async function* listFiles(initSettings = {}) { | ||
@@ -8,0 +7,0 @@ const settings = Object.assign({ ...getDefaultSettings() }, initSettings); |
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
/** | ||
* The simplified type example | ||
* The simplified type example: | ||
* @example | ||
@@ -11,6 +11,6 @@ * type ListEntrySimplifiedFullType = { | ||
* dirent: Dirent, | ||
* stats?: Stats, | ||
* link?: LinkInfo | ||
* stats?: Stats | BigIntStats, | ||
* link?: LinkInfo, | ||
* errors?: { | ||
* [name in "readdir" | "stats" | "readlink"]?: IOErrorType | ||
* [name in "readdir" | "stats" | "readlink"]?: IOError | ||
* }, | ||
@@ -17,0 +17,0 @@ * }; |
32945
5.65%869
6.5%