Skip to main content

Read/Write

Helper functions for reading and writing to text files.

Functions

appendFile()

function appendFile(filePath, data): void

Helper function to synchronously append data to a file.

This will throw an error if the file cannot be appended to.

Parameters

ParameterType
filePathstring
datastring

Returns

void

Defined in

packages/complete-node/src/functions/readWrite.ts:15


deleteLineInFile()

function deleteLineInFile(filePath, lineNumber): void

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".

This will print an error message and exit the program if the file cannot be read.

Parameters

ParameterType
filePathstring
lineNumbernumber

Returns

void

Defined in

packages/complete-node/src/functions/readWrite.ts:30


prependFile()

function prependFile(filePath, data): void

Helper function to synchronously prepend data to a file.

This will throw an error if the file cannot be prepended to.

Parameters

ParameterType
filePathstring
datastring

Returns

void

Defined in

packages/complete-node/src/functions/readWrite.ts:51


readFile()

function readFile(filePath): string

Helper function to synchronously read a file.

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

This will throw an error if the file cannot be read.

Parameters

ParameterType
filePathstring

Returns

string

Defined in

packages/complete-node/src/functions/readWrite.ts:64


readFileAsync()

function readFileAsync(filePath): Promise<string>

Helper function to asynchronously read a file.

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

This will throw an error if the file cannot be read.

Parameters

ParameterType
filePathstring

Returns

Promise<string>

Defined in

packages/complete-node/src/functions/readWrite.ts:83


replaceLineInFile()

function replaceLineInFile(
filePath,
lineNumber,
newLine): void

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".

This will print an error message and exit the program if the file cannot be read.

Parameters

ParameterType
filePathstring
lineNumbernumber
newLinestring

Returns

void

Defined in

packages/complete-node/src/functions/readWrite.ts:102


replaceTextInFile()

function replaceTextInFile(
filePath,
searchValue,
replaceValue): void

Helper function to synchronously replace text in a file.

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

This will print an error message and exit the program if the file cannot be read.

Parameters

ParameterType
filePathstring
searchValuestring | RegExp
replaceValuestring

Returns

void

Defined in

packages/complete-node/src/functions/readWrite.ts:129


writeFile()

function writeFile(filePath, data): void

Helper function to synchronously write data to a file.

This will throw an error if the file cannot be written to.

Parameters

ParameterType
filePathstring
datastring

Returns

void

Defined in

packages/complete-node/src/functions/readWrite.ts:144


writeFileAsync()

function writeFileAsync(filePath, data): Promise<void>

Helper function to asynchronously write data to a file.

This will throw an error if the file cannot be written to.

Parameters

ParameterType
filePathstring
datastring

Returns

Promise<void>

Defined in

packages/complete-node/src/functions/readWrite.ts:157