Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mahabubx7/akar
Akar is a typescript first schema validation library offering flexible, reusable schema for multi-purpose use cases
https://github.com/mahabubx7/akar
akar akarjs
Last synced: 1 day ago
JSON representation
Akar is a typescript first schema validation library offering flexible, reusable schema for multi-purpose use cases
- Host: GitHub
- URL: https://github.com/mahabubx7/akar
- Owner: mahabubx7
- License: mit
- Created: 2024-10-08T19:16:29.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-10-30T13:39:29.000Z (16 days ago)
- Last Synced: 2024-10-30T14:41:35.440Z (16 days ago)
- Topics: akar, akarjs
- Language: TypeScript
- Homepage: http://akar.js.org/
- Size: 3.25 MB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![Run Linters](https://github.com/mahabubx7/akar/actions/workflows/linter.yml/badge.svg)](https://github.com/mahabubx7/akar/actions/workflows/linter.yml) [![Build and Deploy to GitHub Pages](https://github.com/mahabubx7/akar/actions/workflows/pages.yml/badge.svg)](https://github.com/mahabubx7/akar/actions/workflows/pages.yml)
> Docs are available now! But still working on it.
### Installation
```sh [npm]
npm install akarjs
```### Example usages
Here is an example of the use cases for this library.
**User Schema**
```ts
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
// it will get type as:
/*
type UserTypeNormal = {
name: string;
age: number | undefined;
}
*/type UserTypeWithConditionals = InferSchemaWithConditions
// it will get type as:
/*
type UserTypeWithConditionals = {
name: string;
} & {
age?: number;
}
*/
```_For more, please visit our documentation website: [akar.js.org](https://akar.js.org)_
Made with 💚 by @mahabubx7
Thanks,
~/[Mahabub](https://mahabubx7.netlify.app)