Spaces:
Sleeping
Sleeping
Download src/utils/templateParser.js from Discord-Core-Bot/gateway-services: direct link, hf CLI and curl.
- Browser
- Download file 811 Bytes
-
https://huggingface.co/spaces/Discord-Core-Bot/gateway-services/resolve/main/src/utils/templateParser.js
- Command line
-
hf download hf://spaces/Discord-Core-Bot/gateway-services/src/utils/templateParser.js
-
curl -L -o templateParser.js https://huggingface.co/spaces/Discord-Core-Bot/gateway-services/resolve/main/src/utils/templateParser.js
811 Bytes
| /** | |
| * src/utils/templateParser.js | |
| * | |
| * Pure template-string utility. No dependencies, no side effects. | |
| */ | |
| /** | |
| * Replace every {key} placeholder in `template` with the matching value | |
| * from `variables`. | |
| * | |
| * - Unknown placeholders (key not in variables) are left as-is. | |
| * - null / undefined values are replaced with an empty string. | |
| * | |
| * @param {string} template - String containing {key} placeholders | |
| * @param {Record<string, unknown>} variables - Map of placeholder → value | |
| * @returns {string} | |
| */ | |
| export function parseTemplate(template, variables) { | |
| return template.replace(/\{([^{}]+)\}/g, (match, key) => { | |
| if (!Object.prototype.hasOwnProperty.call(variables, key)) return match | |
| const value = variables[key] | |
| return value == null ? '' : String(value) | |
| }) | |
| } |