From 51d34a603d403b904a9fff49c1e127070c313054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20=C3=98sterkilde?= Date: Tue, 30 Jul 2024 21:11:36 +0200 Subject: [PATCH] feat(validathor): Rename args to modifiers (#17) * feat(lib): rename args to modifiers This better indicates the expected intent to the end user * feat(lib): bump version * chore(lib): remove nonexistent schema export --- packages/validathor/CHANGELOG.md | 6 ++++++ packages/validathor/package.json | 2 +- packages/validathor/src/schemas/boolean.ts | 6 +++--- packages/validathor/src/schemas/date.ts | 9 ++++++--- packages/validathor/src/schemas/enum.ts | 6 +++--- packages/validathor/src/schemas/number.ts | 6 +++--- packages/validathor/src/schemas/string.ts | 6 +++--- 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/packages/validathor/CHANGELOG.md b/packages/validathor/CHANGELOG.md index 0f6b617..312e27c 100644 --- a/packages/validathor/CHANGELOG.md +++ b/packages/validathor/CHANGELOG.md @@ -1,5 +1,11 @@ # @nordic-ui/validathor +## 0.0.4 + +### Patch Changes + +- Rename schema `args` to `modifiers` to better indicate intent to end user + ## 0.0.3 ### Patch Changes diff --git a/packages/validathor/package.json b/packages/validathor/package.json index 0257097..75ee659 100644 --- a/packages/validathor/package.json +++ b/packages/validathor/package.json @@ -1,6 +1,6 @@ { "name": "@nordic-ui/validathor", - "version": "0.0.3", + "version": "0.0.4", "description": "A simple validation library", "author": "Kevin Østerkilde ", "main": "dist/index.cjs.js", diff --git a/packages/validathor/src/schemas/boolean.ts b/packages/validathor/src/schemas/boolean.ts index 260665e..d66cc80 100644 --- a/packages/validathor/src/schemas/boolean.ts +++ b/packages/validathor/src/schemas/boolean.ts @@ -4,10 +4,10 @@ import type { Parser } from '@/types' import { assert, TypeError } from '@/utils' import { ERROR_CODES } from '@/utils/errors/errorCodes' -export type BooleanSchemaArgs = Array> +export type BooleanSchemaModifiers = Array> export const boolean = ( - args?: BooleanSchemaArgs, + modifiers?: BooleanSchemaModifiers, message?: { type_error?: string }, @@ -19,7 +19,7 @@ export const boolean = ( new TypeError(message?.type_error || ERROR_CODES.ERR_TYP_7000.message()), ) - validateModifiers(value, args) + validateModifiers(value, modifiers) return value }, diff --git a/packages/validathor/src/schemas/date.ts b/packages/validathor/src/schemas/date.ts index 7f02349..e940cdf 100644 --- a/packages/validathor/src/schemas/date.ts +++ b/packages/validathor/src/schemas/date.ts @@ -4,9 +4,12 @@ import type { Parser } from '@/types' import { assert, TypeError } from '@/utils' import { ERROR_CODES } from '@/utils/errors/errorCodes' -export type DateSchemaArgs = Array | Max | Custom> +export type DateSchemaModifiers = Array | Max | Custom> -export const date = (args?: DateSchemaArgs, message?: { type_error?: string }): Parser => ({ +export const date = ( + modifiers?: DateSchemaModifiers, + message?: { type_error?: string }, +): Parser => ({ name: 'date' as const, parse: (value: unknown) => { assert( @@ -14,7 +17,7 @@ export const date = (args?: DateSchemaArgs, message?: { type_error?: string }): new TypeError(message?.type_error || ERROR_CODES.ERR_TYP_3000.message()), ) - validateModifiers(value, args) + validateModifiers(value, modifiers) return value }, diff --git a/packages/validathor/src/schemas/enum.ts b/packages/validathor/src/schemas/enum.ts index 1b2b643..03c9ffc 100644 --- a/packages/validathor/src/schemas/enum.ts +++ b/packages/validathor/src/schemas/enum.ts @@ -2,10 +2,10 @@ import type { Parser } from '@/types' import { assert, TypeError, ValidationError } from '@/utils' import { ERROR_CODES } from '@/utils/errors/errorCodes' -export type EnumSchemaArgs = Array +export type EnumSchemaModifiers = Array export const enum_ = ( - args?: EnumSchemaArgs, + modifiers?: EnumSchemaModifiers, message?: { type_error?: string error?: string | ((value: string | number) => string) @@ -19,7 +19,7 @@ export const enum_ = ( ) assert( - (args ?? []).includes(value), + (modifiers ?? []).includes(value), new ValidationError( typeof message?.error === 'function' ? message?.error(value) diff --git a/packages/validathor/src/schemas/number.ts b/packages/validathor/src/schemas/number.ts index 3e42765..fbb0a11 100644 --- a/packages/validathor/src/schemas/number.ts +++ b/packages/validathor/src/schemas/number.ts @@ -4,12 +4,12 @@ import type { Parser } from '@/types' import { assert, TypeError } from '@/utils' import { ERROR_CODES } from '@/utils/errors/errorCodes' -export type NumberSchemaArgs = Array< +export type NumberSchemaModifiers = Array< Min | Max | Enumerator | Custom > export const number = ( - args?: NumberSchemaArgs, + modifiers?: NumberSchemaModifiers, message?: { type_error?: string }, @@ -25,7 +25,7 @@ export const number = ( new TypeError(message?.type_error || ERROR_CODES.ERR_TYP_1001.message()), ) - validateModifiers(value, args) + validateModifiers(value, modifiers) return value }, diff --git a/packages/validathor/src/schemas/string.ts b/packages/validathor/src/schemas/string.ts index 4edf1bc..ee632a7 100644 --- a/packages/validathor/src/schemas/string.ts +++ b/packages/validathor/src/schemas/string.ts @@ -6,12 +6,12 @@ import { assert, TypeError } from '@/utils' import { ERROR_CODES } from '@/utils/errors/errorCodes' /** An array of the accepted modifier types */ -export type StringSchemaArgs = Array< +export type StringSchemaModifiers = Array< Min | Max | Email | Enumerator | Custom > export const string = ( - args?: StringSchemaArgs, + modifiers?: StringSchemaModifiers, message?: { type_error?: string }, @@ -24,7 +24,7 @@ export const string = ( ) assert(value !== '', new TypeError(message?.type_error || ERROR_CODES.ERR_VAL_2000.message())) - validateModifiers(value, args) + validateModifiers(value, modifiers) return value },