@contentstack/cli-variants
Version:
Variants plugin
58 lines (57 loc) • 2.56 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.commonMsg = exports.errors = void 0;
exports.$t = $t;
const memoize_1 = __importDefault(require("lodash/memoize"));
const errors = {
CREATE_FAILURE: '{module} creation failed!',
};
exports.errors = errors;
const commonMsg = {
CREATE_SUCCESS: '{module} created successfully!',
};
exports.commonMsg = commonMsg;
const migrationMsg = {
IMPORT_MSG: 'Migrating {module}...',
};
const variantEntry = {
VARIANT_ENTRY_FILE_NOT_FOUND: 'Variant entry file not found!',
IMPORT_ENTRY_NOT_FOUND: 'Entries data not found to import variant entries',
EMPTY_VARIANT_UID_DATA: 'Empty variants entry mapper found!',
VARIANT_ID_NOT_FOUND: 'Variant ID not found',
VARIANT_UID_NOT_FOUND: 'Entry Variant UID not found',
};
const expImportMsg = {
UPDATING_CT_IN_EXP: 'Updating content types in experiences...',
UPDATED_CT_IN_EXP: 'Successfully updated content types in experiences!',
VALIDATE_VARIANT_AND_VARIANT_GRP: 'Validating variant group and variants creation...',
PERSONALIZE_JOB_FAILURE: 'Something went wrong! Failed to fetch some variant and variant groups.',
};
const messages = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, errors), commonMsg), migrationMsg), variantEntry), expImportMsg);
/**
* The function `` is a TypeScript function that replaces placeholders in a message string with
* values from a provided object.
* @param {string} msg - The `msg` parameter is a string that represents the message template with
* placeholders for dynamic values.
* @param args - The `args` parameter is an object that contains key-value pairs where the key is a
* string and the value is also a string. These key-value pairs are used to replace placeholders in the
* `msg` string with the corresponding values.
* @returns the formatted message with the provided arguments replaced in the placeholders.
*/
function $t(msg, args) {
const transfer = (0, memoize_1.default)(function (msg, args) {
if (!msg)
return '';
for (const key of Object.keys(args)) {
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const placeholder = `{${escapedKey}}`;
msg = msg.split(placeholder).join(args[key]);
}
return msg;
});
return transfer(msg, args);
}
exports.default = messages;