diff --git a/bower.json b/bower.json index e4fef69..e04e563 100644 --- a/bower.json +++ b/bower.json @@ -22,6 +22,7 @@ "dependencies": { "purescript-prelude": "^6.0.1", "purescript-functions": "^6.0.0", + "purescript-integers": "^6.0.0", "purescript-maybe": "^6.0.0", "purescript-either": "^6.1.0", "purescript-tuples": "^7.0.0", diff --git a/src/JSON.purs b/src/JSON.purs index a78630a..2c001b2 100644 --- a/src/JSON.purs +++ b/src/JSON.purs @@ -27,6 +27,7 @@ import Prelude import Data.Either (Either(..)) import Data.Function.Uncurried (runFn2, runFn3, runFn7) import Data.Maybe (Maybe(..)) +import Data.Int as Int import JSON.Internal (JArray, JObject, JSON) as Exports import JSON.Internal (JArray, JObject, JSON) import JSON.Internal as Internal @@ -119,6 +120,12 @@ toBoolean json = runFn7 Internal._case fail Just fail fail fail fail json toNumber :: JSON -> Maybe Number toNumber json = runFn7 Internal._case fail fail Just fail fail fail json +-- | Converts a `JSON` `Number` into an `Int`. +-- | +-- | This is provided for convenience only. +toInt :: Json -> Maybe Int +toInt = toNumber >=> Int.fromNumber + -- | Converts a `JSON` value to `String` if the `JSON` is a string. toString :: JSON -> Maybe String toString json = runFn7 Internal._case fail fail fail Just fail fail json