Back to results
satazor/zod-bignumber(opens in a new tab)
Language: TypeScript
BigNumber type for Zod
- stars
- 3
- watchers
- 1
- forks
- 0
- open issues
- 0
- Last updated
- 03/20/2023
Language: TypeScript
BigNumber type for Zod
BigNumber type for Zod.
npm install zod-bignumber
ℹ️ In case you are contributing: this project uses
XOfor linting. Install the plugin of your editor for improved developer experience.
Only input of type string is accepted by default. Output is the result of BigNumber#toString(10).
import { zBigNumber } from 'zod-bignumber'; zBigNumber().safeParse('2.91'); // { success: true, data: '2.91' } zBigNumber().safeParse('2.2222222222222224e+54'); // { success: true, data: '22222222222222222000000000000000000000000000000000000' }
Default value: false
Coerce input value to a string.
import { zBigNumber } from 'zod-bignumber'; zBigNumber({ coerce: true }).safeParse(2.91); // { success: true, data: '2.91' }
Default value: 10
Allows setting the base used when calling toString(base).
import { zBigNumber } from 'zod-bignumber'; zBigNumber({ base: 2 }).safeParse('2'); // { success: true, data: '10' }
You can pass null to not format the number:
import { zBigNumber } from 'zod-bignumber'; zBigNumber({ base: null }).safeParse('2.2222222222222224e+54'); // { success: true, data: '2.2222222222222224e+54' }
Licensed under MIT