extractNumber
Extracts the first number embedded anywhere in a string, or passes through a number.
Unlike a plain parseFloat/parseInt, the number does not need to be at the start of
the string: digits are searched for anywhere, so leading/trailing text (units, labels, …)
is ignored. A - before the digits and a scientific-notation suffix (e/E) are
disambiguated with ExtractNumberOptions.sign and ExtractNumberOptions.exponent.
Returns undefined if no number can be found.
Available since v2.0.4
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to extract a number from |
options | ExtractNumberOptions | Options controlling sign and exponent disambiguation |
Returns
Section titled “Returns”number | undefined — The extracted number, or undefined if none was found
