Skip to content

Stricter Intl Bindings #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Feb 21, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next version

- BREAKING: Adds typed bindings to `Intl`, replacing the options type of `{..}` with records. https://github.com/rescript-association/rescript-core/pull/65
- Add `Dict.forEach`, `Dict.forEachWithKey` and `Dict.mapValues` https://github.com/rescript-association/rescript-core/pull/181
- Remove internal xxxU helper functions that are not needed anymore in uncurried mode. https://github.com/rescript-association/rescript-core/pull/191
- Rename `Object.empty` to `Object.make` for consistency.
Expand Down
1 change: 1 addition & 0 deletions rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
{
"dir": "test",
"subdirs": ["intl"],
"type": "dev"
}
],
Expand Down
9 changes: 9 additions & 0 deletions src/Core__Intl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var Collator;

var DateTimeFormat;

var ListFormat;

var Locale;

var NumberFormat;
Expand All @@ -13,12 +15,19 @@ var PluralRules;

var RelativeTimeFormat;

var Segmenter;

var Segments;

export {
Collator ,
DateTimeFormat ,
ListFormat ,
Locale ,
NumberFormat ,
PluralRules ,
RelativeTimeFormat ,
Segmenter ,
Segments ,
}
/* No side effect */
18 changes: 18 additions & 0 deletions src/Core__Intl.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
module Collator = Core__Intl__Collator
module DateTimeFormat = Core__Intl__DateTimeFormat
module ListFormat = Core__Intl__ListFormat
module Locale = Core__Intl__Locale
module NumberFormat = Core__Intl__NumberFormat
module PluralRules = Core__Intl__PluralRules
module RelativeTimeFormat = Core__Intl__RelativeTimeFormat
module Segmenter = Core__Intl__Segmenter
module Segments = Core__Intl__Segments

/**
@throws RangeError
*/
external getCanonicalLocalesExn: string => array<string> = "Intl.getCanonicalLocales"

/**
@throws RangeError
*/
external getCanonicalLocalesManyExn: array<string> => array<string> = "Intl.getCanonicalLocales"

/**
@throws RangeError
*/
external supportedValuesOfExn: string => array<string> = "Intl.supportedValuesOf"
35 changes: 30 additions & 5 deletions src/intl/Core__Intl__Collator.res
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
type t

type usage = [#sort | #search]
type sensitivity = [#base | #accent | #case | #variant]
type caseFirst = [#upper | #lower | #"false"]

type options = {
localeMatcher?: Core__Intl__Common.localeMatcher,
usage?: usage,
sensitivity?: sensitivity,
ignorePunctuation?: bool,
numeric?: bool,
caseFirst?: caseFirst,
}

type resolvedOptions = {
locale: string,
usage: usage,
sensitivity: sensitivity,
ignorePunctuation: bool,
collation: [Core__Intl__Common.collation | #default],
numeric?: bool,
caseFirst?: caseFirst,
}

type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher}

@new external make: unit => t = "Intl.Collator"
@new external makeWithLocale: string => t = "Intl.Collator"
@new external makeWithLocales: array<string> => t = "Intl.Collator"
@new external makeWithLocaleAndOptions: (string, {..}) => t = "Intl.Collator"
@new external makeWithLocalesAndOptions: (array<string>, {..}) => t = "Intl.Collator"
@new external makeWithOptions: (@as(json`undefined`) _, {..}) => t = "Intl.Collator"
@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.Collator"
@new external makeWithLocalesAndOptions: (array<string>, options) => t = "Intl.Collator"
@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.Collator"

@val external supportedLocalesOf: array<string> => t = "Intl.Collator.supportedLocalesOf"
@val
external supportedLocalesOfWithOptions: (array<string>, {..}) => t =
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
"Intl.Collator.supportedLocalesOf"

@send external resolvedOptions: t => {..} = "resolvedOptions"
@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"

@send external compare: (t, string, string) => int = "compare"
2 changes: 2 additions & 0 deletions src/intl/Core__Intl__Common.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Generated by ReScript, PLEASE EDIT WITH CARE
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */
156 changes: 156 additions & 0 deletions src/intl/Core__Intl__Common.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
type localeMatcher = [#lookup | @as("best fit") #bestFit]

type calendar = [
| #buddhist
| #chinese
| #coptic
| #dangi
| #ethioaa
| #ethiopic
| #gregory
| #hebrew
| #indian
| #islamic
| #"islamic-umalqura"
| #"islamic-tbla"
| #"islamic-civil"
| #"islamic-rgsa"
| #iso8601
| #japanese
| #persian
| #roc
]

type collation = [
| #compat // (Arabic)
| #dict // (Sinhala)
| #emoji // (root)
| #eor // (root)
| #phonebk // (German)
| #phonetic // (Lingala)
| #pinyin // (Chinese)
| #stroke // (Chinese)
| #trad
| #unihan // (Chinese, Japanese, and Korean; not available in Chrome or Edge)
| #zhuyin
] // (Chinese)

type numberingSystem = [
| #adlm
| #ahom
| #arab
| #arabext
| #bali
| #beng
| #bhks
| #brah
| #cakm
| #cham
| #deva
| #diak
| #fullwide
| #gong
| #gonm
| #gujr
| #guru
| #hanidec
| #hmng
| #hmnp
| #java
| #kali
| #kawi
| #khmr
| #knda
| #lana
| #lanatham
| #laoo
| #latn
| #lepc
| #limb
| #mathbold
| #mathdbl
| #mathmono
| #mathsanb
| #mathsans
| #mlym
| #modi
| #mong
| #mroo
| #mtei
| #mymr
| #mymrshan
| #mymrtlng
| #nagm
| #newa
| #nkoo
| #olck
| #orya
| #osma
| #rohg
| #saur
| #segment
| #shrd
| #sind
| #sinh
| #sora
| #sund
| #takr
| #talu
| #tamldec
| #telu
| #thai
| #tibt
| #tirh
| #tnsa
| #vaii
| #wara
| #wcho
]

type oneTo21 = [
| #1
| #2
| #3
| #4
| #5
| #6
| #7
| #8
| #9
| #10
| #11
| #12
| #13
| #14
| #15
| #16
| #17
| #18
| #19
| #20
| #21
]

type zeroTo20 = [
| #0
| #1
| #2
| #3
| #4
| #5
| #6
| #7
| #8
| #9
| #10
| #11
| #12
| #13
| #14
| #15
| #16
| #17
| #18
| #19
| #20
]
Loading