-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from mahabubx7/15-docs-api-ref
feat: #15 docs are complete
- Loading branch information
Showing
13 changed files
with
4,537 additions
and
59 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.