UNPKG

@float-toolkit/react

Version:

A React hook wrapper for Float Toolkit

69 lines 2.6 kB
import FloatToolkit from "@float-toolkit/core"; declare namespace ReactFT { /** * An integer between 1 and 17, which can be used as the default precision for the `useFloatToolkit` hook. */ type Precision = FloatToolkit.Precision; /** * Options that can be set to modify the behavior of the `useFloatToolkit` hook. */ interface Options extends FloatToolkit.Options { } /** * An object containing the version of a FloatToolkit package. */ interface Version extends FloatToolkit.Version { } /** * Contains the version of `@float-toolkit/core` used by the React hook. */ const CORE_VERSION: Version; const VERSION: Version; } /** * Contains the properties and methods from the FloatToolkit class, as well as special ones for React. */ interface ReactFT { /** * An integer between 1 and 17. * Defines the precision (number of decimals) to use by default, if the precision is not specified in the method itself. */ get defaultPrecision(): ReactFT.Precision; set defaultPrecision(newPrecision: ReactFT.Precision); /** * The options object used in this instance of useFloatToolkit. */ get options(): ReactFT.Options; add(numbers: number[], precision?: ReactFT.Precision): number; divide(numbers: number[], precision?: ReactFT.Precision): number; multiply(numbers: number[], precision?: ReactFT.Precision): number; resetOptions(options?: Partial<ReactFT.Options>, resetOutput?: boolean): ReactFT.Options; round(n: number, precision?: ReactFT.Precision): number; setOptions(options?: Partial<ReactFT.Options>, resetOutput?: boolean): ReactFT.Options; subtract(numbers: number[], precision?: ReactFT.Precision): number; /** * A reactive state variable containing the returned value from the last method called. */ output: number; /** * Resets the output to 0. */ resetOutput(): void; } /** * A React hook that returns FloatToolkit methods and an `output` state. * * @param defaultPrecision The precision (number of decimals) to use if not specified in the method itself. Can be changed later. Default value if 10. * @param options An optional configuration object. * * @example * import useFloatToolkit from "@float-toolkit/react"; * * function Sum() { * const { add, output } = useFloatToolkit(2); * } */ declare function useFloatToolkit(defaultPrecision?: ReactFT.Precision, options?: ReactFT.Options): ReactFT; export default useFloatToolkit; export { ReactFT }; //# sourceMappingURL=index.d.ts.map