@kyco-utils/number 0.1.0 → 0.1.2
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/README.md +7 -0
- package/dist/index.cjs +5 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
ADDED
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
+
var DEFAULT_THOUSANDS_SEPARATOR = ",";
|
|
5
|
+
var DEFAULT_DECIMAL_SEPARATOR = ".";
|
|
4
6
|
var getNumberSeparators = (locale) => {
|
|
5
|
-
const parts = new Intl.NumberFormat(locale).formatToParts(
|
|
6
|
-
const thousandsSeparator = parts.find((part) => part.type === "group")?.value ??
|
|
7
|
-
const decimalSeparator = parts.find((part) => part.type === "decimal")?.value ??
|
|
7
|
+
const parts = new Intl.NumberFormat(locale).formatToParts(12345.6);
|
|
8
|
+
const thousandsSeparator = parts.find((part) => part.type === "group")?.value ?? DEFAULT_THOUSANDS_SEPARATOR;
|
|
9
|
+
const decimalSeparator = parts.find((part) => part.type === "decimal")?.value ?? DEFAULT_DECIMAL_SEPARATOR;
|
|
8
10
|
return { thousandsSeparator, decimalSeparator };
|
|
9
11
|
};
|
|
10
12
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;
|
|
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.cjs","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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { UserLocale } from '@kyco-utils/enums';
|
|
2
2
|
import { NumberSeparators } from '@kyco-utils/types';
|
|
3
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
|
+
*/
|
|
4
11
|
declare const getNumberSeparators: (locale: UserLocale) => NumberSeparators;
|
|
5
12
|
|
|
6
13
|
export { getNumberSeparators };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { UserLocale } from '@kyco-utils/enums';
|
|
2
2
|
import { NumberSeparators } from '@kyco-utils/types';
|
|
3
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
|
+
*/
|
|
4
11
|
declare const getNumberSeparators: (locale: UserLocale) => NumberSeparators;
|
|
5
12
|
|
|
6
13
|
export { getNumberSeparators };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
var DEFAULT_THOUSANDS_SEPARATOR = ",";
|
|
3
|
+
var DEFAULT_DECIMAL_SEPARATOR = ".";
|
|
2
4
|
var getNumberSeparators = (locale) => {
|
|
3
|
-
const parts = new Intl.NumberFormat(locale).formatToParts(
|
|
4
|
-
const thousandsSeparator = parts.find((part) => part.type === "group")?.value ??
|
|
5
|
-
const decimalSeparator = parts.find((part) => part.type === "decimal")?.value ??
|
|
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;
|
|
6
8
|
return { thousandsSeparator, decimalSeparator };
|
|
7
9
|
};
|
|
8
10
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";
|
|
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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kyco-utils/number",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Locale-aware number utilities for kyco-utils.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"module": "./dist/index.js",
|
|
26
26
|
"types": "./dist/index.d.ts",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@kyco-utils/enums": "^0.1.
|
|
29
|
-
"@kyco-utils/types": "^0.1.
|
|
28
|
+
"@kyco-utils/enums": "^0.1.1",
|
|
29
|
+
"@kyco-utils/types": "^0.1.1"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public",
|