@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
28 lines (26 loc) • 805 B
JavaScript
import { CachedIntl } from "../utils/intl.mjs";
import configuration from "@intlayer/config/built";
//#region src/formatters/list.ts
/**
* Formats an array of values into a localized list string using the Intl API.
*
* @example
* list(['apple', 'banana', 'orange']);
* // "apple, banana, and orange"
*
* @example
* list(['red', 'green', 'blue'], { locale: Locales.FRENCH, type: 'disjunction' });
* // "rouge, vert ou bleu"
*
* @example
* list([1, 2, 3], { type: 'unit' });
* // "1, 2, 3"
*/
const list = (values, options) => new CachedIntl.ListFormat(options?.locale ?? configuration?.internationalization?.defaultLocale, {
type: options?.type ?? "conjunction",
style: options?.style ?? "long",
...options
}).format(values.map(String));
//#endregion
export { list };
//# sourceMappingURL=list.mjs.map