zarm-web
Version:
基于 React 的桌面端UI库
53 lines (42 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/* eslint-disable */
/**
* String format template
*/
var RE_NARGS = /(%|)\{([0-9a-zA-Z_]+)\}/g;
/**
* format
*
* @param {String} string
* @param {Array} ...args
* @return {String}
*/
function _default(str) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
if (args.length === 1 && _typeof(args[0]) === 'object') {
args = args[0];
}
if (!args || !args.hasOwnProperty) {
// @ts-ignore
args = {};
}
return str.replace(RE_NARGS, function (match, _, i, index) {
var result;
if (str[index - 1] === '{' && str[index + match.length] === '}') {
return i;
} else {
result = Object.prototype.hasOwnProperty.call(args, i) ? args[i] : null;
if (result === null || result === undefined) {
return '';
}
return result;
}
});
}