From 62607f04ff7b4a9f43dfad9577af56c38f460e78 Mon Sep 17 00:00:00 2001 From: Yamiteru Date: Mon, 29 Apr 2024 22:22:51 +0200 Subject: [PATCH] feat: update docs --- README.md | 9 +++++---- package.json | 3 ++- src/assertions/modulo/index.ts | 14 ++++++++++++++ src/assertions/or2/index.ts | 4 ++-- src/error.ts | 10 +++------- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index fbe9257..4f005f6 100644 --- a/README.md +++ b/README.md @@ -143,12 +143,13 @@ As a result it has many opinions that might not sit well with some folks. `Validator` is an obsessed overachiever who wants to be the smallest and fastest one on the track. -- 39 `Assertion`s -- 808 bytes bundle +- 40 `Assertion`s +- 835 bytes bundle - ~ 5x faster data validation than `Zod` - ~ 200x less memory consumption than `Zod` - ~ 50x faster type-checking than `Zod` -- 0 runtime dependencies +- 1 runtime dependency + - [@the-minimal/error](https://github.com/the-minimal/error) (135 bytes) - 100% test coverage ## Simple examples @@ -201,7 +202,7 @@ As a result it has many opinions that might not sit well with some folks. friends: array(string) }); - register("Oh not this is gonna throw"); + register("Oh no this is gonna throw"); register({ email: "yamiteru@icloud.com", diff --git a/package.json b/package.json index 29c0017..059f919 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "access": "public" }, "dependencies": { - "@the-minimal/types": "0.4.0" + "@the-minimal/types": "0.4.0", + "@the-minimal/error": "0.1.0" } } diff --git a/src/assertions/modulo/index.ts b/src/assertions/modulo/index.ts index 0c79788..b079944 100644 --- a/src/assertions/modulo/index.ts +++ b/src/assertions/modulo/index.ts @@ -1,6 +1,20 @@ import { error } from "@error"; import type { Assertion } from "@the-minimal/types"; +/** + * Checks if the remainer is equal to the specified value when the input is divided by the divider. + * + * @param divider - Value used for the division. + * @param remainder - Value that should remain after the division is done. + * + * @example + * ```ts + * const multipleOfTwo = modulo(2, 0); + * + * multipleOfTwo(3); // Error: modulo + * multipleOfTwo(6); // passes + * ``` + */ export const modulo = (divider: number, remainder: number): Assertion => (v: unknown) => diff --git a/src/assertions/or2/index.ts b/src/assertions/or2/index.ts index 1b34cce..afb1022 100644 --- a/src/assertions/or2/index.ts +++ b/src/assertions/or2/index.ts @@ -5,8 +5,8 @@ import type { Assertion } from "@the-minimal/types"; * * If none of them passes it throws an error. * - * @param brand1 - First assertion to be checked. - * @param brand2 - Second assertion to be checked. + * @param assertion1 - First assertion to be checked. + * @param assertion2 - Second assertion to be checked. * * @example * ```ts diff --git a/src/error.ts b/src/error.ts index 839a870..689642b 100644 --- a/src/error.ts +++ b/src/error.ts @@ -1,7 +1,3 @@ -export const error = (cause: unknown, message = "") => { - throw { - name: "Validation", - message, - cause, - }; -}; +import { error as minimalError } from "@the-minimal/error"; + +export const error = minimalError("Assertion");