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

Function numberAttribute

packages/core/src/util/coercion.ts:41–47  ·  view source on GitHub ↗
(value: unknown, fallbackValue = NaN)

Source from the content-addressed store, hash-verified

39 * @see [Built-in transformations](guide/components/inputs#built-in-transformations)
40 */
41export function numberAttribute(value: unknown, fallbackValue = NaN): number {
42 // parseFloat(value) handles most of the cases we're interested in (it treats null, empty string,
43 // and other non-number values as NaN, where Number just uses 0) but it considers the string
44 // '123hello' to be a valid number. Therefore we also check if Number(value) is NaN.
45 const isNumberValue = !isNaN(parseFloat(value as any)) && !isNaN(Number(value));
46 return isNumberValue ? Number(value) : fallbackValue;
47}

Callers 1

coercion_spec.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected