MCPcopy
hub / github.com/vercel/hyper / jsSprintf

Function jsSprintf

bin/yarn-standalone.js:112809–112910  ·  view source on GitHub ↗
(fmt)

Source from the content-addressed store, hash-verified

112807 * numbers, non-decimal numbers, and characters.
112808 */
112809function jsSprintf(fmt)
112810{
112811 var regex = [
112812 '([^%]*)', /* normal text */
112813 '%', /* start of format */
112814 '([\'\\-+ #0]*?)', /* flags (optional) */
112815 '([1-9]\\d*)?', /* width (optional) */
112816 '(\\.([1-9]\\d*))?', /* precision (optional) */
112817 '[lhjztL]*?', /* length mods (ignored) */
112818 '([diouxXfFeEgGaAcCsSp%jr])' /* conversion */
112819 ].join('');
112820
112821 var re = new RegExp(regex);
112822 var args = Array.prototype.slice.call(arguments, 1);
112823 var flags, width, precision, conversion;
112824 var left, pad, sign, arg, match;
112825 var ret = '';
112826 var argn = 1;
112827
112828 mod_assert.equal('string', typeof (fmt));
112829
112830 while ((match = re.exec(fmt)) !== null) {
112831 ret += match[1];
112832 fmt = fmt.substring(match[0].length);
112833
112834 flags = match[2] || '';
112835 width = match[3] || 0;
112836 precision = match[4] || '';
112837 conversion = match[6];
112838 left = false;
112839 sign = false;
112840 pad = ' ';
112841
112842 if (conversion == '%') {
112843 ret += '%';
112844 continue;
112845 }
112846
112847 if (args.length === 0)
112848 throw (new Error('too few args to sprintf'));
112849
112850 arg = args.shift();
112851 argn++;
112852
112853 if (flags.match(/[\' #]/))
112854 throw (new Error(
112855 'unsupported flags: ' + flags));
112856
112857 if (precision.length > 0)
112858 throw (new Error(
112859 'non-zero precision not supported'));
112860
112861 if (flags.match(/-/))
112862 left = true;
112863
112864 if (flags.match(/0/))
112865 pad = '0';
112866

Callers 1

dumpExceptionFunction · 0.85

Calls 7

doPadFunction · 0.85
dumpExceptionFunction · 0.85
jsErrorFunction · 0.85
shiftMethod · 0.80
matchMethod · 0.80
toStringMethod · 0.45
inspectMethod · 0.45

Tested by

no test coverage detected