Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/JSON.purs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Data.Function.Uncurried (runFn2, runFn3, runFn7)
import Data.Int as Int
import Data.Maybe (Maybe(..))
import JSON.Internal (JArray, JObject, JSON)
import JSON.Internal (JArray, JObject, JSON) as Exports
import JSON.Internal (JArray, JObject, JSON, isNull) as Exports
import JSON.Internal as Internal

-- | Attempts to parse a string as a JSON value. If parsing fails, an error message detailing the
Expand Down
2 changes: 2 additions & 0 deletions src/JSON/Internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ export const _index = (nothing, just, ix, arr) =>
ix >= 0 && ix < arr.length ? just(arr[ix]) : nothing;

export const _append = (xs, ys) => xs.concat(ys);

export const isNull = (json) => json == null;
2 changes: 2 additions & 0 deletions src/JSON/Internal.purs
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,5 @@ foreign import _append
JArray
JArray
JArray

foreign import isNull :: JSON -> Boolean
4 changes: 4 additions & 0 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ main = do
assertTrue $ J.fromJObject (JO.fromEntries [ Tuple "a" (J.fromInt 1) ]) == J.fromJObject (JO.fromEntries [ Tuple "a" (J.fromInt 1) ])
assertTrue $ J.fromJObject (JO.fromEntries [ Tuple "a" (J.fromInt 1) ]) < J.fromJObject (JO.fromEntries [ Tuple "a" (J.fromInt 2) ])

log "Check isNull"
assertTrue $ J.isNull J.null
assertTrue $ not $ J.isNull (J.fromInt 1)

log "Check array index"
assertTrue $ JA.index (-1) (JA.fromArray (J.fromInt <$> [ 0, 2, 4 ])) == Nothing
assertTrue $ JA.index 0 (JA.fromArray (J.fromInt <$> [ 0, 2, 4 ])) == Just (J.fromInt 0)
Expand Down