@kyco-utils/number 0.1.2 → 0.1.4
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/index.cjs +26 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -6
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +20 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +29 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +16 -11
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -13
- package/dist/index.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
2
|
// src/index.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
const DEFAULT_THOUSANDS_SEPARATOR = ",";
|
|
4
|
+
const DEFAULT_DECIMAL_SEPARATOR = ".";
|
|
5
|
+
/**
|
|
6
|
+
* Gets the thousands and decimal separators for a given locale
|
|
7
|
+
*
|
|
8
|
+
* @param locale - A supported {@link UserLocale} (BCP 47 language tag).
|
|
9
|
+
* @returns The {@link NumberSeparators} for the locale.
|
|
10
|
+
* @see {@link UserLocale} for the list of supported locales.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { UserLocale } from '@kyco-utils/enums'
|
|
15
|
+
* import { getNumberSeparators } from '@kyco-utils/number'
|
|
16
|
+
*
|
|
17
|
+
* getNumberSeparators(UserLocale.EN_GB) // { thousandsSeparator: ',', decimalSeparator: '.' }
|
|
18
|
+
* getNumberSeparators(UserLocale.DE_DE) // { thousandsSeparator: '.', decimalSeparator: ',' }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const getNumberSeparators = (locale) => {
|
|
22
|
+
const parts = new Intl.NumberFormat(locale).formatToParts(12345.6);
|
|
23
|
+
return {
|
|
24
|
+
thousandsSeparator: parts.find((part) => part.type === "group")?.value ?? DEFAULT_THOUSANDS_SEPARATOR,
|
|
25
|
+
decimalSeparator: parts.find((part) => part.type === "decimal")?.value ?? DEFAULT_DECIMAL_SEPARATOR
|
|
26
|
+
};
|
|
11
27
|
};
|
|
12
|
-
|
|
13
28
|
exports.getNumberSeparators = getNumberSeparators;
|
|
14
|
-
|
|
29
|
+
|
|
15
30
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { UserLocale } from '@kyco-utils/enums'\nimport type { NumberSeparators } from '@kyco-utils/types'\n\nconst DEFAULT_THOUSANDS_SEPARATOR = ','\nconst DEFAULT_DECIMAL_SEPARATOR = '.'\n\n/**\n * Gets the thousands and decimal separators for a given locale\n *\n * @param locale - A supported {@link UserLocale} (BCP 47 language tag).\n * @returns The {@link NumberSeparators} for the locale.\n * @see {@link UserLocale} for the list of supported locales.\n *\n * @example\n * ```ts\n * import { UserLocale } from '@kyco-utils/enums'\n * import { getNumberSeparators } from '@kyco-utils/number'\n *\n * getNumberSeparators(UserLocale.EN_GB) // { thousandsSeparator: ',', decimalSeparator: '.' }\n * getNumberSeparators(UserLocale.DE_DE) // { thousandsSeparator: '.', decimalSeparator: ',' }\n * ```\n */\nexport const getNumberSeparators = (locale: UserLocale): NumberSeparators => {\n // @locale-updates\n const parts = new Intl.NumberFormat(locale).formatToParts(12345.6)\n const thousandsSeparator = parts.find((part) => part.type === 'group')?.value ?? DEFAULT_THOUSANDS_SEPARATOR\n const decimalSeparator = parts.find((part) => part.type === 'decimal')?.value ?? DEFAULT_DECIMAL_SEPARATOR\n\n return { thousandsSeparator, decimalSeparator }\n}\n"],"mappings":";;AAGA,MAAM,8BAA8B;AACpC,MAAM,4BAA4B;;;;;;;;;;;;;;;;;AAkBlC,MAAa,uBAAuB,WAAyC;CAE3E,MAAM,QAAQ,IAAI,KAAK,aAAa,MAAM,CAAC,CAAC,cAAc,OAAO;CAIjE,OAAO;EAAE,oBAHkB,MAAM,MAAM,SAAS,KAAK,SAAS,OAAO,CAAC,EAAE,SAAS;EAGpD,kBAFJ,MAAM,MAAM,SAAS,KAAK,SAAS,SAAS,CAAC,EAAE,SAAS;CAEnC;AAChD"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import { UserLocale } from
|
|
2
|
-
import { NumberSeparators } from
|
|
3
|
-
|
|
1
|
+
import { UserLocale } from "@kyco-utils/enums";
|
|
2
|
+
import { NumberSeparators } from "@kyco-utils/types";
|
|
4
3
|
/**
|
|
5
4
|
* Gets the thousands and decimal separators for a given locale
|
|
6
5
|
*
|
|
7
6
|
* @param locale - A supported {@link UserLocale} (BCP 47 language tag).
|
|
8
7
|
* @returns The {@link NumberSeparators} for the locale.
|
|
9
8
|
* @see {@link UserLocale} for the list of supported locales.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { UserLocale } from '@kyco-utils/enums'
|
|
13
|
+
* import { getNumberSeparators } from '@kyco-utils/number'
|
|
14
|
+
*
|
|
15
|
+
* getNumberSeparators(UserLocale.EN_GB) // { thousandsSeparator: ',', decimalSeparator: '.' }
|
|
16
|
+
* getNumberSeparators(UserLocale.DE_DE) // { thousandsSeparator: '.', decimalSeparator: ',' }
|
|
17
|
+
* ```
|
|
10
18
|
*/
|
|
11
|
-
declare const getNumberSeparators: (locale: UserLocale) => NumberSeparators;
|
|
12
|
-
|
|
13
|
-
export { getNumberSeparators };
|
|
19
|
+
export declare const getNumberSeparators: (locale: UserLocale) => NumberSeparators;
|
|
20
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;qBAsBa,sBAAmB,QAAY,eAAa"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { UserLocale } from "@kyco-utils/enums";
|
|
2
|
+
import { NumberSeparators } from "@kyco-utils/types";
|
|
3
|
+
/**
|
|
4
|
+
* Gets the thousands and decimal separators for a given locale
|
|
5
|
+
*
|
|
6
|
+
* @param locale - A supported {@link UserLocale} (BCP 47 language tag).
|
|
7
|
+
* @returns The {@link NumberSeparators} for the locale.
|
|
8
|
+
* @see {@link UserLocale} for the list of supported locales.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { UserLocale } from '@kyco-utils/enums'
|
|
13
|
+
* import { getNumberSeparators } from '@kyco-utils/number'
|
|
14
|
+
*
|
|
15
|
+
* getNumberSeparators(UserLocale.EN_GB) // { thousandsSeparator: ',', decimalSeparator: '.' }
|
|
16
|
+
* getNumberSeparators(UserLocale.DE_DE) // { thousandsSeparator: '.', decimalSeparator: ',' }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const getNumberSeparators: (locale: UserLocale) => NumberSeparators;
|
|
20
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;qBAsBa,sBAAmB,QAAY,eAAa"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
const DEFAULT_THOUSANDS_SEPARATOR = ",";
|
|
3
|
+
const DEFAULT_DECIMAL_SEPARATOR = ".";
|
|
4
|
+
/**
|
|
5
|
+
* Gets the thousands and decimal separators for a given locale
|
|
6
|
+
*
|
|
7
|
+
* @param locale - A supported {@link UserLocale} (BCP 47 language tag).
|
|
8
|
+
* @returns The {@link NumberSeparators} for the locale.
|
|
9
|
+
* @see {@link UserLocale} for the list of supported locales.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { UserLocale } from '@kyco-utils/enums'
|
|
14
|
+
* import { getNumberSeparators } from '@kyco-utils/number'
|
|
15
|
+
*
|
|
16
|
+
* getNumberSeparators(UserLocale.EN_GB) // { thousandsSeparator: ',', decimalSeparator: '.' }
|
|
17
|
+
* getNumberSeparators(UserLocale.DE_DE) // { thousandsSeparator: '.', decimalSeparator: ',' }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
const getNumberSeparators = (locale) => {
|
|
21
|
+
const parts = new Intl.NumberFormat(locale).formatToParts(12345.6);
|
|
22
|
+
return {
|
|
23
|
+
thousandsSeparator: parts.find((part) => part.type === "group")?.value ?? DEFAULT_THOUSANDS_SEPARATOR,
|
|
24
|
+
decimalSeparator: parts.find((part) => part.type === "decimal")?.value ?? DEFAULT_DECIMAL_SEPARATOR
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export { getNumberSeparators };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { UserLocale } from '@kyco-utils/enums'\nimport type { NumberSeparators } from '@kyco-utils/types'\n\nconst DEFAULT_THOUSANDS_SEPARATOR = ','\nconst DEFAULT_DECIMAL_SEPARATOR = '.'\n\n/**\n * Gets the thousands and decimal separators for a given locale\n *\n * @param locale - A supported {@link UserLocale} (BCP 47 language tag).\n * @returns The {@link NumberSeparators} for the locale.\n * @see {@link UserLocale} for the list of supported locales.\n *\n * @example\n * ```ts\n * import { UserLocale } from '@kyco-utils/enums'\n * import { getNumberSeparators } from '@kyco-utils/number'\n *\n * getNumberSeparators(UserLocale.EN_GB) // { thousandsSeparator: ',', decimalSeparator: '.' }\n * getNumberSeparators(UserLocale.DE_DE) // { thousandsSeparator: '.', decimalSeparator: ',' }\n * ```\n */\nexport const getNumberSeparators = (locale: UserLocale): NumberSeparators => {\n // @locale-updates\n const parts = new Intl.NumberFormat(locale).formatToParts(12345.6)\n const thousandsSeparator = parts.find((part) => part.type === 'group')?.value ?? DEFAULT_THOUSANDS_SEPARATOR\n const decimalSeparator = parts.find((part) => part.type === 'decimal')?.value ?? DEFAULT_DECIMAL_SEPARATOR\n\n return { thousandsSeparator, decimalSeparator }\n}\n"],"mappings":";AAGA,MAAM,8BAA8B;AACpC,MAAM,4BAA4B;;;;;;;;;;;;;;;;;AAkBlC,MAAa,uBAAuB,WAAyC;CAE3E,MAAM,QAAQ,IAAI,KAAK,aAAa,MAAM,CAAC,CAAC,cAAc,OAAO;CAIjE,OAAO;EAAE,oBAHkB,MAAM,MAAM,SAAS,KAAK,SAAS,OAAO,CAAC,EAAE,SAAS;EAGpD,kBAFJ,MAAM,MAAM,SAAS,KAAK,SAAS,SAAS,CAAC,EAAE,SAAS;CAEnC;AAChD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kyco-utils/number",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Locale-aware number utilities for kyco-utils.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -16,27 +16,32 @@
|
|
|
16
16
|
],
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
|
-
"
|
|
20
|
-
"import":
|
|
21
|
-
|
|
19
|
+
"@kyco-utils/source": "./src/index.ts",
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./dist/index.d.mts",
|
|
22
|
+
"default": "./dist/index.mjs"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./dist/index.d.cts",
|
|
26
|
+
"default": "./dist/index.cjs"
|
|
27
|
+
}
|
|
22
28
|
}
|
|
23
29
|
},
|
|
24
30
|
"main": "./dist/index.cjs",
|
|
25
|
-
"module": "./dist/index.
|
|
26
|
-
"types": "./dist/index.d.
|
|
31
|
+
"module": "./dist/index.mjs",
|
|
32
|
+
"types": "./dist/index.d.cts",
|
|
27
33
|
"dependencies": {
|
|
28
|
-
"@kyco-utils/enums": "^0.1.
|
|
29
|
-
"@kyco-utils/types": "^0.1.
|
|
34
|
+
"@kyco-utils/enums": "^0.1.3",
|
|
35
|
+
"@kyco-utils/types": "^0.1.3"
|
|
30
36
|
},
|
|
31
37
|
"publishConfig": {
|
|
32
38
|
"access": "public",
|
|
33
39
|
"provenance": true
|
|
34
40
|
},
|
|
35
41
|
"scripts": {
|
|
36
|
-
"build": "
|
|
37
|
-
"dev": "
|
|
42
|
+
"build": "vp pack",
|
|
43
|
+
"dev": "vp pack --watch",
|
|
38
44
|
"typecheck": "tsc --noEmit",
|
|
39
|
-
"test": "vitest run",
|
|
40
45
|
"lint": "biome check ."
|
|
41
46
|
}
|
|
42
47
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { UserLocale } from '@kyco-utils/enums';
|
|
2
|
-
import { NumberSeparators } from '@kyco-utils/types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Gets the thousands and decimal separators for a given locale
|
|
6
|
-
*
|
|
7
|
-
* @param locale - A supported {@link UserLocale} (BCP 47 language tag).
|
|
8
|
-
* @returns The {@link NumberSeparators} for the locale.
|
|
9
|
-
* @see {@link UserLocale} for the list of supported locales.
|
|
10
|
-
*/
|
|
11
|
-
declare const getNumberSeparators: (locale: UserLocale) => NumberSeparators;
|
|
12
|
-
|
|
13
|
-
export { getNumberSeparators };
|
package/dist/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
var DEFAULT_THOUSANDS_SEPARATOR = ",";
|
|
3
|
-
var DEFAULT_DECIMAL_SEPARATOR = ".";
|
|
4
|
-
var getNumberSeparators = (locale) => {
|
|
5
|
-
const parts = new Intl.NumberFormat(locale).formatToParts(12345.6);
|
|
6
|
-
const thousandsSeparator = parts.find((part) => part.type === "group")?.value ?? DEFAULT_THOUSANDS_SEPARATOR;
|
|
7
|
-
const decimalSeparator = parts.find((part) => part.type === "decimal")?.value ?? DEFAULT_DECIMAL_SEPARATOR;
|
|
8
|
-
return { thousandsSeparator, decimalSeparator };
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { getNumberSeparators };
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAGA,IAAM,2BAAA,GAA8B,GAAA;AACpC,IAAM,yBAAA,GAA4B,GAAA;AAS3B,IAAM,mBAAA,GAAsB,CAAC,MAAA,KAAyC;AAE3E,EAAA,MAAM,QAAQ,IAAI,IAAA,CAAK,aAAa,MAAM,CAAA,CAAE,cAAc,OAAO,CAAA;AACjE,EAAA,MAAM,kBAAA,GAAqB,MAAM,IAAA,CAAK,CAAC,SAAS,IAAA,CAAK,IAAA,KAAS,OAAO,CAAA,EAAG,KAAA,IAAS,2BAAA;AACjF,EAAA,MAAM,gBAAA,GAAmB,MAAM,IAAA,CAAK,CAAC,SAAS,IAAA,CAAK,IAAA,KAAS,SAAS,CAAA,EAAG,KAAA,IAAS,yBAAA;AAEjF,EAAA,OAAO,EAAE,oBAAoB,gBAAA,EAAiB;AAChD","file":"index.js","sourcesContent":["import type { UserLocale } from '@kyco-utils/enums'\nimport type { NumberSeparators } from '@kyco-utils/types'\n\nconst DEFAULT_THOUSANDS_SEPARATOR = ','\nconst DEFAULT_DECIMAL_SEPARATOR = '.'\n\n/**\n * Gets the thousands and decimal separators for a given locale\n *\n * @param locale - A supported {@link UserLocale} (BCP 47 language tag).\n * @returns The {@link NumberSeparators} for the locale.\n * @see {@link UserLocale} for the list of supported locales.\n */\nexport const getNumberSeparators = (locale: UserLocale): NumberSeparators => {\n // @locale-updates\n const parts = new Intl.NumberFormat(locale).formatToParts(12345.6)\n const thousandsSeparator = parts.find((part) => part.type === 'group')?.value ?? DEFAULT_THOUSANDS_SEPARATOR\n const decimalSeparator = parts.find((part) => part.type === 'decimal')?.value ?? DEFAULT_DECIMAL_SEPARATOR\n\n return { thousandsSeparator, decimalSeparator }\n}\n"]}
|