import { Maybe } from 'yummies/types'; interface NumberParserSettings { digits?: number; fallback?: TFallback; /** * Round to upper boundary * 5.1 -> 6 */ ceil?: boolean; /** * Round to bottom boundary * 5.9 -> 5 */ floor?: boolean; clamped?: [min?: Maybe, max?: Maybe]; } /** * Parses a number from raw input and optionally clamps, rounds or limits * fractional digits. * * Strings are normalized by removing spaces and replacing `,` with `.` before * parsing. Invalid inputs return the configured fallback. * * @template TFallback Fallback value type returned when parsing fails. * @param input Raw value to parse. * @param userSettings Parser settings merged with `number.defaultSettings`. * @returns Parsed number or fallback value. * * @example * ```ts * number('1 234,5'); // 1234.5 * ``` * * @example * ```ts * number('bad', { fallback: 0 }); // 0 * ``` */ declare const number: { (input: Maybe, userSettings?: Maybe>): number | TFallback; defaultSettings: NumberParserSettings; }; /** * Converts a value into a percentage of `maxValue` and parses the result with * the shared numeric parser. * * @template TFallback Fallback value type returned when parsing fails. * @param value Current value. * @param maxValue Maximum value representing `100%`. * @param settings Numeric parser settings for the computed percentage. * @returns Parsed percentage or fallback value. * * @example * ```ts * percent(25, 200); // 12.5 * ``` * * @example * ```ts * percent('bad', 100, { fallback: 0 }); // 0 * ``` */ declare const percent: (value: Maybe, maxValue?: Maybe, settings?: Maybe>) => number | TFallback; interface StringParserSettings { fallback?: TFallback; prettyJson?: boolean; } /** * Converts arbitrary input into a string representation. * * Objects are serialized with `JSON.stringify`, optionally pretty-printed, and * nullish values resolve to the configured fallback. * * @template TFallback Fallback value type returned for nullish input. * @param input Raw value to stringify. * @param settings String conversion settings. * @returns Stringified input or fallback value. * * @example * ```ts * string(123); // '123' * ``` * * @example * ```ts * string({ id: 1 }, { prettyJson: true }); * ``` */ declare const string: (input: Maybe, settings?: Maybe>) => string | TFallback; /** * ---header-docs-section--- * # yummies/parser * * ## Description * * Parsers for user-entered **numbers, percents, and strings** with tolerant input and typed * results. Use when normalizing form values, query params, or CSV-like text before validation * schemas run, without duplicating regex and `parseFloat` edge cases in every feature module. * * ## Usage * * ```ts * import { parser } from "yummies/parser"; * ``` */ type _exports_NumberParserSettings = NumberParserSettings; type _exports_StringParserSettings = StringParserSettings; declare const _exports_number: typeof number; declare const _exports_percent: typeof percent; declare const _exports_string: typeof string; declare namespace _exports { export { _exports_number as number, _exports_percent as percent, _exports_string as string }; export type { _exports_NumberParserSettings as NumberParserSettings, _exports_StringParserSettings as StringParserSettings }; } export { _exports as parser };