Namespace

Utils

fabric-weaver.Utils

This namespace serves as a container for utility functions and helper methods used throughout the fabric-weaver project.

View Source utils-old/index.ts, line 2

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.

sequenceDiagram participant Caller participant readFileYaml participant logger participant fs participant yaml Caller->>readFileYaml: Call with yamlFilePath and optional variable readFileYaml->>logger: Log verbose message (Reading YAML file) readFileYaml->>fs: Read file content readFileYaml->>logger: Log verbose message (Parsed YAML content) readFileYaml->>yaml: Parse YAML content readFileYaml->>logger: Log verbose message (Parsed YAML object) alt variable is provided readFileYaml->>readFileYaml: Navigate through parsed YAML using variable path alt Property exists readFileYaml-->>Caller: Return specific property value else Property doesn't exist readFileYaml->>logger: Log error message readFileYaml-->>Caller: Return error end else variable is not provided readFileYaml-->>Caller: Return entire parsed YAML object end
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.

View Source utils/yaml.ts, line 6

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.

sequenceDiagram participant Caller participant writeFileYaml participant logger participant yaml participant fs Caller->>writeFileYaml: Call with path and JSON writeFileYaml->>logger: Log verbose message (Writing YAML file) writeFileYaml->>logger: Log verbose message (Writing YAML content) writeFileYaml->>yaml: Convert JSON to YAML writeFileYaml->>logger: Log verbose message (Writing YAML content to file) writeFileYaml->>fs: Write YAML content to file writeFileYaml-->>Caller: Return (void)
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.

View Source utils/yaml.ts, line 77

void
Example
const config = { database: { host: 'localhost', port: 5432 } };
writeFileYaml('config/settings.yaml', config);