@kyco-utils/number 0.1.4 → 0.2.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/README.md CHANGED
@@ -1,7 +1,26 @@
1
1
  # @kyco-utils/number
2
2
 
3
- A set of utilities for TS projects.
3
+ Locale-aware number utilities.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pnpm add @kyco-utils/number zod
9
+ ```
10
+
11
+ Requires `zod` v4 as a peer dependency (via `@kyco-utils/enums`). ESM only.
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { UserLocale } from '@kyco-utils/enums'
17
+ import { getNumberSeparators } from '@kyco-utils/number'
18
+
19
+ getNumberSeparators(UserLocale.DE_DE) // { thousandsSeparator: '.', decimalSeparator: ',' }
20
+ ```
21
+
22
+ See the [API reference](https://kyco.github.io/kyco-utils/api/@kyco-utils/number) for all exports.
4
23
 
5
24
  ## License
6
25
 
7
- [MIT](LICENSE)
26
+ [MIT](https://github.com/kyco/kyco-utils/blob/main/LICENSE)
package/dist/index.d.mts CHANGED
@@ -1,12 +1,11 @@
1
1
  import { UserLocale } from "@kyco-utils/enums";
2
2
  import { NumberSeparators } from "@kyco-utils/types";
3
3
  /**
4
- * Gets the thousands and decimal separators for a given locale
4
+ * Returns the thousands and decimal separators for a locale, as used by `Intl.NumberFormat`.
5
+ * Falls back to `,` and `.` if the locale doesn't define one.
5
6
  *
6
- * @param locale - A supported {@link UserLocale} (BCP 47 language tag).
7
+ * @param locale - The {@link UserLocale} to get separators for.
7
8
  * @returns The {@link NumberSeparators} for the locale.
8
- * @see {@link UserLocale} for the list of supported locales.
9
- *
10
9
  * @example
11
10
  * ```ts
12
11
  * import { UserLocale } from '@kyco-utils/enums'
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  // src/index.ts
2
+ const SAMPLE_NUMBER = 1234567.8;
2
3
  const DEFAULT_THOUSANDS_SEPARATOR = ",";
3
4
  const DEFAULT_DECIMAL_SEPARATOR = ".";
4
5
  /**
5
- * Gets the thousands and decimal separators for a given locale
6
+ * Returns the thousands and decimal separators for a locale, as used by `Intl.NumberFormat`.
7
+ * Falls back to `,` and `.` if the locale doesn't define one.
6
8
  *
7
- * @param locale - A supported {@link UserLocale} (BCP 47 language tag).
9
+ * @param locale - The {@link UserLocale} to get separators for.
8
10
  * @returns The {@link NumberSeparators} for the locale.
9
- * @see {@link UserLocale} for the list of supported locales.
10
- *
11
11
  * @example
12
12
  * ```ts
13
13
  * import { UserLocale } from '@kyco-utils/enums'
@@ -18,7 +18,7 @@ const DEFAULT_DECIMAL_SEPARATOR = ".";
18
18
  * ```
19
19
  */
20
20
  const getNumberSeparators = (locale) => {
21
- const parts = new Intl.NumberFormat(locale).formatToParts(12345.6);
21
+ const parts = new Intl.NumberFormat(locale).formatToParts(SAMPLE_NUMBER);
22
22
  return {
23
23
  thousandsSeparator: parts.find((part) => part.type === "group")?.value ?? DEFAULT_THOUSANDS_SEPARATOR,
24
24
  decimalSeparator: parts.find((part) => part.type === "decimal")?.value ?? DEFAULT_DECIMAL_SEPARATOR
@@ -1 +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"}
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 SAMPLE_NUMBER = 1234567.8\nconst DEFAULT_THOUSANDS_SEPARATOR = ','\nconst DEFAULT_DECIMAL_SEPARATOR = '.'\n\n/**\n * Returns the thousands and decimal separators for a locale, as used by `Intl.NumberFormat`.\n * Falls back to `,` and `.` if the locale doesn't define one.\n *\n * @param locale - The {@link UserLocale} to get separators for.\n * @returns The {@link NumberSeparators} for the locale.\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(SAMPLE_NUMBER)\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,gBAAgB;AACtB,MAAM,8BAA8B;AACpC,MAAM,4BAA4B;;;;;;;;;;;;;;;;AAiBlC,MAAa,uBAAuB,WAAyC;CAE3E,MAAM,QAAQ,IAAI,KAAK,aAAa,MAAM,CAAC,CAAC,cAAc,aAAa;CAIvE,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.4",
3
+ "version": "0.2.0",
4
4
  "description": "Locale-aware number utilities for kyco-utils.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -17,22 +17,19 @@
17
17
  "exports": {
18
18
  ".": {
19
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
- }
20
+ "types": "./dist/index.d.mts",
21
+ "default": "./dist/index.mjs"
28
22
  }
29
23
  },
30
- "main": "./dist/index.cjs",
31
- "module": "./dist/index.mjs",
32
- "types": "./dist/index.d.cts",
33
24
  "dependencies": {
34
- "@kyco-utils/enums": "^0.1.3",
35
- "@kyco-utils/types": "^0.1.3"
25
+ "@kyco-utils/enums": "^0.2.0",
26
+ "@kyco-utils/types": "^0.2.0"
27
+ },
28
+ "peerDependencies": {
29
+ "zod": "^4.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "zod": "^4.0.0"
36
33
  },
37
34
  "publishConfig": {
38
35
  "access": "public",
@@ -41,7 +38,6 @@
41
38
  "scripts": {
42
39
  "build": "vp pack",
43
40
  "dev": "vp pack --watch",
44
- "typecheck": "tsc --noEmit",
45
- "lint": "biome check ."
41
+ "typecheck": "tsc --noEmit"
46
42
  }
47
43
  }
package/dist/index.cjs DELETED
@@ -1,30 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- // src/index.ts
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
- };
27
- };
28
- exports.getNumberSeparators = getNumberSeparators;
29
-
30
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
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 DELETED
@@ -1,20 +0,0 @@
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.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;qBAsBa,sBAAmB,QAAY,eAAa"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;qBAsBa,sBAAmB,QAAY,eAAa"}