-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b00f53b
commit da5576c
Showing
3 changed files
with
178 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"use strict"; | ||
|
||
export function _new(locales, opts) { | ||
return new Intl.RelativeTimeFormat(locales, opts); | ||
} | ||
|
||
export function _format(relativeTimeFormat, value, unit) { | ||
return relativeTimeFormat.format(value, unit); | ||
} | ||
|
||
export function _formatToParts(relativeTimeFormat, value, unit) { | ||
return relativeTimeFormat.formatToParts(value, unit); | ||
} | ||
|
||
export function _resolvedOptions(relativeTimeFormat) { | ||
return relativeTimeFormat.resolvedOptions(); | ||
} | ||
|
||
export function _supportedLocalesOf(locales, opts) { | ||
return Intl.RelativeTimeFormat.supportedLocalesOf(locales, opts); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
module Web.Intl.RelativeTimeFormat | ||
-- * Types | ||
( RelativeTimeFormat | ||
, RelativeTimeFormatOptions | ||
|
||
-- * Constructor | ||
, new | ||
, new_ | ||
|
||
-- * Methods | ||
, supportedLocalesOf | ||
, supportedLocalesOf_ | ||
, format | ||
, formatToParts | ||
, resolvedOptions | ||
) where | ||
|
||
import Data.Function.Uncurried (Fn2, Fn3) | ||
import Data.Function.Uncurried as Function.Uncurried | ||
import Effect (Effect) | ||
import Effect.Uncurried (EffectFn1, EffectFn2) | ||
import Effect.Uncurried as Effect.Uncurried | ||
import Prim.Row (class Union) | ||
import Unsafe.Coerce as Unsafe.Coerce | ||
import Web.Intl.LocaleOptions (LocaleOptions) | ||
|
||
type RelativeTimeFormatOptions = | ||
( localeMatcher :: String | ||
, numeric :: String | ||
, style :: String | ||
) | ||
|
||
foreign import data RelativeTimeFormat :: Type | ||
|
||
foreign import _new | ||
:: EffectFn2 | ||
(Array String) | ||
(Record RelativeTimeFormatOptions) | ||
RelativeTimeFormat | ||
|
||
new | ||
:: forall options options' | ||
. Union options options' RelativeTimeFormatOptions | ||
=> Array String | ||
-> Record options | ||
-> Effect RelativeTimeFormat | ||
new locales options = | ||
Effect.Uncurried.runEffectFn2 _new locales (Unsafe.Coerce.unsafeCoerce options) | ||
|
||
new_ | ||
:: Array String | ||
-> Effect RelativeTimeFormat | ||
new_ locales = | ||
new locales {} | ||
|
||
foreign import _supportedLocalesOf | ||
:: Fn2 | ||
(Array String) | ||
(Record LocaleOptions) | ||
(Array String) | ||
|
||
supportedLocalesOf | ||
:: forall options options' | ||
. Union options options' LocaleOptions | ||
=> Array String | ||
-> Record options | ||
-> Array String | ||
supportedLocalesOf locales options = | ||
Function.Uncurried.runFn2 _supportedLocalesOf locales (Unsafe.Coerce.unsafeCoerce options) | ||
|
||
supportedLocalesOf_ | ||
:: Array String | ||
-> Array String | ||
supportedLocalesOf_ locales = | ||
supportedLocalesOf locales {} | ||
|
||
foreign import _format | ||
:: Fn3 | ||
RelativeTimeFormat | ||
Int | ||
-- Possible values are: "year", "quarter", "month", "week", "day", "hour", "minute", "second" | ||
String | ||
String | ||
|
||
format :: RelativeTimeFormat -> Int -> String -> String | ||
format = Function.Uncurried.runFn3 _format | ||
|
||
foreign import _formatToParts | ||
:: Fn3 | ||
RelativeTimeFormat | ||
Int | ||
-- Possible values are: "year", "quarter", "month", "week", "day", "hour", "minute", "second" | ||
String | ||
(Array { type :: String, value :: String }) | ||
|
||
formatToParts :: RelativeTimeFormat -> Int -> String -> Array { type :: String, value :: String } | ||
formatToParts = Function.Uncurried.runFn3 _formatToParts | ||
|
||
type ResolvedOptions = | ||
{ locale :: String | ||
, style :: String | ||
, numeric :: String | ||
, numberingSystem :: String | ||
} | ||
|
||
foreign import _resolvedOptions | ||
:: EffectFn1 | ||
RelativeTimeFormat | ||
ResolvedOptions | ||
|
||
resolvedOptions :: RelativeTimeFormat -> Effect ResolvedOptions | ||
resolvedOptions = Effect.Uncurried.runEffectFn1 _resolvedOptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters