release: v0.2.1 — bug修复、代码去重、功能增强、覆盖率88.57%
This commit is contained in:
+11
-3
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* MetonaToast i18n — 国际化管理
|
||||
* @module i18n
|
||||
* @version 0.2.0
|
||||
* @version 0.2.1
|
||||
*/
|
||||
|
||||
import { LOCALES } from './constants.js';
|
||||
@@ -503,10 +503,18 @@ export const formatRelativeTime = (date: Date | number | string, options: Intl.R
|
||||
};
|
||||
|
||||
/**
|
||||
* 格式化列表
|
||||
* 格式化列表 — 优先使用 Intl.ListFormat,降级到逗号拼接
|
||||
*/
|
||||
export const formatList = (list: string[], _options: Record<string, unknown> = {}): string => {
|
||||
// Intl.ListFormat requires ES2021+; fallback to comma join for wider compat
|
||||
const intl = Intl as typeof Intl & { ListFormat?: new (locale: string, options?: Record<string, unknown>) => { format: (items: string[]) => string } };
|
||||
if (typeof intl.ListFormat === 'function') {
|
||||
try {
|
||||
return new intl.ListFormat(currentLocale, {
|
||||
style: 'long',
|
||||
type: 'conjunction',
|
||||
}).format(list);
|
||||
} catch (_e) { /* fallback below */ }
|
||||
}
|
||||
return list.join(', ');
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user