@warlock.js/seal 5.15.0 → 5.17.0

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +22 -0
  3. package/cjs/index.cjs +953 -6977
  4. package/cjs/index.cjs.map +1 -1
  5. package/cjs/object-_2YHdBxJ.cjs +613 -0
  6. package/cjs/object-_2YHdBxJ.cjs.map +1 -0
  7. package/cjs/object.cjs +10 -0
  8. package/cjs/required-methods-GwIEE6hP.cjs +5868 -0
  9. package/cjs/required-methods-GwIEE6hP.cjs.map +1 -0
  10. package/cjs/string-6m5Y83pJ.cjs +943 -0
  11. package/cjs/string-6m5Y83pJ.cjs.map +1 -0
  12. package/cjs/string.cjs +10 -0
  13. package/esm/factory/validators.d.mts +5 -0
  14. package/esm/factory/validators.d.mts.map +1 -1
  15. package/esm/factory/validators.mjs +4 -3
  16. package/esm/factory/validators.mjs.map +1 -1
  17. package/esm/helpers/index.mjs +1 -1
  18. package/esm/helpers/validation-helpers.mjs +1 -1
  19. package/esm/helpers/validation-helpers.mjs.map +1 -1
  20. package/esm/index.mjs +1 -1
  21. package/esm/object.d.mts +15 -0
  22. package/esm/object.d.mts.map +1 -0
  23. package/esm/object.mjs +13 -0
  24. package/esm/object.mjs.map +1 -0
  25. package/esm/rules/common/equals-field-rules.mjs +1 -1
  26. package/esm/rules/conditional/forbidden-if-rules.mjs +2 -2
  27. package/esm/rules/conditional/present-if-rules.mjs +2 -2
  28. package/esm/rules/conditional/present-unless-rules.mjs +1 -1
  29. package/esm/rules/conditional/present-with-rules.mjs +1 -1
  30. package/esm/rules/conditional/present-without-rules.mjs +1 -1
  31. package/esm/rules/conditional/required-if-rules.mjs +2 -2
  32. package/esm/rules/conditional/required-unless-rules.mjs +2 -2
  33. package/esm/rules/conditional/required-when-rule.mjs +1 -1
  34. package/esm/rules/conditional/required-with-rules.mjs +2 -2
  35. package/esm/rules/conditional/required-without-rules.mjs +2 -2
  36. package/esm/rules/core/forbidden.mjs +1 -1
  37. package/esm/rules/core/required.mjs +1 -1
  38. package/esm/rules/date/date-field-comparison-rules.mjs +1 -1
  39. package/esm/rules/date/date.mjs +1 -1
  40. package/esm/rules/file/file-size.mjs +1 -1
  41. package/esm/rules/scalar/accepted-rule.mjs +2 -2
  42. package/esm/rules/scalar/declined-rule.mjs +2 -2
  43. package/esm/string.d.mts +13 -0
  44. package/esm/string.d.mts.map +1 -0
  45. package/esm/string.mjs +13 -0
  46. package/esm/string.mjs.map +1 -0
  47. package/esm/types/context-types.d.mts +2 -1
  48. package/esm/types/context-types.d.mts.map +1 -1
  49. package/esm/validators/base-validator.d.mts.map +1 -1
  50. package/esm/validators/base-validator.mjs +0 -1
  51. package/esm/validators/base-validator.mjs.map +1 -1
  52. package/esm/validators/object-validator.d.mts.map +1 -1
  53. package/esm/validators/object-validator.mjs +0 -3
  54. package/esm/validators/object-validator.mjs.map +1 -1
  55. package/esm/validators/primitive-validator.mjs +0 -1
  56. package/esm/validators/primitive-validator.mjs.map +1 -1
  57. package/esm/validators/string-validator.d.mts.map +1 -1
  58. package/esm/validators/string-validator.mjs +2 -2
  59. package/esm/validators/string-validator.mjs.map +1 -1
  60. package/llms-full.txt +22 -0
  61. package/package.json +21 -1
  62. package/skills/seal-basics/SKILL.md +22 -0
@@ -0,0 +1,943 @@
1
+ const require_required_methods = require('./required-methods-GwIEE6hP.cjs');
2
+ let _mongez_reinforcements = require("@mongez/reinforcements");
3
+
4
+ //#region ../seal/src/mutators/string-mutators.ts
5
+ /** Convert string to lowercase */
6
+ const lowercaseMutator = async (value) => {
7
+ return value?.toString().toLowerCase();
8
+ };
9
+ /** Convert string to uppercase */
10
+ const uppercaseMutator = async (value) => {
11
+ return value?.toString().toUpperCase();
12
+ };
13
+ /** Capitalize only the first letter of the string */
14
+ const capitalizeMutator = async (value) => {
15
+ const str = value?.toString();
16
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
17
+ };
18
+ /** Capitalize the first letter of each word (Title Case) */
19
+ const titleCaseMutator = async (value) => {
20
+ return (0, _mongez_reinforcements.capitalize)(value?.toString());
21
+ };
22
+ /** Convert value to string */
23
+ const stringifyMutator = async (value) => {
24
+ if (!value && value !== 0) return "";
25
+ if (typeof value === "string") return value;
26
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
27
+ };
28
+ /** Trim whitespace */
29
+ const trimMutator = async (value, context) => {
30
+ return (0, _mongez_reinforcements.trim)(value?.toString(), context?.options?.needle ?? " ");
31
+ };
32
+ /**
33
+ * Strip HTML tags with a naive `<...>` regex.
34
+ *
35
+ * This is a **tag stripper, not an XSS sanitizer**: it is not a parser, so
36
+ * malformed/nested markup, attribute payloads, or content re-introduced
37
+ * later in a pipeline can defeat it. Do not rely on this alone to make
38
+ * untrusted rich text safe to render — use a real parser-based sanitizer
39
+ * (e.g. DOMPurify / sanitize-html) for that.
40
+ */
41
+ const stripTagsMutator = async (value) => {
42
+ return value?.toString().replace(/<[^>]*>?/gm, "");
43
+ };
44
+ /**
45
+ * @deprecated Renamed to {@link stripTagsMutator} — the old name implied
46
+ * XSS safety this tag-stripping regex does not provide. Kept as an alias
47
+ * for backward compatibility; switch to `stripTagsMutator`.
48
+ */
49
+ const safeHtmlMutator = stripTagsMutator;
50
+ /** HTML escape */
51
+ const htmlEscapeMutator = async (value) => {
52
+ return value?.toString().replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
53
+ };
54
+ /** Remove special characters */
55
+ const removeSpecialCharactersMutator = async (value) => {
56
+ return value?.toString().replace(/[^a-zA-Z0-9]/g, "");
57
+ };
58
+ /** URL decode */
59
+ const urlDecodeMutator = async (value) => {
60
+ return decodeURIComponent(value);
61
+ };
62
+ /** URL encode */
63
+ const urlEncodeMutator = async (value) => {
64
+ return encodeURIComponent(value);
65
+ };
66
+ /** Convert to camelCase */
67
+ const camelCaseMutator = async (value) => {
68
+ return (0, _mongez_reinforcements.toCamelCase)(value?.toString());
69
+ };
70
+ /** Convert to PascalCase */
71
+ const pascalCaseMutator = async (value) => {
72
+ return (0, _mongez_reinforcements.toStudlyCase)(value?.toString());
73
+ };
74
+ /** Convert to snake_case */
75
+ const snakeCaseMutator = async (value) => {
76
+ return (0, _mongez_reinforcements.toSnakeCase)(value?.toString());
77
+ };
78
+ /** Convert to kebab-case */
79
+ const kebabCaseMutator = async (value) => {
80
+ return (0, _mongez_reinforcements.toKebabCase)(value?.toString());
81
+ };
82
+ /** Convert to URL-friendly slug */
83
+ const slugMutator = async (value) => {
84
+ return value?.toString().toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_]+/g, "-").replace(/--+/g, "-").replace(/^-+|-+$/g, "");
85
+ };
86
+ /** Trim from the left/start */
87
+ const ltrimMutator = async (value, context) => {
88
+ return (0, _mongez_reinforcements.ltrim)(value?.toString(), context?.options?.needle ?? " ");
89
+ };
90
+ /** Trim from the right/end */
91
+ const rtrimMutator = async (value, context) => {
92
+ return (0, _mongez_reinforcements.rtrim)(value?.toString(), context?.options?.needle ?? " ");
93
+ };
94
+ /** Base64 encode */
95
+ const base64EncodeMutator = async (value) => {
96
+ return Buffer.from(value?.toString()).toString("base64");
97
+ };
98
+ /** Base64 decode */
99
+ const base64DecodeMutator = async (value) => {
100
+ return Buffer.from(value?.toString(), "base64").toString("utf-8");
101
+ };
102
+ /** Replace substring or pattern */
103
+ const replaceMutator = async (value, context) => {
104
+ const { search, replace } = context?.options;
105
+ if (!search) return value?.toString();
106
+ return value?.toString().replace(search, replace ?? "");
107
+ };
108
+ /** Replace all occurrences of substring or pattern */
109
+ const replaceAllMutator = async (value, context) => {
110
+ const { search, replace } = context?.options;
111
+ if (!search) return value?.toString();
112
+ const searchValue = typeof search === "string" ? new RegExp(search, "g") : search;
113
+ return value?.toString().replace(searchValue, replace ?? "");
114
+ };
115
+ /** Append/suffix text to the end */
116
+ const appendMutator = async (value, context) => {
117
+ const suffix = context?.options?.suffix ?? "";
118
+ return value?.toString() + suffix;
119
+ };
120
+ /** Prepend/prefix text to the beginning */
121
+ const prependMutator = async (value, context) => {
122
+ return (context?.options?.prefix ?? "") + value?.toString();
123
+ };
124
+ /** Reverse the string */
125
+ const reverseMutator = async (value) => {
126
+ return value?.toString().split("").reverse().join("");
127
+ };
128
+ /** Truncate to a maximum length */
129
+ const truncateMutator = async (value, context) => {
130
+ const str = value?.toString();
131
+ return (0, _mongez_reinforcements.readMoreChars)(str, context?.options?.maxLength ?? 100, context?.options?.suffix ?? "...");
132
+ };
133
+ /** Trim multiple whitespace into single space */
134
+ const trimMultipleWhitespaceMutator = async (value) => {
135
+ return value?.toString().replace(/\s+/g, " ");
136
+ };
137
+ /** Pad string from the start to reach target length */
138
+ const padStartMutator = async (value, context) => {
139
+ const length = context?.options?.length ?? 0;
140
+ const char = context?.options?.char ?? " ";
141
+ return value?.toString().padStart(length, char);
142
+ };
143
+ /** Pad string from the end to reach target length */
144
+ const padEndMutator = async (value, context) => {
145
+ const length = context?.options?.length ?? 0;
146
+ const char = context?.options?.char ?? " ";
147
+ return value?.toString().padEnd(length, char);
148
+ };
149
+ /** Repeat string N times */
150
+ const repeatMutator = async (value, context) => {
151
+ const count = context?.options?.count ?? 1;
152
+ return value?.toString()?.repeat(count);
153
+ };
154
+ /** Mask part of string */
155
+ const maskMutator = async (value, context) => {
156
+ const str = value?.toString();
157
+ const maskChar = context?.options?.char ?? "*";
158
+ const start = context?.options?.start ?? 0;
159
+ const end = context?.options?.end ?? str?.length;
160
+ const visibleStart = str?.substring(0, start);
161
+ const visibleEnd = str?.substring(end);
162
+ const maskedLength = end - start;
163
+ return visibleStart + maskChar.repeat(maskedLength) + visibleEnd;
164
+ };
165
+ /** Unescape HTML entities */
166
+ const unescapeHtmlMutator = async (value) => {
167
+ return value?.toString().replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&#039;/g, "'");
168
+ };
169
+ /** Keep only alphabetic characters */
170
+ const alphaOnlyMutator = async (value) => {
171
+ return value.toString().replace(/[^a-zA-Z]/g, "");
172
+ };
173
+ /** Keep only alphanumeric characters */
174
+ const alphanumericOnlyMutator = async (value) => {
175
+ return value.toString().replace(/[^a-zA-Z0-9]/g, "");
176
+ };
177
+ /** Remove all numeric characters */
178
+ const removeNumbersMutator = async (value) => {
179
+ return value.toString().replace(/[0-9]/g, "");
180
+ };
181
+
182
+ //#endregion
183
+ //#region ../seal/src/validators/primitive-validator.ts
184
+ /**
185
+ * Abstract base validator for primitive-typed fields (string, number, boolean).
186
+ *
187
+ * Provides value-membership rules that are meaningful for any single primitive value
188
+ * but not for complex structures (object, array).
189
+ *
190
+ * Do NOT expose this on the `v` factory — it is an inheritance-only base class.
191
+ *
192
+ * Hierarchy:
193
+ * BaseValidator
194
+ * └── PrimitiveValidator ← enum, in, oneOf, allowsOnly, forbids, notIn
195
+ * ├── StringValidator
196
+ * ├── NumberValidator
197
+ * │ └── FloatValidator
198
+ * ├── BooleanValidator
199
+ * └── ScalarValidator (extends PrimitiveValidator, adds asNumber/asString/accepted/declined)
200
+ *
201
+ * @example
202
+ * class MyValidator extends PrimitiveValidator {
203
+ * // inherits: in(), forbids(), enum(), oneOf(), allowsOnly(), notIn()
204
+ * }
205
+ */
206
+ var PrimitiveValidator = class extends require_required_methods.BaseValidator {
207
+ /**
208
+ * Value must be one of the enum's values
209
+ *
210
+ * @example
211
+ * v.string().enum(Direction) // Direction is a TS enum
212
+ */
213
+ enum(values, errorMessage) {
214
+ return this.addRule(require_required_methods.enumRule, errorMessage, { enum: Object.values(values) });
215
+ }
216
+ /**
217
+ * Value must be one of the given values
218
+ *
219
+ * @example
220
+ * v.string().in(["admin", "user", "guest"])
221
+ * v.number().in([1, 2, 3])
222
+ */
223
+ in(values, errorMessage) {
224
+ return this.addRule(require_required_methods.inRule, errorMessage, { values });
225
+ }
226
+ /**
227
+ * Alias for `in()`
228
+ *
229
+ * @example
230
+ * v.string().oneOf(["active", "inactive"])
231
+ */
232
+ oneOf(values, errorMessage) {
233
+ return this.in(values, errorMessage);
234
+ }
235
+ /**
236
+ * Value must be one of the allowed values (stricter variant)
237
+ *
238
+ * @example
239
+ * v.string().allowsOnly(["yes", "no"])
240
+ */
241
+ allowsOnly(values, errorMessage) {
242
+ return this.addRule(require_required_methods.allowedValuesRule, errorMessage, { allowedValues: values });
243
+ }
244
+ /**
245
+ * Value must NOT be one of the given values
246
+ *
247
+ * @example
248
+ * v.string().forbids(["banned", "blacklisted"])
249
+ * v.number().forbids([0, -1])
250
+ */
251
+ forbids(values, errorMessage) {
252
+ return this.addRule(require_required_methods.notAllowedValuesRule, errorMessage, { notAllowedValues: values });
253
+ }
254
+ /**
255
+ * Alias for `forbids()`
256
+ *
257
+ * @example
258
+ * v.string().notIn(["OK", "NOT OK"])
259
+ */
260
+ notIn(values, errorMessage) {
261
+ return this.forbids(values, errorMessage);
262
+ }
263
+ };
264
+
265
+ //#endregion
266
+ //#region ../seal/src/validators/string-validator.ts
267
+ /**
268
+ * String validator class
269
+ */
270
+ var StringValidator = class extends PrimitiveValidator {
271
+ constructor(errorMessage) {
272
+ super();
273
+ this.addMutableRule(require_required_methods.stringRule, errorMessage);
274
+ }
275
+ /**
276
+ * Check if value is a string type
277
+ */
278
+ matchesType(value) {
279
+ return typeof value === "string";
280
+ }
281
+ /**
282
+ * Stringify the value if not a string
283
+ */
284
+ toString() {
285
+ return this.addMutator(stringifyMutator);
286
+ }
287
+ /** Convert string to uppercase */
288
+ uppercase() {
289
+ return this.addMutator(uppercaseMutator);
290
+ }
291
+ /** Convert string to lowercase */
292
+ lowercase() {
293
+ return this.addMutator(lowercaseMutator);
294
+ }
295
+ /** Capitalize only the first letter of the string */
296
+ capitalize() {
297
+ return this.addMutator(capitalizeMutator);
298
+ }
299
+ /** Capitalize the first letter of each word (Title Case) */
300
+ titleCase() {
301
+ return this.addMutator(titleCaseMutator);
302
+ }
303
+ /** Convert to camelCase */
304
+ camelCase() {
305
+ return this.addMutator(camelCaseMutator);
306
+ }
307
+ /** Convert to PascalCase */
308
+ pascalCase() {
309
+ return this.addMutator(pascalCaseMutator);
310
+ }
311
+ /** Convert to snake_case */
312
+ snakeCase() {
313
+ return this.addMutator(snakeCaseMutator);
314
+ }
315
+ /** Convert to kebab-case */
316
+ kebabCase() {
317
+ return this.addMutator(kebabCaseMutator);
318
+ }
319
+ /**
320
+ * Trim the given needle from the string
321
+ * If no needle is provided, the default is a single space
322
+ */
323
+ trim(needle) {
324
+ return this.addMutator(trimMutator, { needle });
325
+ }
326
+ /** Trim from the left/start */
327
+ ltrim(needle) {
328
+ return this.addMutator(ltrimMutator, { needle });
329
+ }
330
+ /** Trim from the right/end */
331
+ rtrim(needle) {
332
+ return this.addMutator(rtrimMutator, { needle });
333
+ }
334
+ /** Trim multiple whitespace into single space */
335
+ trimMultipleWhitespace() {
336
+ return this.addMutator(trimMultipleWhitespaceMutator);
337
+ }
338
+ /** Pad string from the start to reach target length */
339
+ padStart(length, char = " ") {
340
+ return this.addMutator(padStartMutator, {
341
+ length,
342
+ char
343
+ });
344
+ }
345
+ /** Pad string from the end to reach target length */
346
+ padEnd(length, char = " ") {
347
+ return this.addMutator(padEndMutator, {
348
+ length,
349
+ char
350
+ });
351
+ }
352
+ /**
353
+ * Strip HTML tags with a naive `<...>` regex.
354
+ *
355
+ * This is a **tag stripper, not an XSS sanitizer**: it is not a parser,
356
+ * so malformed/nested markup or content re-introduced later in a
357
+ * pipeline can defeat it. Do not rely on this alone to make untrusted
358
+ * rich text safe to render — use a real parser-based sanitizer (e.g.
359
+ * DOMPurify / sanitize-html) for that.
360
+ */
361
+ stripTags() {
362
+ return this.addMutator(stripTagsMutator);
363
+ }
364
+ /**
365
+ * @deprecated Renamed to {@link StringValidator.stripTags} — the old
366
+ * name implied XSS safety this tag-stripping regex does not provide.
367
+ * Kept as an alias for backward compatibility; switch to `.stripTags()`.
368
+ */
369
+ safeHtml() {
370
+ return this.stripTags();
371
+ }
372
+ /** HTML escape special characters */
373
+ htmlEscape() {
374
+ return this.addMutator(htmlEscapeMutator);
375
+ }
376
+ /** Unescape HTML entities */
377
+ unescapeHtml() {
378
+ return this.addMutator(unescapeHtmlMutator);
379
+ }
380
+ /**
381
+ * Remove special characters
382
+ * This will remove all characters that are not alphanumeric or whitespace
383
+ */
384
+ removeSpecialCharacters() {
385
+ return this.addMutator(removeSpecialCharactersMutator);
386
+ }
387
+ /** Convert to only alphabetic characters */
388
+ toAlpha() {
389
+ return this.addMutator(alphaOnlyMutator);
390
+ }
391
+ /** Convert to only alphanumeric characters */
392
+ toAlphanumeric() {
393
+ return this.addMutator(alphanumericOnlyMutator);
394
+ }
395
+ /** Remove all numeric characters */
396
+ removeNumbers() {
397
+ return this.addMutator(removeNumbersMutator);
398
+ }
399
+ /** URL decode */
400
+ urlDecode() {
401
+ return this.addMutator(urlDecodeMutator);
402
+ }
403
+ /** URL encode */
404
+ urlEncode() {
405
+ return this.addMutator(urlEncodeMutator);
406
+ }
407
+ /** Convert to URL-friendly slug */
408
+ slug() {
409
+ return this.addMutator(slugMutator);
410
+ }
411
+ /** Base64 encode */
412
+ base64Encode() {
413
+ return this.addMutator(base64EncodeMutator);
414
+ }
415
+ /** Base64 decode */
416
+ base64Decode() {
417
+ return this.addMutator(base64DecodeMutator);
418
+ }
419
+ /** Replace substring or pattern */
420
+ replace(search, replace) {
421
+ return this.addMutator(replaceMutator, {
422
+ search,
423
+ replace
424
+ });
425
+ }
426
+ /** Replace all occurrences of substring or pattern */
427
+ replaceAll(search, replace) {
428
+ return this.addMutator(replaceAllMutator, {
429
+ search,
430
+ replace
431
+ });
432
+ }
433
+ /** Append/suffix text to the end */
434
+ append(suffix) {
435
+ return this.addMutator(appendMutator, { suffix });
436
+ }
437
+ /** Prepend/prefix text to the beginning */
438
+ prepend(prefix) {
439
+ return this.addMutator(prependMutator, { prefix });
440
+ }
441
+ /** Reverse the string */
442
+ reverse() {
443
+ return this.addMutator(reverseMutator);
444
+ }
445
+ /** Truncate to a maximum length */
446
+ truncate(maxLength, suffix = "...") {
447
+ return this.addMutator(truncateMutator, {
448
+ maxLength,
449
+ suffix
450
+ });
451
+ }
452
+ /** Repeat string N times */
453
+ repeat(count) {
454
+ return this.addMutator(repeatMutator, { count });
455
+ }
456
+ /** Mask part of string */
457
+ mask(start, end, char = "*") {
458
+ return this.addMutator(maskMutator, {
459
+ start,
460
+ end,
461
+ char
462
+ });
463
+ }
464
+ /** Value must be a valid email */
465
+ email(errorMessage) {
466
+ return this.addRule(require_required_methods.emailRule, errorMessage);
467
+ }
468
+ /** Value must be a valid URL */
469
+ url(errorMessage) {
470
+ return this.addRule(require_required_methods.urlRule, errorMessage);
471
+ }
472
+ /** Value can not have whitespace */
473
+ withoutWhitespace(errorMessage) {
474
+ return this.addRule(require_required_methods.withoutWhitespaceRule, errorMessage);
475
+ }
476
+ /** Value must match the given pattern */
477
+ pattern(pattern, errorMessage) {
478
+ return this.addRule(require_required_methods.patternRule, errorMessage, { pattern });
479
+ }
480
+ /**
481
+ * Value must be a strong password
482
+ * Requirements:
483
+ * - At least 8 characters
484
+ * - At least 1 uppercase letter
485
+ * - At least 1 lowercase letter
486
+ * - At least 1 number
487
+ * - At least 1 special character
488
+ */
489
+ strongPassword(minLength, errorMessage) {
490
+ return this.addRule(require_required_methods.strongPasswordRule, errorMessage, { minLength });
491
+ }
492
+ /** Value must be exactly the given number of words */
493
+ words(words, errorMessage) {
494
+ return this.addRule(require_required_methods.wordsRule, errorMessage, { words });
495
+ }
496
+ /** Value must be at least the given number of words */
497
+ minWords(words, errorMessage) {
498
+ return this.addRule(require_required_methods.minWordsRule, errorMessage, { minWords: words });
499
+ }
500
+ /** Value must be at most the given number of words */
501
+ maxWords(words, errorMessage) {
502
+ return this.addRule(require_required_methods.maxWordsRule, errorMessage, { maxWords: words });
503
+ }
504
+ /** Value length must be greater than the given length */
505
+ minLength(length, errorMessage) {
506
+ return this.addRule(require_required_methods.minLengthRule, errorMessage, { minLength: length });
507
+ }
508
+ /** @alias minLength */
509
+ min(min, errorMessage) {
510
+ return this.minLength(min, errorMessage);
511
+ }
512
+ /** Value length must be less than the given length */
513
+ maxLength(length, errorMessage) {
514
+ return this.addRule(require_required_methods.maxLengthRule, errorMessage, { maxLength: length });
515
+ }
516
+ /** @alias maxLength */
517
+ max(max, errorMessage) {
518
+ return this.maxLength(max, errorMessage);
519
+ }
520
+ /** Value must be of the given length */
521
+ length(length, errorMessage) {
522
+ return this.addRule(require_required_methods.lengthRule, errorMessage, { length });
523
+ }
524
+ /**
525
+ * String length must be between min and max (inclusive)
526
+ *
527
+ * @param min - Minimum length (inclusive)
528
+ * @param max - Maximum length (inclusive)
529
+ *
530
+ * @example
531
+ * ```ts
532
+ * v.string().between(5, 10) // Length: 5 to 10 characters
533
+ * v.string().lengthBetween(8, 20) // Same using alias
534
+ * ```
535
+ *
536
+ * @category Validation Rule
537
+ */
538
+ lengthBetween(min, max, errorMessage) {
539
+ return this.addRule(require_required_methods.betweenLengthRule, errorMessage, {
540
+ minLength: min,
541
+ maxLength: max
542
+ });
543
+ }
544
+ /** Allow only alphabetic characters */
545
+ alpha(errorMessage) {
546
+ return this.addRule(require_required_methods.alphaRule, errorMessage);
547
+ }
548
+ /** Allow only alphanumeric characters */
549
+ alphanumeric(errorMessage) {
550
+ return this.addRule(require_required_methods.alphaNumericRule, errorMessage);
551
+ }
552
+ /** Allow only numeric characters */
553
+ numeric(errorMessage) {
554
+ return this.addRule(require_required_methods.isNumericRule, errorMessage);
555
+ }
556
+ /** Value must starts with the given string */
557
+ startsWith(value, errorMessage) {
558
+ return this.addRule(require_required_methods.startsWithRule, errorMessage, { value });
559
+ }
560
+ /** Value must ends with the given string */
561
+ endsWith(value, errorMessage) {
562
+ return this.addRule(require_required_methods.endsWithRule, errorMessage, { value });
563
+ }
564
+ /** Value must contain the given string */
565
+ contains(value, errorMessage) {
566
+ return this.addRule(require_required_methods.containsRule, errorMessage, { value });
567
+ }
568
+ /** Value must not contain the given string */
569
+ notContains(value, errorMessage) {
570
+ return this.addRule(require_required_methods.notContainsRule, errorMessage, { value });
571
+ }
572
+ /** Value must be a valid IP address */
573
+ ip(errorMessage) {
574
+ return this.addRule(require_required_methods.ipRule, errorMessage);
575
+ }
576
+ /** Value must be a valid IPv4 address */
577
+ ip4(errorMessage) {
578
+ return this.addRule(require_required_methods.ip4Rule, errorMessage);
579
+ }
580
+ /** Value must be a valid IPv6 address */
581
+ ip6(errorMessage) {
582
+ return this.addRule(require_required_methods.ip6Rule, errorMessage);
583
+ }
584
+ /** Check if the string matches a credit card number */
585
+ creditCard(errorMessage) {
586
+ return this.addRule(require_required_methods.isCreditCardRule, errorMessage);
587
+ }
588
+ /** Determine if the value is a valid color */
589
+ color(errorMessage) {
590
+ return this.addRule(require_required_methods.colorRule, errorMessage);
591
+ }
592
+ /** Determine if the value is a valid hex color */
593
+ hexColor(errorMessage) {
594
+ return this.addRule(require_required_methods.hexColorRule, errorMessage);
595
+ }
596
+ /** Determine if the value is a valid HSL color */
597
+ hslColor(errorMessage) {
598
+ return this.addRule(require_required_methods.hslColorRule, errorMessage);
599
+ }
600
+ /** Determine if the value is a valid RGB color */
601
+ rgbColor(errorMessage) {
602
+ return this.addRule(require_required_methods.rgbColorRule, errorMessage);
603
+ }
604
+ /** Determine if the value is a valid RGBA color */
605
+ rgbaColor(errorMessage) {
606
+ return this.addRule(require_required_methods.rgbaColorRule, errorMessage);
607
+ }
608
+ /** Determine if the value is a valid light color */
609
+ lightColor(errorMessage) {
610
+ return this.addRule(require_required_methods.lightColorRule, errorMessage);
611
+ }
612
+ /** Determine if the value is a valid dark color */
613
+ darkColor(errorMessage) {
614
+ return this.addRule(require_required_methods.darkColorRule, errorMessage);
615
+ }
616
+ /**
617
+ * Value must be a valid UUID. Optionally restrict to a specific version.
618
+ *
619
+ * @example
620
+ * v.string().uuid() // any RFC 4122 UUID
621
+ * v.string().uuid(4) // only v4 (random)
622
+ * v.string().uuid(7) // only v7 (timestamp-ordered)
623
+ */
624
+ uuid(version, errorMessage) {
625
+ return this.addRule(require_required_methods.uuidRule, errorMessage, { version });
626
+ }
627
+ /**
628
+ * Value must be a valid CUID. Defaults to CUID2; pass `{ version: 1 }` for legacy.
629
+ *
630
+ * @example
631
+ * v.string().cuid() // CUID2
632
+ * v.string().cuid({ version: 1 }) // legacy CUID1
633
+ */
634
+ cuid(options) {
635
+ const { errorMessage, version } = options ?? {};
636
+ return this.addRule(require_required_methods.cuidRule, errorMessage, { version });
637
+ }
638
+ /** Value must be a valid ULID (26 chars, Crockford base32). */
639
+ ulid(errorMessage) {
640
+ return this.addRule(require_required_methods.ulidRule, errorMessage);
641
+ }
642
+ /**
643
+ * Value must be a valid nanoid string. Default length is 21.
644
+ *
645
+ * @example
646
+ * v.string().nanoid() // 21 chars (default)
647
+ * v.string().nanoid(10) // 10 chars
648
+ */
649
+ nanoid(length, errorMessage) {
650
+ return this.addRule(require_required_methods.nanoidRule, errorMessage, { length });
651
+ }
652
+ /**
653
+ * @inheritdoc
654
+ *
655
+ * Maps String-specific rule options to JSON Schema keywords.
656
+ * Non-representable rules (cross-field, refine, color rules, etc.) are silently omitted.
657
+ *
658
+ * @example
659
+ * ```ts
660
+ * v.string().min(2).max(100).email().toJsonSchema("draft-2020-12")
661
+ * // → { type: "string", minLength: 2, maxLength: 100, format: "email" }
662
+ * ```
663
+ */
664
+ toJsonSchema(target = "draft-2020-12") {
665
+ const schema = { type: "string" };
666
+ const minOpts = require_required_methods.getRuleOptions(this.rules, "minLength");
667
+ if (minOpts?.minLength !== void 0) schema.minLength = minOpts.minLength;
668
+ const maxOpts = require_required_methods.getRuleOptions(this.rules, "maxLength");
669
+ if (maxOpts?.maxLength !== void 0) schema.maxLength = maxOpts.maxLength;
670
+ const betweenOpts = require_required_methods.getRuleOptions(this.rules, "betweenLength");
671
+ if (betweenOpts) {
672
+ if (betweenOpts.minLength !== void 0) schema.minLength = betweenOpts.minLength;
673
+ if (betweenOpts.maxLength !== void 0) schema.maxLength = betweenOpts.maxLength;
674
+ }
675
+ const lengthOpts = require_required_methods.getRuleOptions(this.rules, "length");
676
+ if (lengthOpts?.length !== void 0) {
677
+ schema.minLength = lengthOpts.length;
678
+ schema.maxLength = lengthOpts.length;
679
+ }
680
+ const patternOpts = require_required_methods.getRuleOptions(this.rules, "pattern");
681
+ if (patternOpts?.pattern instanceof RegExp) schema.pattern = patternOpts.pattern.source;
682
+ if (require_required_methods.getRuleOptions(this.rules, "email") !== void 0 || this.rules.some((r) => r.name === "email")) schema.format = "email";
683
+ else if (this.rules.some((r) => r.name === "url")) schema.format = "uri";
684
+ else if (this.rules.some((r) => r.name === "ip")) schema.format = "ipv4";
685
+ else if (this.rules.some((r) => r.name === "ip4")) schema.format = "ipv4";
686
+ else if (this.rules.some((r) => r.name === "ip6")) schema.format = "ipv6";
687
+ else if (this.rules.some((r) => r.name === "uuid")) schema.format = "uuid";
688
+ else if (this.rules.some((r) => r.name === "hexColor")) schema.format = "color";
689
+ if (!schema.format) {
690
+ const cuidOpts = require_required_methods.getRuleOptions(this.rules, "cuid");
691
+ if (cuidOpts) schema.pattern = cuidOpts.version === 1 ? "^c[a-z0-9]{24,}$" : "^[a-z][a-z0-9]{23}$";
692
+ if (this.rules.some((r) => r.name === "ulid")) schema.pattern = "^[0-9A-HJKMNP-TV-Z]{26}$";
693
+ const nanoidOpts = require_required_methods.getRuleOptions(this.rules, "nanoid");
694
+ if (nanoidOpts) schema.pattern = `^[A-Za-z0-9_-]{${nanoidOpts.length ?? 21}}$`;
695
+ }
696
+ const inOpts = require_required_methods.getRuleOptions(this.rules, "in");
697
+ if (inOpts?.values && Array.isArray(inOpts.values)) schema.enum = inOpts.values;
698
+ if (this.isNullable) require_required_methods.applyNullable(schema, target);
699
+ return schema;
700
+ }
701
+ };
702
+
703
+ //#endregion
704
+ //#region ../seal/src/string.ts
705
+ /** Create a string schema without importing the complete `v` factory. */
706
+ const string = (errorMessage) => new StringValidator(errorMessage);
707
+
708
+ //#endregion
709
+ Object.defineProperty(exports, 'PrimitiveValidator', {
710
+ enumerable: true,
711
+ get: function () {
712
+ return PrimitiveValidator;
713
+ }
714
+ });
715
+ Object.defineProperty(exports, 'StringValidator', {
716
+ enumerable: true,
717
+ get: function () {
718
+ return StringValidator;
719
+ }
720
+ });
721
+ Object.defineProperty(exports, 'alphaOnlyMutator', {
722
+ enumerable: true,
723
+ get: function () {
724
+ return alphaOnlyMutator;
725
+ }
726
+ });
727
+ Object.defineProperty(exports, 'alphanumericOnlyMutator', {
728
+ enumerable: true,
729
+ get: function () {
730
+ return alphanumericOnlyMutator;
731
+ }
732
+ });
733
+ Object.defineProperty(exports, 'appendMutator', {
734
+ enumerable: true,
735
+ get: function () {
736
+ return appendMutator;
737
+ }
738
+ });
739
+ Object.defineProperty(exports, 'base64DecodeMutator', {
740
+ enumerable: true,
741
+ get: function () {
742
+ return base64DecodeMutator;
743
+ }
744
+ });
745
+ Object.defineProperty(exports, 'base64EncodeMutator', {
746
+ enumerable: true,
747
+ get: function () {
748
+ return base64EncodeMutator;
749
+ }
750
+ });
751
+ Object.defineProperty(exports, 'camelCaseMutator', {
752
+ enumerable: true,
753
+ get: function () {
754
+ return camelCaseMutator;
755
+ }
756
+ });
757
+ Object.defineProperty(exports, 'capitalizeMutator', {
758
+ enumerable: true,
759
+ get: function () {
760
+ return capitalizeMutator;
761
+ }
762
+ });
763
+ Object.defineProperty(exports, 'htmlEscapeMutator', {
764
+ enumerable: true,
765
+ get: function () {
766
+ return htmlEscapeMutator;
767
+ }
768
+ });
769
+ Object.defineProperty(exports, 'kebabCaseMutator', {
770
+ enumerable: true,
771
+ get: function () {
772
+ return kebabCaseMutator;
773
+ }
774
+ });
775
+ Object.defineProperty(exports, 'lowercaseMutator', {
776
+ enumerable: true,
777
+ get: function () {
778
+ return lowercaseMutator;
779
+ }
780
+ });
781
+ Object.defineProperty(exports, 'ltrimMutator', {
782
+ enumerable: true,
783
+ get: function () {
784
+ return ltrimMutator;
785
+ }
786
+ });
787
+ Object.defineProperty(exports, 'maskMutator', {
788
+ enumerable: true,
789
+ get: function () {
790
+ return maskMutator;
791
+ }
792
+ });
793
+ Object.defineProperty(exports, 'padEndMutator', {
794
+ enumerable: true,
795
+ get: function () {
796
+ return padEndMutator;
797
+ }
798
+ });
799
+ Object.defineProperty(exports, 'padStartMutator', {
800
+ enumerable: true,
801
+ get: function () {
802
+ return padStartMutator;
803
+ }
804
+ });
805
+ Object.defineProperty(exports, 'pascalCaseMutator', {
806
+ enumerable: true,
807
+ get: function () {
808
+ return pascalCaseMutator;
809
+ }
810
+ });
811
+ Object.defineProperty(exports, 'prependMutator', {
812
+ enumerable: true,
813
+ get: function () {
814
+ return prependMutator;
815
+ }
816
+ });
817
+ Object.defineProperty(exports, 'removeNumbersMutator', {
818
+ enumerable: true,
819
+ get: function () {
820
+ return removeNumbersMutator;
821
+ }
822
+ });
823
+ Object.defineProperty(exports, 'removeSpecialCharactersMutator', {
824
+ enumerable: true,
825
+ get: function () {
826
+ return removeSpecialCharactersMutator;
827
+ }
828
+ });
829
+ Object.defineProperty(exports, 'repeatMutator', {
830
+ enumerable: true,
831
+ get: function () {
832
+ return repeatMutator;
833
+ }
834
+ });
835
+ Object.defineProperty(exports, 'replaceAllMutator', {
836
+ enumerable: true,
837
+ get: function () {
838
+ return replaceAllMutator;
839
+ }
840
+ });
841
+ Object.defineProperty(exports, 'replaceMutator', {
842
+ enumerable: true,
843
+ get: function () {
844
+ return replaceMutator;
845
+ }
846
+ });
847
+ Object.defineProperty(exports, 'reverseMutator', {
848
+ enumerable: true,
849
+ get: function () {
850
+ return reverseMutator;
851
+ }
852
+ });
853
+ Object.defineProperty(exports, 'rtrimMutator', {
854
+ enumerable: true,
855
+ get: function () {
856
+ return rtrimMutator;
857
+ }
858
+ });
859
+ Object.defineProperty(exports, 'safeHtmlMutator', {
860
+ enumerable: true,
861
+ get: function () {
862
+ return safeHtmlMutator;
863
+ }
864
+ });
865
+ Object.defineProperty(exports, 'slugMutator', {
866
+ enumerable: true,
867
+ get: function () {
868
+ return slugMutator;
869
+ }
870
+ });
871
+ Object.defineProperty(exports, 'snakeCaseMutator', {
872
+ enumerable: true,
873
+ get: function () {
874
+ return snakeCaseMutator;
875
+ }
876
+ });
877
+ Object.defineProperty(exports, 'string', {
878
+ enumerable: true,
879
+ get: function () {
880
+ return string;
881
+ }
882
+ });
883
+ Object.defineProperty(exports, 'stringifyMutator', {
884
+ enumerable: true,
885
+ get: function () {
886
+ return stringifyMutator;
887
+ }
888
+ });
889
+ Object.defineProperty(exports, 'stripTagsMutator', {
890
+ enumerable: true,
891
+ get: function () {
892
+ return stripTagsMutator;
893
+ }
894
+ });
895
+ Object.defineProperty(exports, 'titleCaseMutator', {
896
+ enumerable: true,
897
+ get: function () {
898
+ return titleCaseMutator;
899
+ }
900
+ });
901
+ Object.defineProperty(exports, 'trimMultipleWhitespaceMutator', {
902
+ enumerable: true,
903
+ get: function () {
904
+ return trimMultipleWhitespaceMutator;
905
+ }
906
+ });
907
+ Object.defineProperty(exports, 'trimMutator', {
908
+ enumerable: true,
909
+ get: function () {
910
+ return trimMutator;
911
+ }
912
+ });
913
+ Object.defineProperty(exports, 'truncateMutator', {
914
+ enumerable: true,
915
+ get: function () {
916
+ return truncateMutator;
917
+ }
918
+ });
919
+ Object.defineProperty(exports, 'unescapeHtmlMutator', {
920
+ enumerable: true,
921
+ get: function () {
922
+ return unescapeHtmlMutator;
923
+ }
924
+ });
925
+ Object.defineProperty(exports, 'uppercaseMutator', {
926
+ enumerable: true,
927
+ get: function () {
928
+ return uppercaseMutator;
929
+ }
930
+ });
931
+ Object.defineProperty(exports, 'urlDecodeMutator', {
932
+ enumerable: true,
933
+ get: function () {
934
+ return urlDecodeMutator;
935
+ }
936
+ });
937
+ Object.defineProperty(exports, 'urlEncodeMutator', {
938
+ enumerable: true,
939
+ get: function () {
940
+ return urlEncodeMutator;
941
+ }
942
+ });
943
+ //# sourceMappingURL=string-6m5Y83pJ.cjs.map