UNPKG

@terminus/ngx-tools

Version:

[![CircleCI][circle-badge]][circle-link] [![codecov][codecov-badge]][codecov-project] [![semantic-release][semantic-release-badge]][semantic-release] [![MIT License][license-image]][license-url] <br> [![NPM version][npm-version-image]][npm-url] [![Github

26 lines (25 loc) 1.08 kB
/** * Coerces a data-bound value (typically a string) to a number. * * @param value - The value to coerce to a number * @param fallbackValue - The value to return if the value is not a valid number * * @example * coerceNumberProperty('12'); // Returns: 12 * coerceNumberProperty<boolean>('foo', false); // Returns: false */ export declare function coerceNumberProperty(value: any): number; export declare function coerceNumberProperty<D>(value: any, fallback: D): number | D; /** * Whether the provided value is considered a number. * * ParseFloat(value) handles most of the cases we're interested in (it treats null, empty string, * and other non-number values as NaN, where Number just uses 0) but it considers the string * '123hello' to be a valid number. Therefore we also check if Number(value) is NaN. * NOTE: TypeScript seems to consider `parseFloat(value)` unsafe. In my tests there are no values which `parseFloat` * cannot handle safely. * * @private * @param value */ export declare const isNumberValue: (value: any) => boolean;