Comparing version 1.5.0-dev.2024042402 to 1.5.0-dev.2024042404
@@ -39,3 +39,4 @@ try{ | ||
'1.5.0-dev.2024042308', '1.5.0-dev.2024042309', '1.5.0-dev.2024042310', | ||
'1.5.0-dev.2024042311', '1.5.0-dev.2024042312', '1.5.0-dev.2024042401', '1.5.0-dev.2024042402' | ||
'1.5.0-dev.2024042311', '1.5.0-dev.2024042312', '1.5.0-dev.2024042401', | ||
'1.5.0-dev.2024042402', '1.5.0-dev.2024042404' | ||
]; a_calc_versions; | ||
@@ -42,0 +43,0 @@ } |
@@ -107,2 +107,9 @@ import { U, StrRemoveSome, If_StrIncludes, Or } from "typescript-treasure"; | ||
export declare const calc_wrap: CalcWrap; | ||
declare const version: string; | ||
declare const version: string; | ||
export declare const add: (a: number|string, b: number|string) => number; | ||
export declare const sub: (a: number|string, b: number|string) => number; | ||
export declare const mul: (a: number|string, b: number|string) => number; | ||
export declare const div: (a: number|string, b: number|string) => number; | ||
export declare const pow: (a: number|string, b: number|string) => number; | ||
export declare const mod: (a: number|string, b: number|string) => number; |
{ | ||
"name": "a-calc", | ||
"version": "1.5.0-dev.2024042402", | ||
"version": "1.5.0-dev.2024042404", | ||
"description": "A very powerful and easy-to-use number precision calculation and formatting library.", | ||
@@ -5,0 +5,0 @@ "main": "./es/index.js", |
115
README.md
# 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) | ||
[![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) | ||
**A black man's life is your mother's life! Your Mother has black blood? Can niggers find their fathers?默** | ||
**Black people should go back to Africa!** | ||
A number precision calculation library derived from actual business, which can solve the following problems: | ||
## Features and Advantages | ||
* The precision problem of JS numerical computation. | ||
* The coding experience with other third-party libraries is poor and formatting is not convenient enough. | ||
* Number calculations may output in scientific notation | ||
* Numeric formatting, thousand-separator output, direct formatting into percentage, retaining positive or negative signs, direct fraction output, etc. | ||
* Calculation or formatting of numbers with units, e.g. `0.1% + 2%` | ||
* Calculation using scientific notation, e.g. `-2e3 + 6` | ||
* Supports four kinds of rounding rules: truncating, incrementing, rounding, and rounding to even (a more precise method). | ||
**:baby_chick:Easy** Push the coding experience to the extreme, the minimalist API is easy to remember. | ||
**:rocket:Fast** Continuously optimizing details, it now operates very quickly. | ||
**💪Powerful** Precise number calculation, number formatting, complete rounding rules, unit calculation, robust type hinting. | ||
**:snake:Flexible** The flexible API allows you to write freely, however you want. | ||
**:corn:Practical** Born from actual business, it covers all practical operations in the business. | ||
> Supported operators : + - * / % ** | ||
**Language:** English | [简体中文](https://github.com/Autumn-one/a-calc-old/blob/main/README_ZH.md) | ||
**Document language:** English | [简体中文](https://github.com/Autumn-one/a-calc-old/blob/main/README_ZH.md) | ||
@@ -33,3 +35,3 @@ ## Installation | ||
// or | ||
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. | ||
const {calc, fmt} = require("a-calc/cjs") | ||
``` | ||
@@ -45,6 +47,7 @@ | ||
**browser** | ||
**Browser side** | ||
```html | ||
<script src="node_modules/a-calc/browser/index.js"></script> | ||
<script src="https://unpkg.com/a-calc@latest/browser/index.js"></script> <!-- cdn --> | ||
<script src="node_modules/a-calc/browser/index.js"></script> <!-- After installing npm, you can also import it locally. Choose either option. --> | ||
<script> | ||
@@ -55,12 +58,28 @@ const {calc, fmt} = a_calc | ||
## Simple calculations (supports scientific notation) | ||
## Get Started | ||
```js | ||
calc("0.1 + 0.2") // 0.3 | ||
```typescript | ||
calc("0.1 + 0.2") // "0.3" | ||
// More complex calculation | ||
calc("0.1 + 0.2 * 0.3 / 0.4 * (0.5 + 0.6)") // 0.265 | ||
// A more complex calculation | ||
calc("0.1 + 0.2 * 0.3 / 0.4 * (0.5 + 0.6)") // "0.265" | ||
// Calculation in scientific notation | ||
calc("-2e2 + 3e+2") // 100 | ||
// Scientific notation calculation | ||
calc("-2e2 + 3e+2") // "100" | ||
// Calculations with units | ||
calc("0.1% + 0.2%", {_unit: true}) // "0.3%" | ||
// Variable operation | ||
calc("(a * (b + c))", {a: 1, b: 2, c: 3}) // "5" | ||
calc("(a * (b + c))", [{a: 1, b: 2}, {c: 3}]) // "5" | ||
calc("a + b", {a: "2$", b: "4$", _unit: true}) // "6$" | ||
calc("a + b", {_fill_data: [{a: "2$"}, {b: "4$"}], _unit: true}) // "6$" | ||
// Calculate and format: Thousands separator | ||
calc("a + b | ,", {a:324232421123, b: 234234242422321}) // "234,558,474,843,444" | ||
// Calculate and format: fractions | ||
calc("2 * 3 | /") // "6/1" | ||
// Calculate and format: output numbers. | ||
calc("1 + 1 | !n") // 2 | ||
``` | ||
@@ -83,3 +102,3 @@ | ||
let b = 888.789 | ||
calc("a + b", {a,b}) // 0.000001 + 888.789 = 888.789001 | ||
calc("a + b", {a,b}) // "888.789001" | ||
@@ -89,3 +108,3 @@ calc("a * (b + c) % d + 7.123", [ | ||
{c: 3, d: 4} | ||
]) // 8.123 | ||
]) // "8.123" | ||
@@ -96,3 +115,3 @@ // A bit more complex | ||
arr: [{ d: 8 }] | ||
}) // 1.25 | ||
}) // "1.25" | ||
@@ -102,3 +121,3 @@ calc("a + b - c",[ | ||
{b: 2, c: 3} | ||
]) | ||
]) // "0" | ||
``` | ||
@@ -112,5 +131,5 @@ | ||
// 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. | ||
calc("1 + 2%", {_unit: true}) // 3% | ||
calc("1 + 2%", {_unit: true}) // "3%" | ||
calc("1.123$$$ + 2.88% | + =6", {_unit: true}) // +4.003000$$$ | ||
calc("1.123$$$ + 2.88% | + =6", {_unit: true}) // "+4.003000$$$" | ||
``` | ||
@@ -139,25 +158,25 @@ | ||
// Operate the decimal places | ||
calc("0.1 + 0.2 | =2") // 0.30 | ||
calc("0.11111 + 0.11111 | <=4") // 0.2222 | ||
calc("0.11 + 0.11 | <=4") // 0.22 | ||
calc("0.1 + 0.2 | >= 5") // 0.30000 | ||
calc("0.0000001+ 0.0000001 | >= 5") // 0.0000002 | ||
calc("0.1 + 0.2 | =2") // "0.30" | ||
calc("0.11111 + 0.11111 | <=4") // "0.2222" | ||
calc("0.11 + 0.11 | <=4") // "0.22" | ||
calc("0.1 + 0.2 | >= 5") // "0.30000" | ||
calc("0.0000001+ 0.0000001 | >= 5") // "0.0000002" | ||
// Preserve positive and negative signs | ||
calc("1 + 1 | +") // +2 | ||
calc("1 + 1 | +") // "+2" | ||
// Thousandth place | ||
calc("10000000 + 100000000 | ,") // 110,000,000 | ||
calc("10000000 + 100000000 | ,") // "110,000,000" | ||
// Fraction | ||
calc("0.025 + 0.2 | /") // 9/40 | ||
calc("0.025 + 0.2 | /") // "9/40" | ||
// Percentage | ||
calc("1 + 1 | %") // 200% | ||
calc("1 + 1 | %") // "200%" | ||
// Scientific notation, note that this e can also be capitalized | ||
calc("1 + 1 | !e") // 2e+0 | ||
calc("1 + 1 | !e") // "2e+0" | ||
// Simultaneously specify decimals and thousandth place while preserving the positive and negative signs | ||
calc("10000000 + 100000000 | +,=10") // +110,000,000.0000000000 | ||
calc("10000000 + 100000000 | +,=10") // "+110,000,000.0000000000" | ||
``` | ||
@@ -175,5 +194,5 @@ | ||
```js | ||
calc("0.11 + 0.22 | =1 ~+") // 0.4 Keep one place and increment it | ||
calc("0.55 | =1 ~5") // 0.6 | ||
calc("0.65 | =1 ~6") // 0.6 | ||
calc("0.11 + 0.22 | =1 ~+") // "0.4" Keep one place and increment it | ||
calc("0.55 | =1 ~5") // "0.6" | ||
calc("0.65 | =1 ~6") // "0.6" | ||
``` | ||
@@ -186,7 +205,7 @@ | ||
```js | ||
calc("0.1 | =2") // 0.10 | ||
fmt("0.1 | =2") // 0.10 | ||
calc("0.1 | =2") // "0.10" | ||
fmt("0.1 | =2") // "0.10" | ||
// calc has the function of fmt, but fmt has better semantics | ||
fmt("1000000 | ,") // 1,000,000 | ||
fmt("1000000 | ,") // "1,000,000" | ||
``` | ||
@@ -228,3 +247,3 @@ | ||
```js | ||
calc("111111 + 11111 | ,",{_fmt: "=2"}) // 122,222.00 Obviously , and =2 are combined, and the format string in the expression has a higher priority. | ||
calc("111111 + 11111 | ,",{_fmt: "=2"}) // "122,222.00" Obviously , and =2 are combined, and the format string in the expression has a higher priority. | ||
``` | ||
@@ -281,3 +300,7 @@ | ||
* 1.5.0 More robust update detection method | ||
* 1.5.0 | ||
- Performance improvement | ||
- Expose high performance function methods, for simple arithmetic expressions you can choose to use simple functions to call,for example:`plus("1", "1")` | ||
- More robust update detection methods | ||
* 1.3.9 Solved the problem of failed rounding due to the part of the injection variable in formatting being 0 (Problem reporter: MangMax) | ||
@@ -284,0 +307,0 @@ * 1.3.8 Solved the packaging failure problem caused by the upgrade of vite5.x (Problem reporter: 武建鹏) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
377
230653
914