Skip to content

Commit 93317f0

Browse files
author
Marcin Szamotulski
committed
splitRegex - move to top level
1 parent 69f0ae9 commit 93317f0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Routing/Parser.purs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ module Routing.Parser (
22
parse
33
) where
44

5-
import Data.Array as A
6-
import Data.Map as M
7-
import Data.String as S
85
import Control.MonadPlus (guard)
6+
import Data.Array as A
97
import Data.Either (fromRight)
108
import Data.List (fromFoldable, List)
9+
import Data.Map as M
1110
import Data.Maybe (Maybe, fromMaybe)
12-
import Data.String.Regex (regex, split) as R
11+
import Data.String as S
12+
import Data.String.Regex (Regex, regex, split) as R
1313
import Data.String.Regex.Flags (noFlags) as R
1414
import Data.Traversable (traverse)
1515
import Data.Tuple (Tuple(..))
@@ -36,8 +36,11 @@ parsePart str = fromMaybe (Path str) do
3636
Tuple <$> (A.head keyVal) <*> (keyVal A.!! 1)
3737

3838

39+
splitRegex :: R.Regex
40+
splitRegex = unsafePartial fromRight $ R.regex "\\/|(?=\\?)" R.noFlags
41+
3942
-- | Parse hash string to `Route` with `decoder` function
4043
-- | applied to every hash part (usually `decodeURIComponent`)
4144
parse :: (String -> String) -> String -> Route
4245
parse decoder hash =
43-
map ( decoder >>> parsePart ) $ fromFoldable (R.split (unsafePartial fromRight $ R.regex "\\/|(?=\\?)" R.noFlags) hash)
46+
map ( decoder >>> parsePart ) $ fromFoldable (R.split splitRegex hash)

0 commit comments

Comments
 (0)