Skip to content

Api documentation of 1.x.x

Sahil Gulati edited this page Sep 7, 2018 · 3 revisions

NOOPath API Documentation.




1. Noopath.setPath(path)

This function will accept path as string. make sure this should be absolute path.

2. Noopath.setIgnorePaths(paths[])

This function will accept array of paths where each path should be absolute path(String). It will add paths which you want to ignore while the creation of config object. This can be either directory or file. Note: Less paths less memory space.

/** Example: Without ignoring any path. **/
{
  var: {
    www: {
      noopath: {
        src: [object],
        node_modules: [object],
        .git: [object]
      }
    }
  }
}
/* Example: When using ignore paths. */

noopath.setIgnorePaths(["/var/www/noopath/node_modules", "/var/www/noopath/.git"])
{
  var: {
    www: {
      noopath: {
        src: [object]
      }
    }
  }
}
            

3. Noopath.setIgnoreExtensions(extension[])

This function will accept array of strings where each string should contain extension. Note: It should not contain . Use extension not .extension. This function will not allow module to add extensions to keys of config object.

/** Example: When not ignoring extensions. **/
{
  var: {
    www: {
      noopath: {
        src: {
           config.json: "/var/www/noopath/src/config.json",
           deploy.yml: "/var/www/noopath/src/deploy.yml",
           build: "/var/www/noopath/src/build.js"
        }
      }
    }
  }
}
/** Example: When using ignoring extensions. **/
noopath.setIgnoreExtensions(["json","yml"])
{
  var: {
    www: {
      noopath: {
        src: {
           config: "/var/www/noopath/src/config.json",
           deploy: "/var/www/noopath/src/deploy.yml",
           build: "/var/www/noopath/src/build.js"
        }
      }
    }
  }
}

4. Noopath.getConfig()

This function will return file system in the form of an object.

/** Example: This will return you the whole object on the basis of the path you have set.**/
{
  var: {
    www: {
      noopath: {
        src: [object],
        node_modules: [object],
        .git: [object]
      }
    }
  }
}

5. Noopath.getFromConfig(string)

This function will accept object oriented string path and return Object/String of path(s) on the basis of string used as input to the function.

/** Example of config object. **/
{
  var: {
    www: {
      noopath: {
        src: {
           config: "/var/www/noopath/src/config.json",
           deploy: "/var/www/noopath/src/deploy.yml",
           build: "/var/www/noopath/src/build.js"
        }
      }
    }
  }
}
/** Getting path from string.**/

noopath.getFromString("var.www.noopath.src.config");
/** Output: /var/www/noopath/src/config.json **/

noopath.getFromString("var.www.noopath.src");
/**
 * Output:
 * {
 *    config: "/var/www/noopath/src/config.json",
 *    deploy: "/var/www/noopath/src/deploy.yml",
 *    build: "/var/www/noopath/src/build.js"
 * }
 **/

6. Noopath.load(filename)

This function will return complete filepath by digging inside complete config object. Input parameter filename should be an existing key, else it give false. Note: In case on multiple keys, It will return first encountered key within the object. It will work perfectly like a loader in case of unique filename.

/** Example of config object. **/
{
  var: {
    www: {
      noopath: {
        src: {
           config: "/var/www/noopath/src/config.json",
           deploy: "/var/www/noopath/src/deploy.yml",
           build: "/var/www/noopath/src/build.js"
        }
      }
    }
  }
}
/** Example of config object. **/
noopath.load("build");

/** Output: /var/www/noopath/src/build.js **/

7. Noopath.loadByFilter(filename, filter_regex_string)

This function will return complete filepath by digging inside complete config object, but difference here is, It will gather all files with that name and return first matched filepath.

/** Example of config object. **/
{
  var: {
    www: {
      noopath: {
        src: {
           config: "/var/www/noopath/src/config.json",
           lib_config: {
                config: "/var/www/noopath/src/lib_config/config.js"
           }
        }
      }
    }
  }
}
/**
 * Noopath returns first encountered key by default.
 */
noopath.loadByFilter("config","config\.js$")
/** Output: /var/www/noopath/src/lib_config/config.js **/

8. Noopath.loadOrElse(...filenames)

This function will return first existing filename. We can pass variable no. of parameters to these functions. This function will sequencially check for each argument(filename).

9. Noopath.loadFromFolder(folder, filename)

(Added in v1.4.0) This function will help you retrieve filename on the basis of folder name and filename (both given as string)
Note:

  • Parent folder can be at any level from bottom to top. Its not just stick to just parent folder.

10. Noopath.debug(bool)

(Added in v1.4.0) This function will help you get console logs for files loaded, filtered or retrieved through loading functions. It can be used for debugging purpose when you are not sure which file is loading.

11. Noopath.getAll(filename)

It will return all filepaths by filename which can be gathered during filtering out.

12 Noopath.clear()

(Added in v1.4.0) By default noopath holds first b structure retrieved and keep on performing loading, filtering operation on that particular object for preventing repeated calculations. There can be case when you want to re-retrieve folder structure within the running code. This will clear old object.
Note:

  • This function will clear previously obtained object. After cleaning object will re-initiated by reading folder structure again.