The name or path of the JSON file to parse.
An optional string representing the directory path from which the JSON file should be loaded. If provided, it will be used as the base directory path. If not provided, the current directory will be used as the base directory path.
Promise The parsed JSON content.
Reading a configuration file:
import JSONInterface from "./Interface/JSON.js";const readConfig: JSONInterface = async (File, From) => { const content = await JSON.parse(await readFile(`${From ?? "."}/${File}`, "utf-8")); return content;}; Copy
import JSONInterface from "./Interface/JSON.js";const readConfig: JSONInterface = async (File, From) => { const content = await JSON.parse(await readFile(`${From ?? "."}/${File}`, "utf-8")); return content;};
Reading from current directory:
const config = await readConfig("package.json"); Copy
const config = await readConfig("package.json");
Reading from specific directory:
const config = await readConfig("tsconfig.json", "./Source"); Copy
const config = await readConfig("tsconfig.json", "./Source");
The function 'JSON' is a TypeScript function that reads a JSON file and returns its parsed content.
Param: File
The name or path of the JSON file to parse.
Param: From
An optional string representing the directory path from which the JSON file should be loaded. If provided, it will be used as the base directory path. If not provided, the current directory will be used as the base directory path.
Returns
Promise The parsed JSON content.
Example
Reading a configuration file:
Example
Reading from current directory:
Example
Reading from specific directory: