UNPKG

@freeword/meta

Version:

Meta package for Freeword: exports all core types, constants, and utilities from the src/ directory.

71 lines 4.67 kB
import readline from 'node:readline'; import { Readable } from 'node:stream'; import type * as TY from '../types/index.ts'; import type * as FT from '../types/FilerTypes.ts'; /** * Creates directory recursively * @param anypath - The pathname or pathinfo of the directory to create -- the `abspath` is used and NOT the `dirpath` * @returns a GoodFilerMkdirResult or a BadFilerMkdirResult */ export declare function mkdirp(anypath: FT.Anypath): Promise<FT.FilerMkdirResult>; /** * Given a pathinfo object, assemble the absolute path */ export declare function _abspathForPathparts(pathinfo: Pick<FT.PathinfoT, 'dirpath' | 'barename' | 'fext'>, ...pathsegs: TY.StringMaybe[]): FT.Abspath; /** * Converts a plain pathname to an absolute path */ export declare function _abspathForPathname(pathname: FT.Pathname, ...pathsegs: TY.StringMaybe[]): FT.Abspath; /** Assemble pathinfo using a (possibly relative) dirpath, a barename and a file extension * @param pathinfo - The pathinfo dna to assemble * dirpath - The directory path (relative or absolute) * barename - The base name of the file (without extension) * fext - The file extension (including the dot) * @param pathsegs - Additional path segments to append to the pathname * @returns A complete pathinfo object, with abspath and dirpath resolved */ export declare function pathinfoFor(anypath: FT.Anypath, ...pathsegs: TY.StringMaybe[]): FT.PathinfoT & { ok: true; basename: TY.Basename; } | FT.BadFilerResult<'badPath' | 'badInput' | 'blankPath'>; export declare function dirpathFor(anypath: FT.Anypath, ...pathsegs: TY.StringMaybe[]): FT.Abspath; export declare function abspathFor(anypath: FT.Anypath, ...pathsegs: TY.StringMaybe[]): FT.Abspath; export declare function barenameFor(anypath: FT.Anypath, ...pathsegs: TY.StringMaybe[]): FT.Barename; export declare function fextFor(anypath: FT.Anypath, ...pathsegs: TY.StringMaybe[]): FT.Fext; export declare function __dirname(importMetaURL: TY.URLStr, ...relpaths: (TY.Relpath | undefined)[]): FT.Abspath; export declare function __relname(importMetaURL: TY.URLStr, ...relpaths: (TY.Relpath | undefined)[]): FT.Abspath; /** * Async generator that reads a file and yields each line * Returns AsyncGenerator<string, FilerReadResult, unknown> */ export declare function starlinesFiddly(anypath: FT.Anypath): AsyncGenerator<string, FT.FilerReadResult<FT.PathinfoT, FT.CoreReadGist>, unknown>; /** Opens a raw filestream with the (decompressed) file contents * @param anypath - The pathname or pathinfo of the file to open. If it ends in `.gz` or `.bz2` it will be decompressed * @returns A Readable stream or a BadFilerResult */ export declare function openFilestream(anypath: FT.Anypath): FT.FilerReadResult<Readable, FT.CoreReadGist>; export declare function openLinestream(anypath: FT.Anypath): FT.FilerReadResult<readline.Interface, FT.CoreReadGist>; /** Loads the contents of a file, returning either { ok: true, val: stringContentsOfThatFile, ...pathinfo }, or a BadFilerResult * Like the other filer methods, it never throws: consult result.ok for a tagged union */ export declare function loadtext(anypath: FT.Anypath): Promise<FT.FilerReadResult<string, FT.CoreReadGist>>; /** * Async generator that reads a file and yields each line * Returns AsyncGenerator<string, FilerReadResult, unknown> */ export declare function starlines(anypath: FT.Anypath): AsyncGenerator<string, FT.FilerReadResult<number, FT.CoreReadGist>, unknown>; export declare function starjsonEntries<VT, KT extends string | number = number>(anypath: FT.Anypath): AsyncGenerator<[KT, VT, number], FT.FilerReadResult<number, FT.CoreReadGist | 'consumeErr'>, unknown>; export declare function starjsonl<VT>(anypath: FT.Anypath): AsyncGenerator<VT, void, unknown>; export declare function starjsonl<VT>(anypath: FT.Anypath): AsyncGenerator<null, void, VT>; export declare function starjsonl(anypath: FT.Anypath): AsyncGenerator<any, void, unknown>; export declare function starjsonkeys<KT extends string | number = number>(anypath: FT.Anypath): AsyncGenerator<KT, void, KT>; /** * Creates directory and writes each line from an iterable/async iterable to a file * Returns FilerResult<PathinfoT> */ export declare function dumptext(anypath: FT.Anypath, lines: Iterable<string> | AsyncIterable<string>): Promise<FT.FilerWriteResult<FT.PathinfoT, 'writeErr' | 'fsErr' | 'badPath' | 'badInput' | 'blankPath'>>; /** * Pretty prints JSON and calls dumptext. Returns FilerResult<PathinfoT> */ export declare function dumpjson(anypath: FT.Anypath, data: any): Promise<FT.FilerWriteResult<FT.PathinfoT, FT.CoreWriteGist>>; //# sourceMappingURL=Filer.d.ts.map