import { type MaxLengthString, type MinLengthString, type NonEmptyString, type RelaxedExclude, type SupportedLength } from 'ts-type-forge'; import { type Type } from '../type.mjs'; export declare function string(defaultValue?: string): Type; export declare function string(defaultValue: S & DefaultValueType, constraints: C): Type>; type RawConstraints = Partial>; /** * The set of constraints accepted by {@link string}. */ export type StringTypeConstraints = RawConstraints; /** * The result type produced by {@link string} for a given set of constraints * `C` (e.g. `nonempty` yields {@link NonEmptyString}, `minLength` / * `maxLength` yield {@link MinLengthString} / {@link MaxLengthString}, * `startsWith` narrows to a template literal type, etc.). */ export type StringConstraintsResultType = ConstraintsResultType; type DefaultValueType = DefaultValueWhenNonemptyIsOn & DefaultValueWhenMinLengthIsOn & DefaultValueWhenMaxLengthIsOn & DefaultValueWhenStartsWithIsOn & DefaultValueWhenEndsWithIsOn & DefaultValueWhenIncludesIsOn & DefaultValueWhenUppercaseIsOn & DefaultValueWhenLowercaseIsOn; type ConstraintsResultType = ConstraintsResultTypeWhenNonemptyIsOn & ConstraintsResultTypeWhenMinLengthIsOn & ConstraintsResultTypeWhenMaxLengthIsOn & DefaultValueWhenStartsWithIsOn & DefaultValueWhenEndsWithIsOn & DefaultValueWhenIncludesIsOn; type DefaultValueWhenStartsWithIsOn = C extends Readonly<{ startsWith: infer S extends string; }> ? `${S}${string}` : string; type DefaultValueWhenEndsWithIsOn = C extends Readonly<{ endsWith: infer E extends string; }> ? `${string}${E}` : string; type DefaultValueWhenIncludesIsOn = C extends Readonly<{ includes: infer M extends string; }> ? `${string}${M}${string}` : string; type DefaultValueWhenUppercaseIsOn = C extends Readonly<{ uppercase: true; }> ? CastUppercase : string; type DefaultValueWhenLowercaseIsOn = C extends Readonly<{ lowercase: true; }> ? CastLowercase : string; type CastLowercase = S extends Lowercase ? S : never; type CastUppercase = S extends Uppercase ? S : never; type DefaultValueWhenNonemptyIsOn = C extends Readonly<{ nonempty: true; }> ? RejectEmptyString : string; type RejectEmptyString = S extends '' ? never : S; type ConstraintsResultTypeWhenNonemptyIsOn = C extends Readonly<{ nonempty: true; }> ? NonEmptyString : string; /** * The length-bound literals supported at the type level: * `RelaxedExclude` (i.e. `1 | 2 | ... | 2048`, the shared * cap of the branded length-constrained types in ts-type-forge). Only bounds * within this range are encoded in the result brand; larger literals and * non-literal `number`s collapse to plain `string` to keep the type-level * computation cheap (the runtime constraint applies regardless). Non-integer * bounds and bounds less than 1 throw a `TypeError` when the type is * constructed. */ type SupportedLengthLiteral = RelaxedExclude; type ConstraintsResultTypeWhenMinLengthIsOn = C extends Readonly<{ minLength: infer M extends SupportedLengthLiteral; }> ? MinLengthString : string; type ConstraintsResultTypeWhenMaxLengthIsOn = C extends Readonly<{ maxLength: infer M extends SupportedLengthLiteral; }> ? MaxLengthString : string; type DefaultValueWhenMinLengthIsOn = C extends Readonly<{ minLength: infer M extends SupportedLengthLiteral; }> ? StringWithMinLength : string; type DefaultValueWhenMaxLengthIsOn = C extends Readonly<{ maxLength: infer M extends SupportedLengthLiteral; }> ? StringWithMaxLength : string; type StringWithMinLength = HasLengthAtLeast extends true ? S : never; type StringWithMaxLength = HasLengthAtMost extends true ? S : never; type HasLengthAtLeast = string extends S ? true : Acc['length'] extends N ? true : S extends '' ? false : S extends `${infer _}${infer Rest}` ? HasLengthAtLeast : false; type HasLengthAtMost = string extends S ? true : S extends '' ? true : Acc['length'] extends N ? false : S extends `${infer _}${infer Rest}` ? HasLengthAtMost : false; export {}; //# sourceMappingURL=string.d.mts.map