prototype-helper 0.1.1 → 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/@types/index.d.ts CHANGED
@@ -1,8 +0,0 @@
1
- interface Number {
2
- toComma(): string;
3
- ampersand(amp: number): number;
4
- safeDivision(value: number): number;
5
- safeMultiply(value: number): number;
6
- safeAdd(value: number): number;
7
- safeSubtract(value: number): number;
8
- }
package/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # Typescript Prototype Helper
2
+
3
+ Adds a convenient prototype function package.
4
+
5
+ # Prototype Helper
6
+
7
+ ## Number
8
+
9
+ ### toComma()
10
+
11
+ It is a function that attaches a three-digit comma.
12
+
13
+ ```ts
14
+ let test = 123;
15
+ test.toComma(); // "123"
16
+ test = 123456;
17
+ test.toComma(); // "123,456"
18
+ //
19
+ ```
20
+
21
+ ### ampersand()
22
+
23
+ Ampsand that safely handles floating point errors.
24
+
25
+ ```ts
26
+ console.log(35 % 0.8); // 0.5999999999999981
27
+ console.log((35).ampersand(0.8)); // 0.6
28
+ ```
29
+
30
+ ### safeAdd()
31
+
32
+ Addition to safely handling floating point errors.
33
+
34
+ Calculate only up to 15 decimal places.
35
+
36
+ ```ts
37
+ console.log(0.1 + 0.2); // 0.30000000000000004
38
+ console.log((0.1).safeAdd(0.2)); // 0.3
39
+ ```
40
+
41
+ ### safeSubtract()
42
+
43
+ Subtraction that safely handles floating point errors.
44
+
45
+ Calculate only up to 15 decimal places.
46
+
47
+ ```ts
48
+ console.log(0.1 - 0.3); // -0.19999999999999998
49
+ console.log((0.1).safeSubtract(0.3)); // 0.2
50
+ ```
51
+
52
+ ### safeDivision()
53
+
54
+ Division that safely handles floating point errors.
55
+
56
+ Calculate only up to 15 decimal places.
57
+
58
+ ```ts
59
+ console.log(0.2 / 0.6); // 0.33333333333333337
60
+ console.log((0.2).safeDivision(0.6)); // 0.3333333333333333
61
+ ```
62
+
63
+ ### safeMultiply()
64
+
65
+ Division that safely handles floating point errors.
66
+
67
+ Calculate only up to 15 decimal places.
68
+
69
+ ```ts
70
+ console.log(0.1 * 0.2); // 0.020000000000000004
71
+ console.log((0.1).safeMultiply(0.2)); // 0.02
72
+ ```
73
+
74
+ ### padZero()
75
+
76
+ Fix the number of digits to be marked.
77
+
78
+ ```ts
79
+ console.log("30222.50380000".padPoint(5)); // 30222.50380
80
+ console.log((30222).padPoint(3)); // 30222.000
81
+ console.log((30222.12).padPoint(5).toComma()); // 30,222.12000
82
+ ```
83
+
84
+ ### padPoint()
85
+
86
+ Fix the decimal place to be marked.
87
+
88
+ ```ts
89
+ console.log("30222.50380000".padPoint(5)); // 30222.50380
90
+ console.log((30222).padPoint(3)); // 30222.000
91
+ console.log((30222.12).padPoint(5).toComma()); // 30,222.12000
92
+ ```
93
+
94
+ ---
95
+
96
+ ## String
97
+
98
+ ### toComma()
99
+
100
+ It is a function that attaches a three-digit comma.
101
+
102
+ ```ts
103
+ let test = "123";
104
+ test.toComma(); // "123"
105
+ test = "123456";
106
+ test.toComma(); // "123,456"
107
+ //
108
+ ```
109
+
110
+ ## Object
111
+
112
+ ## Array
113
+
114
+ ### toComma
115
+
116
+ ---
117
+
118
+ # Override Helper
119
+
120
+ ## Math
121
+
122
+ ### round10()
123
+
124
+ ### floor10()
125
+
126
+ ### ceil10()
127
+
128
+ A function that allows you to use decimal points for discarding/rounding/round.
129
+
130
+ I used the code of the MDN below.
131
+
132
+ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil#decimal_adjustment
133
+
134
+ ```ts
135
+ console.log(Math.round10(112.5345, 3)); //112.535
136
+ console.log(Math.floor10(112.5345, 3)); //112.534
137
+ console.log(Math.ceil10(112.5345, 3)); //112.535
138
+ ```
139
+
140
+ ### randomRange()
141
+
142
+ Create random numbers within that range.
143
+
144
+ (Includes maximum and minimum values.)
145
+
146
+ ```ts
147
+ console.log(Math.randomRange(112.5, 200, 1)); //135.1
148
+ console.log(Math.randomRange(0, 200)); //169
149
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prototype-helper",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -49,6 +49,11 @@
49
49
  "js",
50
50
  "json"
51
51
  ],
52
+ "moduleDirectories": [
53
+ "node_modules",
54
+ "bower_components",
55
+ "src"
56
+ ],
52
57
  "globals": {
53
58
  "ts-jest": {
54
59
  "diagnostics": true