@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
23 lines (21 loc) • 669 B
JavaScript
import { getCachedIntl } from "../utils/intl.mjs";
import { internationalization } from "@intlayer/config/built";
//#region src/formatters/compact.ts
/**
* Formats a numeric value using compact notation (e.g., 1K, 1M, 1B)
* based on locale and formatting options.
*
* @example
* compact(1200); // "1.2K"
*
* @example
* compact("1000000", { locale: Locales.FRENCH, compactDisplay: "long" });
* // "1 million"
*/
const compact = (value, options) => getCachedIntl(Intl.NumberFormat, options?.locale ?? internationalization?.defaultLocale, {
...options,
notation: "compact"
}).format(Number(value));
//#endregion
export { compact };
//# sourceMappingURL=compact.mjs.map