UNPKG

deep-case-crafter

Version:

Transforms deeply nested object, array, Map, and Set keys between common case formats while preserving TypeScript type safety

38 lines (37 loc) 1.58 kB
/** * Determines whether the given string qualifies as a single word. * * A string is considered a "single word" if: * - It does not contain any delimiters such as underscores (`_`), hyphens (`-`), or spaces. * - It contains only alphanumeric characters (letters and digits). Any other character (e.g., punctuation) will cause it to be considered as not a single word. * - For strings longer than one character: * - If the entire string is lowercase, it's considered a single word. * - If the string starts with an uppercase letter and the rest are lowercase, it's considered a single word. * - Single-character strings and empty strings are treated as a single word. * * @param {string} str - The string to check. * @returns {boolean} Returns `true` if the input string qualifies as a single word, otherwise returns `false`. * * @example * // Returns true because "hello" is a single word (all lowercase). * detectSingleWord("hello"); * * @example * // Returns true because "Hello" is considered a single word (capitalized first letter only). * detectSingleWord("Hello"); * * @example * // Returns false because "hello_world" contains an underscore. * detectSingleWord("hello_world"); * * @example * // Returns false because "hello world" contains a space. * detectSingleWord("hello world"); * * @example * // Returns false because "hello@world" contains a special character. * detectSingleWord("hello@world"); * * @internal This function is for internal use by the library */ export default function detectSingleWord(str: string): boolean;