{"version":3,"file":"words-tWG2QPXb.cjs","names":["results: string[]"],"sources":["../src/internal/words.ts"],"sourcesContent":["import type { Words } from \"type-fest\";\n\n// @see https://github.com/sindresorhus/type-fest/blob/main/source/internal/characters.d.ts#L5-L31\nconst WHITESPACE = [\n \"\\u{9}\", // '\\t'\n \"\\u{A}\", // '\\n'\n \"\\u{B}\", // '\\v'\n \"\\u{C}\", // '\\f'\n \"\\u{D}\", // '\\r'\n \"\\u{20}\", // ' '\n \"\\u{85}\",\n \"\\u{A0}\",\n \"\\u{1680}\",\n \"\\u{2000}\",\n \"\\u{2001}\",\n \"\\u{2002}\",\n \"\\u{2003}\",\n \"\\u{2004}\",\n \"\\u{2005}\",\n \"\\u{2006}\",\n \"\\u{2007}\",\n \"\\u{2008}\",\n \"\\u{2009}\",\n \"\\u{200A}\",\n \"\\u{2028}\",\n \"\\u{2029}\",\n \"\\u{202F}\",\n \"\\u{205F}\",\n \"\\u{3000}\",\n \"\\u{FEFF}\",\n] as const;\n\n// @see https://github.com/sindresorhus/type-fest/blob/main/source/internal/characters.d.ts#L33\nconst WORD_SEPARATORS = new Set([\"-\", \"_\", ...WHITESPACE]);\n\nexport const words = (\n data: S,\n): string extends S ? string[] : Words => {\n const results: string[] = [];\n let word = \"\";\n\n const flush = (): void => {\n if (word.length > 0) {\n results.push(word);\n word = \"\";\n }\n };\n\n for (const character of data) {\n if (WORD_SEPARATORS.has(character)) {\n // Separator encountered; flush the current word & exclude the separator.\n flush();\n continue;\n }\n\n // Detect transitions:\n // 1. Lowercase to uppercase (e.g., \"helloWorld\")\n if (/[a-z]$/u.test(word) && /[A-Z]/u.test(character)) {\n flush();\n }\n // 2. Uppercase to lowercase following multiple uppercase letters (e.g., \"HELLOWorld\")\n // When the text transitions from 2 upper case letters to a lower case\n // letter. (one upper case letter is considered part of the word, e.g.\n // \"Dog\").\n else if (/[A-Z][A-Z]$/u.test(word) && /[a-z]/u.test(character)) {\n const lastCharacter = word.slice(-1);\n word = word.slice(0, -1);\n flush();\n word = lastCharacter;\n }\n // 3. Digit to non-digit or non-digit to digit (e.g., \"123abc\" or \"abc123\")\n else if (/\\d$/u.test(word) !== /\\d/u.test(character)) {\n flush();\n }\n\n // Add the current character to the current word.\n word += character;\n }\n\n // Flush any remaining word.\n flush();\n\n // @ts-expect-error [ts2322] -- TypeScript can't infer this type...\n return results;\n};\n"],"mappings":"AAiCA,MAAM,EAAkB,IAAI,IAAI,CAAC,IAAK,IAAK,GA9BxB;4EA2BlB,CAGwD,CAAC,CAE7C,EACX,GAC2C,CAC3C,IAAMA,EAAoB,EAAE,CACxB,EAAO,GAEL,MAAoB,CACpB,EAAK,OAAS,IAChB,EAAQ,KAAK,EAAK,CAClB,EAAO,KAIX,IAAK,IAAM,KAAa,EAAM,CAC5B,GAAI,EAAgB,IAAI,EAAU,CAAE,CAElC,GAAO,CACP,SAKF,GAAI,UAAU,KAAK,EAAK,EAAI,SAAS,KAAK,EAAU,CAClD,GAAO,SAMA,eAAe,KAAK,EAAK,EAAI,SAAS,KAAK,EAAU,CAAE,CAC9D,IAAM,EAAgB,EAAK,MAAM,GAAG,CACpC,EAAO,EAAK,MAAM,EAAG,GAAG,CACxB,GAAO,CACP,EAAO,OAGA,OAAO,KAAK,EAAK,GAAK,MAAM,KAAK,EAAU,EAClD,GAAO,CAIT,GAAQ,EAOV,OAHA,GAAO,CAGA"}