1.0.3 • Published 9 months ago

akarjs v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Docs are available now! But still working on it.

Installation

npm install akarjs

Example usages

Here is an example of the use cases for this library.

User Schema

import { a, InferSchema, InferSchemaWithConditions } from "akarjs"

const userSchema = a.object({
  name: a.string().min(4),
  age: a.number().integer().min(15).optional()
})

// now, parse it to get: ValidationResult OR ValidationErrors
console.log(userSchema.parse({ name: "Mahabub" }))
// Success: { value: { name: "Mahabub" } }

console.log(userSchema.parse({ name: "Mahabub", age: 26 }))
// Success: { value: { name: "Mahabub", age: 26 } }

console.log(userSchema.parse({ name: "Mahabub", age: 10 }))
// Error: { errors: [{ reason: "Minimum age value is >= 15", field: "age", value: 10 }] }

console.log(userSchema.parse({ age: 10 }))
// Error: { errors: [{ reason: "name is required", field: "name", value: undefiend }] }

// Infer types
type UserTypeNormal = InferSchema<typeof userSchema>
// it will get type as:
/*
type UserTypeNormal = {
  name: string;
  age: number | undefined;
}
*/

type UserTypeWithConditionals = InferSchemaWithConditions<typeof userSchema>
// it will get type as:
/*
type UserTypeWithConditionals = {
  name: string;
} & {
  age?: number;
}
*/

For more, please visit our documentation website: akar.js.org

Made with 💚 by @mahabubx7

Thanks,

~/Mahabub

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

1.0.0-beta.2

9 months ago

1.0.0-beta.1

9 months ago

1.0.0-beta.0

9 months ago