Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Loader

Required by system to perform file initialization.

Hierarchy

Index

Constructors

constructor

  • new Loader(rootDir: string | null, arg_relativeInitDir: string | null, arg_initFilename: string | null, callback: ConstructorCallback | null): Loader
  • throws

    LoaderError Will throw unexpected_constructor

    Parameters

    • rootDir: string | null

      Absolute root directory.

    • arg_relativeInitDir: string | null
    • arg_initFilename: string | null
    • callback: ConstructorCallback | null

      Callback to call with Promise of completion.

    Returns Loader

Methods

Static getFile

  • getFile(rootDir: string, relativeDir: string, file: string): Promise<Buffer>
  • Gets file contents.

    Usage

    // Load files
    var grapefruitJuicer = Loader.getFile("c:\machines", "appliances", "grapefruitJuicer.txt");
    
    // Output the result
    grapefruitJuicer.then(function(result){ // grapefruitJuicer - on resolve
      console.log(result);
    }, function(error){ // grapefruitJuicer - on reject
      console.error("Could not load a file.");
    });
    
    // Input - grapefruitJuicer.txt
    // 1000W powerful juicer
    
    // Output
    // 1000W powerful juicer

    Parameters

    • rootDir: string

      Absolute root directory.

    • relativeDir: string

      Directory relative to root.

    • file: string

      Full file name.

    Returns Promise<Buffer>

    File contents.

Static isDir

  • isDir(rootDir: string, relativeDir: string): Promise<boolean>
  • Checks if is a directory.

    Usage

    // Verify directory
    Loader.isDir("c:\machines\appliances","grapefruitJuicer.txt").then(function(result){
      console.log(result);
    });
    
    // Input - grapefruitJuicer.txt
    // 1000W powerful juicer
    
    // Output
    // false

    Parameters

    • rootDir: string

      Absolute root directory.

    • relativeDir: string

      Relative directory to root.

    Returns Promise<boolean>

    Returns true if a directory, false if not.

Static isFile

  • isFile(rawPath: string): Promise<boolean>
  • Checks if is a file

    Usage

    // Verify file
    Loader.isFile("c:\machines\appliances\grapefruitJuicer.txt").then(function(result){
      console.log(result);
    });
    
    // Input - grapefruitJuicer.txt
    // 1000W powerful juicer
    
    // Output
    // true

    Parameters

    • rawPath: string

      Full filepath.

    Returns Promise<boolean>

    Returns true if a file, false if not.

Static join

  • join(...pathArrays: Array<string | Array<string>>): string | Array<string>
  • Join a root directory with a file/folder or an array of files/folders to absolute path.

    Usage

    // Join and log result
    console.log(Loader.join("c:\machines", "appliances"))
    
    // Output
    // c:\machines\appliances

    Parameters

    • Rest ...pathArrays: Array<string | Array<string>>

      File/folder name|names.

    Returns string | Array<string>

    Absolute path|paths.

Static list

  • list(rootDir: string, relativeDir: string): Promise<Array<string>>
  • Returns an array of strings, representing the contents of a folder.

    Usage

    // List directory contents
    Loader.list("c:","machines").then(function(result){
      console.log(result);
    }, function(error){
      console.error("Folder not found.");
    });
    
    // Output
    // ["machines", "appliances"]

    Parameters

    • rootDir: string

      Root directory.

    • relativeDir: string

      Relative directory.

    Returns Promise<Array<string>>

    Array with contents; Rejects with errors from fs.readdir.

Static toRelative

  • toRelative(dir: string, target: string | Array<string>): string | Array<string>
  • Extracts relative path from rootDir to target.

    Usage

    // Convert path and output the result
    console.log(Loader.toRelative("c:\machines\refrigerators", "c:\machines\appliances"));
    
    // Output
    // ..\appliances

    Parameters

    • dir: string

      Source folder.

    • target: string | Array<string>

      File/folder name|names.

    Returns string | Array<string>

    Relative path|paths.

Static yamlToObject

  • yamlToObject(string: string): any
  • Converts YAML string to a JS object.

    Usage

    // Ouput conversion of YAML to JSON
    console.log(Loader.yamlToObject("Wine: Red"));
    
    // Output
    // {"Wine": "Red"}

    Parameters

    • string: string

      YAML string.

    Returns any

    Javascript object.

Generated using TypeDoc