commafy-anything 3.0.2 → 3.0.3

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.
Files changed (3) hide show
  1. package/README.md +46 -12
  2. package/dist/index.cjs +0 -2
  3. package/package.json +14 -14
package/README.md CHANGED
@@ -7,21 +7,26 @@
7
7
  npm i commafy-anything
8
8
  ```
9
9
 
10
- Adds comma's to a number. A simple and small integration.
10
+ Return a number as string with `,` or `K`. A simple and small integration.
11
11
 
12
12
  ## Motivation
13
13
 
14
- U built this package because I needed to add comma's to numbers! And I wanted to build it myself. 😄
14
+ U built this package because I needed to add comma's and K to numbers! And I wanted to build it myself. 😄
15
15
 
16
- ## Meet the family
16
+ ## Meet the family (more tiny utils with TS support)
17
17
 
18
- - [copy-anything 🎭](https://github.com/mesqueeb/copy-anything)
18
+ - [is-what 🙉](https://github.com/mesqueeb/is-what)
19
+ - [is-where 🙈](https://github.com/mesqueeb/is-where)
19
20
  - [merge-anything 🥡](https://github.com/mesqueeb/merge-anything)
21
+ - [check-anything 👁](https://github.com/mesqueeb/check-anything)
22
+ - [remove-anything ✂️](https://github.com/mesqueeb/remove-anything)
23
+ - [getorset-anything 🐊](https://github.com/mesqueeb/getorset-anything)
24
+ - [map-anything 🗺](https://github.com/mesqueeb/map-anything)
20
25
  - [filter-anything ⚔️](https://github.com/mesqueeb/filter-anything)
21
- - [find-and-replace-anything 🎣](https://github.com/mesqueeb/find-and-replace-anything)
22
- - [compare-anything 🛰](https://github.com/mesqueeb/compare-anything)
26
+ - [copy-anything 🎭](https://github.com/mesqueeb/copy-anything)
27
+ - [case-anything 🐫](https://github.com/mesqueeb/case-anything)
23
28
  - [flatten-anything 🏏](https://github.com/mesqueeb/flatten-anything)
24
- - [is-what 🙉](https://github.com/mesqueeb/is-what)
29
+ - [nestify-anything 🧅](https://github.com/mesqueeb/nestify-anything)
25
30
 
26
31
  ## Usage
27
32
 
@@ -35,20 +40,47 @@ commafy(1000000) === '1,000,000'
35
40
  // etc.
36
41
  ```
37
42
 
43
+ ### K
44
+
45
+ You can show numbers as 1K.
46
+
47
+ ```js
48
+ const options = { K: true }
49
+ // when smaller than 1000 will be shown as is, without K
50
+ commafy(123, options) === '123'
51
+
52
+ // when larger than 1000 it will round up/down behind the K
53
+ commafy(1234, options) === '1K'
54
+ commafy(10234, options) === '10K'
55
+ commafy(100234, options) === '100K'
56
+ commafy(1000234, options) === '1,000K'
57
+
58
+ commafy(1955, options) === '2K'
59
+ commafy(10955, options) === '11K'
60
+ commafy(100955, options) === '101K'
61
+ commafy(1000955, options) === '1,001K'
62
+ ```
63
+
38
64
  ### Thousands
39
65
 
66
+ You can disable a comma to be added when the number is between `1000` ~ `9999`.
67
+
40
68
  ```js
41
69
  // default:
42
70
  commafy(1000) === '1,000'
43
71
 
44
- // thousands:
45
- const options = {thousandsComma: false}
72
+ const options = { thousandsComma: false }
46
73
  commafy(1000, options) === '1000'
74
+ commafy(9999, options) === '9999'
75
+
76
+ // beyond 9999 it will always have a comma
47
77
  commafy(10000, options) === '10,000'
48
78
  ```
49
79
 
50
80
  ### Spaced decimals
51
81
 
82
+ You can add spaces to decimals.
83
+
52
84
  ```js
53
85
  // default:
54
86
  commafy(1.0001) === '1.0001'
@@ -57,7 +89,7 @@ commafy(1.000001) === '1.000001'
57
89
  commafy(1.0000001) === '1.0000001'
58
90
 
59
91
  // spaced decimals:
60
- const options = {spacedDecimals: true}
92
+ const options = { spacedDecimals: true }
61
93
  commafy(1.0001, options) === '1.0001'
62
94
  commafy(1.00001, options) === '1.000 01'
63
95
  commafy(1.000001, options) === '1.000 001'
@@ -66,12 +98,14 @@ commafy(1.0000001, options) === '1.000 0001'
66
98
 
67
99
  ### Strip decimals
68
100
 
101
+ You can add strip away decimals.
102
+
69
103
  ```js
70
104
  // default:
71
105
  commafy(1.0001) === '1.0001'
72
106
 
73
107
  // strip decimals:
74
- const options = {stripDecimals: true}
108
+ const options = { stripDecimals: true }
75
109
  commafy(1.001, options) === '1'
76
110
  commafy(1.999, options) === '1'
77
111
  ```
@@ -81,7 +115,7 @@ commafy(1.999, options) === '1'
81
115
  I'm using simple regular expressions. The source code is in TypeScript, but the essense of my source code looks something like this:
82
116
 
83
117
  ```js
84
- function commafy (num, {stripDecimals, spacedDecimals} = {}) {
118
+ function commafy(num, { stripDecimals, spacedDecimals } = {}) {
85
119
  const str = num.toString().split('.')
86
120
  if (str[0].length >= 4) {
87
121
  str[0] = str[0].replace(/(\d)(?=(\d{3})+$)/g, '$1,')
package/dist/index.cjs CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  /**
6
4
  * Adds comma's to a number
7
5
  *
package/package.json CHANGED
@@ -2,16 +2,16 @@
2
2
  "name": "commafy-anything",
3
3
  "sideEffects": false,
4
4
  "type": "module",
5
- "version": "3.0.2",
5
+ "version": "3.0.3",
6
6
  "description": "Adds comma's to a number. A simple and small integration",
7
7
  "module": "./dist/index.es.js",
8
8
  "main": "./dist/index.cjs",
9
9
  "types": "./dist/types/index.d.ts",
10
10
  "exports": {
11
11
  ".": {
12
+ "types": "./dist/types/index.d.ts",
12
13
  "import": "./dist/index.es.js",
13
- "require": "./dist/index.cjs",
14
- "types": "./dist/types/index.d.ts"
14
+ "require": "./dist/index.cjs"
15
15
  }
16
16
  },
17
17
  "files": [
@@ -23,7 +23,7 @@
23
23
  "scripts": {
24
24
  "test": "vitest run",
25
25
  "lint": "tsc --noEmit && eslint ./src --ext .ts",
26
- "build": "rollup -c ./scripts/build.js",
26
+ "build": "rollup --bundleConfigAsCjs -c ./scripts/build.js",
27
27
  "release": "npm run lint && del dist && npm run build && np"
28
28
  },
29
29
  "repository": {
@@ -44,18 +44,18 @@
44
44
  },
45
45
  "homepage": "https://github.com/mesqueeb/commafy-anything#readme",
46
46
  "devDependencies": {
47
- "@typescript-eslint/eslint-plugin": "^5.10.1",
48
- "@typescript-eslint/parser": "^5.10.1",
47
+ "@typescript-eslint/eslint-plugin": "^5.59.2",
48
+ "@typescript-eslint/parser": "^5.59.2",
49
49
  "del-cli": "^4.0.1",
50
- "eslint": "^8.7.0",
51
- "eslint-config-prettier": "^8.3.0",
50
+ "eslint": "^8.40.0",
51
+ "eslint-config-prettier": "^8.8.0",
52
52
  "eslint-plugin-tree-shaking": "^1.10.0",
53
- "np": "^7.6.0",
54
- "prettier": "^2.5.1",
55
- "rollup": "^2.66.1",
56
- "rollup-plugin-typescript2": "^0.31.1",
57
- "typescript": "^4.5.5",
58
- "vitest": "^0.2.3"
53
+ "np": "^7.7.0",
54
+ "prettier": "^2.8.8",
55
+ "rollup": "^3.21.5",
56
+ "rollup-plugin-typescript2": "^0.34.1",
57
+ "typescript": "^4.9.5",
58
+ "vitest": "^0.31.0"
59
59
  },
60
60
  "np": {
61
61
  "yarn": false,