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

Method transform

packages/common/src/pipes/number_pipe.ts:279–314  ·  view source on GitHub ↗
(
    value: number | string | null | undefined,
    currencyCode: string = this._defaultCurrencyCode,
    display: 'code' | 'symbol' | 'symbol-narrow' | string | boolean = 'symbol',
    digitsInfo?: string,
    locale?: string,
  )

Source from the content-addressed store, hash-verified

277 locale?: string,
278 ): string | null;
279 transform(
280 value: number | string | null | undefined,
281 currencyCode: string = this._defaultCurrencyCode,
282 display: 'code' | 'symbol' | 'symbol-narrow' | string | boolean = 'symbol',
283 digitsInfo?: string,
284 locale?: string,
285 ): string | null {
286 if (!isValue(value)) return null;
287
288 locale ||= this._locale;
289
290 if (typeof display === 'boolean') {
291 if (typeof ngDevMode === 'undefined' || ngDevMode) {
292 console.warn(
293 `Warning: the currency pipe has been changed in Angular v5. The symbolDisplay option (third parameter) is now a string instead of a boolean. The accepted values are "code", "symbol" or "symbol-narrow".`,
294 );
295 }
296 display = display ? 'symbol' : 'code';
297 }
298
299 let currency: string = currencyCode || this._defaultCurrencyCode;
300 if (display !== 'code') {
301 if (display === 'symbol' || display === 'symbol-narrow') {
302 currency = getCurrencySymbol(currency, display === 'symbol' ? 'wide' : 'narrow', locale);
303 } else {
304 currency = display;
305 }
306 }
307
308 try {
309 const num = strToNumber(value);
310 return formatCurrency(num, locale, currency, currencyCode, digitsInfo);
311 } catch (error) {
312 throw invalidPipeArgumentError(CurrencyPipe, (error as Error).message);
313 }
314 }
315}
316
317function isValue(value: number | string | null | undefined): value is number | string {

Callers

nothing calls this directly

Calls 6

getCurrencySymbolFunction · 0.90
formatCurrencyFunction · 0.90
invalidPipeArgumentErrorFunction · 0.90
isValueFunction · 0.85
strToNumberFunction · 0.85
warnMethod · 0.65

Tested by

no test coverage detected