-
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.
Merge pull request #20 from pete-murphy/locale-sensitive-functions
feat: Add locale-sensitive functions
- Loading branch information
Showing
10 changed files
with
428 additions
and
28 deletions.
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
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
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
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,13 @@ | ||
"use strict"; | ||
|
||
export function _toLocaleString(locales, options, date) { | ||
return date.toLocaleString(locales, options); | ||
} | ||
|
||
export function _toLocaleDateString(locales, options, date) { | ||
return date.toLocaleDateString(locales, options); | ||
} | ||
|
||
export function _toLocaleTimeString(locales, options, date) { | ||
return date.toLocaleTimeString(locales, options); | ||
} |
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,103 @@ | ||
module JS.LocaleSensitive.Date | ||
( toLocaleString | ||
, toLocaleDateString | ||
, toLocaleTimeString | ||
) where | ||
|
||
import ConvertableOptions (class ConvertOptionsWithDefaults) | ||
import Data.DateTime (DateTime) | ||
import Data.JSDate (JSDate) | ||
import Data.JSDate as JSDate | ||
import Effect (Effect) | ||
import Effect.Uncurried (EffectFn3) | ||
import Effect.Uncurried as Effect.Uncurried | ||
import JS.Intl.DateTimeFormat (DateTimeFormatOptions, ToDateTimeFormatOptions) | ||
import JS.Intl.DateTimeFormat as DateTimeFormat | ||
import JS.Intl.Locale (Locale) | ||
|
||
foreign import _toLocaleString | ||
:: EffectFn3 | ||
(Array Locale) | ||
{ | DateTimeFormatOptions } | ||
JSDate | ||
String | ||
|
||
foreign import _toLocaleDateString | ||
:: EffectFn3 | ||
(Array Locale) | ||
{ | DateTimeFormatOptions } | ||
JSDate | ||
String | ||
|
||
foreign import _toLocaleTimeString | ||
:: EffectFn3 | ||
(Array Locale) | ||
{ | DateTimeFormatOptions } | ||
JSDate | ||
String | ||
|
||
-- | Returns a string with a language-sensitive representation of a date and | ||
-- | time in the user agent's timezone. | ||
-- | When formatting large numbers of dates, it is better to use | ||
-- | `Intl.DateTimeFormat.format`. | ||
toLocaleString | ||
:: forall provided | ||
. ConvertOptionsWithDefaults | ||
ToDateTimeFormatOptions | ||
{ | DateTimeFormatOptions } | ||
{ | provided } | ||
{ | DateTimeFormatOptions } | ||
=> Array Locale | ||
-> { | provided } | ||
-> DateTime | ||
-> Effect String | ||
toLocaleString locales providedOptions dateTime = | ||
Effect.Uncurried.runEffectFn3 | ||
_toLocaleString | ||
locales | ||
(DateTimeFormat.convertOptionsWithDefaults providedOptions) | ||
(JSDate.fromDateTime dateTime) | ||
|
||
-- | Returns a string with a language-sensitive representation of a date in the | ||
-- | user agent's timezone. | ||
-- | When formatting large numbers of dates, it is better to use | ||
-- | `Intl.DateTimeFormat.format`. | ||
toLocaleDateString | ||
:: forall provided | ||
. ConvertOptionsWithDefaults | ||
ToDateTimeFormatOptions | ||
{ | DateTimeFormatOptions } | ||
{ | provided } | ||
{ | DateTimeFormatOptions } | ||
=> Array Locale | ||
-> { | provided } | ||
-> DateTime | ||
-> Effect String | ||
toLocaleDateString locales providedOptions dateTime = | ||
Effect.Uncurried.runEffectFn3 | ||
_toLocaleDateString | ||
locales | ||
(DateTimeFormat.convertOptionsWithDefaults providedOptions) | ||
(JSDate.fromDateTime dateTime) | ||
|
||
-- | Returns a string with a language-sensitive representation of a time in the | ||
-- | user agent's timezone. | ||
-- | When formatting large numbers of dates, it is better to use | ||
-- | `Intl.DateTimeFormat.format`. | ||
toLocaleTimeString | ||
:: forall provided | ||
. ConvertOptionsWithDefaults | ||
ToDateTimeFormatOptions | ||
{ | DateTimeFormatOptions } | ||
{ | provided } | ||
{ | DateTimeFormatOptions } | ||
=> Array Locale | ||
-> { | provided } | ||
-> DateTime | ||
-> Effect String | ||
toLocaleTimeString locales providedOptions dateTime = | ||
Effect.Uncurried.runEffectFn3 | ||
_toLocaleTimeString | ||
locales | ||
(DateTimeFormat.convertOptionsWithDefaults providedOptions) | ||
(JSDate.fromDateTime dateTime) |
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,5 @@ | ||
"use strict"; | ||
|
||
export function _toLocaleString(locales, options, number) { | ||
return number.toLocaleString(locales, options); | ||
} |
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,38 @@ | ||
module JS.LocaleSensitive.Number | ||
( toLocaleString | ||
) where | ||
|
||
import ConvertableOptions (class ConvertOptionsWithDefaults) | ||
import Effect (Effect) | ||
import Effect.Uncurried (EffectFn3) | ||
import Effect.Uncurried as Effect.Uncurried | ||
import JS.Intl.Locale (Locale) | ||
import JS.Intl.NumberFormat (NumberFormatOptions, ToNumberFormatOptions) | ||
import JS.Intl.NumberFormat as NumberFormat | ||
|
||
foreign import _toLocaleString | ||
:: EffectFn3 | ||
(Array Locale) | ||
{ | NumberFormatOptions } | ||
Number | ||
String | ||
|
||
-- | Returns a string with a language-sensitive representation of this number. | ||
-- | When formatting large numbers of numbers, it is better to use | ||
-- | `Intl.NumberFormat.format` instead. | ||
toLocaleString | ||
:: forall provided | ||
. ConvertOptionsWithDefaults | ||
ToNumberFormatOptions | ||
{ | NumberFormatOptions } | ||
{ | provided } | ||
{ | NumberFormatOptions } | ||
=> Array Locale | ||
-> { | provided } | ||
-> Number | ||
-> Effect String | ||
toLocaleString locales providedOptions = | ||
Effect.Uncurried.runEffectFn3 | ||
_toLocaleString | ||
locales | ||
(NumberFormat.convertOptionsWithDefaults providedOptions) |
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,13 @@ | ||
"use strict"; | ||
|
||
export function _localeCompare(locales, options, a, b) { | ||
return a.localeCompare(b, locales, options); | ||
} | ||
|
||
export function _toLocaleLowerCase(locales, string) { | ||
return string.toLocaleLowerCase(locales); | ||
} | ||
|
||
export function _toLocaleUpperCase(locales, string) { | ||
return string.toLocaleUpperCase(locales); | ||
} |
Oops, something went wrong.