1.0.2 • Published 2 days ago

@schemasjs/zod-numbers v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 days ago

@SchemasJS/zod-numbers

build

Zod schemas for numbers and their types.

Numbers

DataSchemaTypeValues
Unsigned integers
Unsigned integer 8 bitsUint8SchemaUint80 to 255
Unsigned integer 16 bitsUint16SchemaUint160 to 65535
Unsigned integer 32 bitsUint32SchemaUint320 to 4294967295
Unsigned Big IntegerBigUintSchemaBigUint0 to 2^64-1
Integers
Integer 8 bitsInt8SchemaInt8-128 to 127
Integer 16 bitsInt16SchemaInt16-32768 to 32767
Integer 32 bitsInt32SchemaInt32-2147483648 to 2147483647
Big IntegerBigIntSchemabuilt-in TS-2^63 to 2^63-1
Floats
Float 32 bitFloat32SchemaFloat32-3.4e38 to 3.4e38
Float 64 bitFloat64SchemaFloat64-1.8e308 to 1.8e308

Typed Arrays

It contains typed arrays too.

DataSchemaTypeValues
Unsigned integers
Unsigned integer 8 bitsUint8ArraySchemabuilt-in TS0 to 255
Unsigned integer 16 bitsUint16ArraySchemabuilt-in TS0 to 65535
Unsigned integer 32 bitsUint32ArraySchemabuilt-in TS0 to 4294967295
Unsigned Big IntegerBigUint64ArraySchemabuilt-in TS0 to 2^64-1
Integers
Integer 8 bitsInt8ArraySchemabuilt-in TS-128 to 127
Integer 16 bitsInt16ArraySchemabuilt-in TS-32768 to 32767
Integer 32 bitsInt32ArraySchemabuilt-in TS-2147483648 to 2147483647
Big IntegerBigInt64ArraySchemabuilt-in TS-2^63 to 2^63-1
Floats
Float 32 bitFloat32ArraySchemabuilt-in TS-3.4e38 to 3.4e38
Float 64 bitFloat64ArraySchemabuilt-in TS-1.8e308 to 1.8e308

There is a cool feature: It is added if you introduce a number, it could be transformed into an typed array. For example:

import { Uint8ArraTransform, Uint16ArrayTransform } from @schemasjs/zod-numbers

const num = 256

console.log(Uint8ArrayTransform.parse(num)) // [255, 1]
console.log(Uint16ArrayTransform.parse(num)) // [256]
DataSchemaTypeValues
Unsigned integers
Unsigned integer 8 bitsUint8ArrayTransformbuilt-in TS0 to 255
Unsigned integer 16 bitsUint16ArrayTransformbuilt-in TS0 to 65535
Unsigned integer 32 bitsUint32ArrayTransformbuilt-in TS0 to 4294967295
Unsigned Big IntegerBigUint64ArrayTransformbuilt-in TS0 to 2^64-1
Integers
Integer 8 bitsInt8ArrayTransformbuilt-in TS-128 to 127
Integer 16 bitsInt16ArrayTransformbuilt-in TS-32768 to 32767
Integer 32 bitsInt32ArrayTransformbuilt-in TS-2147483648 to 2147483647
Big IntegerBigInt64ArrayTransformbuilt-in TS-2^63 to 2^63-1
Floats
Float 32 bitFloat32ArrayTransformbuilt-in TS-3.4e38 to 3.4e38
Float 64 bitFloat64ArrayTransformbuilt-in TS-1.8e308 to 1.8e308