1.0.2 • Published 3 years ago

node-read-file-helper v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

node-read-file-helper

Helper functions to read files as text, JSON, and additional formats.

Installation

npm i node-read-file-helper

Usage

const { readFileAsTextSync } = require('node-read-file-helper');
const path = require('path');

const asString = readFileAsTextSync(path.resolve('./myFile.txt'));

Table of contents

Functions

Functions

readFileAsJSON

readFileAsJSON<T>(path): Promise<T>

Reads the file as JSON content asynchronously

export

Type parameters

NameDescription
TThe JSON structure after parsing

Parameters

NameTypeDescription
pathstringThe path to the file to read

Returns

Promise<T>

Promise that will resolve to the parsed JSON

Defined in

index.ts:61


readFileAsJSONSync

readFileAsJSONSync<T>(path): T

Reads the file as JSON content

export

Type parameters

NameDescription
TThe JSON structure after parsing

Parameters

NameTypeDescription
pathstringThe path to the file to read

Returns

T

The parsed JSON

Defined in

index.ts:49


readFileAsText

readFileAsText(path): Promise<string>

Reads file as text asynchronously

export

Parameters

NameTypeDescription
pathstringThe path to the file to read

Returns

Promise<string>

The file contents

Defined in

index.ts:23


readFileAsTextSync

readFileAsTextSync(path): string

Reads a file as text

export

Parameters

NameTypeDescription
pathstringThe path to the file to read

Returns

string

The file contents as text

Defined in

index.ts:10