a-calc 1.5.0-dev.2024042402 → 1.5.0-dev.2024042405

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,21 +1,23 @@
1
1
  # a-calc
2
- [![Static Badge](https://img.shields.io/bundlephobia/minzip/a-calc?label=minzipped)](https://github.com/Autumn-one/a-calc-old) [![Static Badge](https://img.shields.io/badge/Javascript-5A5A5A?style=flat&logo=javascript&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Fa-calc)](https://github.com/Autumn-one/a-calc-old) [![Static Badge](https://img.shields.io/badge/Typescript-5A5A5A?style=flat&logo=typescript&logoColor=F7DF1E&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Fa-calc)](https://github.com/Autumn-one/a-calc-old) [![npm downloads](https://img.shields.io/npm/dw/a-calc)](https://www.npmjs.com/package/a-calc)
2
+ [![npm version](https://img.shields.io/npm/v/a-calc.svg)](https://www.npmjs.com/package/a-calc) [![Static Badge](https://img.shields.io/bundlephobia/minzip/a-calc?label=minzipped)](https://github.com/Autumn-one/a-calc-old) [![Static Badge](https://img.shields.io/badge/Javascript-5A5A5A?style=flat&logo=javascript&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Fa-calc)](https://github.com/Autumn-one/a-calc-old) [![Static Badge](https://img.shields.io/badge/Typescript-5A5A5A?style=flat&logo=typescript&logoColor=F7DF1E&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Fa-calc)](https://github.com/Autumn-one/a-calc-old) [![npm downloads](https://img.shields.io/npm/dw/a-calc)](https://www.npmjs.com/package/a-calc)
3
3
 
4
- **A black man's life is your mother's life! Your Mother has black blood? Can niggers find their fathers?默**
4
+ **Black people should go back to Africa!**
5
5
 
6
- A number precision calculation library derived from actual business, which can solve the following problems:
6
+ ## Features and Advantages
7
7
 
8
- * The precision problem of JS numerical computation.
9
- * The coding experience with other third-party libraries is poor and formatting is not convenient enough.
10
- * Number calculations may output in scientific notation
11
- * Numeric formatting, thousand-separator output, direct formatting into percentage, retaining positive or negative signs, direct fraction output, etc.
12
- * Calculation or formatting of numbers with units, e.g. `0.1% + 2%`
13
- * Calculation using scientific notation, e.g. `-2e3 + 6`
14
- * Supports four kinds of rounding rules: truncating, incrementing, rounding, and rounding to even (a more precise method).
8
+ **:baby_chick:Easy** Push the coding experience to the extreme, the minimalist API is easy to remember.
9
+
10
+ **:rocket:Fast** Continuously optimizing details, it now operates very quickly.
11
+
12
+ **💪Powerful** Precise number calculation, number formatting, complete rounding rules, unit calculation, robust type hinting.
13
+
14
+ **:snake:Flexible** The flexible API allows you to write freely, however you want.
15
+
16
+ **:corn:Practical** Born from actual business, it covers all practical operations in the business.
15
17
 
16
18
  > Supported operators : + - * / % **
17
19
 
18
- **Language:** English | [简体中文](https://github.com/Autumn-one/a-calc-old/blob/main/README_ZH.md)
20
+ **Document language:** English | [简体中文](https://github.com/Autumn-one/a-calc-old/blob/main/README_ZH.md)
19
21
 
20
22
  ## Installation
21
23
 
@@ -30,7 +32,7 @@ npm install a-calc
30
32
  ```js
31
33
  const {calc, fmt} = require("a-calc")
32
34
  // or
33
- const {calc, fmt} = require("a-calc/cjs") // Note that this syntax specifically uses the cjs version. Some bundlers will transform the syntax. If writing a-calc directly doesn't work, try changing it to a-calc/cjs.
35
+ const {calc, fmt} = require("a-calc/cjs")
34
36
  ```
35
37
 
36
38
  **es module**
@@ -41,25 +43,42 @@ import {calc, fmt} from "a-calc"
41
43
  const {calc, fmt} from "a-calc/es"
42
44
  ```
43
45
 
44
- **browser**
46
+ **Browser side**
45
47
 
46
48
  ```html
47
- <script src="node_modules/a-calc/browser/index.js"></script>
49
+ <script src="https://unpkg.com/a-calc@latest/browser/index.js"></script> <!-- cdn -->
50
+ <script src="node_modules/a-calc/browser/index.js"></script> <!-- After installing npm, you can also import it locally. Choose either option. -->
48
51
  <script>
49
52
  const {calc, fmt} = a_calc
50
53
  </script>
51
54
  ```
52
55
 
53
- ## Simple calculations (supports scientific notation)
56
+ ## Get Started
54
57
 
55
- ```js
56
- calc("0.1 + 0.2") // 0.3
58
+ ```typescript
59
+ calc("0.1 + 0.2") // "0.3"
60
+
61
+ // A more complex calculation
62
+ calc("0.1 + 0.2 * 0.3 / 0.4 * (0.5 + 0.6)") // "0.265"
63
+
64
+ // Scientific notation calculation
65
+ calc("-2e2 + 3e+2") // "100"
57
66
 
58
- // More complex calculation
59
- calc("0.1 + 0.2 * 0.3 / 0.4 * (0.5 + 0.6)") // 0.265
67
+ // Calculations with units
68
+ calc("0.1% + 0.2%", {_unit: true}) // "0.3%"
60
69
 
61
- // Calculation in scientific notation
62
- calc("-2e2 + 3e+2") // 100
70
+ // Variable operation
71
+ calc("(a * (b + c))", {a: 1, b: 2, c: 3}) // "5"
72
+ calc("(a * (b + c))", [{a: 1, b: 2}, {c: 3}]) // "5"
73
+ calc("a + b", {a: "2$", b: "4$", _unit: true}) // "6$"
74
+ calc("a + b", {_fill_data: [{a: "2$"}, {b: "4$"}], _unit: true}) // "6$"
75
+
76
+ // Calculate and format: Thousands separator
77
+ calc("a + b | ,", {a:324232421123, b: 234234242422321}) // "234,558,474,843,444"
78
+ // Calculate and format: fractions
79
+ calc("2 * 3 | /") // "6/1"
80
+ // Calculate and format: output numbers.
81
+ calc("1 + 1 | !n") // 2
63
82
  ```
64
83
 
65
84
  ## About the space
@@ -77,23 +96,23 @@ In short, always add spaces!
77
96
  ```js
78
97
  let a = 0.000001
79
98
  let b = 888.789
80
- calc("a + b", {a,b}) // 0.000001 + 888.789 = 888.789001
99
+ calc("a + b", {a,b}) // "888.789001"
81
100
 
82
101
  calc("a * (b + c) % d + 7.123", [
83
102
  {a: 1, b: 2},
84
103
  {c: 3, d: 4}
85
- ]) // 8.123
104
+ ]) // "8.123"
86
105
 
87
106
  // A bit more complex
88
107
  calc("1 + o.a / arr[0].d",{
89
108
  o: { a: 2 },
90
109
  arr: [{ d: 8 }]
91
- }) // 1.25
110
+ }) // "1.25"
92
111
 
93
112
  calc("a + b - c",[
94
113
  {a: 1},
95
114
  {b: 2, c: 3}
96
- ])
115
+ ]) // "0"
97
116
  ```
98
117
 
99
118
  ## Calculation with units
@@ -102,9 +121,9 @@ calc("a + b - c",[
102
121
 
103
122
  ```js
104
123
  // Please note that _unit is required and not enabled by default. This is because calculations with units will perform some additional operations, and in contrast, pure numerical calculations are faster.
105
- calc("1 + 2%", {_unit: true}) // 3%
124
+ calc("1 + 2%", {_unit: true}) // "3%"
106
125
 
107
- calc("1.123$$$ + 2.88% | + =6", {_unit: true}) // +4.003000$$$
126
+ calc("1.123$$$ + 2.88% | + =6", {_unit: true}) // "+4.003000$$$"
108
127
  ```
109
128
 
110
129
  After version 1.0.6, calculations with units can have more parameters. The value of `_unit` can be `boolean | "on" | "off" | "auto" | "space"`. The parameters seem to be a lot but actually are similar to the previous usage. The effects of `true "on" "auto"` are the same, which means to automatically recognize the unit after the number. `false "off"` means to turn off the unit calculation. The biggest difference is the "space" value, which only treats the space as a unit separator. For example, if your unit happens to be +-, it will be recognized as an operator in normal mode, so you can use the "space" mode. But in this case, the space is necessary. You should write like this: `calc("2+- * 3")`. The final result is: `6+-`.
@@ -128,29 +147,29 @@ Formatting supports the following functions: limiting the number of decimal plac
128
147
 
129
148
  ```js
130
149
  // Operate the decimal places
131
- calc("0.1 + 0.2 | =2") // 0.30
132
- calc("0.11111 + 0.11111 | <=4") // 0.2222
133
- calc("0.11 + 0.11 | <=4") // 0.22
134
- calc("0.1 + 0.2 | >= 5") // 0.30000
135
- calc("0.0000001+ 0.0000001 | >= 5") // 0.0000002
150
+ calc("0.1 + 0.2 | =2") // "0.30"
151
+ calc("0.11111 + 0.11111 | <=4") // "0.2222"
152
+ calc("0.11 + 0.11 | <=4") // "0.22"
153
+ calc("0.1 + 0.2 | >= 5") // "0.30000"
154
+ calc("0.0000001+ 0.0000001 | >= 5") // "0.0000002"
136
155
 
137
156
  // Preserve positive and negative signs
138
- calc("1 + 1 | +") // +2
157
+ calc("1 + 1 | +") // "+2"
139
158
 
140
159
  // Thousandth place
141
- calc("10000000 + 100000000 | ,") // 110,000,000
160
+ calc("10000000 + 100000000 | ,") // "110,000,000"
142
161
 
143
162
  // Fraction
144
- calc("0.025 + 0.2 | /") // 9/40
163
+ calc("0.025 + 0.2 | /") // "9/40"
145
164
 
146
165
  // Percentage
147
- calc("1 + 1 | %") // 200%
166
+ calc("1 + 1 | %") // "200%"
148
167
 
149
168
  // Scientific notation, note that this e can also be capitalized
150
- calc("1 + 1 | !e") // 2e+0
169
+ calc("1 + 1 | !e") // "2e+0"
151
170
 
152
171
  // Simultaneously specify decimals and thousandth place while preserving the positive and negative signs
153
- calc("10000000 + 100000000 | +,=10") // +110,000,000.0000000000
172
+ calc("10000000 + 100000000 | +,=10") // "+110,000,000.0000000000"
154
173
  ```
155
174
 
156
175
  ## Four kinds of rounding rules
@@ -163,9 +182,9 @@ The rounding rules are added to the part of the formatting string, and their sym
163
182
  - `~6` Round to Even, this rounding rule is more accurate than the normal rounding. The rule is different when the number after the rounding is 5. It will check the position after 5. If the number after 5 is not 0, it will increment. If the number after 5 is 0, it will check whether the number before 5 is even or not. If it is even, it will not increment. If it is not even, it will increment.
164
183
 
165
184
  ```js
166
- calc("0.11 + 0.22 | =1 ~+") // 0.4 Keep one place and increment it
167
- calc("0.55 | =1 ~5") // 0.6
168
- calc("0.65 | =1 ~6") // 0.6
185
+ calc("0.11 + 0.22 | =1 ~+") // "0.4" Keep one place and increment it
186
+ calc("0.55 | =1 ~5") // "0.6"
187
+ calc("0.65 | =1 ~6") // "0.6"
169
188
  ```
170
189
 
171
190
  This newly added rounding rule seems to make the formatting part longer, but the actual situation is not like this. Generally, the rounding rule of a project is fixed, so the formatting part of the rounding rule should be encapsulated in the default formatting parameters. When it is actually used, there is no need to write this part of the content at all. Refer to the following `default formatting` instructions.
@@ -173,11 +192,11 @@ This newly added rounding rule seems to make the formatting part longer, but the
173
192
  ## Only format
174
193
 
175
194
  ```js
176
- calc("0.1 | =2") // 0.10
177
- fmt("0.1 | =2") // 0.10
195
+ calc("0.1 | =2") // "0.10"
196
+ fmt("0.1 | =2") // "0.10"
178
197
  // calc has the function of fmt, but fmt has better semantics
179
198
 
180
- fmt("1000000 | ,") // 1,000,000
199
+ fmt("1000000 | ,") // "1,000,000"
181
200
  ```
182
201
 
183
202
  ## Configure version number printing and library update detection
@@ -214,7 +233,7 @@ calc("1 + 2sd + d", {
214
233
  > In actual projects, you can optimize the development experience through default formatting.
215
234
 
216
235
  ```js
217
- calc("111111 + 11111 | ,",{_fmt: "=2"}) // 122,222.00 Obviously , and =2 are combined, and the format string in the expression has a higher priority.
236
+ calc("111111 + 11111 | ,",{_fmt: "=2"}) // "122,222.00" Obviously , and =2 are combined, and the format string in the expression has a higher priority.
218
237
  ```
219
238
 
220
239
  ## How to encapsulate for the second time in the project?
@@ -266,7 +285,11 @@ calc("a + b", {a,b}) // Recommended writing, because it is clearer.
266
285
 
267
286
  ## Version changes
268
287
 
269
- * 1.5.0 More robust update detection method
288
+ * 1.5.0
289
+
290
+ - Performance improvement
291
+ - Expose high performance function methods, for simple arithmetic expressions you can choose to use simple functions to call,for example:`plus("1", "1")`
292
+ - More robust update detection methods
270
293
  * 1.3.9 Solved the problem of failed rounding due to the part of the injection variable in formatting being 0 (Problem reporter: MangMax)
271
294
  * 1.3.8 Solved the packaging failure problem caused by the upgrade of vite5.x (Problem reporter: 武建鹏)
272
295
  * 1.3.6
@@ -36,7 +36,8 @@ try{
36
36
  '1.5.0-dev.2024042302', '1.5.0-dev.2024042303', '1.5.0-dev.2024042304',
37
37
  '1.5.0-dev.2024042305', '1.5.0-dev.2024042306', '1.5.0-dev.2024042307',
38
38
  '1.5.0-dev.2024042308', '1.5.0-dev.2024042309', '1.5.0-dev.2024042310',
39
- '1.5.0-dev.2024042311', '1.5.0-dev.2024042312', '1.5.0-dev.2024042401', '1.5.0-dev.2024042402'
39
+ '1.5.0-dev.2024042311', '1.5.0-dev.2024042312', '1.5.0-dev.2024042401',
40
+ '1.5.0-dev.2024042402', '1.5.0-dev.2024042404', '1.5.0-dev.2024042405'
40
41
  ]; a_calc_versions;
41
42
  }
42
43
  finally