toNumber
lang
Converts value to a number.
Installation
Import
import { toNumber } from '@tulx/utils';Source Code
Implementation
/**
* Converts value to a number.
*
* @param value - The value to convert.
* @returns Returns the converted number.
*
* @example
* ```ts
* toNumber(3.2); // 3.2
* toNumber(Number.MIN_VALUE); // 5e-324
* toNumber(Infinity); // Infinity
* toNumber('3.2'); // 3.2
* ```
*/
export function toNumber(value: unknown): number {
return Number(value);
}
Example
import { toNumber } from '@tulx/utils';
toNumber(3.2); // 3.2
toNumber(Number.MIN_VALUE); // 5e-324
toNumber(Infinity); // Infinity
toNumber('3.2'); // 3.2Related Functions
castArray
Casts value as an array if it's not one.
clone
Creates a shallow clone of value.
cloneDeep
This method is like clone except that it recursively clones value.
cloneDeepWith
This method is like cloneDeep except that it accepts customizer which is invoked to produce the cloned value.
cloneWith
This method is like clone except that it accepts customizer which is invoked to produce the cloned value.
conformsTo
Checks if object conforms to source by invoking the predicate properties of source with the corresponding property values of object.