Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #15 docs are complete #17

Merged
merged 4 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading