commafy-anything 3.0.3 → 3.0.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/cjs/index.cjs +24 -0
- package/dist/cjs/index.d.cts +16 -0
- package/dist/{types/index.d.ts → index.d.ts} +16 -14
- package/dist/index.js +22 -0
- package/package.json +19 -13
- package/dist/index.cjs +0 -32
- package/dist/index.es.js +0 -30
|
@@ -0,0 +1,24 @@
|
|
|
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;
|
|
@@ -0,0 +1,16 @@
|
|
|
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 };
|
|
@@ -1,14 +1,16 @@
|
|
|
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
|
-
|
|
10
|
-
stripDecimals?: boolean;
|
|
11
|
-
spacedDecimals?: boolean;
|
|
12
|
-
thousandsComma?: boolean;
|
|
13
|
-
K?: boolean;
|
|
14
|
-
}): string;
|
|
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 };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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(".");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { commafy };
|
package/package.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commafy-anything",
|
|
3
|
-
"
|
|
4
|
-
"type": "module",
|
|
5
|
-
"version": "3.0.3",
|
|
3
|
+
"version": "3.0.4",
|
|
6
4
|
"description": "Adds comma's to a number. A simple and small integration",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"types": "./dist/
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
}
|
|
15
20
|
}
|
|
16
21
|
},
|
|
17
22
|
"files": [
|
|
@@ -23,7 +28,7 @@
|
|
|
23
28
|
"scripts": {
|
|
24
29
|
"test": "vitest run",
|
|
25
30
|
"lint": "tsc --noEmit && eslint ./src --ext .ts",
|
|
26
|
-
"build": "rollup
|
|
31
|
+
"build": "rollup -c ./rollup.config.js",
|
|
27
32
|
"release": "npm run lint && del dist && npm run build && np"
|
|
28
33
|
},
|
|
29
34
|
"repository": {
|
|
@@ -46,14 +51,15 @@
|
|
|
46
51
|
"devDependencies": {
|
|
47
52
|
"@typescript-eslint/eslint-plugin": "^5.59.2",
|
|
48
53
|
"@typescript-eslint/parser": "^5.59.2",
|
|
49
|
-
"del-cli": "^
|
|
54
|
+
"del-cli": "^5.0.0",
|
|
50
55
|
"eslint": "^8.40.0",
|
|
51
56
|
"eslint-config-prettier": "^8.8.0",
|
|
52
57
|
"eslint-plugin-tree-shaking": "^1.10.0",
|
|
53
58
|
"np": "^7.7.0",
|
|
54
59
|
"prettier": "^2.8.8",
|
|
55
|
-
"rollup": "^3.
|
|
56
|
-
"rollup-plugin-
|
|
60
|
+
"rollup": "^3.23.0",
|
|
61
|
+
"rollup-plugin-dts": "^5.3.0",
|
|
62
|
+
"rollup-plugin-esbuild": "^5.0.0",
|
|
57
63
|
"typescript": "^4.9.5",
|
|
58
64
|
"vitest": "^0.31.0"
|
|
59
65
|
},
|
package/dist/index.cjs
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Adds comma's to a number
|
|
5
|
-
*
|
|
6
|
-
* @export
|
|
7
|
-
* @param {(string | number)} num the number to commafy
|
|
8
|
-
* @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)
|
|
9
|
-
* @returns {string} eg. '1,000,000'
|
|
10
|
-
*/
|
|
11
|
-
function commafy(num, options) {
|
|
12
|
-
const { stripDecimals = false, spacedDecimals = false, thousandsComma = true, K = false } = options || {};
|
|
13
|
-
const [wholeNrStr, decimalStr = ''] = num.toString().split('.');
|
|
14
|
-
const str = [wholeNrStr, decimalStr];
|
|
15
|
-
const minLength = thousandsComma ? 4 : 5;
|
|
16
|
-
if (!K && wholeNrStr.length >= minLength) {
|
|
17
|
-
str[0] = wholeNrStr.replace(/(\d)(?=(\d{3})+$)/g, '$1,');
|
|
18
|
-
}
|
|
19
|
-
if (K && wholeNrStr.length > 3) {
|
|
20
|
-
const numInK = Math.round(num / 1000);
|
|
21
|
-
const commafied = numInK.toString().replace(/(\d)(?=(\d{3})+$)/g, '$1,');
|
|
22
|
-
str[0] = commafied + 'K';
|
|
23
|
-
}
|
|
24
|
-
if (stripDecimals || !decimalStr || K)
|
|
25
|
-
return str[0];
|
|
26
|
-
if (spacedDecimals && decimalStr.length >= minLength) {
|
|
27
|
-
str[1] = decimalStr.replace(/(\d{3})/g, '$1 ').trim();
|
|
28
|
-
}
|
|
29
|
-
return str.join('.');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
exports.commafy = commafy;
|
package/dist/index.es.js
DELETED
|
@@ -1,30 +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
|
-
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.length >= minLength) {
|
|
15
|
-
str[0] = wholeNrStr.replace(/(\d)(?=(\d{3})+$)/g, '$1,');
|
|
16
|
-
}
|
|
17
|
-
if (K && 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('.');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { commafy };
|