UNPKG

element-ui

Version:

A Component Library for Vue.js.

56 lines (43 loc) 1.41 kB
'use strict'; exports.__esModule = true; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; exports.default = function (Vue) { var hasOwn = Vue.util.hasOwn; /** * template * * @param {String} string * @param {Array} ...args * @return {String} */ function template(string) { for (var _len = arguments.length, args = 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) { args = {}; } return string.replace(RE_NARGS, function (match, prefix, i, index) { var result = void 0; if (string[index - 1] === '{' && string[index + match.length] === '}') { return i; } else { result = hasOwn(args, i) ? args[i] : null; if (result === null || result === undefined) { return ''; } return result; } }); } return template; }; /** * String format template * - Inspired: * https://github.com/Matt-Esch/string-template/index.js */ var RE_NARGS = /(%|)\{([0-9a-zA-Z_]+)\}/g;