Skip to content

Intl types: simplify bindings for constructors / functions with optional arguments #198

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 2 commits into from
Mar 4, 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: Intl types: simplify bindings for constructors / functions with optional arguments. https://github.com/rescript-association/rescript-core/pull/198
- Fix: Expose Intl.Common. https://github.com/rescript-association/rescript-core/pull/197

## 1.1.0
Expand Down
12 changes: 3 additions & 9 deletions src/intl/Core__Intl__Collator.res
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,10 @@ type resolvedOptions = {

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, 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"
@new external make: (~locales: array<string>=?, ~options: options=?) => t = "Intl.Collator"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative here could be:

Suggested change
@new external make: (~locales: array<string>=?, ~options: options=?) => t = "Intl.Collator"
@new external make: (array<string>, ~options: options=?) => t = "Intl.Collator"

as passing an empty array is effectively the same This would be more convenient if the common case is to pass one or more locales, but less so if it the default is more common. Not sure which is though.


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

@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"
Expand Down
10 changes: 2 additions & 8 deletions src/intl/Core__Intl__DateTimeFormat.res
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,10 @@ type dateTimeRangePart = {
source: dateTimeRangeSource,
}

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

@val external supportedLocalesOf: array<string> => t = "Intl.DateTimeFormat.supportedLocalesOf"
@val
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?) => t =
"Intl.DateTimeFormat.supportedLocalesOf"

@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"
Expand Down
12 changes: 3 additions & 9 deletions src/intl/Core__Intl__ListFormat.res
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,10 @@ type resolvedOptions = {

type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher}

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

@val external supportedLocalesOf: array<string> => t = "Intl.ListFormat.supportedLocalesOf"
@new external make: (~locales: array<string>=?, ~options: options=?) => t = "Intl.ListFormat"

@val
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?) => t =
"Intl.ListFormat.supportedLocalesOf"

@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"
Expand Down
3 changes: 1 addition & 2 deletions src/intl/Core__Intl__Locale.res
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ type options = {
region?: string,
}

@new external make: string => t = "Intl.Locale"
@new external makeWithOptions: (string, options) => t = "Intl.Locale"
@new external make: (string, ~options: options=?) => t = "Intl.Locale"

@get external baseName: t => string = "baseName"
@get external calendar: t => option<string> = "calendar"
Expand Down
11 changes: 2 additions & 9 deletions src/intl/Core__Intl__NumberFormat.res
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,10 @@ type numberFormatRangePart = {
source: rangeSource,
}

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

@val external supportedLocalesOf: array<string> => t = "Intl.NumberFormat.supportedLocalesOf"
@new external make: (~locales: array<string>=?, ~options: options=?) => t = "Intl.NumberFormat"

@val
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?) => t =
"Intl.NumberFormat.supportedLocalesOf"

@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"
Expand Down
10 changes: 2 additions & 8 deletions src/intl/Core__Intl__PluralRules.res
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,10 @@ type resolvedOptions = {

type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher}

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

@val external supportedLocalesOf: array<string> => t = "Intl.PluralRules.supportedLocalesOf"
@val
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?) => t =
"Intl.PluralRules.supportedLocalesOf"

@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"
Expand Down
12 changes: 3 additions & 9 deletions src/intl/Core__Intl__RelativeTimeFormat.res
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@ type relativeTimePart = {
unit?: timeUnit,
}

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

@val
external supportedLocalesOf: array<string> => t = "Intl.RelativeTimeFormat.supportedLocalesOf"
@val
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?) => t =
"Intl.RelativeTimeFormat.supportedLocalesOf"

@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"
Expand Down
12 changes: 3 additions & 9 deletions src/intl/Core__Intl__Segmenter.res
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@ type resolvedOptions = {locale: string, granularity: granularity}

type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher}

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

@val external supportedLocalesOf: array<string> => t = "Intl.Segmenter.supportedLocalesOf"
@new external make: (~locales: array<string>=?, ~options: options=?) => t = "Intl.Segmenter"

@val
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?) => t =
"Intl.Segmenter.supportedLocalesOf"

@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"
Expand Down
134 changes: 0 additions & 134 deletions test/Intl/IntlTests.mjs

This file was deleted.

46 changes: 0 additions & 46 deletions test/Intl/Intl__CollatorTest.mjs

This file was deleted.

Loading