zod-bignumber
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

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

Package Sidebar

Install

npm i zod-bignumber

Weekly Downloads

104

Version

1.0.6

License

MIT

Unpacked Size

15.4 kB

Total Files

7

Last publish

Collaborators

  • satazor