Skip to content

add Intl.supportedValuesOf #53511

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 5 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions src/lib/es2022.intl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,17 @@ declare namespace Intl {
*/
supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options?: Pick<SegmenterOptions, "localeMatcher">): BCP47LanguageTag[];
};

type EnumerationKeys = "calendar" | "collation" | "currency" | "numberingSystem" | "timeZone" | "unit";
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if we should be defining a type alias for this - especially one as broadly named as EnumerationKeys.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could inline it or just make it a string if preferred, but the proposal that added it is called Intl enumeration so I thought the name was fitting. 😄

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think for now let's inline it if that works.


/**
* Returns a list of the supported collation, calendar, currency, numbering system, timezones, and units by the implementation.
*
* @param key A string indicating the category of values to return.
*
* @returns {string[]} A list of the supported values.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @returns {string[]} A list of the supported values.
* @returns A sorted array of the supported values.

*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
*/
function supportedValuesOf(key: EnumerationKeys): string[];
}
9 changes: 9 additions & 0 deletions tests/baselines/reference/es2022IntlAPIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ for (const zoneName of timezoneNames) {
timeZoneName: zoneName,
});
}

const enumerationKeys = ['calendar', 'collation', 'currency', 'numberingSystem', 'timeZone', 'unit'] as const;
for (const key of enumerationKeys) {
var supported = Intl.supportedValuesOf(key);
}


//// [es2022IntlAPIs.js]
Expand All @@ -18,3 +23,7 @@ for (const zoneName of timezoneNames) {
timeZoneName: zoneName,
});
}
const enumerationKeys = ['calendar', 'collation', 'currency', 'numberingSystem', 'timeZone', 'unit'];
for (const key of enumerationKeys) {
var supported = Intl.supportedValuesOf(key);
}
16 changes: 16 additions & 0 deletions tests/baselines/reference/es2022IntlAPIs.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,19 @@ for (const zoneName of timezoneNames) {
});
}

const enumerationKeys = ['calendar', 'collation', 'currency', 'numberingSystem', 'timeZone', 'unit'] as const;
>enumerationKeys : Symbol(enumerationKeys, Decl(es2022IntlAPIs.ts, 9, 5))
>const : Symbol(const)

for (const key of enumerationKeys) {
>key : Symbol(key, Decl(es2022IntlAPIs.ts, 10, 10))
>enumerationKeys : Symbol(enumerationKeys, Decl(es2022IntlAPIs.ts, 9, 5))

var supported = Intl.supportedValuesOf(key);
>supported : Symbol(supported, Decl(es2022IntlAPIs.ts, 11, 5))
>Intl.supportedValuesOf : Symbol(Intl.supportedValuesOf, Decl(lib.es2022.intl.d.ts, --, --))
>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2019.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --) ... and 3 more)
>supportedValuesOf : Symbol(Intl.supportedValuesOf, Decl(lib.es2022.intl.d.ts, --, --))
>key : Symbol(key, Decl(es2022IntlAPIs.ts, 10, 10))
}

24 changes: 24 additions & 0 deletions tests/baselines/reference/es2022IntlAPIs.types
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,27 @@ for (const zoneName of timezoneNames) {
});
}

const enumerationKeys = ['calendar', 'collation', 'currency', 'numberingSystem', 'timeZone', 'unit'] as const;
>enumerationKeys : readonly ["calendar", "collation", "currency", "numberingSystem", "timeZone", "unit"]
>['calendar', 'collation', 'currency', 'numberingSystem', 'timeZone', 'unit'] as const : readonly ["calendar", "collation", "currency", "numberingSystem", "timeZone", "unit"]
>['calendar', 'collation', 'currency', 'numberingSystem', 'timeZone', 'unit'] : readonly ["calendar", "collation", "currency", "numberingSystem", "timeZone", "unit"]
>'calendar' : "calendar"
>'collation' : "collation"
>'currency' : "currency"
>'numberingSystem' : "numberingSystem"
>'timeZone' : "timeZone"
>'unit' : "unit"

for (const key of enumerationKeys) {
>key : "calendar" | "collation" | "currency" | "numberingSystem" | "timeZone" | "unit"
>enumerationKeys : readonly ["calendar", "collation", "currency", "numberingSystem", "timeZone", "unit"]

var supported = Intl.supportedValuesOf(key);
>supported : string[]
>Intl.supportedValuesOf(key) : string[]
>Intl.supportedValuesOf : (key: Intl.EnumerationKeys) => string[]
>Intl : typeof Intl
>supportedValuesOf : (key: Intl.EnumerationKeys) => string[]
>key : "calendar" | "collation" | "currency" | "numberingSystem" | "timeZone" | "unit"
}

5 changes: 5 additions & 0 deletions tests/cases/conformance/es2022/es2022IntlAPIs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ for (const zoneName of timezoneNames) {
timeZoneName: zoneName,
});
}

const enumerationKeys = ['calendar', 'collation', 'currency', 'numberingSystem', 'timeZone', 'unit'] as const;
for (const key of enumerationKeys) {
var supported = Intl.supportedValuesOf(key);
}