Skip to content

Commit

Permalink
of_ returns nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-murphy committed Jun 10, 2023
1 parent 674d499 commit 6d04dc1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
9 changes: 8 additions & 1 deletion spago.dhall
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{ name = "web-intl"
, dependencies =
[ "effect", "functions", "js-date", "prelude", "unsafe-coerce" ]
[ "effect"
, "functions"
, "js-date"
, "maybe"
, "nullable"
, "prelude"
, "unsafe-coerce"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs" ]
, license = "MIT"
Expand Down
9 changes: 6 additions & 3 deletions src/Web/Intl/DisplayNames.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module Web.Intl.DisplayNames

import Data.Function.Uncurried (Fn2)
import Data.Function.Uncurried as Function.Uncurried
import Data.Maybe (Maybe)
import Data.Nullable (Nullable)
import Data.Nullable as Nullable
import Effect (Effect)
import Effect.Uncurried (EffectFn2)
import Effect.Uncurried as Effect.Uncurried
Expand Down Expand Up @@ -65,7 +68,7 @@ supportedLocalesOf locales options =
Function.Uncurried.runFn2 _supportedLocalesOf locales (Unsafe.Coerce.unsafeCoerce options)

foreign import _of
:: Fn2 DisplayNames String String
:: Fn2 DisplayNames String (Nullable String)

of_ :: DisplayNames -> String -> String
of_ = Function.Uncurried.runFn2 _of
of_ :: DisplayNames -> String -> Maybe String
of_ displayNames key = Nullable.toMaybe (Function.Uncurried.runFn2 _of displayNames key)
3 changes: 2 additions & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Prelude
import Data.Either (Either(..))
import Data.JSDate (JSDate)
import Data.JSDate as JSDate
import Data.Maybe (Maybe(..))
import Data.String (Pattern(..), Replacement(..))
import Data.String as String
import Effect (Effect)
Expand Down Expand Up @@ -289,7 +290,7 @@ test_DisplayNames = do
Console.log "DisplayNames.of_"
Test.assertEqual
{ actual: DisplayNames.of_ displayNames "en-US"
, expected: "American English"
, expected: Just "American English"
}

test_ListFormat :: Effect Unit
Expand Down

0 comments on commit 6d04dc1

Please sign in to comment.