UNPKG

@web3r/flowerkit

Version:

Tree-shakable JavaScript and TypeScript utility library for frontend/browser apps: DOM, events, arrays, objects, strings, date, JSON, and network helpers (ESM/CJS, SSR-friendly).

1 lines 1.47 kB
{"version":3,"file":"index.mjs","sources":[""],"sourcesContent":["export type TGetWordsArgs = Parameters<typeof getWords>;\r\n\r\nexport type TGetWordsReturn = ReturnType<typeof getWords>;\r\n\r\n/**\r\n * Splits a string into words:\r\n * Splits camelCase boundaries: \"helloWorld\" -> \"hello World\"\r\n * Removes non-letter separators\r\n *\r\n * @param {string} str Source string\r\n * @returns {string[]} Array of words (letters-only segments)\r\n * @throws {TypeError} If str is not a string\r\n * @example\r\n * getWords(\"helloWorld! what's_up?\"); // [\"hello\",\"World\",\"what\",\"s\",\"up\"]\r\n */\r\nexport const getWords = (str: string): string[] => {\r\n if (typeof str !== \"string\") {\r\n throw new TypeError(\"getWords: str must be a string\");\r\n }\r\n\r\n const nonCharRegex = /[^a-zA-Z]+/g;\r\n const camelCaseRegex = /([a-z])([A-Z])/g;\r\n\r\n const replacer = (_: string, a: string, b: string) => a + \" \" + b;\r\n\r\n return str\r\n .replace(camelCaseRegex, replacer)\r\n .split(nonCharRegex)\r\n .filter((word) => word.length > 0);\r\n};\r\n"],"names":["getWords","str","TypeError","nonCharRegex","camelCaseRegex","replacer","_","a","b","replace","split","filter","word","length"],"mappings":";;;;;;;;;;;AAeO,MAAMA,SAAYC,MACvB,UAAWA,MAAQ,SACjB,MAAM,IAAIC,UAAU,kCAGtB,MAAMC,aAAe,cACrB,MAAMC,eAAiB,kBAEvB,MAAMC,SAAWA,CAACC,EAAWC,EAAWC,IAAcD,EAAI,IAAMC,EAEhE,OAAOP,IACJQ,QAAQL,eAAgBC,UACxBK,MAAMP,cACNQ,OAAQC,MAASA,KAAKC,OAAS"}