Skip to content
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
2 changes: 2 additions & 0 deletions .changeset/funny-shoes-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
7 changes: 4 additions & 3 deletions packages/spec/src/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ const localeMap = {
export type LocaleCodeShort = keyof typeof localeMap;
export type LocaleCodeFull = (typeof localeMap)[LocaleCodeShort][number];
export type LocaleCode = LocaleCodeShort | LocaleCodeFull;
export type LocaleDelimiter = "-" | "_" | null;

export const localeCodesShort = Object.keys(localeMap) as LocaleCodeShort[];
export const localeCodesFull = Object.values(localeMap).flat() as LocaleCodeFull[];
Expand Down Expand Up @@ -239,7 +240,7 @@ export const resolveLocaleCode = (value: LocaleCode): LocaleCodeFull => {
throw new Error(`Invalid locale code: ${value}`);
};

export const getLocaleCodeDelimiter = (locale: string): string | null => {
export const getLocaleCodeDelimiter = (locale: string): LocaleDelimiter => {
if (locale.includes("_")) {
return "_";
} else if (locale.includes("-")) {
Expand All @@ -249,7 +250,7 @@ export const getLocaleCodeDelimiter = (locale: string): string | null => {
}
};

export const resolveOverriddenLocale = (locale: string, delimiter?: "-" | "_" | null): string => {
export const resolveOverriddenLocale = (locale: string, delimiter?: LocaleDelimiter): string => {
if (!delimiter) {
return locale;
}
Expand All @@ -262,6 +263,6 @@ export const resolveOverriddenLocale = (locale: string, delimiter?: "-" | "_" |
return locale.replace(currentDelimiter, delimiter);
};

export function normalizeLocale(locale: string) {
export function normalizeLocale(locale: string): string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not necessary since Typescript automatically infers simple types like this. But it also does not hurt to be explicit since the method is exported from the lib 🙃

return locale.replaceAll("_", "-").replace(/([a-z]{2,3}-)r/, "$1");
}