smart-unit 1.0.3 → 1.0.4
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 +21 -1
- package/README.zh-CN.md +21 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/smart-unit)
|
|
6
6
|
[](https://www.npmjs.com/package/smart-unit)
|
|
7
7
|
[](https://bundlephobia.com/package/smart-unit)
|
|
8
|
+
[](https://github.com/flycran/smart-unit/actions)
|
|
8
9
|
[](./LICENSE)
|
|
9
10
|
|
|
10
11
|
English | [中文](./README.zh-CN.md)
|
|
@@ -13,6 +14,16 @@ English | [中文](./README.zh-CN.md)
|
|
|
13
14
|
|
|
14
15
|
**smart-unit** is a lightweight utility for automatic unit conversion with intelligent formatting.
|
|
15
16
|
|
|
17
|
+
```ts
|
|
18
|
+
import SmartUnit from 'smart-unit';
|
|
19
|
+
|
|
20
|
+
const size = new SmartUnit(['B', 'KB', 'MB', 'GB'], { baseDigit: 1024 });
|
|
21
|
+
|
|
22
|
+
size.format(1024 * 1024 * 100); // "100MB"
|
|
23
|
+
size.format(1536); // "1.5KB"
|
|
24
|
+
size.parse('2.5GB'); // 2684354560
|
|
25
|
+
```
|
|
26
|
+
|
|
16
27
|
## Features
|
|
17
28
|
|
|
18
29
|
- 🎯 **Smart Formatting** — Automatically selects the optimal unit for display
|
|
@@ -21,6 +32,7 @@ English | [中文](./README.zh-CN.md)
|
|
|
21
32
|
- 🧮 **High Precision** — Optional `decimal.js` integration for arbitrary precision
|
|
22
33
|
- 📦 **TypeScript First** — Full type safety
|
|
23
34
|
- 🪶 **Lightweight** — Core functionality with minimal footprint
|
|
35
|
+
- ✅ **Well Tested** — Comprehensive test suite with 100% coverage
|
|
24
36
|
|
|
25
37
|
## Install
|
|
26
38
|
|
|
@@ -104,7 +116,7 @@ Formats a number to the optimal unit string.
|
|
|
104
116
|
```ts
|
|
105
117
|
const size = new SmartUnit(['B', 'KB', 'MB'], { baseDigit: 1024, fractionDigits: 2 });
|
|
106
118
|
|
|
107
|
-
size.format(1536); // => "1.
|
|
119
|
+
size.format(1536); // => "1.50KB"
|
|
108
120
|
size.format(1536, 0); // => "2KB"
|
|
109
121
|
size.format(1536, '1-3'); // => "1.5KB" (min 1, max 3 decimals)
|
|
110
122
|
```
|
|
@@ -203,6 +215,14 @@ const currency = new SmartUnit(['', 'K', 'M', 'B', 'T'], {
|
|
|
203
215
|
currency.format('12345678901234567890'); // => "12345678.90T"
|
|
204
216
|
```
|
|
205
217
|
|
|
218
|
+
## Testing
|
|
219
|
+
|
|
220
|
+
Run the test suite:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
npm test
|
|
224
|
+
```
|
|
225
|
+
|
|
206
226
|
## TypeScript
|
|
207
227
|
|
|
208
228
|
smart-unit is written in TypeScript and provides full type safety.
|
package/README.zh-CN.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/smart-unit)
|
|
6
6
|
[](https://www.npmjs.com/package/smart-unit)
|
|
7
7
|
[](https://bundlephobia.com/package/smart-unit)
|
|
8
|
+
[](https://github.com/flycran/smart-unit/actions)
|
|
8
9
|
[](./LICENSE)
|
|
9
10
|
|
|
10
11
|
[English](./README.md) | 中文
|
|
@@ -13,6 +14,16 @@
|
|
|
13
14
|
|
|
14
15
|
**smart-unit** 是一个轻量级的自动单位转换工具,支持智能格式化输出。
|
|
15
16
|
|
|
17
|
+
```ts
|
|
18
|
+
import SmartUnit from 'smart-unit';
|
|
19
|
+
|
|
20
|
+
const size = new SmartUnit(['B', 'KB', 'MB', 'GB'], { baseDigit: 1024 });
|
|
21
|
+
|
|
22
|
+
size.format(1024 * 1024 * 100); // "100MB"
|
|
23
|
+
size.format(1536); // "1.5KB"
|
|
24
|
+
size.parse('2.5GB'); // 2684354560
|
|
25
|
+
```
|
|
26
|
+
|
|
16
27
|
## 特性
|
|
17
28
|
|
|
18
29
|
- 🎯 **智能格式化** — 自动选择最优单位进行展示
|
|
@@ -21,6 +32,7 @@
|
|
|
21
32
|
- 🧮 **高精度** — 可选 `decimal.js` 集成,支持任意精度计算
|
|
22
33
|
- 📦 **TypeScript 优先** — 完整的类型安全
|
|
23
34
|
- 🪶 **轻量级** — 核心功能,体积小巧
|
|
35
|
+
- ✅ **测试完善** — 全面的测试套件,100% 覆盖率
|
|
24
36
|
|
|
25
37
|
## 安装
|
|
26
38
|
|
|
@@ -104,7 +116,7 @@ time.parse('2.5h'); // => 9000000 (ms)
|
|
|
104
116
|
```ts
|
|
105
117
|
const size = new SmartUnit(['B', 'KB', 'MB'], { baseDigit: 1024, fractionDigits: 2 });
|
|
106
118
|
|
|
107
|
-
size.format(1536); // => "1.
|
|
119
|
+
size.format(1536); // => "1.50KB"
|
|
108
120
|
size.format(1536, 0); // => "2KB"
|
|
109
121
|
size.format(1536, '1-3'); // => "1.5KB"(最少1位,最多3位小数)
|
|
110
122
|
```
|
|
@@ -203,6 +215,14 @@ const currency = new SmartUnit(['', 'K', 'M', 'B', 'T'], {
|
|
|
203
215
|
currency.format('12345678901234567890'); // => "12345678.90T"
|
|
204
216
|
```
|
|
205
217
|
|
|
218
|
+
## 测试
|
|
219
|
+
|
|
220
|
+
运行测试套件:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
npm test
|
|
224
|
+
```
|
|
225
|
+
|
|
206
226
|
## TypeScript
|
|
207
227
|
|
|
208
228
|
smart-unit 使用 TypeScript 编写,提供完整的类型安全。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smart-unit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Elegant unit conversion utility with automatic unit selection and high-precision support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -59,4 +59,4 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"decimal.js": "^10.5.0"
|
|
61
61
|
}
|
|
62
|
-
}
|
|
62
|
+
}
|