https://github.com/softstack/joi-bigint
https://github.com/softstack/joi-bigint
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/softstack/joi-bigint
- Owner: softstack
- License: mit
- Created: 2023-08-01T13:06:07.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-04T18:53:51.000Z (over 1 year ago)
- Last Synced: 2025-05-11T12:56:20.830Z (about 2 months ago)
- Language: TypeScript
- Size: 104 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# joi-bigint
Joi extension for bigint
## Features
- Converts number and string.
- The supported rules are: greater, less, max, min, multiple, negative, port, positive and sign## Usage
```typescript
import BaseJoi from 'joi';
import { extendJoi } from '@softstack/joi-bigint';const Joi = extendJoi(BaseJoi);
const schema = Joi.bigint().min(3n).required();const result1 = schema.validate(3n);
console.log(result1);
// { value: 3n }const result2 = schema.validate(3);
console.log(result2);
// { value: 3n }const result3 = schema.validate('3');
console.log(result3);
// { value: 3n }const result4 = schema.validate(123.456);
console.log(result4);
// {
// value: 123.456,
// error: [Error [ValidationError]: "value" must be a bigint] {
// _original: 123.456,
// details: [ [Object] ]
// }
// }const result5 = schema.validate(2n);
console.log(result5);
// {
// value: 2n,
// error: [Error [ValidationError]: "value" must be greater than or equal to 3] {
// _original: 2n,
// details: [ [Object] ]
// }
// }
```