import type {TitlecaseCharacter} from './internal/characters.d.ts'; import type {AllExtend} from './all-extend.d.ts'; import type {IsStringLiteral} from './is-string-literal.d.ts'; import type {UnwrapBrandedPrimitive} from './unwrap-branded-primitive.d.ts'; /** Returns a boolean for whether the given string literal is lowercase. Checks union members separately; mixed results return `boolean`. Returns `boolean` for `any` and `false` for `never`. Only string inputs are accepted. @example ``` import type {IsLowercase} from 'type-fest'; type A = IsLowercase<'abc'>; //=> true type B = IsLowercase<'Abc'>; //=> false type C = IsLowercase; //=> boolean ``` */ export type IsLowercase = // Check a whole literal directly to avoid a character walk and its recursion limit. IsStringLiteral extends true // The template form reads a string enum member by its value, since the member itself is not assignable to `Lowercase`. ? S extends unknown ? `${UnwrapBrandedPrimitive}` extends Lowercase ? true : false : never : AllExtend<_IsLowercase, true>; /** Loops through each part in the string and returns a boolean array indicating whether each part is lowercase. */ type _IsLowercase = S extends `${infer First}${infer Rest}` // A known mismatch decides the result even when the rest of the input is long or unknown. ? IsLowercaseHelper extends false ? [false] : _IsLowercase]> : [...Accumulator, IsLowercaseHelper]; /** Returns a boolean for whether an individual part of the string is lowercase. */ type IsLowercaseHelper = S extends Lowercase ? true : S extends Uppercase | Capitalize | `${string}${Uppercase}${string}` ? false // A titlecase character is changed by both lowercasing and uppercasing, so it is neither, but none of the patterns above name it either. : S extends TitlecaseCharacter ? false : boolean; export {};