Skip to content

Commit bed43c6

Browse files
committed
update readme
1 parent 31c6985 commit bed43c6

File tree

5 files changed

+74
-18
lines changed

5 files changed

+74
-18
lines changed

README.ZH-CN.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212

1313
## 特性
14-
- :v: 使用 [big.js](https://github.com/MikeMcl/big.js) 自动处理 JavaScript 小数精度,并支持大整数
15-
- :rocket: 执行快、体积小,压缩后只有 17.2 KB, GZIP 后仅 5.9 KB
14+
- :v: 使用 [bignumber.js](https://github.com/MikeMcl/bignumber.js) 自动处理 JavaScript 小数精度,并支持大整数
15+
- :rocket: 执行快、体积小,压缩后只有 17.2 KB, GZIP 后仅 5.9 KB (无 bignumber.js 依赖版本压缩后只有 10.5 KB, GZIP 后仅 3.3 KB)
1616
- :writing_hand: 非常容易扩展自己的自定义运算符
1717
- :vulcan_salute: 支持表达式变量占位符
1818

@@ -29,7 +29,7 @@ yarn add decimal-eval
2929
```
3030

3131
### 使用
32-
支持基本的四则运算 (`+`, `-`, `*`, `/`), 并默认使用 [big.js](https://github.com/MikeMcl/big.js) 自动处理 JavaScript 小数精度,并支持大整数
32+
支持基本的四则运算 (`+`, `-`, `*`, `/`), 并默认使用 [bignumber.js](https://github.com/MikeMcl/bignumber.js) 自动处理 JavaScript 小数精度,并支持大整数
3333

3434
```js
3535
import {evaluate} from 'decimal-eval';
@@ -105,7 +105,7 @@ evaluate({ def: 1 }); // 抛出错误,字段名 `abc` 未初始化
105105
安装一个运算符,运算符通过 `Parser.createBinaryOperator()``Parser.createUnaryOperator()` 方法创建
106106

107107
#### Parser.useAdapter(adapter)
108-
为四则运算 (`+`, `-`, `*`, `/`) 设置计算方法适配器,默认使用 [big.js](https://github.com/MikeMcl/big.js) 计算
108+
为四则运算 (`+`, `-`, `*`, `/`) 设置计算方法适配器,默认使用 [bignumber.js](https://github.com/MikeMcl/bignumber.js) 计算
109109

110110
```js
111111
Parser.useAdapter({
@@ -120,7 +120,7 @@ Parser.useAdapter({
120120
## 进阶
121121

122122
### 使用 Pure 包 (无依赖)
123-
当需要使用自定义方法去处理小数精度问题时,你可以使用 Pure 包,可以减少 60% 的体积,这个包不包含 `big.js`
123+
当需要使用自定义方法去处理小数精度问题时,你可以使用 Pure 包,可以减少 60% 的体积,这个包不包含 `bignumber.js`
124124

125125
```js
126126
import {evaluate, Parser} from 'decimal-eval/dist/pure';
@@ -135,12 +135,12 @@ evaluate('0.1 + 0.2'); // '0.30000000000000004'
135135
evaluate('9007199254740992 + 1'); // '9007199254740992'
136136
```
137137

138-
### 导出 `big.js`
139-
[Big.js](https://github.com/MikeMcl/big.js) 对处理 JavaScript 小数精度问题很有用,而不用重复安装
138+
### 导出 `bignumber.js`
139+
[bignumber.js](https://github.com/MikeMcl/bignumber.js) 对处理 JavaScript 小数精度问题很有用,而不用重复安装
140140

141141
```js
142-
import {Big} from 'decimal-eval';
143-
const val = new Big(0.1).plus(0.2);
142+
import {BigNumber} from 'decimal-eval';
143+
const val = new BigNumber(0.1).plus(0.2);
144144
console.log(String(val)); // '0.3'
145145
```
146146

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ A tiny, safe, fast JavaScript library for decimal arithmetic expressions.
1010
English | [简体中文](./README.ZH-CN.md)
1111

1212
## Features
13-
- :v: Automatically deal with the JavaScript decimal precision problem by [big.js](https://github.com/MikeMcl/big.js), and supports big number
14-
- :rocket: Fast and tiny, only 17.2 KB minified and 5.9 KB gzipped
13+
- :v: Automatically deal with the JavaScript decimal precision problem by [bignumber.js](https://github.com/MikeMcl/bignumber.js), and supports big number
14+
- :rocket: Fast and tiny, only 28.7 KB minified and 11.2 KB gzipped (pure only 10.5 KB minified and 3.3 KB gzipped without bignumber.js)
1515
- :writing_hand: Easy to extend custom operator
1616
- :vulcan_salute: Supports expression scope variables
1717

@@ -29,7 +29,7 @@ yarn add decimal-eval
2929

3030
### Usage
3131
Supports the four arithmetic operations (`+`, `-`, `*`, `/`),
32-
and automatically deal with JavaScript decimal precision by [big.js](https://github.com/MikeMcl/big.js), and supports big number.
32+
and automatically deal with JavaScript decimal precision by [bignumber.js](https://github.com/MikeMcl/bignumber.js), and supports big number.
3333

3434
```js
3535
import {evaluate} from 'decimal-eval';
@@ -113,7 +113,7 @@ Install an operator which created by the `Parser.createBinaryOperator()` or `Par
113113

114114
#### Parser.useAdapter(adapter)
115115
Set custom calculation adapter methods for four arithmetic (`+`, `-`, `*`, `/`).
116-
[Big.js](https://github.com/MikeMcl/big.js) is used by default.
116+
[bignumber.js](https://github.com/MikeMcl/bignumber.js) is used by default.
117117

118118
```js
119119
Parser.useAdapter({
@@ -129,7 +129,7 @@ Parser.useAdapter({
129129

130130
### Use pure package (no dependencies)
131131
When using a custom method to deal with the decimal precision problem, you can use a pure package, which can reduce the size by about 60%.
132-
It doesn't include `big.js`.
132+
It doesn't include `bignumber.js`.
133133

134134
```js
135135
import {evaluate, Parser} from 'decimal-eval/dist/pure';
@@ -144,12 +144,12 @@ evaluate('0.1 + 0.2'); // '0.30000000000000004'
144144
evaluate('9007199254740992 + 1'); // '9007199254740992'
145145
```
146146

147-
### Re-export `big.js`
148-
Useful for deal JavaScript decimal precision problem without having to install [big.js](https://github.com/MikeMcl/big.js) again.
147+
### Re-export `bignumber.js`
148+
Useful for deal JavaScript decimal precision problem without having to install [bignumber.js](https://github.com/MikeMcl/bignumber.js) again.
149149

150150
```js
151-
import {Big} from 'decimal-eval';
152-
const val = new Big(0.1).plus(0.2);
151+
import {BigNumber} from 'decimal-eval';
152+
const val = new BigNumber(0.1).plus(0.2);
153153
console.log(String(val)); // '0.3'
154154
```
155155

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"build": "rollup -c",
1212
"test": "jest",
1313
"dts": "node scripts/dts.js",
14+
"size": "node scripts/size.js",
1415
"lint": "eslint {src,test}/**/*.ts --fix"
1516
},
1617
"keywords": [
@@ -103,6 +104,7 @@
103104
"del": "^6.0.0",
104105
"eslint": "^7.26.0",
105106
"eslint-config-alloy": "^4.1.0",
107+
"gzip-size": "^6.0.0",
106108
"husky": "^4.3.8",
107109
"jest": "^26.6.3",
108110
"lint-staged": "^10.5.4",

scripts/size.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const {execSync} = require('child_process');
4+
const gzipSize = require('gzip-size');
5+
6+
const distRoot = path.join(__dirname, '../dist');
7+
8+
const files = {
9+
'index.min.js': {
10+
size: null,
11+
gzipSize: null,
12+
},
13+
'pure.min.js': {
14+
size: null,
15+
gzipSize: null,
16+
}
17+
};
18+
19+
execSync('npm run build', {
20+
cwd: path.join(__dirname, '..'),
21+
stdio: 'inherit'
22+
});
23+
24+
Object.keys(files).forEach(name => {
25+
const filename = path.join(distRoot, name);
26+
files[name] = {
27+
size: fs.statSync(filename).size,
28+
gzipSize: gzipSize.fileSync(filename)
29+
};
30+
});
31+
32+
function getBundleSize(name, isGZIP = false) {
33+
const target = files[name];
34+
let size = isGZIP ? target.gzipSize : target.size;
35+
return (size / 1024).toFixed(1);
36+
}
37+
38+
console.log(`
39+
===================== BUNDLE SIZE =====================
40+
index min: ${getBundleSize('index.min.js')} KB gzip: ${getBundleSize('index.min.js', true)} KB
41+
pure min: ${getBundleSize('pure.min.js')} KB gzip: ${getBundleSize('pure.min.js', true)} KB
42+
`);

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,6 +2363,11 @@ domexception@^2.0.1:
23632363
dependencies:
23642364
webidl-conversions "^5.0.0"
23652365

2366+
duplexer@^0.1.2:
2367+
version "0.1.2"
2368+
resolved "https://registry.nlark.com/duplexer/download/duplexer-0.1.2.tgz#3abe43aef3835f8ae077d136ddce0f276b0400e6"
2369+
integrity sha1-Or5DrvODX4rgd9E23c4PJ2sEAOY=
2370+
23662371
ecc-jsbn@~0.1.1:
23672372
version "0.1.2"
23682373
resolved "https://registry.npm.taobao.org/ecc-jsbn/download/ecc-jsbn-0.1.2.tgz#3a83a904e54353287874c564b7549386849a98c9"
@@ -2945,6 +2950,13 @@ growly@^1.3.0:
29452950
resolved "https://registry.npm.taobao.org/growly/download/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
29462951
integrity sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=
29472952

2953+
gzip-size@^6.0.0:
2954+
version "6.0.0"
2955+
resolved "https://registry.npm.taobao.org/gzip-size/download/gzip-size-6.0.0.tgz#065367fd50c239c0671cbcbad5be3e2eeb10e462"
2956+
integrity sha1-BlNn/VDCOcBnHLy61b4+LusQ5GI=
2957+
dependencies:
2958+
duplexer "^0.1.2"
2959+
29482960
har-schema@^2.0.0:
29492961
version "2.0.0"
29502962
resolved "https://registry.nlark.com/har-schema/download/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92"

0 commit comments

Comments
 (0)