module Data.JSString.Text
( textToJSString
, textFromJSString
, lazyTextToJSString
, lazyTextFromJSString
, textFromJSVal
, lazyTextFromJSVal
) where
import GHCJS.Prim.Internal (JSVal)
import Data.Coerce (coerce)
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import Data.JSString.Internal.Type
import Language.Javascript.JSaddle.Types (JSM, GHCJSPure(..))
import Language.Javascript.JSaddle.Native.Internal
(valueToString)
textToJSString :: T.Text -> JSString
textToJSString = coerce
textFromJSString :: JSString -> T.Text
textFromJSString = coerce
lazyTextToJSString :: TL.Text -> JSString
lazyTextToJSString = coerce . TL.toStrict
lazyTextFromJSString :: JSString -> TL.Text
lazyTextFromJSString = TL.fromStrict . coerce
textFromJSVal :: JSVal -> GHCJSPure T.Text
textFromJSVal j = GHCJSPure $ textFromJSString <$> valToJSString j
lazyTextFromJSVal :: JSVal -> GHCJSPure TL.Text
lazyTextFromJSVal j = GHCJSPure $ lazyTextFromJSString <$> valToJSString j
valToJSString :: JSVal -> JSM JSString
valToJSString = valueToString