zod-bignumber
v1.0.6
Published
BigNumber type for Zod
Downloads
2,436
Readme
zod-bignumber
BigNumber type for Zod
.
Installation
npm install zod-bignumber
ℹ️ In case you are contributing: this project uses
XO
for linting. Install the plugin of your editor for improved developer experience.
Usage
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' }
Params
coerce
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' }
base
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' }
License
Licensed under MIT