72 lines
2.6 KiB
JavaScript
72 lines
2.6 KiB
JavaScript
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
var variables_exports = {};
|
|
__export(variables_exports, {
|
|
DATE_VARS: () => DATE_VARS,
|
|
DEFAULT_VARS: () => DEFAULT_VARS,
|
|
_substitute: () => _substitute,
|
|
resolve: () => resolve,
|
|
resolveVariables: () => resolveVariables,
|
|
substitute: () => substitute
|
|
});
|
|
module.exports = __toCommonJS(variables_exports);
|
|
var import_constants = require("@polymech/core/constants");
|
|
var import_config = require("./config.js");
|
|
const DATE_VARS = () => {
|
|
return {
|
|
YYYY: new Date(Date.now()).getFullYear(),
|
|
MM: new Date(Date.now()).getMonth() + 1,
|
|
DD: new Date(Date.now()).getDate(),
|
|
HH: new Date(Date.now()).getHours(),
|
|
SS: new Date(Date.now()).getSeconds()
|
|
};
|
|
};
|
|
const _substitute = (template, map, keep = true, alt = false) => {
|
|
const transform = (k) => k || "";
|
|
return template.replace(alt ? import_constants.REGEX_VAR_ALT : import_constants.REGEX_VAR, (match, key, format) => {
|
|
if (map[key]) {
|
|
return transform(map[key]).toString();
|
|
} else if (map[key.replace(/-/g, "_")]) {
|
|
return transform(map[key.replace(/-/g, "_")]).toString();
|
|
} else if (keep) {
|
|
return "${" + key + "}";
|
|
} else {
|
|
return "";
|
|
}
|
|
});
|
|
};
|
|
const substitute = (alt, template, vars = {}, keep = true) => alt ? _substitute(template, vars, keep, alt) : _substitute(template, vars, keep, alt);
|
|
const DEFAULT_VARS = (vars) => {
|
|
return {
|
|
...import_config.DEFAULT_ROOTS,
|
|
...DATE_VARS(),
|
|
...vars
|
|
};
|
|
};
|
|
const resolveVariables = (_path, alt = false, vars = {}) => substitute(alt, _path, DEFAULT_VARS(vars));
|
|
const resolve = (_path, alt = false, vars = {}) => resolveVariables(_path, alt, vars);
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
DATE_VARS,
|
|
DEFAULT_VARS,
|
|
_substitute,
|
|
resolve,
|
|
resolveVariables,
|
|
substitute
|
|
});
|
|
//# sourceMappingURL=variables.cjs.map
|