Skip to main content

fs

Library of helper functions for handling files and folders.

ensureDir()​

function ensureDir(location, options?): Promise<void>

Asynchronously create a folder structure if it does not exist.

Parameters​

location​

string

folder structure in path format.

options?​

EnsureDirOptions

Returns​

Promise<void>

Example​

import { ensureDir } from '@graphql-markdown/utils/fs';

await ensureDir("./.temp/local")

// Creates both folders if they do not exists.

Defined in​

fs.ts:60


fileExists()​

function fileExists(location): Promise<boolean>

Asynchronously check if a file or folder exists at the path location.

Parameters​

location​

string

file or folder location.

Returns​

Promise<boolean>

true if the path is valid, else false if not.

Example​

import { fileExists } from '@graphql-markdown/utils/fs';

await fileExists("./.temp/local")

// Expected true if path is valid, false if not

Defined in​

fs.ts:35


saveFile()​

function saveFile(
location,
content,
prettify?): Promise<void>

Asynchronously save a file with a string content at specified location in local FS. Override the file content if the file already exists. The function calls ensureDir(dirname(location)) to create the folder structure if missing.

Parameters​

location​

string

file location.

content​

string

data to be written into the file (UTF-8 string).

prettify?​

PrettifyCallbackFunction

optional callback function for prettifying the content.

Returns​

Promise<void>

true if the path is valid, else false if not.

Example​

import { saveFile } from '@graphql-markdown/utils/fs';

await saveFile("./.temp/local.md", "foobar")

// Created .temp folder if it does not exists, and save data into local.md

Defined in​

fs.ts:97