Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ yarn.lock
/node_modules/
/output/
/tmp/
/.psc-package/

.psc-ide-port

20 changes: 10 additions & 10 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
"url": "git://github.com/purescript-contrib/purescript-string-extras.git"
},
"dependencies": {
"purescript-strings": "^3.3.1",
"purescript-prelude": "^3.1.0",
"purescript-maybe": "^3.0.0",
"purescript-partial": "^1.2.1",
"purescript-either": "^3.1.0",
"purescript-foldable-traversable": "^3.6.1",
"purescript-unicode": "^3.0.1",
"purescript-arrays": "^4.2.0"
"purescript-strings": "^4.0.0",
"purescript-prelude": "^4.0.0",
"purescript-maybe": "^4.0.0",
"purescript-partial": "^2.0.0",
"purescript-either": "^4.0.0",
"purescript-foldable-traversable": "^4.0.0",
"purescript-unicode": "^4.0.0",
"purescript-arrays": "^5.0.0"
},
"devDependencies": {
"purescript-assert": "^3.0.0",
"purescript-console": "^3.0.0"
"purescript-assert": "^4.0.0",
"purescript-console": "^4.1.0"
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"test": "pulp test"
},
"devDependencies": {
"pulp": "^12.0.1",
"purescript": "^0.11.6",
"purescript-psa": "^0.5.1",
"pulp": "^12.3.0",
"purescript": "^0.12.0",
"purescript-psa": "^0.6.0",
"rimraf": "^2.6.2"
}
}
17 changes: 17 additions & 0 deletions psc-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "purescript-strings-extra",
"set": "psc-0.12.0",
"source": "https://github.com/purescript/package-sets.git",
"depends": [
"console",
"assert",
"arrays",
"unicode",
"foldable-traversable",
"either",
"partial",
"maybe",
"strings",
"prelude"
]
}
14 changes: 8 additions & 6 deletions src/Data/String/Extra.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ module Data.String.Extra
) where

import Data.Array as Array
import Data.Array.NonEmpty as NonEmptyArray
import Data.Char.Unicode as Unicode
import Data.Either (fromRight)
import Data.Foldable (foldMap)
import Data.String as String
import Data.String.CodeUnits as SCU
import Data.String.Regex (Regex)
import Data.String.Regex as Regex
import Data.String.Regex.Flags as Flags
Expand Down Expand Up @@ -66,8 +68,8 @@ words string =

upfirst :: String -> String
upfirst =
String.uncons >>> foldMap \{ head, tail } ->
String.singleton (Unicode.toUpper head) <> toUnicodeLower tail
SCU.uncons >>> foldMap \{ head, tail } ->
SCU.singleton (Unicode.toUpper head) <> toUnicodeLower tail

regexGlobal :: String -> Regex
regexGlobal regexStr =
Expand All @@ -76,23 +78,23 @@ regexGlobal regexStr =
asciiWords :: String -> Array String
asciiWords =
Regex.match (regexGlobal "[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+")
>>> foldMap Array.catMaybes
>>> foldMap NonEmptyArray.catMaybes

hasUnicodeWords :: String -> Boolean
hasUnicodeWords =
Regex.test (regexGlobal "[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9]")

toUnicodeLower :: String -> String
toUnicodeLower =
String.toCharArray >>> map Unicode.toLower >>> String.fromCharArray
SCU.toCharArray >>> map Unicode.toLower >>> SCU.fromCharArray

toUnicodeUpper :: String -> String
toUnicodeUpper =
String.toCharArray >>> map Unicode.toUpper >>> String.fromCharArray
SCU.toCharArray >>> map Unicode.toUpper >>> SCU.fromCharArray

unicodeWords :: String -> Array String
unicodeWords =
Regex.match (regexGlobal regexStr) >>> foldMap Array.catMaybes
Regex.match (regexGlobal regexStr) >>> foldMap NonEmptyArray.catMaybes
where
-- https://github.com/lodash/lodash/blob/master/.internal/unicodeWords.js
-- Used to compose unicode character classes.
Expand Down
8 changes: 4 additions & 4 deletions test/Main.purs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Test.Main where

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Data.String.Extra as String
import Effect (Effect)
import Effect.Console (log)
import Prelude (Unit, ($), (==), (*>), discard)
import Test.Assert (ASSERT, assert)
import Test.Assert (assert)

main :: forall eff. Eff (assert :: ASSERT, console :: CONSOLE | eff) Unit
main :: Effect Unit
main = do
log "camelCase" *> do
assert $ String.camelCase "" == ""
Expand Down