2016-08-27 03:27:32 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
const EnigError = require('./enig_error.js').EnigError;
|
2017-09-09 19:59:23 +00:00
|
|
|
|
|
|
|
const {
|
2018-06-22 05:15:04 +00:00
|
|
|
pad,
|
|
|
|
stylizeString,
|
|
|
|
renderStringLength,
|
|
|
|
renderSubstr,
|
2022-06-05 20:04:25 +00:00
|
|
|
formatByteSize,
|
|
|
|
formatByteSizeAbbr,
|
|
|
|
formatCount,
|
|
|
|
formatCountAbbr,
|
|
|
|
} = require('./string_util.js');
|
2016-08-27 03:27:32 +00:00
|
|
|
|
2023-10-01 21:09:14 +00:00
|
|
|
const colorCodes = require('./color_codes.js');
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// deps
|
2022-06-05 20:04:25 +00:00
|
|
|
const _ = require('lodash');
|
|
|
|
const moment = require('moment');
|
2016-08-27 03:27:32 +00:00
|
|
|
|
|
|
|
/*
|
2018-06-23 03:26:46 +00:00
|
|
|
String formatting HEAVILY inspired by David Chambers string-format library
|
|
|
|
and the mini-language branch specifically which was gratiously released
|
|
|
|
under the DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE.
|
2016-08-27 03:27:32 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
We need some extra functionality. Namely, support for RA style pipe codes
|
|
|
|
and ANSI escape sequences.
|
2016-08-27 03:27:32 +00:00
|
|
|
*/
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
class ValueError extends EnigError {}
|
|
|
|
class KeyError extends EnigError {}
|
2016-08-27 03:27:32 +00:00
|
|
|
|
|
|
|
const SpecRegExp = {
|
2022-06-05 20:04:25 +00:00
|
|
|
FillAlign: /^(.)?([<>=^])/,
|
|
|
|
Sign: /^[ +-]/,
|
|
|
|
Width: /^\d*/,
|
|
|
|
Precision: /^\d+/,
|
2016-08-27 03:27:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function tokenizeFormatSpec(spec) {
|
2018-06-22 05:15:04 +00:00
|
|
|
const tokens = {
|
2022-06-05 20:04:25 +00:00
|
|
|
fill: '',
|
|
|
|
align: '',
|
|
|
|
sign: '',
|
|
|
|
'#': false,
|
|
|
|
0: false,
|
|
|
|
width: '',
|
|
|
|
',': false,
|
|
|
|
precision: '',
|
|
|
|
type: '',
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let index = 0;
|
|
|
|
let match;
|
|
|
|
|
|
|
|
function incIndexByMatch() {
|
|
|
|
index += match[0].length;
|
|
|
|
}
|
|
|
|
|
|
|
|
match = SpecRegExp.FillAlign.exec(spec);
|
2022-06-05 20:04:25 +00:00
|
|
|
if (match) {
|
|
|
|
if (match[1]) {
|
2018-06-22 05:15:04 +00:00
|
|
|
tokens.fill = match[1];
|
|
|
|
}
|
|
|
|
tokens.align = match[2];
|
|
|
|
incIndexByMatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
match = SpecRegExp.Sign.exec(spec.slice(index));
|
2022-06-05 20:04:25 +00:00
|
|
|
if (match) {
|
2018-06-22 05:15:04 +00:00
|
|
|
tokens.sign = match[0];
|
|
|
|
incIndexByMatch();
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if ('#' === spec.charAt(index)) {
|
2018-06-22 05:15:04 +00:00
|
|
|
tokens['#'] = true;
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if ('0' === spec.charAt(index)) {
|
2018-06-22 05:15:04 +00:00
|
|
|
tokens['0'] = true;
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
|
|
|
|
match = SpecRegExp.Width.exec(spec.slice(index));
|
|
|
|
tokens.width = match[0];
|
|
|
|
incIndexByMatch();
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (',' === spec.charAt(index)) {
|
2018-06-22 05:15:04 +00:00
|
|
|
tokens[','] = true;
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if ('.' === spec.charAt(index)) {
|
2018-06-22 05:15:04 +00:00
|
|
|
++index;
|
|
|
|
|
|
|
|
match = SpecRegExp.Precision.exec(spec.slice(index));
|
2022-06-05 20:04:25 +00:00
|
|
|
if (!match) {
|
2018-06-22 05:15:04 +00:00
|
|
|
throw new ValueError('Format specifier missing precision');
|
|
|
|
}
|
|
|
|
|
|
|
|
tokens.precision = match[0];
|
|
|
|
incIndexByMatch();
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (index < spec.length) {
|
2018-06-22 05:15:04 +00:00
|
|
|
tokens.type = spec.charAt(index);
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (index < spec.length) {
|
2018-06-22 05:15:04 +00:00
|
|
|
throw new ValueError('Invalid conversion specification');
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (tokens[','] && 's' === tokens.type) {
|
|
|
|
throw new ValueError(`Cannot specify ',' with 's'`); // eslint-disable-line quotes
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return tokens;
|
2016-08-27 03:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function quote(s) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return `"${s.replace(/"/g, '\\"')}"`;
|
2016-08-27 03:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPadAlign(align) {
|
2022-06-05 20:04:25 +00:00
|
|
|
return (
|
|
|
|
{
|
|
|
|
'<': 'left',
|
|
|
|
'>': 'right',
|
|
|
|
'^': 'center',
|
|
|
|
}[align] || '>'
|
|
|
|
);
|
2016-08-27 03:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function formatString(value, tokens) {
|
2022-06-05 20:04:25 +00:00
|
|
|
const fill = tokens.fill || (tokens['0'] ? '0' : ' ');
|
|
|
|
const align = tokens.align || (tokens['0'] ? '=' : '<');
|
2018-06-23 03:26:46 +00:00
|
|
|
const precision = Number(tokens.precision || renderStringLength(value) + 1);
|
2016-08-27 03:27:32 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if ('' !== tokens.type && 's' !== tokens.type) {
|
2018-06-22 05:15:04 +00:00
|
|
|
throw new ValueError(`Unknown format code "${tokens.type}" for String object`);
|
|
|
|
}
|
2016-08-27 03:27:32 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (tokens[',']) {
|
|
|
|
throw new ValueError(`Cannot specify ',' with 's'`); // eslint-disable-line quotes
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
2016-08-27 03:27:32 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (tokens.sign) {
|
2018-06-22 05:15:04 +00:00
|
|
|
throw new ValueError('Sign not allowed in string format specifier');
|
|
|
|
}
|
2016-08-27 03:27:32 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (tokens['#']) {
|
2018-06-22 05:15:04 +00:00
|
|
|
throw new ValueError('Alternate form (#) not allowed in string format specifier');
|
|
|
|
}
|
2016-08-27 03:27:32 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if ('=' === align) {
|
2018-06-22 05:15:04 +00:00
|
|
|
throw new ValueError('"=" alignment not allowed in string format specifier');
|
|
|
|
}
|
2016-08-27 03:27:32 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
return pad(
|
|
|
|
renderSubstr(value, 0, precision),
|
|
|
|
Number(tokens.width),
|
|
|
|
fill,
|
|
|
|
getPadAlign(align)
|
|
|
|
);
|
2016-08-27 03:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const FormatNumRegExp = {
|
2022-06-05 20:04:25 +00:00
|
|
|
UpperType: /[A-Z]/,
|
|
|
|
ExponentRep: /e[+-](?=\d$)/,
|
2016-08-27 03:27:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function formatNumberHelper(n, precision, type) {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (FormatNumRegExp.UpperType.test(type)) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return formatNumberHelper(n, precision, type.toLowerCase()).toUpperCase();
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
switch (type) {
|
|
|
|
case 'c':
|
|
|
|
return String.fromCharCode(n);
|
|
|
|
case 'd':
|
|
|
|
return n.toString(10);
|
|
|
|
case 'b':
|
|
|
|
return n.toString(2);
|
|
|
|
case 'o':
|
|
|
|
return n.toString(8);
|
|
|
|
case 'x':
|
|
|
|
return n.toString(16);
|
|
|
|
case 'e':
|
|
|
|
return n.toExponential(precision).replace(FormatNumRegExp.ExponentRep, '$&0');
|
|
|
|
case 'f':
|
|
|
|
return n.toFixed(precision);
|
|
|
|
case 'g':
|
2018-06-23 03:26:46 +00:00
|
|
|
// we don't want useless trailing zeros. parseFloat -> back to string fixes this for us
|
2018-06-22 05:15:04 +00:00
|
|
|
return parseFloat(n.toPrecision(precision || 1)).toString();
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
case '%':
|
|
|
|
return formatNumberHelper(n * 100, precision, 'f') + '%';
|
|
|
|
case '':
|
|
|
|
return formatNumberHelper(n, precision, 'd');
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
default:
|
|
|
|
throw new ValueError(
|
|
|
|
`Unknown format code "${type}" for object of type 'float'`
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
2016-08-27 03:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function formatNumber(value, tokens) {
|
2022-06-05 20:04:25 +00:00
|
|
|
const fill = tokens.fill || (tokens['0'] ? '0' : ' ');
|
|
|
|
const align = tokens.align || (tokens['0'] ? '=' : '>');
|
2023-10-01 21:09:14 +00:00
|
|
|
const width = Number(tokens.width);value.replace(/\x1b\[[0-9;]*m/g, '');
|
2022-06-05 20:04:25 +00:00
|
|
|
const type = tokens.type || (tokens.precision ? 'g' : '');
|
|
|
|
|
|
|
|
if (['c', 'd', 'b', 'o', 'x', 'X'].indexOf(type) > -1) {
|
|
|
|
if (0 !== value % 1) {
|
|
|
|
throw new ValueError(
|
|
|
|
`Cannot format non-integer with format specifier "${type}"`
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if ('' !== tokens.sign && 'c' !== type) {
|
2018-06-23 03:26:46 +00:00
|
|
|
throw new ValueError(`Sign not allowed with integer format specifier 'c'`); // eslint-disable-line quotes
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (tokens[','] && 'd' !== type) {
|
2018-06-22 05:15:04 +00:00
|
|
|
throw new ValueError(`Cannot specify ',' with '${type}'`);
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if ('' !== tokens.precision) {
|
2018-06-22 05:15:04 +00:00
|
|
|
throw new ValueError('Precision not allowed in integer format specifier');
|
|
|
|
}
|
2022-06-05 20:04:25 +00:00
|
|
|
} else if (['e', 'E', 'f', 'F', 'g', 'G', '%'].indexOf(type) > -1) {
|
|
|
|
if (tokens['#']) {
|
|
|
|
throw new ValueError(
|
|
|
|
'Alternate form (#) not allowed in float format specifier'
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
const s = formatNumberHelper(Math.abs(value), Number(tokens.precision || 6), type);
|
|
|
|
const sign =
|
|
|
|
value < 0 || 1 / value < 0 ? '-' : '-' === tokens.sign ? '' : tokens.sign;
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
const prefix =
|
|
|
|
tokens['#'] && ['b', 'o', 'x', 'X'].indexOf(type) > -1 ? '0' + type : '';
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (tokens[',']) {
|
|
|
|
const match = /^(\d*)(.*)$/.exec(s);
|
2018-06-23 03:26:46 +00:00
|
|
|
const separated = match[1].replace(/.(?=(...)+$)/g, '$&,') + match[2];
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if ('=' !== align) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return pad(sign + separated, width, fill, getPadAlign(align));
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if ('0' === fill) {
|
2018-06-22 05:15:04 +00:00
|
|
|
const shortfall = Math.max(0, width - sign.length - separated.length);
|
2022-06-05 20:04:25 +00:00
|
|
|
const digits = /^\d*/.exec(separated)[0].length;
|
|
|
|
let padding = '';
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: do this differntly...
|
2022-06-05 20:04:25 +00:00
|
|
|
for (let n = 0; n < shortfall; n++) {
|
2018-06-22 05:15:04 +00:00
|
|
|
padding = ((digits + n) % 4 === 3 ? ',' : '0') + padding;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sign + (/^,/.test(padding) ? '0' : '') + padding + separated;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sign + pad(separated, width - sign.length, fill, getPadAlign('>'));
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (0 === width) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return sign + prefix + s;
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if ('=' === align) {
|
|
|
|
return (
|
|
|
|
sign +
|
|
|
|
prefix +
|
|
|
|
pad(s, width - sign.length - prefix.length, fill, getPadAlign('>'))
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pad(sign + prefix + s, width, fill, getPadAlign(align));
|
2016-08-27 03:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const transformers = {
|
2018-06-23 03:26:46 +00:00
|
|
|
// String standard
|
2022-06-05 20:04:25 +00:00
|
|
|
toUpperCase: String.prototype.toUpperCase,
|
|
|
|
toLowerCase: String.prototype.toLowerCase,
|
2018-06-23 03:26:46 +00:00
|
|
|
|
|
|
|
// some super l33b BBS styles!!
|
2022-06-05 20:04:25 +00:00
|
|
|
styleUpper: s => stylizeString(s, 'upper'),
|
|
|
|
styleLower: s => stylizeString(s, 'lower'),
|
|
|
|
styleTitle: s => stylizeString(s, 'title'),
|
|
|
|
styleFirstLower: s => stylizeString(s, 'first lower'),
|
|
|
|
styleSmallVowels: s => stylizeString(s, 'small vowels'),
|
|
|
|
styleBigVowels: s => stylizeString(s, 'big vowels'),
|
|
|
|
styleSmallI: s => stylizeString(s, 'small i'),
|
|
|
|
styleMixed: s => stylizeString(s, 'mixed'),
|
|
|
|
styleL33t: s => stylizeString(s, 'l33t'),
|
2023-10-01 21:09:14 +00:00
|
|
|
sanitized: s => stylizeString(s, 'sanitized'),
|
2018-06-23 03:26:46 +00:00
|
|
|
|
|
|
|
// :TODO:
|
|
|
|
// toMegs(), toKilobytes(), ...
|
|
|
|
// toList(), toCommaList(),
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
sizeWithAbbr: n => formatByteSize(n, true, 2),
|
|
|
|
sizeWithoutAbbr: n => formatByteSize(n, false, 2),
|
|
|
|
sizeAbbr: n => formatByteSizeAbbr(n),
|
|
|
|
countWithAbbr: n => formatCount(n, true, 0),
|
|
|
|
countWithoutAbbr: n => formatCount(n, false, 0),
|
|
|
|
countAbbr: n => formatCountAbbr(n),
|
2019-01-06 04:17:53 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
durationHours: h => moment.duration(h, 'hours').humanize(),
|
|
|
|
durationMinutes: m => moment.duration(m, 'minutes').humanize(),
|
|
|
|
durationSeconds: s => moment.duration(s, 'seconds').humanize(),
|
2016-08-27 03:27:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function transformValue(transformerName, value) {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (transformerName in transformers) {
|
2018-06-22 05:15:04 +00:00
|
|
|
const transformer = transformers[transformerName];
|
2022-06-05 20:04:25 +00:00
|
|
|
value = transformer.apply(value, [value]);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
2016-08-27 03:27:32 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
return value;
|
2016-08-27 03:27:32 +00:00
|
|
|
}
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: Use explicit set of chars for paths & function/transforms such that } is allowed as fill/etc.
|
2022-06-05 20:04:25 +00:00
|
|
|
const REGEXP_BASIC_FORMAT = /{([^.!:}]+(?:\.[^.!:}]+)*)(?:!([^:}]+))?(?::([^}]+))?}/g;
|
2016-08-27 03:27:32 +00:00
|
|
|
|
|
|
|
function getValue(obj, path) {
|
2018-06-22 05:15:04 +00:00
|
|
|
const value = _.get(obj, path);
|
2022-06-05 20:04:25 +00:00
|
|
|
if (!_.isUndefined(value)) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return _.isFunction(value) ? value() : value;
|
|
|
|
}
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
throw new KeyError(quote(path));
|
2016-08-27 03:27:32 +00:00
|
|
|
}
|
|
|
|
|
2023-10-01 21:09:14 +00:00
|
|
|
module.exports = function format(fmt, obj, stripMciColorCodes = false) {
|
2018-06-22 05:15:04 +00:00
|
|
|
const re = REGEXP_BASIC_FORMAT;
|
2022-06-05 20:04:25 +00:00
|
|
|
re.lastIndex = 0; // reset from prev
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
let match;
|
|
|
|
let pos;
|
|
|
|
let out = '';
|
2022-06-05 20:04:25 +00:00
|
|
|
let objPath;
|
2018-06-22 05:15:04 +00:00
|
|
|
let transformer;
|
|
|
|
let formatSpec;
|
|
|
|
let value;
|
|
|
|
let tokens;
|
|
|
|
|
|
|
|
do {
|
2022-06-05 20:04:25 +00:00
|
|
|
pos = re.lastIndex;
|
|
|
|
match = re.exec(fmt);
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (match) {
|
|
|
|
if (match.index > pos) {
|
2018-06-22 05:15:04 +00:00
|
|
|
out += fmt.slice(pos, match.index);
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
objPath = match[1];
|
2018-06-23 03:26:46 +00:00
|
|
|
transformer = match[2];
|
2022-06-05 20:04:25 +00:00
|
|
|
formatSpec = match[3];
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-08-05 16:50:47 +00:00
|
|
|
try {
|
2022-06-05 20:04:25 +00:00
|
|
|
value = getValue(obj, objPath);
|
|
|
|
if (transformer) {
|
2018-08-05 16:50:47 +00:00
|
|
|
value = transformValue(transformer, value);
|
|
|
|
}
|
|
|
|
|
2023-10-01 21:09:14 +00:00
|
|
|
// This is used in cases where the output shouldn't allow color codes
|
|
|
|
if (stripMciColorCodes) {
|
|
|
|
value = colorCodes.stripMciColorCodes(value);
|
|
|
|
}
|
|
|
|
|
2018-08-05 16:50:47 +00:00
|
|
|
tokens = tokenizeFormatSpec(formatSpec || '');
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (_.isNumber(value)) {
|
2018-08-05 16:50:47 +00:00
|
|
|
out += formatNumber(value, tokens);
|
|
|
|
} else {
|
|
|
|
out += formatString(value, tokens);
|
|
|
|
}
|
2022-06-05 20:04:25 +00:00
|
|
|
} catch (e) {
|
|
|
|
if (e instanceof KeyError) {
|
|
|
|
out += match[0]; // preserve full thing
|
|
|
|
} else if (e instanceof ValueError) {
|
2018-08-05 16:50:47 +00:00
|
|
|
out += value.toString();
|
|
|
|
}
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-05 20:04:25 +00:00
|
|
|
} while (0 !== re.lastIndex);
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// remainder
|
2022-06-05 20:04:25 +00:00
|
|
|
if (pos < fmt.length) {
|
2018-06-22 05:15:04 +00:00
|
|
|
out += fmt.slice(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
2016-08-27 03:27:32 +00:00
|
|
|
};
|