UNPKG

@augment-vir/common

Version:

A collection of augments, helpers types, functions, and classes for any JavaScript environment.

90 lines (89 loc) 3.43 kB
import { type FirstLetterLowercase, type FirstLetterUppercase, type PartialWithUndefined } from '@augment-vir/core'; /** * The different string cases. * * @category String * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare enum StringCase { Upper = "upper", Lower = "lower" } /** * Options for casing functions in `@augment-vir/common`. * * @category String * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export type CasingOptions = { /** * Capitalize the first letter of the string. * * @default StringCase.Lower */ firstLetterCase: StringCase; }; /** * Default options for {@link CasingOptions}. * * @category String * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare const defaultCasingOptions: Required<CasingOptions>; /** * Convert the first letter of a string to either lower or uppercase. * * @category String * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export type FirstLetterCase<SpecificCase extends StringCase, Value extends string> = SpecificCase extends StringCase.Lower ? FirstLetterLowercase<Value> : FirstLetterUppercase<Value>; /** * Set the first letter of the input to uppercase or lowercase. * * @category String * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare function setFirstLetterCasing<const SpecificCase extends StringCase, const Value extends string>(input: Value, stringCase: SpecificCase): FirstLetterCase<SpecificCase, Value>; /** * Indicates whether the given string has different lower and upper case variants. (Some strings * don't, such as all numbers or `'√'`.) * * @category String * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare function hasCase(input: string): boolean; /** * Options for {@link isCase}. * * @category String * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export type IsCaseOptions = { /** * Set to `true` to fail on characters that don't have different upper and lower case versions * (such as punctuation, like `'.'` or symbols, like `'√'`). * * @default false */ rejectNoCaseCharacters: boolean; }; /** * Checks if the given string is exclusively of the specific case. * * Note that some characters have no casing, such as punctuation (they have no difference between * upper and lower casings). By default, those letters always return `true` for this function, * regardless of which `caseType` is provided. To instead return `false` for any such characters, * pass in an options object and set `rejectNoCaseCharacters` to true. * * @category String * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare function isCase(input: string, caseType: StringCase, options?: PartialWithUndefined<IsCaseOptions>): boolean;