@@ -11,10 +11,11 @@ module Data.String.Extra
1111
1212import Data.Array as Array
1313import Data.Array.NonEmpty as NonEmptyArray
14- import Data.Char.Unicode as Unicode
14+ import Data.String.Unicode as Unicode
15+ import Data.CodePoint.Unicode as UCP
1516import Data.Foldable (foldMap )
1617import Data.String as String
17- import Data.String.CodeUnits as SCU
18+ import Data.String.CodePoints as SCP
1819import Data.String.Regex (Regex )
1920import Data.String.Regex as Regex
2021import Data.String.Regex.Unsafe (unsafeRegex )
@@ -29,7 +30,7 @@ import Prelude ((>>>), (<>), ($), map)
2930camelCase :: String -> String
3031camelCase =
3132 words >>> Array .uncons >>> foldMap \{ head, tail } ->
32- toUnicodeLower head <> foldMap pascalCase tail
33+ Unicode .toLower head <> foldMap pascalCase tail
3334
3435-- | Converts a `String` to kebab case
3536-- |
@@ -38,7 +39,7 @@ camelCase =
3839-- | ```
3940kebabCase :: String -> String
4041kebabCase =
41- words >>> map toUnicodeLower >>> String .joinWith " -"
42+ words >>> map Unicode .toLower >>> String .joinWith " -"
4243
4344-- | Converts a `String` to Pascal case
4445-- |
@@ -56,7 +57,7 @@ pascalCase =
5657-- | ```
5758snakeCase :: String -> String
5859snakeCase =
59- words >>> map toUnicodeLower >>> String .joinWith " _"
60+ words >>> map Unicode .toLower >>> String .joinWith " _"
6061
6162-- | Converts the first character in a `String` to upper case, lower-casing
6263-- | the rest of the string.
@@ -66,8 +67,8 @@ snakeCase =
6667-- | ```
6768upperCaseFirst :: String -> String
6869upperCaseFirst =
69- SCU .uncons >>> foldMap \{ head, tail } ->
70- SCU .singleton ( Unicode .toUpper head) <> toUnicodeLower tail
70+ SCP .uncons >>> foldMap \{ head, tail } ->
71+ SCP .fromCodePointArray ( UCP .toTitle head) <> Unicode .toLower tail
7172
7273-- | Separates a `String` into words based on Unicode separators, capital
7374-- | letters, dashes, underscores, etc.
@@ -118,14 +119,6 @@ hasUnicodeWords :: String -> Boolean
118119hasUnicodeWords =
119120 Regex .test regexHasUnicodeWords
120121
121- toUnicodeLower :: String -> String
122- toUnicodeLower =
123- SCU .toCharArray >>> map Unicode .toLower >>> SCU .fromCharArray
124-
125- toUnicodeUpper :: String -> String
126- toUnicodeUpper =
127- SCU .toCharArray >>> map Unicode .toUpper >>> SCU .fromCharArray
128-
129122regexUnicodeWords :: Regex
130123regexUnicodeWords =
131124 regexGlobal
0 commit comments