MCPcopy Index your code
hub / github.com/angular/angular / parseNumberFormat

Function parseNumberFormat

packages/common/src/i18n/format_number.ts:303–359  ·  view source on GitHub ↗
(format: string, minusSign = '-')

Source from the content-addressed store, hash-verified

301}
302
303function parseNumberFormat(format: string, minusSign = '-'): ParsedNumberFormat {
304 const p = {
305 minInt: 1,
306 minFrac: 0,
307 maxFrac: 0,
308 posPre: '',
309 posSuf: '',
310 negPre: '',
311 negSuf: '',
312 gSize: 0,
313 lgSize: 0,
314 };
315
316 const patternParts = format.split(PATTERN_SEP);
317 const positive = patternParts[0];
318 const negative = patternParts[1];
319
320 const positiveParts =
321 positive.indexOf(DECIMAL_SEP) !== -1
322 ? positive.split(DECIMAL_SEP)
323 : [
324 positive.substring(0, positive.lastIndexOf(ZERO_CHAR) + 1),
325 positive.substring(positive.lastIndexOf(ZERO_CHAR) + 1),
326 ],
327 integer = positiveParts[0],
328 fraction = positiveParts[1] || '';
329
330 p.posPre = integer.substring(0, integer.indexOf(DIGIT_CHAR));
331
332 for (let i = 0; i < fraction.length; i++) {
333 const ch = fraction.charAt(i);
334 if (ch === ZERO_CHAR) {
335 p.minFrac = p.maxFrac = i + 1;
336 } else if (ch === DIGIT_CHAR) {
337 p.maxFrac = i + 1;
338 } else {
339 p.posSuf += ch;
340 }
341 }
342
343 const groups = integer.split(GROUP_SEP);
344 p.gSize = groups[1] ? groups[1].length : 0;
345 p.lgSize = groups[2] || groups[1] ? (groups[2] || groups[1]).length : 0;
346
347 if (negative) {
348 const trunkLen = positive.length - p.posPre.length - p.posSuf.length,
349 pos = negative.indexOf(DIGIT_CHAR);
350
351 p.negPre = negative.substring(0, pos).replace(/'/g, '');
352 p.negSuf = negative.slice(pos + trunkLen).replace(/'/g, '');
353 } else {
354 p.negPre = minusSign + p.posPre;
355 p.negSuf = p.posSuf;
356 }
357
358 return p;
359}
360

Callers 3

formatCurrencyFunction · 0.85
formatPercentFunction · 0.85
formatNumberFunction · 0.85

Calls 3

indexOfMethod · 0.80
charAtMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…