MCPcopy
hub / github.com/microsoft/SandDance / format

Function format

docs/app/js/sanddance-app.js:15339–15390  ·  view source on GitHub ↗
(value)

Source from the content-addressed store, hash-verified

15337 // For fixed precision, it must be in [0, 20].
15338 precision = precision === undefined ? 6 : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision)) : Math.max(0, Math.min(20, precision));
15339 function format(value) {
15340 var valuePrefix = prefix, valueSuffix = suffix, i, n, c;
15341 if (type === "c") {
15342 valueSuffix = formatType(value) + valueSuffix;
15343 value = "";
15344 } else {
15345 value = +value;
15346 // Determine the sign. -0 is not less than 0, but 1 / -0 is!
15347 var valueNegative = value < 0 || 1 / value < 0;
15348 // Perform the initial formatting.
15349 value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
15350 // Trim insignificant zeros.
15351 if (trim) value = (0, _formatTrimJsDefault.default)(value);
15352 // If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.
15353 if (valueNegative && +value === 0 && sign !== "+") valueNegative = false;
15354 // Compute the prefix and suffix.
15355 valuePrefix = (valueNegative ? sign === "(" ? sign : minus : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
15356 valueSuffix = (type === "s" ? prefixes[8 + (0, _formatPrefixAutoJs.prefixExponent) / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
15357 // Break the formatted value into the integer “value” part that can be
15358 // grouped, and fractional or exponential “suffix” part that is not.
15359 if (maybeSuffix) {
15360 i = -1, n = value.length;
15361 while(++i < n)if (c = value.charCodeAt(i), 48 > c || c > 57) {
15362 valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
15363 value = value.slice(0, i);
15364 break;
15365 }
15366 }
15367 }
15368 // If the fill character is not "0", grouping is applied before padding.
15369 if (comma && !zero) value = group(value, Infinity);
15370 // Compute the padding.
15371 var length = valuePrefix.length + value.length + valueSuffix.length, padding = length < width ? new Array(width - length + 1).join(fill) : "";
15372 // If the fill character is "0", grouping is applied after padding.
15373 if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
15374 // Reconstruct the final output based on the desired alignment.
15375 switch(align){
15376 case "<":
15377 value = valuePrefix + value + valueSuffix + padding;
15378 break;
15379 case "=":
15380 value = valuePrefix + padding + value + valueSuffix;
15381 break;
15382 case "^":
15383 value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length);
15384 break;
15385 default:
15386 value = padding + valuePrefix + value + valueSuffix;
15387 break;
15388 }
15389 return numerals(value);
15390 }
15391 format.toString = function() {
15392 return specifier + "";
15393 };

Callers 8

formatFloatFunction · 0.70
formatSpanFunction · 0.70
timeMultiFormatFunction · 0.70
newFormatFunction · 0.70
domainCaptionFunction · 0.70
calendarFunction · 0.70
transformFunction · 0.70
dataScope.tsxFile · 0.50

Calls 6

replaceMethod · 0.80
groupFunction · 0.70
inferColumnsFunction · 0.70
preformatBodyFunction · 0.70
isTemporalFunction · 0.70
labelFormatFunction · 0.70

Tested by

no test coverage detected