Skip to main content

Read/Write

Helper functions for reading and writing to text files.

Functions

appendFile()

function appendFile(filePath, data): Promise<void>;

Defined in: functions/readWrite.ts:15

Helper function to asynchronously append data to a file. If the file does not exist, it will be automatically created.

Parameters

ParameterType
filePathstring
datastring

Returns

Promise<void>

Throws

If the file cannot be appended to.


deleteLineInFile()

function deleteLineInFile(filePath, lineNumber): Promise<void>;

Defined in: functions/readWrite.ts:35

Helper function to delete a specific line in a text file.

This assumes that the file is a text file and uses an encoding of "utf8".

Parameters

ParameterType
filePathstring
lineNumbernumber

Returns

Promise<void>

Throws

If the line number does not exist in the text file or the file cannot be written to.


prependFile()

function prependFile(filePath, data): Promise<void>;

Defined in: functions/readWrite.ts:59

Helper function to synchronously prepend data to a file.

Parameters

ParameterType
filePathstring
datastring

Returns

Promise<void>

Throws

IF the file cannot be written to.


readFile()

function readFile(filePath): Promise<string>;

Defined in: functions/readWrite.ts:73

Helper function to asynchronously read a file.

This assumes that the file is a text file and uses an encoding of "utf8".

Parameters

ParameterType
filePathstring

Returns

Promise<string>


replaceLineInFile()

function replaceLineInFile(
filePath,
lineNumber,
newLine): Promise<void>;

Defined in: functions/readWrite.ts:90

Helper function to replace a specific line in a text file.

This assumes that the file is a text file and uses an encoding of "utf8".

Parameters

ParameterType
filePathstring
lineNumbernumber
newLinestring

Returns

Promise<void>

Throws

If the line number does not exist in the text file or the file cannot be written to.


replaceTextInFile()

function replaceTextInFile(
filePath,
searchValue,
replaceValue): Promise<void>;

Defined in: functions/readWrite.ts:117

Helper function to asynchronously replace text in a file.

This assumes that the file is a text file and uses an encoding of "utf8".

Parameters

ParameterType
filePathstring
searchValuestring | RegExp
replaceValuestring

Returns

Promise<void>

Throws

If the file cannot be written to.


writeFile()

function writeFile(filePath, data): Promise<void>;

Defined in: functions/readWrite.ts:132

Helper function to asynchronously write data to a file.

Parameters

ParameterType
filePathstring
datastring

Returns

Promise<void>

Throws

If the file cannot be written to.