@@ -41,7 +41,7 @@ import Data.Array.NonEmpty (NonEmptyArray, fromArray, toArray)
41import Data.Bifunctor (lmap)
41import Data.Bifunctor (lmap)
42import Data.BigInt (BigInt)
42import Data.BigInt (BigInt)
43import Data.BigInt as BigInt
43import Data.BigInt as BigInt
44−import Data.Either (Either, hush, note)
44+import Data.Either (Either(..), hush, note)
45import Data.FoldableWithIndex (foldrWithIndex)
45import Data.FoldableWithIndex (foldrWithIndex)
46import Data.Identity (Identity(..))
46import Data.Identity (Identity(..))
47import Data.Int as Int
47import Data.Int as Int
@@ -51,6 +51,7 @@ import Data.Map as Map
51import Data.Maybe (Maybe(..), fromMaybe, fromMaybe', maybe)
51import Data.Maybe (Maybe(..), fromMaybe, fromMaybe', maybe)
52import Data.Newtype (class Newtype)
52import Data.Newtype (class Newtype)
53import Data.Nullable (Nullable, toMaybe, toNullable)
53import Data.Nullable (Nullable, toMaybe, toNullable)
54+import Data.Number as Number
54import Data.Symbol (class IsSymbol, reflectSymbol)
55import Data.Symbol (class IsSymbol, reflectSymbol)
55import Data.Traversable (sequence, traverse)
56import Data.Traversable (sequence, traverse)
56import Data.TraversableWithIndex (traverseWithIndex)
57import Data.TraversableWithIndex (traverseWithIndex)
@@ -185,18 +186,25 @@ readBigInt ∷
185readBigInt = unsafeReadTagged "BigInt"
186readBigInt = unsafeReadTagged "BigInt"
187instance ReadForeign BigInt where
188instance ReadForeign BigInt where
188− readImpl fValue = tryInt fValue <|> readBigInt fValue <|> tryString fValue
189+ readImpl fValue = tryInt fValue <|> tryNumber fValue <|> readBigInt fValue <|> tryString fValue
190 tryInt f = readInt f <#> BigInt.fromInt
191 tryInt f = readInt f <#> BigInt.fromInt
194+ if Number.round num == num then
195+ BigInt.fromNumber num
196+ # note (err $ "Cannot convert Number " <> show num <> " to BigInt")
199+ (Left $ err $ "Cannot convert decimal Number " <> show num <> " to BigInt")
191 tryString f = do
201 tryString f = do
192 bi ← readString f
202 bi ← readString f
193 BigInt.fromString bi
203 BigInt.fromString bi
194− # note
204+ # note ( err $ "Cannot convert String " <> bi <> " to BigInt")
195− ( singleton $ ForeignError $ "String " <> bi <>
196− " could not be converted to BigInt"
199−
206+ err = pure <<< ForeignError
200instance ReadForeign String where
208instance ReadForeign String where
201 readImpl = readString
209 readImpl = readString