smart-unit 1.0.2 → 1.0.3

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
@@ -102,7 +102,7 @@ Creates a unit converter instance.
102
102
  Formats a number to the optimal unit string.
103
103
 
104
104
  ```ts
105
- const size = new SmartUnit(['B', 'KB', 1024, 'MB'], { fractionDigits: 2 });
105
+ const size = new SmartUnit(['B', 'KB', 'MB'], { baseDigit: 1024, fractionDigits: 2 });
106
106
 
107
107
  size.format(1536); // => "1.5KB"
108
108
  size.format(1536, 0); // => "2KB"
@@ -114,7 +114,7 @@ size.format(1536, '1-3'); // => "1.5KB" (min 1, max 3 decimals)
114
114
  Parses a unit string back to base unit value.
115
115
 
116
116
  ```ts
117
- const size = new SmartUnit(['B', 'KB', 1024, 'MB']);
117
+ const size = new SmartUnit(['B', 'KB', 'MB'], { baseDigit: 1024 });
118
118
 
119
119
  size.parse('1.5KB'); // => 1536
120
120
  size.parse('2MB'); // => 2097152
@@ -125,7 +125,7 @@ size.parse('2MB'); // => 2097152
125
125
  Gets the optimal unit and converted value without formatting.
126
126
 
127
127
  ```ts
128
- const size = new SmartUnit(['B', 'KB', 1024, 'MB']);
128
+ const size = new SmartUnit(['B', 'KB', 'MB'], { baseDigit: 1024 });
129
129
 
130
130
  size.getUnit(1536);
131
131
  // => { num: 1.5, unit: 'KB' }
@@ -152,7 +152,7 @@ length.toBase(100, 'cm'); // => 1000 (mm)
152
152
  Extracts numeric value and unit from a formatted string.
153
153
 
154
154
  ```ts
155
- const size = new SmartUnit(['B', 'KB', 1024, 'MB']);
155
+ const size = new SmartUnit(['B', 'KB', 'MB'], { baseDigit: 1024 });
156
156
 
157
157
  size.splitUnit('1.5KB'); // => { num: 1.5, unit: 'KB' }
158
158
  ```
@@ -188,7 +188,7 @@ const freq = new SmartUnit(['Hz', 'kHz', 'MHz', 'GHz'], {
188
188
  fractionDigits: 2,
189
189
  });
190
190
 
191
- freq.format(2400000000); // => "2.4GHz"
191
+ freq.format(2400000000); // => "2.40GHz"
192
192
  ```
193
193
 
194
194
  ### Financial Amounts (High Precision)
package/README.zh-CN.md CHANGED
@@ -102,7 +102,7 @@ time.parse('2.5h'); // => 9000000 (ms)
102
102
  将数字格式化为最优单位字符串。
103
103
 
104
104
  ```ts
105
- const size = new SmartUnit(['B', 'KB', 1024, 'MB'], { fractionDigits: 2 });
105
+ const size = new SmartUnit(['B', 'KB', 'MB'], { baseDigit: 1024, fractionDigits: 2 });
106
106
 
107
107
  size.format(1536); // => "1.5KB"
108
108
  size.format(1536, 0); // => "2KB"
@@ -114,7 +114,7 @@ size.format(1536, '1-3'); // => "1.5KB"(最少1位,最多3位小数)
114
114
  将单位字符串解析回基本单位值。
115
115
 
116
116
  ```ts
117
- const size = new SmartUnit(['B', 'KB', 1024, 'MB']);
117
+ const size = new SmartUnit(['B', 'KB', 'MB'], { baseDigit: 1024 });
118
118
 
119
119
  size.parse('1.5KB'); // => 1536
120
120
  size.parse('2MB'); // => 2097152
@@ -125,7 +125,7 @@ size.parse('2MB'); // => 2097152
125
125
  获取最优单位和转换后的值(不进行格式化)。
126
126
 
127
127
  ```ts
128
- const size = new SmartUnit(['B', 'KB', 1024, 'MB']);
128
+ const size = new SmartUnit(['B', 'KB', 'MB'], { baseDigit: 1024 });
129
129
 
130
130
  size.getUnit(1536);
131
131
  // => { num: 1.5, unit: 'KB' }
@@ -152,7 +152,7 @@ length.toBase(100, 'cm'); // => 1000 (mm)
152
152
  从格式化字符串中提取数值和单位。
153
153
 
154
154
  ```ts
155
- const size = new SmartUnit(['B', 'KB', 1024, 'MB']);
155
+ const size = new SmartUnit(['B', 'KB', 'MB'], { baseDigit: 1024 });
156
156
 
157
157
  size.splitUnit('1.5KB'); // => { num: 1.5, unit: 'KB' }
158
158
  ```
@@ -188,7 +188,7 @@ const freq = new SmartUnit(['Hz', 'kHz', 'MHz', 'GHz'], {
188
188
  fractionDigits: 2,
189
189
  });
190
190
 
191
- freq.format(2400000000); // => "2.4GHz"
191
+ freq.format(2400000000); // => "2.40GHz"
192
192
  ```
193
193
 
194
194
  ### 金融金额(高精度)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-unit",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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",