79 lines
2.0 KiB
TypeScript
79 lines
2.0 KiB
TypeScript
import { formatDisplayName } from "../formatter/formatter.js";
|
|
import type { DisplayNameStyle } from "../formatter.types.js";
|
|
|
|
/**
|
|
* Format an ISO 639 language code as a localised language name.
|
|
* Pre-binds `formatDisplayName` with `type: "language"`.
|
|
*/
|
|
export function formatLanguageName(
|
|
code: string,
|
|
locale: string,
|
|
style?: DisplayNameStyle
|
|
): string {
|
|
return formatDisplayName(code, locale, {
|
|
type: "language",
|
|
...(style !== undefined ? { style } : {}),
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Format an ISO 3166 region code as a localised region/country name.
|
|
* Pre-binds `formatDisplayName` with `type: "region"`.
|
|
*/
|
|
export function formatRegionName(
|
|
code: string,
|
|
locale: string,
|
|
style?: DisplayNameStyle
|
|
): string {
|
|
return formatDisplayName(code, locale, {
|
|
type: "region",
|
|
...(style !== undefined ? { style } : {}),
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Format an ISO 4217 currency code as a localised currency name.
|
|
* Pre-binds `formatDisplayName` with `type: "currency"`.
|
|
*/
|
|
export function formatCurrencyName(
|
|
code: string,
|
|
locale: string,
|
|
style?: DisplayNameStyle
|
|
): string {
|
|
return formatDisplayName(code, locale, {
|
|
type: "currency",
|
|
...(style !== undefined ? { style } : {}),
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Format an ISO 15924 script code as a localised script name.
|
|
* Pre-binds `formatDisplayName` with `type: "script"`.
|
|
*/
|
|
export function formatScriptName(
|
|
code: string,
|
|
locale: string,
|
|
style?: DisplayNameStyle
|
|
): string {
|
|
return formatDisplayName(code, locale, {
|
|
type: "script",
|
|
...(style !== undefined ? { style } : {}),
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Format a calendar identifier (`"gregory"`, `"buddhist"`, `"islamic"`,
|
|
* etc.) as a localised calendar name. Pre-binds `formatDisplayName`
|
|
* with `type: "calendar"`.
|
|
*/
|
|
export function formatCalendarName(
|
|
code: string,
|
|
locale: string,
|
|
style?: DisplayNameStyle
|
|
): string {
|
|
return formatDisplayName(code, locale, {
|
|
type: "calendar",
|
|
...(style !== undefined ? { style } : {}),
|
|
});
|
|
}
|