This namespace serves as a container for utility functions and helper methods used throughout the fabric-weaver project.
Methods
# static readFileYaml(yamlFilePath, variableopt) → {Record.<string, any>|T}
This function reads a YAML file from the given path, parses its content, and returns either the entire parsed YAML object or a specific property value based on the provided path.
Reads and parses a YAML file, optionally retrieving a specific property.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
yamlFilePath |
string
|
The path to the YAML file to be read. |
|
variable |
string
|
<optional> |
Optional. A dot-notated path string that specifies the property to retrieve from the parsed YAML. |
Returns the entire parsed YAML object if no variable is provided, or the value of the specified property if variable is provided.
Record.<string, any>
|
T
Examples
// Example 1: Read the entire YAML file
const config = readFileYaml("config/settings.yaml");
console.log(config);
// Example 2: Retrieve a specific property from the YAML file
const dbHost = readFileYaml("config/settings.yaml", "database.host");
console.log(dbHost);
// Example 3: Handle an error if the property does not exist
const invalidProperty = readFileYaml("config/settings.yaml", "server.port");
# static writeFileYaml(path, json) → {void}
This function takes a JSON object and writes it to a specified file path in YAML format. It uses js-yaml to convert the JSON to YAML, and then writes the content to the file.
Writes a JSON object to a YAML file.
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string
|
The file path where the YAML content will be written. |
json |
T
|
The JSON object to be converted to YAML and written to the file. |
void
Example
const config = { database: { host: 'localhost', port: 5432 } };
writeFileYaml('config/settings.yaml', config);