commafy-anything 3.0.4 → 4.0.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/index.d.ts CHANGED
@@ -6,11 +6,9 @@
6
6
  * @param {{ stripDecimals?: boolean, spacedDecimals?: boolean, thousandsComma?: boolean, K?: boolean }} [options] By default thousandsComma is enabled, if disabled it shows `1000` without comma (but `10,000` with)
7
7
  * @returns {string} eg. '1,000,000'
8
8
  */
9
- declare function commafy(num: number, options?: {
9
+ export declare function commafy(num: number, options?: {
10
10
  stripDecimals?: boolean;
11
11
  spacedDecimals?: boolean;
12
12
  thousandsComma?: boolean;
13
13
  K?: boolean;
14
14
  }): string;
15
-
16
- export { commafy };
package/dist/index.js CHANGED
@@ -1,22 +1,28 @@
1
- function commafy(num, options) {
2
- const { stripDecimals = false, spacedDecimals = false, thousandsComma = true, K = false } = options || {};
3
- const [wholeNrStr, decimalStr = ""] = num.toString().split(".");
4
- const str = [wholeNrStr, decimalStr];
5
- const minLength = thousandsComma ? 4 : 5;
6
- if (!K && wholeNrStr.length >= minLength) {
7
- str[0] = wholeNrStr.replace(/(\d)(?=(\d{3})+$)/g, "$1,");
8
- }
9
- if (K && wholeNrStr.length > 3) {
10
- const numInK = Math.round(num / 1e3);
11
- const commafied = numInK.toString().replace(/(\d)(?=(\d{3})+$)/g, "$1,");
12
- str[0] = commafied + "K";
13
- }
14
- if (stripDecimals || !decimalStr || K)
15
- return str[0];
16
- if (spacedDecimals && decimalStr.length >= minLength) {
17
- str[1] = decimalStr.replace(/(\d{3})/g, "$1 ").trim();
18
- }
19
- return str.join(".");
1
+ /**
2
+ * Adds comma's to a number
3
+ *
4
+ * @export
5
+ * @param {(string | number)} num the number to commafy
6
+ * @param {{ stripDecimals?: boolean, spacedDecimals?: boolean, thousandsComma?: boolean, K?: boolean }} [options] By default thousandsComma is enabled, if disabled it shows `1000` without comma (but `10,000` with)
7
+ * @returns {string} eg. '1,000,000'
8
+ */
9
+ export function commafy(num, options) {
10
+ const { stripDecimals = false, spacedDecimals = false, thousandsComma = true, K = false, } = options || {};
11
+ const [wholeNrStr, decimalStr = ''] = num.toString().split('.');
12
+ const str = [wholeNrStr, decimalStr];
13
+ const minLength = thousandsComma ? 4 : 5;
14
+ if (!K && wholeNrStr && wholeNrStr.length >= minLength) {
15
+ str[0] = wholeNrStr.replace(/(\d)(?=(\d{3})+$)/g, '$1,');
16
+ }
17
+ if (K && wholeNrStr && wholeNrStr.length > 3) {
18
+ const numInK = Math.round(num / 1000);
19
+ const commafied = numInK.toString().replace(/(\d)(?=(\d{3})+$)/g, '$1,');
20
+ str[0] = commafied + 'K';
21
+ }
22
+ if (stripDecimals || !decimalStr || K)
23
+ return str[0] ?? '';
24
+ if (spacedDecimals && decimalStr.length >= minLength) {
25
+ str[1] = decimalStr.replace(/(\d{3})/g, '$1 ').trim();
26
+ }
27
+ return str.join('.');
20
28
  }
21
-
22
- export { commafy };
package/package.json CHANGED
@@ -1,97 +1,44 @@
1
1
  {
2
2
  "name": "commafy-anything",
3
- "version": "3.0.4",
3
+ "version": "4.0.0",
4
4
  "description": "Adds comma's to a number. A simple and small integration",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
- "types": "./dist/index.d.ts",
8
- "module": "./dist/index.js",
9
- "main": "./dist/index.js",
10
7
  "exports": {
11
- ".": {
12
- "require": {
13
- "types": "./dist/cjs/index.d.cts",
14
- "default": "./dist/cjs/index.cjs"
15
- },
16
- "import": {
17
- "types": "./dist/index.d.ts",
18
- "default": "./dist/index.js"
19
- }
20
- }
8
+ ".": "./dist/index.js"
21
9
  },
22
- "files": [
23
- "dist"
24
- ],
25
10
  "engines": {
26
- "node": ">=12.13"
11
+ "node": ">=18"
27
12
  },
28
13
  "scripts": {
29
14
  "test": "vitest run",
30
- "lint": "tsc --noEmit && eslint ./src --ext .ts",
31
- "build": "rollup -c ./rollup.config.js",
32
- "release": "npm run lint && del dist && npm run build && np"
15
+ "lint": "tsc --noEmit && eslint ./src",
16
+ "build": "del-cli dist && tsc",
17
+ "release": "npm run lint && npm run build && np"
33
18
  },
34
- "repository": {
35
- "type": "git",
36
- "url": "git+https://github.com/mesqueeb/commafy-anything.git"
19
+ "devDependencies": {
20
+ "del-cli": "^5.1.0",
21
+ "np": "^10.0.5",
22
+ "vitest": "^1.6.0",
23
+ "@cycraft/eslint": "^0.3.0",
24
+ "@cycraft/tsconfig": "^0.1.2"
37
25
  },
26
+ "files": [
27
+ "dist"
28
+ ],
38
29
  "keywords": [
39
30
  "comma",
40
31
  "comma's",
41
32
  "commafy",
42
33
  "number"
43
34
  ],
44
- "author": "Luca Ban - Mesqueeb",
35
+ "author": "Luca Ban - Mesqueeb (https://cycraft.co)",
45
36
  "funding": "https://github.com/sponsors/mesqueeb",
46
37
  "license": "MIT",
47
- "bugs": {
48
- "url": "https://github.com/mesqueeb/commafy-anything/issues"
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/mesqueeb/commafy-anything.git"
49
41
  },
50
42
  "homepage": "https://github.com/mesqueeb/commafy-anything#readme",
51
- "devDependencies": {
52
- "@typescript-eslint/eslint-plugin": "^5.59.2",
53
- "@typescript-eslint/parser": "^5.59.2",
54
- "del-cli": "^5.0.0",
55
- "eslint": "^8.40.0",
56
- "eslint-config-prettier": "^8.8.0",
57
- "eslint-plugin-tree-shaking": "^1.10.0",
58
- "np": "^7.7.0",
59
- "prettier": "^2.8.8",
60
- "rollup": "^3.23.0",
61
- "rollup-plugin-dts": "^5.3.0",
62
- "rollup-plugin-esbuild": "^5.0.0",
63
- "typescript": "^4.9.5",
64
- "vitest": "^0.31.0"
65
- },
66
- "np": {
67
- "yarn": false,
68
- "branch": "production"
69
- },
70
- "eslintConfig": {
71
- "ignorePatterns": [
72
- "node_modules",
73
- "dist",
74
- "scripts",
75
- "test"
76
- ],
77
- "root": true,
78
- "parser": "@typescript-eslint/parser",
79
- "plugins": [
80
- "@typescript-eslint",
81
- "tree-shaking"
82
- ],
83
- "extends": [
84
- "eslint:recommended",
85
- "plugin:@typescript-eslint/eslint-recommended",
86
- "plugin:@typescript-eslint/recommended",
87
- "prettier"
88
- ],
89
- "rules": {
90
- "@typescript-eslint/no-empty-function": "off",
91
- "@typescript-eslint/no-explicit-any": "off",
92
- "@typescript-eslint/ban-ts-ignore": "off",
93
- "tree-shaking/no-side-effects-in-initialization": "error",
94
- "@typescript-eslint/ban-ts-comment": "off"
95
- }
96
- }
43
+ "bugs": "https://github.com/mesqueeb/commafy-anything/issues"
97
44
  }
@@ -1,24 +0,0 @@
1
- 'use strict';
2
-
3
- function commafy(num, options) {
4
- const { stripDecimals = false, spacedDecimals = false, thousandsComma = true, K = false } = options || {};
5
- const [wholeNrStr, decimalStr = ""] = num.toString().split(".");
6
- const str = [wholeNrStr, decimalStr];
7
- const minLength = thousandsComma ? 4 : 5;
8
- if (!K && wholeNrStr.length >= minLength) {
9
- str[0] = wholeNrStr.replace(/(\d)(?=(\d{3})+$)/g, "$1,");
10
- }
11
- if (K && wholeNrStr.length > 3) {
12
- const numInK = Math.round(num / 1e3);
13
- const commafied = numInK.toString().replace(/(\d)(?=(\d{3})+$)/g, "$1,");
14
- str[0] = commafied + "K";
15
- }
16
- if (stripDecimals || !decimalStr || K)
17
- return str[0];
18
- if (spacedDecimals && decimalStr.length >= minLength) {
19
- str[1] = decimalStr.replace(/(\d{3})/g, "$1 ").trim();
20
- }
21
- return str.join(".");
22
- }
23
-
24
- exports.commafy = commafy;
@@ -1,16 +0,0 @@
1
- /**
2
- * Adds comma's to a number
3
- *
4
- * @export
5
- * @param {(string | number)} num the number to commafy
6
- * @param {{ stripDecimals?: boolean, spacedDecimals?: boolean, thousandsComma?: boolean, K?: boolean }} [options] By default thousandsComma is enabled, if disabled it shows `1000` without comma (but `10,000` with)
7
- * @returns {string} eg. '1,000,000'
8
- */
9
- declare function commafy(num: number, options?: {
10
- stripDecimals?: boolean;
11
- spacedDecimals?: boolean;
12
- thousandsComma?: boolean;
13
- K?: boolean;
14
- }): string;
15
-
16
- export { commafy };