Skip to content

Commit

Permalink
Merge pull request #17 from mahabubx7/15-docs-api-ref
Browse files Browse the repository at this point in the history
feat: #15 docs are complete
  • Loading branch information
mahabubx7 authored Oct 20, 2024
2 parents da5fc6c + 3711924 commit 2952c86
Show file tree
Hide file tree
Showing 13 changed files with 4,537 additions and 59 deletions.
475 changes: 474 additions & 1 deletion docs/api/array.md

Large diffs are not rendered by default.

100 changes: 98 additions & 2 deletions docs/api/boolean.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,101 @@
# Boolean

::: info
Work in progress ⏳
## Summary

Boolean is a data type that can have one of two values: `true` or `false`.

## Table of Contents

- [Schema & Validators](#schema--validators)
- [default](#default)
- [exact](#exact)
- [Conclusion](#conclusion)

## Schema & Validators

## default

By default, the boolean schema does not have any validators. It only checks if the value is a boolean.

::: code-group

```typescript
// define a schema for boolean
const booleanSchema = a.boolean()

// validate & parse the boolean
const resultOne = booleanSchema.parse(true) // valid
const resultTow = booleanSchema.parse(false) // valid

console.log(resultOne, resultTow)
```

```javascript
// define a schema for boolean
const booleanSchema = a.boolean()

// validate & parse the boolean
const resultOne = booleanSchema.parse(true) // valid
const resultTow = booleanSchema.parse(false) // valid

console.log(resultOne, resultTow)
```

:::

**Output**

```bash
{ value: true }

{ value: false }
```
## `.exact(value: boolean)`
The `exact` validator checks if the value is exactly equal to the provided value.
::: code-group
```typescript
// define a schema for boolean with exact validator
const booleanSchema = a.boolean().exact(true)
// validate & parse the boolean
const resultOne = booleanSchema.parse(true) // valid
const resultTow = booleanSchema.parse(false) // invalid
console.log(resultOne, resultTow)
```
```javascript
// define a schema for boolean with exact validator
const booleanSchema = a.boolean().exact(true)
// validate & parse the boolean
const resultOne = booleanSchema.parse(true) // valid
const resultTow = booleanSchema.parse(false) // invalid
console.log(resultOne, resultTow)
```
:::
**Output**
```bash
{ value: true }
{
errors: [
{
reason: 'Value must be true',
value: false
}
]
}
```
## Conclusion
In this chapter, we learned about the Boolean data type. We learned that it can have one of two values: `true` or `false`.
131 changes: 129 additions & 2 deletions docs/api/enum.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,132 @@
# Enum

::: info
Work in progress ⏳
## Summary

Enum is a data type that can have one of a specific set of values. It is similar to a string, but it is limited to a specific set of values.

## Table of Contents

- [Schema & Validators](#schema--validators)
- [default](#default)
- [Conclusion](#conclusion)

## Schema & Validators

::: code-group

```typescript
// define a schema for enum
const enumSchema = a.enum(["red", "green", "blue"] as const)

// validate & parse the enum
const resultOne = enumSchema.parse("red") // valid
const resultTow = enumSchema.parse("green") // valid
const resultThree = enumSchema.parse("blue") // valid
/*
* You might not be able to insert any other value other than the specified values
* while writing the code in TypeScript, but you can insert any value in JavaScript. Specify the values as const to prevent this.
*/
// const resultFour = enumSchema.parse("yellow") // invalid

console.log(resultOne, resultTow, resultThree)
```

```javascript
// define a schema for enum
const enumSchema = a.enum(["red", "green", "blue"])

// validate & parse the enum
const resultOne = enumSchema.parse("red") // valid
const resultTow = enumSchema.parse("green") // valid
const resultThree = enumSchema.parse("blue") // valid
/*
* You might not be able to insert any other value other than the specified values
* while writing the code in TypeScript, but you can insert any value in JavaScript. Specify the values as const to prevent this.
*/
const resultFour = enumSchema.parse("yellow") // invalid

console.log(resultOne, resultTow, resultThree, resultFour)
```

:::

**Output**

::: code-group

```bash [typescript]
{ value: 'red' }

{ value: 'green' }

{ value: 'blue' }
```
```bash [javascript]
{ value: 'red' }

{ value: 'green' }

{ value: 'blue' }

{
errors: [
{
reason: 'Value must be one of the specified values',
value: 'yellow'
}
]
}
```
:::
## `.default(value: string)`
The `default` validator sets the default value of the schema if the value is `undefined`.
::: code-group
```typescript
// define a schema for enum with default value
const enumSchema = a.enum(["red", "green", "blue"] as const).default("red")
// validate & parse the enum
const resultOne = enumSchema.parse(undefined) // valid
const resultTow = enumSchema.parse("green") // valid
console.log(resultOne, resultTow)
```
```javascript
// define a schema for enum with default value
const enumSchema = a.enum(["red", "green", "blue"]).default("red")
// validate & parse the enum
const resultOne = enumSchema.parse(undefined) // valid
const resultTow = enumSchema.parse("green") // valid
console.log(resultOne, resultTow)
```
:::
**Output**
::: code-group
```bash [typescript]
{ value: 'red' }
{ value: 'green' }
```
```bash [javascript]
{ value: 'red' }
{ value: 'green' }
```
## Conclusion
This is the end of the Enum documentation. If you have any questions or suggestions, please feel free to open an issue on the [GitHub repository](https://github.com/mahabubx7/akar)
11 changes: 8 additions & 3 deletions docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

Welcome to the `Akar.js`. This page will walk you through the available API references of this library.

::: info
Work in progress ⏳
:::
## Table of Contents

- [Array](/api/array)
- [Object](/api/object)
- [String](/api/string)
- [Number](/api/number)
- [Enum](/api/enum)
- [Boolean](/api/boolean)
Loading

0 comments on commit 2952c86

Please sign in to comment.