MCPcopy
hub / github.com/skygragon/leetcode-cli / tsprintf

Function tsprintf

lib/sprintf.js:25–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23}
24
25const tsprintf = function() {
26 const args = Array.from(arguments);
27 let fmt = args.shift();
28 return fmt.replace(/%[^s%]*[s%]/g, function(s) {
29 if (s === '%%') return '%';
30
31 let x = '' + args.shift();
32 let n = 0;
33
34 s = s.slice(1, s.length-1);
35 if (s.length > 0) {
36 switch (s[0]) {
37 case '-':
38 n = parseInt(s.slice(1)) || 0;
39 x = padRight(x, n, ' ');
40 break;
41 case '=':
42 n = parseInt(s.slice(1)) || 0;
43 x = padCenter(x, n, ' ');
44 break;
45 case '0':
46 n = parseInt(s.slice(1)) || 0;
47 x = padLeft(x, n, '0');
48 break;
49 default:
50 n = parseInt(s) || 0;
51 x = padLeft(x, n, ' ');
52 break;
53 }
54 }
55
56 return x;
57 });
58};
59
60module.exports = tsprintf;

Callers

nothing calls this directly

Calls 3

padRightFunction · 0.85
padCenterFunction · 0.85
padLeftFunction · 0.85

Tested by

no test coverage detected