Skip to content

Commit 5a8f558

Browse files
Update for changes to purescript-unicode (#16)
Co-authored-by: Thomas Honeyman <[email protected]>
1 parent 7ea13b5 commit 5a8f558

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/Data/String/Extra.purs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ module Data.String.Extra
1111

1212
import Data.Array as Array
1313
import 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
1516
import Data.Foldable (foldMap)
1617
import Data.String as String
17-
import Data.String.CodeUnits as SCU
18+
import Data.String.CodePoints as SCP
1819
import Data.String.Regex (Regex)
1920
import Data.String.Regex as Regex
2021
import Data.String.Regex.Unsafe (unsafeRegex)
@@ -29,7 +30,7 @@ import Prelude ((>>>), (<>), ($), map)
2930
camelCase :: String -> String
3031
camelCase =
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
-- | ```
3940
kebabCase :: String -> String
4041
kebabCase =
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
-- | ```
5758
snakeCase :: String -> String
5859
snakeCase =
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
-- | ```
6768
upperCaseFirst :: String -> String
6869
upperCaseFirst =
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
118119
hasUnicodeWords =
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-
129122
regexUnicodeWords :: Regex
130123
regexUnicodeWords =
131124
regexGlobal

0 commit comments

Comments
 (0)