Skip to content

Latest commit

 

History

History
177 lines (121 loc) · 5.97 KB

fileutils.js.md

File metadata and controls

177 lines (121 loc) · 5.97 KB

file

Functions for local file I/O. All functions are synchronous.

readFile(fileName) ⇒ string | buffer

Reads a local file and returns the contents.

Kind: Exported function
Returns: string | buffer - - File contents, will be converted to a string if possible

Param Type Description
fileName string Path to local file

writeFile(fileName, fileContent) ⏏

Writes buffer or string content to a local file.

Kind: Exported function

Param Type Description
fileName string Path to local file
fileContent string | buffer Content to write

isFile(fileName) ⇒ boolean

Check if a local file exists.

Kind: Exported function
Returns: boolean - True if the file exists

Param Type Description
fileName string Path to local file

isFolder(folderName) ⇒ boolean

Check if the given path is a folder.

Kind: Exported function
Returns: boolean - True if the give path exists and is a folder

Param Type Description
folderName string Path to local folder

makeFolder(folderName) ⇒ boolean

Create a new folder at the given path.

Kind: Exported function
Returns: boolean - True if the folder was successfully created

Param Type Description
folderName string Path to local folder

listFolders(folderName) ⇒ array

Return a list of folders at the given path. Does not include hidden folders.

Kind: Exported function
Returns: array - A list of folder names

Param Type Description
folderName string Path to local folder

listFiles(folderName) ⇒ array

Return a list of files at the given path. Does not include hidden files.

Kind: Exported function
Returns: array - A list of files names

Param Type Description
folderName string Path to local folder

deleteFolder(folderName) ⇒ boolean

Delete the folder at the given path.

Kind: Exported function
Returns: boolean - Returns true if the folder was successfully deleted

Param Type Description
folderName string Path to local folder

deleteFile(fileName) ⇒ boolean

Deletes the local file.

Kind: Exported function
Returns: boolean - True if the file exists and was deleted.

Param Type Description
fileName string Path to local file

readJSON(fileName) ⇒ object

Reads the local JSON file and returns its object representation.

Kind: Exported function
Returns: object - Contents of the local file parsed as an object

Param Type Description
fileName string Path to local file

writeJSON(fileName, fileContent) ⏏

Writes a serializable object as JSON to a local file.

Kind: Exported function

Param Type Description
fileName string Path to local file
fileContent object Content to write as JSON

updateJSON(fileName, updateObject) ⏏

Given an object, reads a local JSON file and merges the object with file contents, writing back the merged object as JSON.

Kind: Exported function

Param Type Description
fileName string Path to local file
updateObject object A serializable object to be merged with the JSON file

checkCommand(commandString) ⇒ boolean

Checks whether the command exists, i.e. can be run with an exec() statement.

Kind: Exported function
Returns: boolean - True if the command exists

Param Type Description
commandString string A shell comment to be tested