Skip to content

Commit

Permalink
Add toInt
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMartinez committed Aug 31, 2023
1 parent c9e053d commit 823b832
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions src/JSON.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 823b832

Please sign in to comment.