Source: utils/refinery.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.regexRefinery = exports.refineRuntimeVals = exports.refineRelativePaths = void 0;
/**
 * Refines relative paths with `$.`
 * @param content local instance of json content
 * @param uniqueKeys Filtered keys from keywords
 * @returns refined json content with `"<$...."`
 */
function refineRelativePaths(content, uniqueKeys) {
    uniqueKeys?.map(eachKey => {
        let keyRegex = new RegExp(eachKey.replace("$", "\\$"), 'g');
        content = content.replace(keyRegex, "\"<" + eachKey + ">\"");
    });
    return content;
}
exports.refineRelativePaths = refineRelativePaths;
/**
 * Refines runtime variables for `inject()`
 * @param content local instance of json content
 * @param uniqueKeys
 * @returns `content`
 */
function refineRuntimeVals(content, uniqueKeys) {
    uniqueKeys?.map(eachKey => {
        content = content.replace(new RegExp(eachKey, "g"), "\"<-" + eachKey.split("<")[1].split(">")[0] + "->\"");
    });
    return content;
}
exports.refineRuntimeVals = refineRuntimeVals;
/**
 * Refines special characters from the string content.
 *
 * Characters in scope: ,[?*+{$^
 * @param content content to be refined
 * @returns
 */
function regexRefinery(content) {
    if (content === null || content === undefined)
        return content;
    return content.replace(/\./g, "\\.")
        .replace(/\[/g, "\\[")
        .replace(/\?/g, "\\?")
        .replace(/\*/g, "\\*")
        .replace(/\+/g, "\\+")
        .replace(/\{/g, "\\{")
        .replace(/\$/g, "\\$")
        .replace(/\^/g, "\\^");
}
exports.regexRefinery = regexRefinery;