@ripetchor/vivi 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -2
- package/dist/index.d.mts +7 -1
- package/dist/index.mjs +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Vivi
|
|
1
|
+
# Vivi
|
|
2
2
|
|
|
3
3
|
WARNING: This package is primarily intended for personal use. It may contain bugs or unexpected behavior. Use at your own risk.
|
|
4
4
|
|
|
@@ -38,6 +38,7 @@ import { stringValidator, numberValidator, refine /* etc. */ } from '@ripetchor/
|
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
### Primitive validation
|
|
41
|
+
|
|
41
42
|
```ts
|
|
42
43
|
const name = v.string().parse('Alice');
|
|
43
44
|
console.log(name); // Alice
|
|
@@ -50,6 +51,7 @@ console.log(active); // true
|
|
|
50
51
|
```
|
|
51
52
|
|
|
52
53
|
### Nullable and optional
|
|
54
|
+
|
|
53
55
|
```ts
|
|
54
56
|
const nullableName = v.nullable(v.string()).parse(null);
|
|
55
57
|
console.log(nullableName); // null
|
|
@@ -59,6 +61,7 @@ console.log(optionalAge); // undefined
|
|
|
59
61
|
```
|
|
60
62
|
|
|
61
63
|
### Array validation
|
|
64
|
+
|
|
62
65
|
```ts
|
|
63
66
|
const numbers = v.array(v.number()).parse([1, 2, 3]);
|
|
64
67
|
console.log(numbers); // [1, 2, 3]
|
|
@@ -72,6 +75,7 @@ console.log(users); // [{ name: 'Lana', age: 28 }, { name: 'Mikaela', age: 25 },
|
|
|
72
75
|
```
|
|
73
76
|
|
|
74
77
|
### Object validation
|
|
78
|
+
|
|
75
79
|
```ts
|
|
76
80
|
const exactUser = v.object({ name: v.string(), age: v.number() }, { mode: 'exact' }).parse({ name: 'Alice', age: 25 });
|
|
77
81
|
console.log(exactUser); // { name: 'Alice', age: 25 }
|
|
@@ -84,12 +88,14 @@ console.log(passthroughUser); // { name: 'Charlie', age: 40 }
|
|
|
84
88
|
```
|
|
85
89
|
|
|
86
90
|
### Union validation
|
|
91
|
+
|
|
87
92
|
```ts
|
|
88
93
|
const value = v.union([v.string(), v.number()]).parse('Hello');
|
|
89
94
|
console.log(value); // 'Hello'
|
|
90
95
|
```
|
|
91
96
|
|
|
92
97
|
### Literal validation
|
|
98
|
+
|
|
93
99
|
```ts
|
|
94
100
|
const l1 = v.literal("yes").parse("yes");
|
|
95
101
|
console.log(l1); // 'yes'
|
|
@@ -99,6 +105,7 @@ v.literal("yes").parse("yeS");
|
|
|
99
105
|
```
|
|
100
106
|
|
|
101
107
|
### Refinements
|
|
108
|
+
|
|
102
109
|
```ts
|
|
103
110
|
const schema = refine(
|
|
104
111
|
v.string(),
|
|
@@ -116,27 +123,56 @@ if (!result.success) {
|
|
|
116
123
|
} else {
|
|
117
124
|
console.log(result.data);
|
|
118
125
|
}
|
|
126
|
+
|
|
127
|
+
// =========================================
|
|
128
|
+
|
|
129
|
+
const userSchema = v.object({
|
|
130
|
+
password: v.string(),
|
|
131
|
+
confirmPassword: v.string(),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const refinedUserSchema = v.refine(userSchema, [
|
|
135
|
+
(user) =>
|
|
136
|
+
user.password === user.confirmPassword || {
|
|
137
|
+
path: ["confirmPassword"],
|
|
138
|
+
message: "Passwords do not match",
|
|
139
|
+
},
|
|
140
|
+
]);
|
|
141
|
+
|
|
142
|
+
const result = refinedUserSchema.safeParse({
|
|
143
|
+
password: "secret123",
|
|
144
|
+
confirmPassword: "secret321",
|
|
145
|
+
});
|
|
146
|
+
console.log(result); // [ { path: ["confirmPassword"], message "Passwordsdo not match"} ]
|
|
119
147
|
```
|
|
120
148
|
|
|
149
|
+
- `true` → validation passes
|
|
150
|
+
- `false` → generic "Refinement failed"
|
|
151
|
+
- `string` → error message with empy path
|
|
152
|
+
- `{ message, path }` → **precise error targeting**
|
|
153
|
+
|
|
121
154
|
### Fallback
|
|
155
|
+
|
|
122
156
|
```ts
|
|
123
157
|
const fallbackValue = v.fallback(v.number(), 42).parse('invalid');
|
|
124
158
|
console.log(fallbackValue); // 42
|
|
125
159
|
```
|
|
126
|
-
|
|
127
160
|
### Email validation
|
|
161
|
+
|
|
128
162
|
```ts
|
|
129
163
|
const email = v.email().parse('test@example.com');
|
|
130
164
|
console.log(email); // 'test@example.com'
|
|
131
165
|
```
|
|
132
166
|
|
|
133
167
|
### Date validation
|
|
168
|
+
|
|
134
169
|
```ts
|
|
135
170
|
const birthday = v.date().parse(new Date('1990-01-01'));
|
|
136
171
|
console.log(birthday); // 1990-01-01T00:00:00.000Z
|
|
137
172
|
```
|
|
138
173
|
|
|
139
174
|
### Pipe transformations
|
|
175
|
+
|
|
140
176
|
```ts
|
|
141
177
|
const transformed = v.pipe(
|
|
142
178
|
v.string(),
|
|
@@ -147,6 +183,7 @@ console.log(transformed); // 'HELLO'
|
|
|
147
183
|
```
|
|
148
184
|
|
|
149
185
|
### Safe parsing
|
|
186
|
+
|
|
150
187
|
```ts
|
|
151
188
|
const result1 = v.number().safeParse(123);
|
|
152
189
|
console.log(result1); // { success: true, data: 123 }
|
|
@@ -156,6 +193,7 @@ console.log(result2); // { success: false, error: ViviError }
|
|
|
156
193
|
```
|
|
157
194
|
|
|
158
195
|
### Abort on first issue
|
|
196
|
+
|
|
159
197
|
```ts
|
|
160
198
|
try {
|
|
161
199
|
v.array(v.number(), { abort: true }).parse([1, "x", 3, "y"]);
|
|
@@ -201,6 +239,7 @@ const value = v.match(
|
|
|
201
239
|
```
|
|
202
240
|
|
|
203
241
|
### Type inference
|
|
242
|
+
|
|
204
243
|
```ts
|
|
205
244
|
const userValidator = v.object({ name: v.string(), age: v.number() });
|
|
206
245
|
type User = v.infer<typeof userValidator>;
|
|
@@ -208,3 +247,81 @@ type User = v.infer<typeof userValidator>;
|
|
|
208
247
|
const user: User = { name: 'Alice', age: 25 };
|
|
209
248
|
console.log(user); // { name: 'Alice', age: 25 }
|
|
210
249
|
```
|
|
250
|
+
### Issues utils
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
import { v, flattenErrors, issuesToObject, issuesToString } from "@ripetchor/utils";
|
|
254
|
+
|
|
255
|
+
const schema = v.object({
|
|
256
|
+
user: v.object({
|
|
257
|
+
name: v.string(),
|
|
258
|
+
email: v.email(),
|
|
259
|
+
address: v.object({
|
|
260
|
+
street: v.string(),
|
|
261
|
+
city: v.string(),
|
|
262
|
+
zip: v.string(),
|
|
263
|
+
}),
|
|
264
|
+
}),
|
|
265
|
+
credentials: v.object({
|
|
266
|
+
password: v.string(),
|
|
267
|
+
confirmPassword: v.string(),
|
|
268
|
+
}),
|
|
269
|
+
agreeToTerms: v.literal(true),
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
const invalidData = {
|
|
273
|
+
user: {
|
|
274
|
+
name: 1,
|
|
275
|
+
email: 2,
|
|
276
|
+
address: {
|
|
277
|
+
street: 3,
|
|
278
|
+
city: 4,
|
|
279
|
+
zip: 5,
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
credentials: {
|
|
283
|
+
password: 6,
|
|
284
|
+
confirmPassword: 7,
|
|
285
|
+
},
|
|
286
|
+
agreeToTerms: false,
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const result = schema.safeParse(invalidData);
|
|
290
|
+
|
|
291
|
+
console.log(issuesToString(result.error.issues));
|
|
292
|
+
// user.name: Expected string
|
|
293
|
+
// user.email: Expected string
|
|
294
|
+
// user.address.street: Expected string
|
|
295
|
+
// user.address.city: Expected string
|
|
296
|
+
// user.address.zip: Expected string
|
|
297
|
+
// credentials.password: Expected string
|
|
298
|
+
// credentials.confirmPassword: Expected string
|
|
299
|
+
// agreeToTerms: Expected literal true
|
|
300
|
+
|
|
301
|
+
console.log(issuesToObject(result.error.issues));
|
|
302
|
+
// {
|
|
303
|
+
// user: {
|
|
304
|
+
// name: 'Expected string',
|
|
305
|
+
// email: 'Expected string',
|
|
306
|
+
// address: {
|
|
307
|
+
// street: 'Expected string',
|
|
308
|
+
// city: 'Expected string',
|
|
309
|
+
// zip: 'Expected string'
|
|
310
|
+
// }
|
|
311
|
+
// },
|
|
312
|
+
// credentials: { password: 'Expected string', confirmPassword: 'Expected string' },
|
|
313
|
+
// agreeToTerms: 'Expected literal true'
|
|
314
|
+
// }
|
|
315
|
+
|
|
316
|
+
console.log(flattenErrors(result.error.issues));
|
|
317
|
+
// {
|
|
318
|
+
// 'user.name': 'Expected string',
|
|
319
|
+
// 'user.email': 'Expected string',
|
|
320
|
+
// 'user.address.street': 'Expected string',
|
|
321
|
+
// 'user.address.city': 'Expected string',
|
|
322
|
+
// 'user.address.zip': 'Expected string',
|
|
323
|
+
// 'credentials.password': 'Expected string',
|
|
324
|
+
// 'credentials.confirmPassword': 'Expected string',
|
|
325
|
+
// agreeToTerms: 'Expected literal true'
|
|
326
|
+
// }
|
|
327
|
+
```
|
package/dist/index.d.mts
CHANGED
|
@@ -146,6 +146,12 @@ declare function unionValidator<T extends ReadonlyArray<ViviValidator<unknown>>>
|
|
|
146
146
|
//#region src/unknown-validator.d.ts
|
|
147
147
|
declare function unknownValidator(): ViviValidator<unknown>;
|
|
148
148
|
//#endregion
|
|
149
|
+
//#region src/shared/error-utils.d.ts
|
|
150
|
+
type ValidationErrors<T> = { [K in keyof T]?: T[K] extends object ? ValidationErrors<T[K]> : string };
|
|
151
|
+
declare function issuesToString(issues: ReadonlyArray<ViviIssue>): string;
|
|
152
|
+
declare function issuesToObject<T extends object>(issues: ReadonlyArray<ViviIssue>): ValidationErrors<T>;
|
|
153
|
+
declare function flattenErrors(issues: ReadonlyArray<ViviIssue>): Record<string, string>;
|
|
154
|
+
//#endregion
|
|
149
155
|
//#region src/refinement-utils/number-refinements.d.ts
|
|
150
156
|
declare function min(minValue: number, message?: string): (value: number) => string | true;
|
|
151
157
|
declare function max(maxValue: number, message?: string): (value: number) => string | true;
|
|
@@ -221,4 +227,4 @@ declare namespace v {
|
|
|
221
227
|
type infer<T extends ViviValidator<unknown>> = Infer<T>;
|
|
222
228
|
}
|
|
223
229
|
//#endregion
|
|
224
|
-
export { ViviError, abs, arrayValidator, between, bigintValidator, booleanValidator, ceil, clamp, createValidator as customValidator, dateValidator, v as default, v, emailValidator, endsWith, even, fallback, finite, floor, gt, includes, instanceValidator, integer, length, literalValidator, lowercase, lt, match, max, maxLength, min, minLength, negative, nonEmpty, normalizeSpaces, notIncludes, nullValidator, nullableValidator, numberValidator, objectValidator, odd, optionalValidator, pattern, pipe, positive, refine, replace, round, startsWith, stringValidator, toLowerCase, toUpperCase, trim, trimmed, truncateEnd, truncateStart, undefinedValidator, unionValidator, unknownValidator, uppercase, uuid4 };
|
|
230
|
+
export { ViviError, abs, arrayValidator, between, bigintValidator, booleanValidator, ceil, clamp, createValidator as customValidator, dateValidator, v as default, v, emailValidator, endsWith, even, fallback, finite, flattenErrors, floor, gt, includes, instanceValidator, integer, issuesToObject, issuesToString, length, literalValidator, lowercase, lt, match, max, maxLength, min, minLength, negative, nonEmpty, normalizeSpaces, notIncludes, nullValidator, nullableValidator, numberValidator, objectValidator, odd, optionalValidator, pattern, pipe, positive, refine, replace, round, startsWith, stringValidator, toLowerCase, toUpperCase, trim, trimmed, truncateEnd, truncateStart, undefinedValidator, unionValidator, unknownValidator, uppercase, uuid4 };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
var e=class e extends Error{issues;constructor(t){super(`Vivi validation error`),this.name=e.name,this.issues=t}static single(t,n){return new e([{message:t,path:n}])}merge(t){return new e([...this.issues,...t.issues])}};function t(e,t,n){for(let r=0;r<t.length;r++){let i=t[r],a=[];for(let e=0;e<n.length;e++)a.push(n[e]);for(let e=0;e<i.path.length;e++)a.push(i.path[e]);e.push({message:i.message,path:a})}}function n(t){return{parse(e,n=[]){return t(e,n)},safeParse(n){try{return{success:!0,data:t(n,[])}}catch(t){if(t instanceof e)return{success:!1,error:t};let n=t instanceof Error?t.message:`Unknown validation error`;return{success:!1,error:e.single(n,[])}}}}}function r(e,t,n){return typeof e==`function`?e(n):e??t}function i(i,a){return n((n,o)=>{if(!Array.isArray(n))throw e.single(r(a?.error,`Expected array`,n),o);let s=[],c=[];for(let r=0;r<n.length;r++){let l=i.safeParse(n[r]);if(l.success)s[r]=l.data;else if(t(c,l.error.issues,o.concat(r)),a?.abort)throw new e(c)}if(c.length>0)throw new e(c);return s})}function a(t){return n((n,i)=>{if(typeof n!=`bigint`)throw e.single(r(t?.error,`Expected bigint`,n),i);return n})}function o(t){return n((n,i)=>{if(typeof n!=`boolean`)throw e.single(r(t?.error,`Expected boolean`,n),i);return n})}function s(t){return n((n,i)=>{if(!(n instanceof Date)||isNaN(n.getTime()))throw e.single(r(t?.error,`Expected Date`,n),i);return n})}const c=/^(?!\.)(?!.*\.\.)([a-z0-9_'+\-\.]*)[a-z0-9_+\-]@([a-z0-9][a-z0-9\-]*\.)+[a-z]{2,}$/i;function l(t){let i=t?.pattern??c;return n((n,a)=>{if(typeof n!=`string`)throw e.single(r(t?.error,`Expected string`,n),a);if(!i.test(n))throw e.single(r(t?.error,`Invalid email format`,n),a);return n})}function u(t,r){return n((n,i)=>{try{return t.parse(n,i)}catch(t){if(t instanceof e)return r;throw t}})}function d(t,i){return n((n,a)=>{if(!(n instanceof t))throw e.single(r(i?.error,`Expected instance of ${t.name}`,n),a);return n})}function f(t,i){return n((n,a)=>{if(n
|
|
1
|
+
var e=class e extends Error{issues;constructor(t){super(`Vivi validation error`),this.name=e.name,this.issues=t}static single(t,n){return new e([{message:t,path:n}])}merge(t){return new e([...this.issues,...t.issues])}};function t(e,t,n){for(let r=0;r<t.length;r++){let i=t[r],a=[];for(let e=0;e<n.length;e++)a.push(n[e]);for(let e=0;e<i.path.length;e++)a.push(i.path[e]);e.push({message:i.message,path:a})}}function n(t){return{parse(e,n=[]){return t(e,n)},safeParse(n){try{return{success:!0,data:t(n,[])}}catch(t){if(t instanceof e)return{success:!1,error:t};let n=t instanceof Error?t.message:`Unknown validation error`;return{success:!1,error:e.single(n,[])}}}}}function r(e,t,n){return typeof e==`function`?e(n):e??t}function i(i,a){return n((n,o)=>{if(!Array.isArray(n))throw e.single(r(a?.error,`Expected array`,n),o);let s=[],c=[];for(let r=0;r<n.length;r++){let l=i.safeParse(n[r]);if(l.success)s[r]=l.data;else if(t(c,l.error.issues,o.concat(r)),a?.abort)throw new e(c)}if(c.length>0)throw new e(c);return s})}function a(t){return n((n,i)=>{if(typeof n!=`bigint`)throw e.single(r(t?.error,`Expected bigint`,n),i);return n})}function o(t){return n((n,i)=>{if(typeof n!=`boolean`)throw e.single(r(t?.error,`Expected boolean`,n),i);return n})}function s(t){return n((n,i)=>{if(!(n instanceof Date)||isNaN(n.getTime()))throw e.single(r(t?.error,`Expected Date`,n),i);return n})}const c=/^(?!\.)(?!.*\.\.)([a-z0-9_'+\-\.]*)[a-z0-9_+\-]@([a-z0-9][a-z0-9\-]*\.)+[a-z]{2,}$/i;function l(t){let i=t?.pattern??c;return n((n,a)=>{if(typeof n!=`string`)throw e.single(r(t?.error,`Expected string`,n),a);if(!i.test(n))throw e.single(r(t?.error,`Invalid email format`,n),a);return n})}function u(t,r){return n((n,i)=>{try{return t.parse(n,i)}catch(t){if(t instanceof e)return r;throw t}})}function d(t,i){return n((n,a)=>{if(!(n instanceof t))throw e.single(r(i?.error,`Expected instance of ${t.name}`,n),a);return n})}function f(t,i){return n((n,a)=>{if(!Object.is(n,t))throw e.single(r(i?.error,`Expected literal ${String(t)}`,n),a);return t})}function p(t){return n((n,i)=>{if(!Object.is(n,null))throw e.single(r(t?.error,`Expected null`,n),i);return null})}function m(e){return n((t,n)=>Object.is(t,null)?null:e.parse(t,n))}function h(t){return n((n,i)=>{if(typeof n!=`number`)throw e.single(r(t?.error,`Expected number`,n),i);return n})}function ee(t,n,i){if(typeof t!=`object`||!t||Array.isArray(t))throw e.single(r(i,`Expected object`,t),n)}function te(n,r,i,a,o,s,c){let l=i.safeParse(r);if(l.success)c&&(c[n]=l.data);else if(t(o,l.error.issues,a.concat(n)),s)throw new e(o)}function g(t,n,i,a,o,s,c){switch(i){case`passthrough`:c&&(c[t]=n);break;case`exact`:if(a.push({message:r(void 0,`Unexpected property`,n),path:o.concat(t)}),s)throw new e(a);break}}function _(t,n,i,a,o,s,c=`strip`){for(let l=0;l<n.length;l++){let u=n[l];if(!(u in t)){let t=i[u].safeParse(null).success;if((c===`exact`||t)&&(a.push({message:r(void 0,`Missing required property`,void 0),path:o.concat(u)}),s))throw new e(a)}}}function v(t,r){let i=r?.mode??`strip`;return n((n,a)=>{ee(n,a,r?.error);let o=n,s={},c=[],l=Object.keys(o),u=Object.keys(t);for(let e=0;e<l.length;e++){let n=l[e],u=o[n],d=t[n];d?te(n,u,d,a,c,r?.abort,s):g(n,u,i,c,a,r?.abort,s)}if(_(o,u,t,c,a,r?.abort,i),c.length>0)throw new e(c);return s})}function y(e){return n((t,n)=>{if(!Object.is(t,void 0))return e.parse(t,n)})}function b(e,...t){return n((n,r)=>{let i=e.parse(n,r);for(let e=0;e<t.length;e++)i=t[e](i);return i})}function x(e,t){let n=[];if(Object.is(e,!1))n.push({path:t,message:`Refinement failed`});else if(typeof e==`string`)n.push({path:t,message:e});else if(e&&typeof e==`object`&&`message`in e){let r=e,i=r.path?t.concat(r.path):t;n.push({path:i,message:r.message})}else if(Array.isArray(e))for(let r=0;r<e.length;r++){let i=e[r],a=i.path?t.concat(i.path):t;n.push({path:a,message:i.message})}return n}function S(t,r,i){return n((n,a)=>{let o=t.parse(n,a),s=[];for(let e=0;e<r.length;e++){let t=x(r[e](o),a);for(let e=0;e<t.length;e++)s.push(t[e]);if(i?.abort&&t.length>0)break}if(s.length>0)throw new e(s);return o})}function C(e,t,n){return e.success?t(e.data):n(e.error)}function w(t){return n((n,i)=>{if(typeof n!=`string`)throw e.single(r(t?.error,`Expected string`,n),i);return n})}function T(t){return n((n,i)=>{if(!Object.is(n,void 0))throw e.single(r(t?.error,`Expected undefined`,n),i)})}function E(i,a){return n((n,o)=>{let s=[];for(let e=0;e<i.length;e++){let r=i[e].safeParse(n);if(r.success)return r.data;t(s,r.error.issues,o)}throw s.length>0?new e(s):e.single(r(a?.error,`No union variant matched`,n),o)})}function D(){return n(e=>e)}function O(e){return e.map(e=>{let t=e.path.join(`.`);return t?`${t}: ${e.message}`:e.message}).join(`
|
|
2
|
+
`)}function k(e){let t={};for(let n of e){if(n.path.length===0)continue;let e=t;for(let t=0;t<n.path.length;t++){let r=n.path[t];t===n.path.length-1?e[r]=n.message:((!e[r]||typeof e[r]!=`object`)&&(e[r]={}),e=e[r])}}return t}function A(e){let t={};for(let n of e)n.path.length!==0&&(t[n.path.join(`.`)]=n.message);return t}function j(e,t){return function(n){return n>=e||t||`Must be >= ${e}`}}function M(e,t){return function(n){return n<=e||t||`Must be <= ${e}`}}function N(e,t){return function(n){return n>e||t||`Must be > ${e}`}}function P(e,t){return function(n){return n<e||t||`Must be < ${e}`}}function F(e){return function(t){return Number.isInteger(t)||e||`Must be an integer`}}function I(e){return function(t){return Number.isFinite(t)||e||`Must be a finite number`}}function L(e){return function(t){return t>0||e||`Must be positive`}}function R(e){return function(t){return t<0||e||`Must be negative`}}function z(e,t,n){return function(r){return r>=e&&r<=t||n||`Must be between ${e} and ${t}`}}function B(e){return function(t){return t%2==0||e||`Must be an even number`}}function V(e){return function(t){return t%2!=0||e||`Must be an odd number`}}function H(e,t){return function(n){return n.length>=e||t||`Must have at least ${e} characters`}}function U(e,t){return function(n){return n.length<=e||t||`Must have at most ${e} characters`}}function W(e,t){return function(n){return n.length===e||t||`Must have exactly ${e} characters`}}function ne(e,t){return function(n){return e.test(n)||t||`Invalid format`}}function G(e,t){return function(n){return n.startsWith(e)||t||`Must start with "${e}"`}}function K(e,t){return function(n){return n.endsWith(e)||t||`Must end with "${e}"`}}function q(e){return function(t){return t.length>0||e||`Must not be empty`}}function J(e,t){return function(n){return n.includes(e)||t||`Must include "${e}"`}}function Y(e,t){return function(n){return!n.includes(e)||t||`Must not include "${e}"`}}function X(e){return function(t){return t.trim()===t||e||`Must not have leading or trailing spaces`}}function Z(e){return function(t){return t===t.toLowerCase()||e||`Must be lowercase`}}function re(e){return function(t){return t===t.toUpperCase()||e||`Must be uppercase`}}function ie(e){let t=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;return function(n){return t.test(n)||e||`Must be a valid UUID v4`}}function ae(){return function(e){return Math.round(e)}}function oe(){return function(e){return Math.floor(e)}}function se(){return function(e){return Math.ceil(e)}}function Q(e,t){return function(n){return Math.min(Math.max(n,e),t)}}function ce(){return function(e){return Math.abs(e)}}function le(){return function(e){return e.trim()}}function ue(){return function(e){return e.toLowerCase()}}function de(){return function(e){return e.toUpperCase()}}function fe(e,t,n){return function(r){if(typeof e==`string`){let i=``;return n?.global&&(i+=`g`),n?.ignoreCase&&(i+=`i`),r.replace(new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),i),t)}else return r.replace(e,t)}}function pe(e,t=``){return function(n){return n.length>e?n.slice(0,e)+t:n}}function me(e,t=``){return function(n){return n.length<=e?n:t+n.slice(n.length-e)}}function he(){return function(e){return e.replace(/\s+/g,` `).trim()}}const $={array:i,bigint:a,boolean:o,date:s,email:l,fallback:u,instance:d,literal:f,null:p,nullable:m,number:h,object:v,optional:y,string:w,undefined:T,union:E,unknown:D,refine:S,pipe:b,match:C};var ge=$;export{e as ViviError,ce as abs,i as arrayValidator,z as between,a as bigintValidator,o as booleanValidator,se as ceil,Q as clamp,n as customValidator,s as dateValidator,ge as default,l as emailValidator,K as endsWith,B as even,u as fallback,I as finite,A as flattenErrors,oe as floor,N as gt,J as includes,d as instanceValidator,F as integer,k as issuesToObject,O as issuesToString,W as length,f as literalValidator,Z as lowercase,P as lt,C as match,M as max,U as maxLength,j as min,H as minLength,R as negative,q as nonEmpty,he as normalizeSpaces,Y as notIncludes,p as nullValidator,m as nullableValidator,h as numberValidator,v as objectValidator,V as odd,y as optionalValidator,ne as pattern,b as pipe,L as positive,S as refine,fe as replace,ae as round,G as startsWith,w as stringValidator,ue as toLowerCase,de as toUpperCase,le as trim,X as trimmed,pe as truncateEnd,me as truncateStart,T as undefinedValidator,E as unionValidator,D as unknownValidator,re as uppercase,ie as uuid4,$ as v};
|