fcf.getPathInfo() function
{module , subpath } fcf.getPathInfo (string a_path, a_isServerPath = fcf.isServer (), boolean a_quiet = false)
Package: fcf-framework-core
File: fcf-framework-core:fcf.js
Available from version: 2.0.2
Returns the module and the subpath by the path
Arguments
- A source path to a resource. The path can be set as absolute, as relative in a project or in FCF notations
- If true then a_path contains the path on the server, otherwise a_path is the network address
- If the argument is equal to false and a_path not belong an application directory or a directory of the module, then an exception throws of fcf.Exception with the GET_PATH_INFO_ERROR error code.
If the argument is equal to the
Result
{module , subpath }
- Returns an object containing the name of the module and the subpath in this module.
If the path refers to the root of the application, then
If the module could not be determined, an empty object is returned or an exception throws.
Example: Application of a function on the server side
{
let path = fcf.getPath("express:") + "/index.js";
let result = fcf.getPathInfo(path);
console.log("Path: ", path);
console.log("Result:", result);
}
console.log("");
{
let path = "fcf-framework-core:fcf.js";
let result = fcf.getPathInfo(path);
console.log("Path: ", path);
console.log("Result:", result);
}
console.log("");
{
let path = "./index.js";
let result = fcf.getPathInfo(path);
console.log("Path: ", path);
console.log("Result:", result);
}
console.log("");
{
let path = "/INCORRECT_PATH/index.js";
let result = fcf.getPathInfo(path, true, true);
console.log("Path: ", path);
console.log("Result:", result);
}
Output:
Path: /home/user/development/project/node_modules/express/index.js
Result: { module: 'express:index.js', subpath: '' }
Path: fcf-framework-core:fcf.js
Result: { module: 'fcf-framework-core', subpath: 'fcf.js' }
Path: ./index.js
Result: { module: '', subpath: 'index.js' }
Path: /INCORRECT_PATH/index.js
Result: {}