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