@intlayer/core 5.7.8 → 5.8.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/formatters/compact.cjs +47 -0
- package/dist/cjs/formatters/compact.cjs.map +1 -0
- package/dist/cjs/formatters/currency.cjs +51 -0
- package/dist/cjs/formatters/currency.cjs.map +1 -0
- package/dist/cjs/formatters/date.cjs +83 -0
- package/dist/cjs/formatters/date.cjs.map +1 -0
- package/dist/cjs/formatters/index.cjs +37 -0
- package/dist/cjs/formatters/index.cjs.map +1 -0
- package/dist/cjs/formatters/list.cjs +48 -0
- package/dist/cjs/formatters/list.cjs.map +1 -0
- package/dist/cjs/formatters/number.cjs +44 -0
- package/dist/cjs/formatters/number.cjs.map +1 -0
- package/dist/cjs/formatters/percentage.cjs +54 -0
- package/dist/cjs/formatters/percentage.cjs.map +1 -0
- package/dist/cjs/formatters/relativeTime.cjs +75 -0
- package/dist/cjs/formatters/relativeTime.cjs.map +1 -0
- package/dist/cjs/formatters/units.cjs +49 -0
- package/dist/cjs/formatters/units.cjs.map +1 -0
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleName.cjs +5 -15
- package/dist/cjs/localization/getLocaleName.cjs.map +1 -1
- package/dist/cjs/types/index.cjs +2 -2
- package/dist/cjs/types/index.cjs.map +1 -1
- package/dist/cjs/utils/intl.cjs +74 -0
- package/dist/cjs/utils/intl.cjs.map +1 -0
- package/dist/esm/formatters/compact.mjs +13 -0
- package/dist/esm/formatters/compact.mjs.map +1 -0
- package/dist/esm/formatters/currency.mjs +17 -0
- package/dist/esm/formatters/currency.mjs.map +1 -0
- package/dist/esm/formatters/date.mjs +49 -0
- package/dist/esm/formatters/date.mjs.map +1 -0
- package/dist/esm/formatters/index.mjs +9 -0
- package/dist/esm/formatters/index.mjs.map +1 -0
- package/dist/esm/formatters/list.mjs +14 -0
- package/dist/esm/formatters/list.mjs.map +1 -0
- package/dist/esm/formatters/number.mjs +10 -0
- package/dist/esm/formatters/number.mjs.map +1 -0
- package/dist/esm/formatters/percentage.mjs +20 -0
- package/dist/esm/formatters/percentage.mjs.map +1 -0
- package/dist/esm/formatters/relativeTime.mjs +41 -0
- package/dist/esm/formatters/relativeTime.mjs.map +1 -0
- package/dist/esm/formatters/units.mjs +15 -0
- package/dist/esm/formatters/units.mjs.map +1 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/localization/getLocaleName.mjs +5 -15
- package/dist/esm/localization/getLocaleName.mjs.map +1 -1
- package/dist/esm/types/index.mjs +1 -1
- package/dist/esm/types/index.mjs.map +1 -1
- package/dist/esm/utils/intl.mjs +39 -0
- package/dist/esm/utils/intl.mjs.map +1 -0
- package/dist/types/formatters/compact.d.ts +16 -0
- package/dist/types/formatters/compact.d.ts.map +1 -0
- package/dist/types/formatters/currency.d.ts +16 -0
- package/dist/types/formatters/currency.d.ts.map +1 -0
- package/dist/types/formatters/date.d.ts +16 -0
- package/dist/types/formatters/date.d.ts.map +1 -0
- package/dist/types/formatters/index.d.ts +9 -0
- package/dist/types/formatters/index.d.ts.map +1 -0
- package/dist/types/formatters/list.d.ts +20 -0
- package/dist/types/formatters/list.d.ts.map +1 -0
- package/dist/types/formatters/number.d.ts +12 -0
- package/dist/types/formatters/number.d.ts.map +1 -0
- package/dist/types/formatters/percentage.d.ts +12 -0
- package/dist/types/formatters/percentage.d.ts.map +1 -0
- package/dist/types/formatters/relativeTime.d.ts +8 -0
- package/dist/types/formatters/relativeTime.d.ts.map +1 -0
- package/dist/types/formatters/units.d.ts +12 -0
- package/dist/types/formatters/units.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/localization/getLocaleName.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/utils/intl.d.ts +12 -0
- package/dist/types/utils/intl.d.ts.map +1 -0
- package/package.json +59 -14
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var compact_exports = {};
|
|
30
|
+
__export(compact_exports, {
|
|
31
|
+
compact: () => compact
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(compact_exports);
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
+
var import_intl = require('../utils/intl.cjs');
|
|
36
|
+
const compact = (value, options) => new import_intl.Intl.NumberFormat(
|
|
37
|
+
options?.locale ?? import_built.default.internationalization.defaultLocale,
|
|
38
|
+
{
|
|
39
|
+
...options,
|
|
40
|
+
notation: "compact"
|
|
41
|
+
}
|
|
42
|
+
).format(Number(value));
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
compact
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=compact.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/formatters/compact.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { LocalesValues } from '@intlayer/config/client';\nimport { Intl } from '../utils/intl';\n\n/**\n * Formats a numeric value using compact notation (e.g., 1K, 1M, 1B)\n * based on locale and formatting options.\n *\n * @example\n * compact({ value: 1200 }); // \"1.2K\"\n *\n * @example\n * compact({ value: \"1000000\", locale: Locales.FRENCH, compactDisplay: \"long\" });\n * // \"1 million\"\n */\nexport const compact = (\n value: string | number,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n new Intl.NumberFormat(\n options?.locale ?? configuration.internationalization.defaultLocale,\n {\n ...options,\n notation: 'compact',\n }\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAE1B,kBAAqB;AAad,MAAM,UAAU,CACrB,OACA,YAEA,IAAI,iBAAK;AAAA,EACP,SAAS,UAAU,aAAAA,QAAc,qBAAqB;AAAA,EACtD;AAAA,IACE,GAAG;AAAA,IACH,UAAU;AAAA,EACZ;AACF,EAAE,OAAO,OAAO,KAAK,CAAC;","names":["configuration"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var currency_exports = {};
|
|
30
|
+
__export(currency_exports, {
|
|
31
|
+
currency: () => currency
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(currency_exports);
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
+
var import_intl = require('../utils/intl.cjs');
|
|
36
|
+
const currency = (value, options) => new import_intl.Intl.NumberFormat(
|
|
37
|
+
options?.locale ?? import_built.default.internationalization.defaultLocale,
|
|
38
|
+
{
|
|
39
|
+
style: "currency",
|
|
40
|
+
currency: options?.currency ?? "USD",
|
|
41
|
+
currencyDisplay: options?.currencyDisplay ?? "symbol",
|
|
42
|
+
minimumFractionDigits: options?.minimumFractionDigits ?? 2,
|
|
43
|
+
maximumFractionDigits: options?.maximumFractionDigits ?? 2,
|
|
44
|
+
...options
|
|
45
|
+
}
|
|
46
|
+
).format(Number(value));
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
currency
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=currency.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/formatters/currency.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type LocalesValues } from '@intlayer/config/client';\nimport { Intl } from '../utils/intl';\n\n/**\n * Formats a numeric or string value into a localized currency string using the Intl API.\n *\n * @example\n * currency({ value: 1234.5, currency: 'EUR' });\n * // \"€1,234.50\"\n *\n * @example\n * currency({ value: \"5000\", locale: Locales.FRENCH, currency: \"CAD\", currencyDisplay: \"code\" });\n * // \"5 000,00 CAD\"\n */\nexport const currency = (\n value: string | number,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n new Intl.NumberFormat(\n options?.locale ?? configuration.internationalization.defaultLocale,\n {\n style: 'currency',\n currency: options?.currency ?? 'USD',\n currencyDisplay: options?.currencyDisplay ?? 'symbol',\n minimumFractionDigits: options?.minimumFractionDigits ?? 2,\n maximumFractionDigits: options?.maximumFractionDigits ?? 2,\n ...options,\n }\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAE1B,kBAAqB;AAad,MAAM,WAAW,CACtB,OACA,YAEA,IAAI,iBAAK;AAAA,EACP,SAAS,UAAU,aAAAA,QAAc,qBAAqB;AAAA,EACtD;AAAA,IACE,OAAO;AAAA,IACP,UAAU,SAAS,YAAY;AAAA,IAC/B,iBAAiB,SAAS,mBAAmB;AAAA,IAC7C,uBAAuB,SAAS,yBAAyB;AAAA,IACzD,uBAAuB,SAAS,yBAAyB;AAAA,IACzD,GAAG;AAAA,EACL;AACF,EAAE,OAAO,OAAO,KAAK,CAAC;","names":["configuration"]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var date_exports = {};
|
|
30
|
+
__export(date_exports, {
|
|
31
|
+
date: () => date
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(date_exports);
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
+
var import_intl = require('../utils/intl.cjs');
|
|
36
|
+
const presets = {
|
|
37
|
+
short: {
|
|
38
|
+
year: "2-digit",
|
|
39
|
+
month: "2-digit",
|
|
40
|
+
day: "2-digit",
|
|
41
|
+
hour: "2-digit",
|
|
42
|
+
minute: "2-digit"
|
|
43
|
+
},
|
|
44
|
+
long: {
|
|
45
|
+
year: "numeric",
|
|
46
|
+
month: "long",
|
|
47
|
+
day: "numeric",
|
|
48
|
+
hour: "numeric",
|
|
49
|
+
minute: "numeric"
|
|
50
|
+
},
|
|
51
|
+
full: {
|
|
52
|
+
year: "numeric",
|
|
53
|
+
month: "long",
|
|
54
|
+
day: "numeric",
|
|
55
|
+
hour: "numeric",
|
|
56
|
+
minute: "numeric",
|
|
57
|
+
hour12: false
|
|
58
|
+
},
|
|
59
|
+
dateOnly: {
|
|
60
|
+
year: "numeric",
|
|
61
|
+
month: "short",
|
|
62
|
+
day: "numeric"
|
|
63
|
+
},
|
|
64
|
+
timeOnly: {
|
|
65
|
+
hour: "numeric",
|
|
66
|
+
minute: "numeric",
|
|
67
|
+
second: "numeric"
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const date = (date2, options) => {
|
|
71
|
+
const dateTime = new Date(date2);
|
|
72
|
+
const resolvedOptions = typeof options === "string" ? presets[options] ?? {} : options;
|
|
73
|
+
const formatter = new import_intl.Intl.DateTimeFormat(
|
|
74
|
+
options?.locale ?? import_built.default.internationalization.defaultLocale,
|
|
75
|
+
resolvedOptions
|
|
76
|
+
);
|
|
77
|
+
return formatter.format(dateTime);
|
|
78
|
+
};
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
date
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=date.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/formatters/date.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type LocalesValues } from '@intlayer/config/client';\nimport { Intl } from '../utils/intl';\n\ntype DateTimePreset = 'short' | 'long' | 'dateOnly' | 'timeOnly' | 'full';\n\nconst presets: Record<DateTimePreset, Intl.DateTimeFormatOptions> = {\n short: {\n year: '2-digit',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n },\n long: {\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n },\n full: {\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n hour12: false,\n },\n dateOnly: {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n },\n timeOnly: {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n },\n};\n\n/**\n * Formats a date/time value into a localized string using Intl.DateTimeFormat.\n *\n * @example\n * date({ date: new Date(), options: \"short\" });\n * // \"08/02/25, 14:30\"\n *\n * @example\n * date({ date: \"2025-08-02T14:30:00Z\", locale: Locales.FRENCH, options: { month: \"long\", day: \"numeric\" } });\n * // \"2 août\"\n */\nexport const date = (\n date: Date | string | number,\n options?: Intl.DateTimeFormatOptions & { locale?: LocalesValues }\n): string => {\n const dateTime = new Date(date);\n\n const resolvedOptions =\n typeof options === 'string' ? (presets[options] ?? {}) : options;\n\n const formatter = new Intl.DateTimeFormat(\n options?.locale ?? configuration.internationalization.defaultLocale,\n resolvedOptions\n );\n\n return formatter.format(dateTime);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAE1B,kBAAqB;AAIrB,MAAM,UAA8D;AAAA,EAClE,OAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,KAAK;AAAA,IACL,MAAM;AAAA,IACN,QAAQ;AAAA,EACV;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,OAAO;AAAA,IACP,KAAK;AAAA,IACL,MAAM;AAAA,IACN,QAAQ;AAAA,EACV;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,OAAO;AAAA,IACP,KAAK;AAAA,IACL,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AAAA,EACA,UAAU;AAAA,IACR,MAAM;AAAA,IACN,OAAO;AAAA,IACP,KAAK;AAAA,EACP;AAAA,EACA,UAAU;AAAA,IACR,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AACF;AAaO,MAAM,OAAO,CAClBA,OACA,YACW;AACX,QAAM,WAAW,IAAI,KAAKA,KAAI;AAE9B,QAAM,kBACJ,OAAO,YAAY,WAAY,QAAQ,OAAO,KAAK,CAAC,IAAK;AAE3D,QAAM,YAAY,IAAI,iBAAK;AAAA,IACzB,SAAS,UAAU,aAAAC,QAAc,qBAAqB;AAAA,IACtD;AAAA,EACF;AAEA,SAAO,UAAU,OAAO,QAAQ;AAClC;","names":["date","configuration"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var formatters_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(formatters_exports);
|
|
18
|
+
__reExport(formatters_exports, require('./compact.cjs'), module.exports);
|
|
19
|
+
__reExport(formatters_exports, require('./currency.cjs'), module.exports);
|
|
20
|
+
__reExport(formatters_exports, require('./date.cjs'), module.exports);
|
|
21
|
+
__reExport(formatters_exports, require('./list.cjs'), module.exports);
|
|
22
|
+
__reExport(formatters_exports, require('./number.cjs'), module.exports);
|
|
23
|
+
__reExport(formatters_exports, require('./percentage.cjs'), module.exports);
|
|
24
|
+
__reExport(formatters_exports, require('./relativeTime.cjs'), module.exports);
|
|
25
|
+
__reExport(formatters_exports, require('./units.cjs'), module.exports);
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
...require('./compact.cjs'),
|
|
29
|
+
...require('./currency.cjs'),
|
|
30
|
+
...require('./date.cjs'),
|
|
31
|
+
...require('./list.cjs'),
|
|
32
|
+
...require('./number.cjs'),
|
|
33
|
+
...require('./percentage.cjs'),
|
|
34
|
+
...require('./relativeTime.cjs'),
|
|
35
|
+
...require('./units.cjs')
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/formatters/index.ts"],"sourcesContent":["export * from './compact';\nexport * from './currency';\nexport * from './date';\nexport * from './list';\nexport * from './number';\nexport * from './percentage';\nexport * from './relativeTime';\nexport * from './units';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,sBAAd;AACA,+BAAc,uBADd;AAEA,+BAAc,mBAFd;AAGA,+BAAc,mBAHd;AAIA,+BAAc,qBAJd;AAKA,+BAAc,yBALd;AAMA,+BAAc,2BANd;AAOA,+BAAc,oBAPd;","names":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var list_exports = {};
|
|
30
|
+
__export(list_exports, {
|
|
31
|
+
list: () => list
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(list_exports);
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
+
var import_intl = require('../utils/intl.cjs');
|
|
36
|
+
const list = (values, options) => new import_intl.Intl.ListFormat(
|
|
37
|
+
options?.locale ?? import_built.default.internationalization.defaultLocale,
|
|
38
|
+
{
|
|
39
|
+
type: options?.type ?? "conjunction",
|
|
40
|
+
style: options?.style ?? "long",
|
|
41
|
+
...options
|
|
42
|
+
}
|
|
43
|
+
).format(values.map(String));
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
list
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=list.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/formatters/list.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type LocalesValues } from '@intlayer/config/client';\nimport { Intl } from '../utils/intl';\n\n/**\n * Formats an array of values into a localized list string using the Intl API.\n *\n * @example\n * list(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * @example\n * list(['red', 'green', 'blue'], { locale: Locales.FRENCH, type: 'disjunction' });\n * // \"rouge, vert ou bleu\"\n *\n * @example\n * list([1, 2, 3], { type: 'unit' });\n * // \"1, 2, 3\"\n */\nexport const list = (\n values: (string | number)[],\n options?: Intl.ListFormatOptions & { locale?: LocalesValues }\n): string =>\n new Intl.ListFormat(\n options?.locale ?? configuration.internationalization.defaultLocale,\n {\n type: options?.type ?? 'conjunction',\n style: options?.style ?? 'long',\n ...options,\n }\n ).format(values.map(String));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAE1B,kBAAqB;AAiBd,MAAM,OAAO,CAClB,QACA,YAEA,IAAI,iBAAK;AAAA,EACP,SAAS,UAAU,aAAAA,QAAc,qBAAqB;AAAA,EACtD;AAAA,IACE,MAAM,SAAS,QAAQ;AAAA,IACvB,OAAO,SAAS,SAAS;AAAA,IACzB,GAAG;AAAA,EACL;AACF,EAAE,OAAO,OAAO,IAAI,MAAM,CAAC;","names":["configuration"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var number_exports = {};
|
|
30
|
+
__export(number_exports, {
|
|
31
|
+
number: () => number
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(number_exports);
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
+
var import_intl = require('../utils/intl.cjs');
|
|
36
|
+
const number = (value, options) => new import_intl.Intl.NumberFormat(
|
|
37
|
+
options?.locale ?? import_built.default.internationalization.defaultLocale,
|
|
38
|
+
options
|
|
39
|
+
).format(Number(value));
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
number
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=number.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/formatters/number.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type LocalesValues } from '@intlayer/config/client';\nimport { Intl } from '../utils/intl';\n\n/**\n * Formats a numeric value using locale-aware formatting.\n *\n * @example\n * number({ value: 123456.789 }); // \"123,456.789\"\n * number({ value: \"1000000\", locale: Locales.FRENCH }); // \"1 000 000\"\n */\nexport const number = (\n value: string | number,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n new Intl.NumberFormat(\n options?.locale ?? configuration.internationalization.defaultLocale,\n options\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAE1B,kBAAqB;AASd,MAAM,SAAS,CACpB,OACA,YAEA,IAAI,iBAAK;AAAA,EACP,SAAS,UAAU,aAAAA,QAAc,qBAAqB;AAAA,EACtD;AACF,EAAE,OAAO,OAAO,KAAK,CAAC;","names":["configuration"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var percentage_exports = {};
|
|
30
|
+
__export(percentage_exports, {
|
|
31
|
+
percentage: () => percentage
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(percentage_exports);
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
+
var import_intl = require('../utils/intl.cjs');
|
|
36
|
+
const percentage = (value, options) => {
|
|
37
|
+
let numericValue = Number(value);
|
|
38
|
+
if (numericValue > 1) {
|
|
39
|
+
numericValue = numericValue / 100;
|
|
40
|
+
}
|
|
41
|
+
const formatter = new import_intl.Intl.NumberFormat(
|
|
42
|
+
options?.locale ?? import_built.default.internationalization.defaultLocale,
|
|
43
|
+
{
|
|
44
|
+
style: "percent",
|
|
45
|
+
...options
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
return formatter.format(Number(numericValue));
|
|
49
|
+
};
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
percentage
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=percentage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/formatters/percentage.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type LocalesValues } from '@intlayer/config/client';\nimport { Intl } from '../utils/intl';\n\n/**\n * Formats a number as a percentage string (e.g., 0.25 → \"25%\").\n *\n * @example\n * percentage({ value: 0.25 }) // \"25%\"\n * percentage({ value: 0.25, minimumFractionDigits: 2 }) // \"25.00%\"\n */\nexport const percentage = (\n value: string | number,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string => {\n let numericValue = Number(value);\n\n // Normalize: if user passes 10, treat it as 10% instead of 1000%\n if (numericValue > 1) {\n numericValue = numericValue / 100;\n }\n\n const formatter = new Intl.NumberFormat(\n options?.locale ?? configuration.internationalization.defaultLocale,\n {\n style: 'percent',\n ...options,\n }\n );\n\n return formatter.format(Number(numericValue));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAE1B,kBAAqB;AASd,MAAM,aAAa,CACxB,OACA,YACW;AACX,MAAI,eAAe,OAAO,KAAK;AAG/B,MAAI,eAAe,GAAG;AACpB,mBAAe,eAAe;AAAA,EAChC;AAEA,QAAM,YAAY,IAAI,iBAAK;AAAA,IACzB,SAAS,UAAU,aAAAA,QAAc,qBAAqB;AAAA,IACtD;AAAA,MACE,OAAO;AAAA,MACP,GAAG;AAAA,IACL;AAAA,EACF;AAEA,SAAO,UAAU,OAAO,OAAO,YAAY,CAAC;AAC9C;","names":["configuration"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var relativeTime_exports = {};
|
|
30
|
+
__export(relativeTime_exports, {
|
|
31
|
+
relativeTime: () => relativeTime
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(relativeTime_exports);
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
+
var import_intl = require('../utils/intl.cjs');
|
|
36
|
+
const diffInUnit = (from, to, unit) => {
|
|
37
|
+
const msDiff = to.getTime() - from.getTime();
|
|
38
|
+
const sec = msDiff / 1e3;
|
|
39
|
+
switch (unit) {
|
|
40
|
+
case "second":
|
|
41
|
+
return sec;
|
|
42
|
+
case "minute":
|
|
43
|
+
return sec / 60;
|
|
44
|
+
case "hour":
|
|
45
|
+
return sec / 3600;
|
|
46
|
+
case "day":
|
|
47
|
+
return sec / 86400;
|
|
48
|
+
case "month":
|
|
49
|
+
return sec / (30 * 86400);
|
|
50
|
+
// approx
|
|
51
|
+
case "quarter":
|
|
52
|
+
return sec / (3 * 30 * 86400);
|
|
53
|
+
// 3 months approx
|
|
54
|
+
case "year":
|
|
55
|
+
return sec / (365 * 86400);
|
|
56
|
+
// approx
|
|
57
|
+
default:
|
|
58
|
+
return sec;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const relativeTime = (from, to = /* @__PURE__ */ new Date(), options) => {
|
|
62
|
+
const fromDate = new Date(from);
|
|
63
|
+
const toDate = new Date(to);
|
|
64
|
+
const unit = options?.unit ?? "second";
|
|
65
|
+
const value = diffInUnit(fromDate, toDate, unit);
|
|
66
|
+
return new import_intl.Intl.RelativeTimeFormat(
|
|
67
|
+
options?.locale ?? import_built.default.internationalization.defaultLocale,
|
|
68
|
+
options
|
|
69
|
+
).format(Math.round(value), unit);
|
|
70
|
+
};
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
relativeTime
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=relativeTime.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/formatters/relativeTime.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type LocalesValues } from '@intlayer/config/client';\nimport { Intl } from '../utils/intl';\n\ntype RelativeTimeUnit = Intl.RelativeTimeFormatUnit;\n\n/**\n * Calculate the difference between 2 dates in the given unit.\n */\nconst diffInUnit = (from: Date, to: Date, unit: RelativeTimeUnit): number => {\n const msDiff = to.getTime() - from.getTime();\n const sec = msDiff / 1000;\n\n switch (unit) {\n case 'second':\n return sec;\n case 'minute':\n return sec / 60;\n case 'hour':\n return sec / 3600;\n case 'day':\n return sec / 86400;\n case 'month':\n return sec / (30 * 86400); // approx\n case 'quarter':\n return sec / (3 * 30 * 86400); // 3 months approx\n case 'year':\n return sec / (365 * 86400); // approx\n default:\n return sec;\n }\n};\n\nexport const relativeTime = (\n from: Date | string | number,\n to: Date | string | number = new Date(),\n options?: Intl.RelativeTimeFormatOptions & {\n locale?: LocalesValues;\n unit?: RelativeTimeUnit;\n }\n): string => {\n const fromDate = new Date(from);\n const toDate = new Date(to);\n const unit = options?.unit ?? 'second';\n\n const value = diffInUnit(fromDate, toDate, unit);\n\n return new Intl.RelativeTimeFormat(\n options?.locale ?? configuration.internationalization.defaultLocale,\n options\n ).format(Math.round(value), unit);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAE1B,kBAAqB;AAOrB,MAAM,aAAa,CAAC,MAAY,IAAU,SAAmC;AAC3E,QAAM,SAAS,GAAG,QAAQ,IAAI,KAAK,QAAQ;AAC3C,QAAM,MAAM,SAAS;AAErB,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO,MAAM;AAAA,IACf,KAAK;AACH,aAAO,MAAM;AAAA,IACf,KAAK;AACH,aAAO,MAAM;AAAA,IACf,KAAK;AACH,aAAO,OAAO,KAAK;AAAA;AAAA,IACrB,KAAK;AACH,aAAO,OAAO,IAAI,KAAK;AAAA;AAAA,IACzB,KAAK;AACH,aAAO,OAAO,MAAM;AAAA;AAAA,IACtB;AACE,aAAO;AAAA,EACX;AACF;AAEO,MAAM,eAAe,CAC1B,MACA,KAA6B,oBAAI,KAAK,GACtC,YAIW;AACX,QAAM,WAAW,IAAI,KAAK,IAAI;AAC9B,QAAM,SAAS,IAAI,KAAK,EAAE;AAC1B,QAAM,OAAO,SAAS,QAAQ;AAE9B,QAAM,QAAQ,WAAW,UAAU,QAAQ,IAAI;AAE/C,SAAO,IAAI,iBAAK;AAAA,IACd,SAAS,UAAU,aAAAA,QAAc,qBAAqB;AAAA,IACtD;AAAA,EACF,EAAE,OAAO,KAAK,MAAM,KAAK,GAAG,IAAI;AAClC;","names":["configuration"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var units_exports = {};
|
|
30
|
+
__export(units_exports, {
|
|
31
|
+
units: () => units
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(units_exports);
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
+
var import_intl = require('../utils/intl.cjs');
|
|
36
|
+
const units = (value, options) => new import_intl.Intl.NumberFormat(
|
|
37
|
+
options.locale ?? import_built.default.internationalization.defaultLocale,
|
|
38
|
+
{
|
|
39
|
+
style: "unit",
|
|
40
|
+
unit: options.unit ?? "day",
|
|
41
|
+
unitDisplay: options.unitDisplay ?? "short",
|
|
42
|
+
useGrouping: options.useGrouping ?? false
|
|
43
|
+
}
|
|
44
|
+
).format(Number(value));
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
units
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=units.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/formatters/units.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type LocalesValues } from '@intlayer/config/client';\nimport { Intl } from '../utils/intl';\n\n/**\n * Formats a numeric value as a localized unit string.\n *\n * @example\n * units({ value: 5, unit: \"kilometer\", unitDisplay: \"long\", locale: \"en-GB\" })\n * // \"5 kilometers\"\n */\nexport const units = (\n value: number | string,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n new Intl.NumberFormat(\n options.locale ?? configuration.internationalization.defaultLocale,\n {\n style: 'unit',\n unit: options.unit ?? 'day',\n unitDisplay: options.unitDisplay ?? 'short',\n useGrouping: options.useGrouping ?? false,\n }\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAE1B,kBAAqB;AASd,MAAM,QAAQ,CACnB,OACA,YAEA,IAAI,iBAAK;AAAA,EACP,QAAQ,UAAU,aAAAA,QAAc,qBAAqB;AAAA,EACrD;AAAA,IACE,OAAO;AAAA,IACP,MAAM,QAAQ,QAAQ;AAAA,IACtB,aAAa,QAAQ,eAAe;AAAA,IACpC,aAAa,QAAQ,eAAe;AAAA,EACtC;AACF,EAAE,OAAO,OAAO,KAAK,CAAC;","names":["configuration"]}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -16,21 +16,25 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var index_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(index_exports);
|
|
18
18
|
__reExport(index_exports, require('./dictionaryManipulator/index.cjs'), module.exports);
|
|
19
|
+
__reExport(index_exports, require('./formatters/index.cjs'), module.exports);
|
|
19
20
|
__reExport(index_exports, require('./interpreter/index.cjs'), module.exports);
|
|
20
21
|
__reExport(index_exports, require('./localization/index.cjs'), module.exports);
|
|
21
22
|
__reExport(index_exports, require('./transpiler/index.cjs'), module.exports);
|
|
22
23
|
__reExport(index_exports, require('./types/index.cjs'), module.exports);
|
|
23
24
|
__reExport(index_exports, require('./utils/checkIsURLAbsolute.cjs'), module.exports);
|
|
25
|
+
__reExport(index_exports, require('./utils/intl.cjs'), module.exports);
|
|
24
26
|
__reExport(index_exports, require('./utils/isSameKeyPath.cjs'), module.exports);
|
|
25
27
|
__reExport(index_exports, require('./utils/isValidReactElement.cjs'), module.exports);
|
|
26
28
|
// Annotate the CommonJS export names for ESM import in node:
|
|
27
29
|
0 && (module.exports = {
|
|
28
30
|
...require('./dictionaryManipulator/index.cjs'),
|
|
31
|
+
...require('./formatters/index.cjs'),
|
|
29
32
|
...require('./interpreter/index.cjs'),
|
|
30
33
|
...require('./localization/index.cjs'),
|
|
31
34
|
...require('./transpiler/index.cjs'),
|
|
32
35
|
...require('./types/index.cjs'),
|
|
33
36
|
...require('./utils/checkIsURLAbsolute.cjs'),
|
|
37
|
+
...require('./utils/intl.cjs'),
|
|
34
38
|
...require('./utils/isSameKeyPath.cjs'),
|
|
35
39
|
...require('./utils/isValidReactElement.cjs')
|
|
36
40
|
});
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryManipulator/index';\nexport * from './interpreter/index';\nexport * from './localization/index';\nexport * from './transpiler/index';\nexport * from './types/index';\nexport * from './utils/checkIsURLAbsolute';\nexport * from './utils/isSameKeyPath';\nexport * from './utils/isValidReactElement';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,0CAAd;AACA,0BAAc
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryManipulator/index';\nexport * from './formatters/index';\nexport * from './interpreter/index';\nexport * from './localization/index';\nexport * from './transpiler/index';\nexport * from './types/index';\nexport * from './utils/checkIsURLAbsolute';\nexport * from './utils/intl';\nexport * from './utils/isSameKeyPath';\nexport * from './utils/isValidReactElement';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,0CAAd;AACA,0BAAc,+BADd;AAEA,0BAAc,gCAFd;AAGA,0BAAc,iCAHd;AAIA,0BAAc,+BAJd;AAKA,0BAAc,0BALd;AAMA,0BAAc,uCANd;AAOA,0BAAc,yBAPd;AAQA,0BAAc,kCARd;AASA,0BAAc,wCATd;","names":[]}
|
|
@@ -21,22 +21,12 @@ __export(getLocaleName_exports, {
|
|
|
21
21
|
getLocaleName: () => getLocaleName
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(getLocaleName_exports);
|
|
24
|
-
|
|
24
|
+
var import_intl = require('../utils/intl.cjs');
|
|
25
25
|
const getLocaleName = (displayLocale, targetLocale = displayLocale) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
return displayLocale;
|
|
33
|
-
}
|
|
34
|
-
let dn = dnCache.get(targetLocale);
|
|
35
|
-
if (!dn) {
|
|
36
|
-
dn = new Intl.DisplayNames([targetLocale], { type: "language" });
|
|
37
|
-
dnCache.set(targetLocale, dn);
|
|
38
|
-
}
|
|
39
|
-
return dn.of(displayLocale) ?? "Unknown locale";
|
|
26
|
+
let displayNames = new import_intl.Intl.DisplayNames(targetLocale, {
|
|
27
|
+
type: "language"
|
|
28
|
+
});
|
|
29
|
+
return displayNames.of(displayLocale) ?? "Unknown locale";
|
|
40
30
|
};
|
|
41
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
42
32
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/localization/getLocaleName.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\
|
|
1
|
+
{"version":3,"sources":["../../../src/localization/getLocaleName.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport { Intl } from '../utils/intl';\n\nexport const getLocaleName = (\n displayLocale: LocalesValues,\n targetLocale: LocalesValues = displayLocale\n): string => {\n // new Intl.DisplayNames() is fairly heavy: under the hood every call parses CLDR data and builds a resolver table. In your LocaleSwitcher it’s invoked:\n let displayNames = new Intl.DisplayNames(targetLocale, {\n type: 'language',\n });\n\n return displayNames.of(displayLocale) ?? 'Unknown locale';\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAqB;AAEd,MAAM,gBAAgB,CAC3B,eACA,eAA8B,kBACnB;AAEX,MAAI,eAAe,IAAI,iBAAK,aAAa,cAAc;AAAA,IACrD,MAAM;AAAA,EACR,CAAC;AAED,SAAO,aAAa,GAAG,aAAa,KAAK;AAC3C;","names":[]}
|
package/dist/cjs/types/index.cjs
CHANGED
|
@@ -16,14 +16,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var types_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(types_exports);
|
|
18
18
|
__reExport(types_exports, require('./dictionary.cjs'), module.exports);
|
|
19
|
-
__reExport(types_exports, require('./nodeType.cjs'), module.exports);
|
|
20
19
|
__reExport(types_exports, require('./keyPath.cjs'), module.exports);
|
|
20
|
+
__reExport(types_exports, require('./nodeType.cjs'), module.exports);
|
|
21
21
|
__reExport(types_exports, require('./translation.cjs'), module.exports);
|
|
22
22
|
// Annotate the CommonJS export names for ESM import in node:
|
|
23
23
|
0 && (module.exports = {
|
|
24
24
|
...require('./dictionary.cjs'),
|
|
25
|
-
...require('./nodeType.cjs'),
|
|
26
25
|
...require('./keyPath.cjs'),
|
|
26
|
+
...require('./nodeType.cjs'),
|
|
27
27
|
...require('./translation.cjs')
|
|
28
28
|
});
|
|
29
29
|
//# sourceMappingURL=index.cjs.map
|