UNPKG

@lou.codes/parsers

Version:

👁️‍🗨️ Parsers without nonsense

25 lines (24 loc) 764 B
import type { Radix } from "@lou.codes/types"; /** * Curried function to parse strings to numbers based on different radixes. * * @category Number * @remarks * Parses a `string` to a `number` with the given `radix`, returning `undefined` * instead of `NaN` if it fails. * @example * ```typescript * const parseDecimal = parseInteger(10); * * parseDecimal("101"); // 101 * parseDecimal("101.5"); // 101 * parseDecimal("invalid"); // undefined * ``` * @see {@link undefineNaN} * * @param radix Radix to use for parsing (`16` for hexadecimal, `10` for decimal, and so on). * @returns Curried function with `radix` in context. */ export declare const parseInteger: ( radix: Radix, ) => (string: string) => import("@lou.codes/types").Maybe<number>;