Skip to main content

Read/Write

Helper functions for reading and writing to text files.

Functions

appendFile()

function appendFile(filePath, data): void

Defined in: packages/complete-node/src/functions/readWrite.ts:16

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

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

Parameters

ParameterType
filePathstring
datastring

Returns

void


appendFileAsync()

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

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

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

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

Parameters

ParameterType
filePathstring
datastring

Returns

Promise<void>


deleteLineInFile()

function deleteLineInFile(filePath, lineNumber): void

Defined in: packages/complete-node/src/functions/readWrite.ts:48

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


prependFile()

function prependFile(filePath, data): void

Defined in: packages/complete-node/src/functions/readWrite.ts:69

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


readFile()

function readFile(filePath): string

Defined in: packages/complete-node/src/functions/readWrite.ts:82

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


readFileAsync()

function readFileAsync(filePath): Promise<string>

Defined in: packages/complete-node/src/functions/readWrite.ts:101

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>


replaceLineInFile()

function replaceLineInFile(
filePath,
lineNumber,
newLine): void

Defined in: packages/complete-node/src/functions/readWrite.ts:120

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


replaceTextInFile()

function replaceTextInFile(
filePath,
searchValue,
replaceValue): void

Defined in: packages/complete-node/src/functions/readWrite.ts:147

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


writeFile()

function writeFile(filePath, data): void

Defined in: packages/complete-node/src/functions/readWrite.ts:162

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


writeFileAsync()

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

Defined in: packages/complete-node/src/functions/readWrite.ts:175

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>