react-application-core
Version:
A react-based application core for the business applications.
55 lines • 1.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.strongHtmlReplace = exports.replaceByParameters = exports.regexpReplace = exports.htmlStrongReplacer = exports.replacerFactory = void 0;
var R = require("ramda");
var type_1 = require("./type");
/**
* @stable [28.01.2019]
* @param {string} before
* @param {string} after
* @returns {(matchedValue: string) => string}
*/
exports.replacerFactory = function (before, after) {
return function (matchedValue) { return "" + before + matchedValue + after; };
};
/**
* @stable [28.01.2019]
* @type {(matchedValue: string) => string}
*/
exports.htmlStrongReplacer = exports.replacerFactory('<b>', '</b>');
/**
* @stable [05.05.2020]
* @param {StringNumberT} inputValue
* @param {string} replacedValue
* @param {(...matchedValue: string[]) => string} replacer
* @param {string} flags
* @returns {string}
*/
exports.regexpReplace = function (inputValue, replacedValue, replacer, flags) {
if (flags === void 0) { flags = 'ig'; }
return (type_1.TypeUtils.isString(inputValue)
? inputValue
: String(inputValue)).replace(new RegExp(replacedValue, flags), replacer);
};
/**
* @stable [05.05.2020]
* @param {string} value
* @param {IKeyValue} parameters
* @returns {string}
*/
exports.replaceByParameters = function (value, parameters) {
if (R.isNil(parameters)) {
return value;
}
return exports.regexpReplace(value, '{([a-zA-Z0-9]+)}', function (_, param) { return parameters[param]; });
};
/**
* @stable [28.01.2019]
* @param {StringNumberT} inputValue
* @param {string} replacedValue
* @returns {string}
*/
exports.strongHtmlReplace = function (inputValue, replacedValue) {
return exports.regexpReplace(inputValue, replacedValue, exports.htmlStrongReplacer);
};
//# sourceMappingURL=replace.js.map