Provide utils from purescript-globals instead of FFI (#145)

This commit is contained in:
Nick Saunders 2019-08-16 12:03:38 -07:00 committed by Connor Prussin
parent ae56c9f0a1
commit 88e1dcde9e
4 changed files with 11 additions and 23 deletions

View File

@ -46,6 +46,7 @@
"purescript-strings": "^4.0.0",
"purescript-tuples": "^5.1.0",
"purescript-type-equality": "^3.0.0",
"purescript-unsafe-coerce": "^4.0.0"
"purescript-unsafe-coerce": "^4.0.0",
"purescript-globals": "^4.1.0"
}
}

View File

@ -1,6 +1,6 @@
{
"name": "purescript-httpure",
"set": "psc-0.12.2",
"set": "psc-0.13.2-20190815",
"source": "https://github.com/purescript/package-sets.git",
"depends": [
"aff",
@ -13,6 +13,7 @@
"exceptions",
"foldable-traversable",
"foreign",
"globals",
"lists",
"maybe",
"newtype",

View File

@ -1,11 +0,0 @@
"use strict";
exports.encodeURIComponent = encodeURIComponent
exports.decodeURIComponentImpl = function(s) {
try {
return decodeURIComponent(s);
} catch(error) {
return null;
}
};

View File

@ -1,6 +1,6 @@
module HTTPure.Utils
( encodeURIComponent
, decodeURIComponent
( module Global
, encodeURIComponent
, replacePlus
, urlDecode
) where
@ -8,16 +8,13 @@ module HTTPure.Utils
import Prelude
import Data.Maybe as Maybe
import Data.Nullable as Nullable
import Data.String as String
import Global (decodeURIComponent) as Global
import Global.Unsafe (unsafeEncodeURIComponent)
foreign import encodeURIComponent :: String -> String
foreign import decodeURIComponentImpl :: String -> Nullable.Nullable String
decodeURIComponent :: String -> Maybe.Maybe String
decodeURIComponent = Nullable.toMaybe <<< decodeURIComponentImpl
encodeURIComponent :: String -> String
encodeURIComponent = unsafeEncodeURIComponent
replacePlus :: String -> String
@ -27,4 +24,4 @@ replacePlus =
urlDecode :: String -> String
urlDecode s =
Maybe.fromMaybe s $ decodeURIComponent s
Maybe.fromMaybe s $ Global.decodeURIComponent s