Last change
on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
3.1 KB
|
Line | |
---|
1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | export function coerceNumberProperty(value, fallbackValue = 0) {
|
---|
9 | return _isNumberValue(value) ? Number(value) : fallbackValue;
|
---|
10 | }
|
---|
11 | /**
|
---|
12 | * Whether the provided value is considered a number.
|
---|
13 | * @docs-private
|
---|
14 | */
|
---|
15 | export function _isNumberValue(value) {
|
---|
16 | // parseFloat(value) handles most of the cases we're interested in (it treats null, empty string,
|
---|
17 | // and other non-number values as NaN, where Number just uses 0) but it considers the string
|
---|
18 | // '123hello' to be a valid number. Therefore we also check if Number(value) is NaN.
|
---|
19 | return !isNaN(parseFloat(value)) && !isNaN(Number(value));
|
---|
20 | }
|
---|
21 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnVtYmVyLXByb3BlcnR5LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9jb2VyY2lvbi9udW1iZXItcHJvcGVydHkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBV0gsTUFBTSxVQUFVLG9CQUFvQixDQUFDLEtBQVUsRUFBRSxhQUFhLEdBQUcsQ0FBQztJQUNoRSxPQUFPLGNBQWMsQ0FBQyxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUMsQ0FBQyxhQUFhLENBQUM7QUFDL0QsQ0FBQztBQUVEOzs7R0FHRztBQUNILE1BQU0sVUFBVSxjQUFjLENBQUMsS0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