@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
60 lines (59 loc) • 2.57 kB
TypeScript
import type { RParseRequestFromFile } from '../r-bridge/retriever';
/**
* Represents a table, identified by a header and a list of rows.
*/
export interface Table {
header: string[];
rows: string[][];
}
/**
* Retrieves all files in the given directory recursively
* @param dir - Directory path to start the search from
* @param suffix - Suffix of the files to be retrieved
* Based on {@link https://stackoverflow.com/a/45130990}
*/
export declare function getAllFiles(dir: string, suffix?: RegExp): AsyncGenerator<string>;
/**
* Retrieves all R files in a given directory (asynchronously)
*
*
* @param input - directory-path to start the search from, can be a file as well. Will just return the file then.
* @param limit - limit the number of files to be retrieved
*
* @returns Number of files processed (normally ≤ `limit`, is ≥ `limit` if limit was reached).
* Will be `1`, if `input` is an R file (and `0` if it isn't).
*
* @see getAllFiles
*/
export declare function allRFiles(input: string, limit?: number): AsyncGenerator<RParseRequestFromFile, number>;
/**
* Retrieves all R files in a given set of directories and files (asynchronously)
*
* @param inputs - Files or directories to validate for R-files
* @param limit - Limit the number of files to be retrieved
* @returns Number of files processed (≤ limit)
*
* @see allRFiles
*/
export declare function allRFilesFrom(inputs: string[], limit?: number): AsyncGenerator<RParseRequestFromFile, number>;
export declare function writeTableAsCsv(table: Table, file: string, sep?: string, newline?: string): void;
/**
* Reads a file line by line and calls the given function for each line.
* The `lineNumber` starts at `0`.
*
* See {@link readLineByLineSync} for a synchronous version.
*/
export declare function readLineByLine(filePath: string, onLine: (line: Buffer, lineNumber: number) => Promise<void>): Promise<void>;
/**
* Reads a file line by line and calls the given function for each line.
* The `lineNumber` starts at `0`.
*
* See {@link readLineByLine} for an asynchronous version.
*/
export declare function readLineByLineSync(filePath: string, onLine: (line: Buffer, lineNumber: number) => void): void;
/**
* Chops off the last part of the given directory path after a path separator, essentially returning the path's parent directory.
* If an absolute path is passed, the returned path is also absolute.
* @param directory - The directory whose parent to return
*/
export declare function getParentDirectory(directory: string): string;