UNPKG

fs-utils-sync

Version:

The fs-utils-sync package provides a collection of well-tested, synchronous file system utility functions. It promotes consistency and readability across projects by providing a unified approach to common file operations, saving you development time and i

60 lines (59 loc) 1.91 kB
import { ISortDirection } from 'web-utils-kit'; /** * Path Element * The most relevant information regarding a path element, extracted by making use of the lstat * function. */ type IPathElement = { path: string; baseName: string; extName: string; isFile: boolean; isDirectory: boolean; isSymbolicLink: boolean; size: number; creation: number; }; /** * Read Directory Options * The options that can be provided to the readdirSync function to determine the output's format. */ type IReadDirectoryOptions = { encoding: BufferEncoding | null; withFileTypes?: false | undefined; recursive?: boolean | undefined; } | BufferEncoding | null; /** * Directory Elements Options * When querying the path elements from within a directory, a series of filters and sorting options * can be provided. */ type IDirectoryElementsKeySort = 'baseName' | 'size' | 'creation'; type IDirectoryElementsOptions = { sortByKey: IDirectoryElementsKeySort; sortOrder: ISortDirection; includeExts: string[]; }; /** * Directory Path Elements * The output emitted when retrieving all the path elements within a directory. */ type IDirectoryPathElements = { directories: IPathElement[]; files: IPathElement[]; symbolicLinks: IPathElement[]; }; /** * Read File Options * The options that can be provided to the readFileSync function to determine the output's format. */ type IReadStringFileOptions = { encoding: BufferEncoding; flag?: string | undefined; } | BufferEncoding; type IReadBufferFileOptions = { encoding?: null | undefined; flag?: string | undefined; } | null; type IReadFileOptions = IReadBufferFileOptions | IReadStringFileOptions; export type { IPathElement, IReadDirectoryOptions, IDirectoryElementsKeySort, IDirectoryElementsOptions, IDirectoryPathElements, IReadBufferFileOptions, IReadStringFileOptions, IReadFileOptions, };