import { JsonSchemaResult, JsonSchemaTarget } from "../standard-schema/json-schema.mjs"; import { PrimitiveValidator } from "./primitive-validator.mjs"; import { UUIDVersion } from "../rules/string/id-formats.mjs"; //#region ../@warlock.js/seal/src/validators/string-validator.d.ts /** * String validator class */ declare class StringValidator extends PrimitiveValidator { constructor(errorMessage?: string); /** * Check if value is a string type */ matchesType(value: any): boolean; /** * Stringify the value if not a string */ toString(): this; /** Convert string to uppercase */ uppercase(): this; /** Convert string to lowercase */ lowercase(): this; /** Capitalize only the first letter of the string */ capitalize(): this; /** Capitalize the first letter of each word (Title Case) */ titleCase(): this; /** Convert to camelCase */ camelCase(): this; /** Convert to PascalCase */ pascalCase(): this; /** Convert to snake_case */ snakeCase(): this; /** Convert to kebab-case */ kebabCase(): this; /** * Trim the given needle from the string * If no needle is provided, the default is a single space */ trim(needle?: string): this; /** Trim from the left/start */ ltrim(needle?: string): this; /** Trim from the right/end */ rtrim(needle?: string): this; /** Trim multiple whitespace into single space */ trimMultipleWhitespace(): this; /** Pad string from the start to reach target length */ padStart(length: number, char?: string): this; /** Pad string from the end to reach target length */ padEnd(length: number, char?: string): this; /** Remove HTML tags (safe HTML) */ safeHtml(): this; /** HTML escape special characters */ htmlEscape(): this; /** Unescape HTML entities */ unescapeHtml(): this; /** * Remove special characters * This will remove all characters that are not alphanumeric or whitespace */ removeSpecialCharacters(): this; /** Convert to only alphabetic characters */ toAlpha(): this; /** Convert to only alphanumeric characters */ toAlphanumeric(): this; /** Remove all numeric characters */ removeNumbers(): this; /** URL decode */ urlDecode(): this; /** URL encode */ urlEncode(): this; /** Convert to URL-friendly slug */ slug(): this; /** Base64 encode */ base64Encode(): this; /** Base64 decode */ base64Decode(): this; /** Replace substring or pattern */ replace(search: string | RegExp, replace: string): this; /** Replace all occurrences of substring or pattern */ replaceAll(search: string | RegExp, replace: string): this; /** Append/suffix text to the end */ append(suffix: string): this; /** Prepend/prefix text to the beginning */ prepend(prefix: string): this; /** Reverse the string */ reverse(): this; /** Truncate to a maximum length */ truncate(maxLength: number, suffix?: string): this; /** Repeat string N times */ repeat(count: number): this; /** Mask part of string */ mask(start: number, end?: number, char?: string): this; /** Value must be a valid email */ email(errorMessage?: string): this; /** Value must be a valid URL */ url(errorMessage?: string): this; /** Value can not have whitespace */ withoutWhitespace(errorMessage?: string): this; /** Value must match the given pattern */ pattern(pattern: RegExp, errorMessage?: string): this; /** * Value must be a strong password * Requirements: * - At least 8 characters * - At least 1 uppercase letter * - At least 1 lowercase letter * - At least 1 number * - At least 1 special character */ strongPassword(minLength?: number, errorMessage?: string): this; /** Value must be exactly the given number of words */ words(words: number, errorMessage?: string): this; /** Value must be at least the given number of words */ minWords(words: number, errorMessage?: string): this; /** Value must be at most the given number of words */ maxWords(words: number, errorMessage?: string): this; /** Value length must be greater than the given length */ minLength(length: number, errorMessage?: string): this; /** @alias minLength */ min(min: number, errorMessage?: string): this; /** Value length must be less than the given length */ maxLength(length: number, errorMessage?: string): this; /** @alias maxLength */ max(max: number, errorMessage?: string): this; /** Value must be of the given length */ length(length: number, errorMessage?: string): this; /** * String length must be between min and max (inclusive) * * @param min - Minimum length (inclusive) * @param max - Maximum length (inclusive) * * @example * ```ts * v.string().between(5, 10) // Length: 5 to 10 characters * v.string().lengthBetween(8, 20) // Same using alias * ``` * * @category Validation Rule */ lengthBetween(min: number, max: number, errorMessage?: string): this; /** Allow only alphabetic characters */ alpha(errorMessage?: string): this; /** Allow only alphanumeric characters */ alphanumeric(errorMessage?: string): this; /** Allow only numeric characters */ numeric(errorMessage?: string): this; /** Value must starts with the given string */ startsWith(value: string, errorMessage?: string): this; /** Value must ends with the given string */ endsWith(value: string, errorMessage?: string): this; /** Value must contain the given string */ contains(value: string, errorMessage?: string): this; /** Value must not contain the given string */ notContains(value: string, errorMessage?: string): this; /** Value must be a valid IP address */ ip(errorMessage?: string): this; /** Value must be a valid IPv4 address */ ip4(errorMessage?: string): this; /** Value must be a valid IPv6 address */ ip6(errorMessage?: string): this; /** Check if the string matches a credit card number */ creditCard(errorMessage?: string): this; /** Determine if the value is a valid color */ color(errorMessage?: string): this; /** Determine if the value is a valid hex color */ hexColor(errorMessage?: string): this; /** Determine if the value is a valid HSL color */ hslColor(errorMessage?: string): this; /** Determine if the value is a valid RGB color */ rgbColor(errorMessage?: string): this; /** Determine if the value is a valid RGBA color */ rgbaColor(errorMessage?: string): this; /** Determine if the value is a valid light color */ lightColor(errorMessage?: string): this; /** Determine if the value is a valid dark color */ darkColor(errorMessage?: string): this; /** * Value must be a valid UUID. Optionally restrict to a specific version. * * @example * v.string().uuid() // any RFC 4122 UUID * v.string().uuid(4) // only v4 (random) * v.string().uuid(7) // only v7 (timestamp-ordered) */ uuid(version?: UUIDVersion, errorMessage?: string): this; /** * Value must be a valid CUID. Defaults to CUID2; pass `{ version: 1 }` for legacy. * * @example * v.string().cuid() // CUID2 * v.string().cuid({ version: 1 }) // legacy CUID1 */ cuid(options?: { version?: 1 | 2; errorMessage?: string; }): this; /** Value must be a valid ULID (26 chars, Crockford base32). */ ulid(errorMessage?: string): this; /** * Value must be a valid nanoid string. Default length is 21. * * @example * v.string().nanoid() // 21 chars (default) * v.string().nanoid(10) // 10 chars */ nanoid(length?: number, errorMessage?: string): this; /** * @inheritdoc * * Maps String-specific rule options to JSON Schema keywords. * Non-representable rules (cross-field, refine, color rules, etc.) are silently omitted. * * @example * ```ts * v.string().min(2).max(100).email().toJsonSchema("draft-2020-12") * // → { type: "string", minLength: 2, maxLength: 100, format: "email" } * ``` */ toJsonSchema(target?: JsonSchemaTarget): JsonSchemaResult; } //#endregion export { StringValidator }; //# sourceMappingURL=string-validator.d.mts.map