Commit 95141c92 authored by James Laver's avatar James Laver Committed by Alexandre Delanoë

add Gargantext.Utils.Regex for low level regex work

parent f17c98df
function _cloneRegex(r) { return new RegExp(r.source, r.flags); }
function _getRegexLastIndex(r) { return r.lastIndex; }
function _execRegex(r, s) { return r.exec(s); }
module.exports={
_cloneRegex: _cloneRegex,
_getRegexLastIndex: _getRegexLastIndex,
_execRegex: _execRegex
};
-- | Utilities for working with regexes in a naughty mutable manner
module Gargantext.Utils.Regex where
import Effect (Effect)
import Prelude ((<$>))
import Data.Maybe (Maybe(..))
import Effect.Uncurried (EffectFn2, runEffectFn2)
import Data.Function.Uncurried (Fn1, runFn1)
import Data.Nullable (Nullable, toMaybe)
import Data.String.Regex (Regex)
foreign import _cloneRegex :: Fn1 Regex Regex
foreign import _getRegexLastIndex :: Fn1 Regex Int
foreign import _execRegex :: EffectFn2 Regex String (Nullable String)
cloneRegex :: Regex -> Regex
cloneRegex = runFn1 _cloneRegex
getRegexLastIndex :: Regex -> Int
getRegexLastIndex = runFn1 _getRegexLastIndex
execRegex :: Regex -> String -> Effect (Maybe String)
execRegex r s = toMaybe <$> runEffectFn2 _execRegex r s
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment