@wener/common 2.0.5 → 2.0.6

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.
Files changed (206) hide show
  1. package/lib/ai/qwen3vl/index.js +1 -1
  2. package/lib/ai/qwen3vl/utils.js +15 -15
  3. package/lib/ai/vision/DocLayoutElementTypeSchema.js +22 -22
  4. package/lib/ai/vision/ImageAnnotationSchema.js +63 -47
  5. package/lib/ai/vision/index.js +2 -2
  6. package/lib/ai/vision/resolveImageAnnotation.js +81 -95
  7. package/lib/cn/ChineseResidentIdNo.js +55 -41
  8. package/lib/cn/ChineseResidentIdNo.mod.js +6 -1
  9. package/lib/cn/ChineseResidentIdNo.test.js +22 -21
  10. package/lib/cn/DivisionCode.js +220 -235
  11. package/lib/cn/DivisionCode.mod.js +6 -1
  12. package/lib/cn/DivisionCode.test.js +92 -121
  13. package/lib/cn/Mod11.js +18 -37
  14. package/lib/cn/Mod31.js +23 -41
  15. package/lib/cn/UnifiedSocialCreditCode.js +143 -137
  16. package/lib/cn/UnifiedSocialCreditCode.mod.js +6 -1
  17. package/lib/cn/UnifiedSocialCreditCode.test.js +21 -15
  18. package/lib/cn/formatChineseAmount.js +46 -71
  19. package/lib/cn/index.js +6 -6
  20. package/lib/cn/mod.js +5 -3
  21. package/lib/cn/parseChineseNumber.js +81 -85
  22. package/lib/cn/parseChineseNumber.test.js +183 -261
  23. package/lib/cn/pinyin/cartesianProduct.js +19 -19
  24. package/lib/cn/pinyin/cartesianProduct.test.js +78 -178
  25. package/lib/cn/pinyin/loader.js +13 -11
  26. package/lib/cn/pinyin/preload.js +2 -1
  27. package/lib/cn/pinyin/toPinyin.test.js +149 -161
  28. package/lib/cn/pinyin/toPinyinPure.js +28 -23
  29. package/lib/cn/pinyin/transform.js +11 -11
  30. package/lib/cn/types.d.js +2 -2
  31. package/lib/consola/createStandardConsolaReporter.js +14 -15
  32. package/lib/consola/formatLogObject.js +149 -133
  33. package/lib/consola/formatLogObject.test.js +167 -178
  34. package/lib/consola/index.js +2 -2
  35. package/lib/data/formatSort.js +14 -12
  36. package/lib/data/formatSort.test.js +33 -33
  37. package/lib/data/index.js +3 -3
  38. package/lib/data/maybeNumber.js +23 -23
  39. package/lib/data/parseSort.js +75 -68
  40. package/lib/data/parseSort.test.js +196 -187
  41. package/lib/data/resolvePagination.js +38 -39
  42. package/lib/data/resolvePagination.test.js +228 -218
  43. package/lib/data/types.d.js +2 -2
  44. package/lib/dayjs/dayjs.js +20 -20
  45. package/lib/dayjs/formatDuration.js +56 -56
  46. package/lib/dayjs/formatDuration.test.js +63 -77
  47. package/lib/dayjs/index.js +4 -4
  48. package/lib/dayjs/parseDuration.js +21 -26
  49. package/lib/dayjs/parseRelativeTime.js +65 -66
  50. package/lib/dayjs/parseRelativeTime.test.js +227 -243
  51. package/lib/dayjs/resolveRelativeTime.js +73 -72
  52. package/lib/dayjs/resolveRelativeTime.test.js +296 -307
  53. package/lib/decimal/index.js +1 -1
  54. package/lib/decimal/parseDecimal.js +12 -12
  55. package/lib/drain3/Drain.js +303 -338
  56. package/lib/drain3/LogCluster.js +25 -25
  57. package/lib/drain3/Node.js +24 -24
  58. package/lib/drain3/TemplateMiner.js +197 -196
  59. package/lib/drain3/index.js +5 -5
  60. package/lib/drain3/persistence/FilePersistence.js +19 -19
  61. package/lib/drain3/persistence/MemoryPersistence.js +8 -8
  62. package/lib/drain3/persistence/PersistenceHandler.js +2 -2
  63. package/lib/drain3/types.js +2 -2
  64. package/lib/emittery/emitter.js +7 -7
  65. package/lib/emittery/index.js +1 -1
  66. package/lib/foundation/schema/SexType.js +15 -12
  67. package/lib/foundation/schema/index.js +1 -1
  68. package/lib/foundation/schema/parseSexType.js +15 -16
  69. package/lib/foundation/schema/types.js +8 -6
  70. package/lib/fs/FileSystemError.js +18 -18
  71. package/lib/fs/IFileSystem.d.js +2 -2
  72. package/lib/fs/MemoryFileSystem.test.js +172 -181
  73. package/lib/fs/createBrowserFileSystem.js +222 -235
  74. package/lib/fs/createMemoryFileSystem.js +472 -510
  75. package/lib/fs/createSandboxFileSystem.js +102 -101
  76. package/lib/fs/createWebDavFileSystem.js +162 -149
  77. package/lib/fs/createWebFileSystem.js +197 -220
  78. package/lib/fs/findMimeType.js +14 -14
  79. package/lib/fs/index.js +7 -7
  80. package/lib/fs/minio/createMinioFileSystem.js +959 -956
  81. package/lib/fs/minio/index.js +1 -1
  82. package/lib/fs/orpc/FileSystemContract.js +57 -57
  83. package/lib/fs/orpc/createContractClientFileSystem.js +88 -88
  84. package/lib/fs/orpc/index.js +2 -2
  85. package/lib/fs/orpc/server/createFileSystemContractImpl.js +62 -60
  86. package/lib/fs/orpc/server/index.js +1 -1
  87. package/lib/fs/s3/createS3MiniFileSystem.js +756 -737
  88. package/lib/fs/s3/index.js +1 -1
  89. package/lib/fs/s3/s3mini.test.js +524 -553
  90. package/lib/fs/scandir.js +56 -56
  91. package/lib/fs/server/createDatabaseFileSystem.js +834 -741
  92. package/lib/fs/server/createNodeFileSystem.js +407 -405
  93. package/lib/fs/server/dbfs.test.js +201 -214
  94. package/lib/fs/server/index.js +1 -1
  95. package/lib/fs/server/loadTestDatabase.js +40 -43
  96. package/lib/fs/tests/runFileSystemTest.js +352 -316
  97. package/lib/fs/types.js +17 -20
  98. package/lib/fs/utils/getFileUrl.js +24 -30
  99. package/lib/fs/utils.js +17 -17
  100. package/lib/fs/webdav/index.js +1 -1
  101. package/lib/index.js +2 -2
  102. package/lib/jsonschema/JsonSchema.js +216 -155
  103. package/lib/jsonschema/JsonSchema.test.js +123 -124
  104. package/lib/jsonschema/forEachJsonSchema.js +41 -41
  105. package/lib/jsonschema/index.js +2 -2
  106. package/lib/jsonschema/types.d.js +2 -2
  107. package/lib/meta/defineFileType.js +32 -38
  108. package/lib/meta/defineInit.js +39 -35
  109. package/lib/meta/defineMetadata.js +37 -34
  110. package/lib/meta/defineMetadata.test.js +13 -12
  111. package/lib/meta/index.js +3 -3
  112. package/lib/orpc/createOpenApiContractClient.js +26 -24
  113. package/lib/orpc/createRpcContractClient.js +37 -31
  114. package/lib/orpc/index.js +2 -2
  115. package/lib/orpc/resolveLinkPlugins.js +25 -25
  116. package/lib/password/PHC.js +187 -189
  117. package/lib/password/PHC.test.js +517 -535
  118. package/lib/password/Password.js +85 -80
  119. package/lib/password/Password.test.js +330 -364
  120. package/lib/password/createArgon2PasswordAlgorithm.js +50 -51
  121. package/lib/password/createBase64PasswordAlgorithm.js +11 -11
  122. package/lib/password/createBcryptPasswordAlgorithm.js +20 -18
  123. package/lib/password/createPBKDF2PasswordAlgorithm.js +65 -52
  124. package/lib/password/createScryptPasswordAlgorithm.js +74 -63
  125. package/lib/password/index.js +5 -5
  126. package/lib/password/server/index.js +1 -1
  127. package/lib/resource/Identifiable.js +2 -2
  128. package/lib/resource/ListQuery.js +42 -42
  129. package/lib/resource/getTitleOfResource.js +5 -5
  130. package/lib/resource/index.js +2 -2
  131. package/lib/resource/schema/AnyResourceSchema.js +91 -89
  132. package/lib/resource/schema/BaseResourceSchema.js +26 -26
  133. package/lib/resource/schema/ResourceActionType.js +117 -115
  134. package/lib/resource/schema/ResourceStatus.js +94 -92
  135. package/lib/resource/schema/ResourceType.js +25 -23
  136. package/lib/resource/schema/index.js +5 -5
  137. package/lib/resource/schema/types.js +86 -55
  138. package/lib/resource/schema/types.test.js +16 -13
  139. package/lib/s3/formatS3Url.js +60 -60
  140. package/lib/s3/formatS3Url.test.js +238 -261
  141. package/lib/s3/index.js +2 -2
  142. package/lib/s3/parseS3Url.js +61 -60
  143. package/lib/s3/parseS3Url.test.js +270 -269
  144. package/lib/schema/SchemaRegistry.js +41 -42
  145. package/lib/schema/SchemaRegistry.mod.js +1 -1
  146. package/lib/schema/TypeSchema.d.js +2 -2
  147. package/lib/schema/createSchemaData.js +113 -67
  148. package/lib/schema/findJsonSchemaByPath.js +28 -23
  149. package/lib/schema/formatZodError.js +112 -131
  150. package/lib/schema/formatZodError.test.js +192 -195
  151. package/lib/schema/getSchemaCache.js +7 -7
  152. package/lib/schema/getSchemaOptions.js +17 -16
  153. package/lib/schema/index.js +6 -6
  154. package/lib/schema/toJsonSchema.js +195 -189
  155. package/lib/schema/toJsonSchema.test.js +34 -26
  156. package/lib/schema/validate.js +105 -96
  157. package/lib/tools/generateSchema.js +40 -40
  158. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +74 -74
  159. package/lib/utils/buildBaseUrl.js +8 -8
  160. package/lib/utils/buildRedactorFormSchema.js +54 -53
  161. package/lib/utils/getEstimateProcessTime.js +24 -19
  162. package/lib/utils/index.js +3 -3
  163. package/lib/utils/resolveFeatureOptions.js +9 -9
  164. package/package.json +14 -14
  165. package/src/ai/vision/index.ts +2 -2
  166. package/src/cn/index.ts +1 -2
  167. package/src/consola/index.ts +1 -1
  168. package/src/data/index.ts +3 -4
  169. package/src/data/resolvePagination.ts +2 -2
  170. package/src/dayjs/formatDuration.ts +8 -9
  171. package/src/dayjs/index.ts +1 -1
  172. package/src/dayjs/parseRelativeTime.ts +1 -1
  173. package/src/dayjs/resolveRelativeTime.ts +1 -1
  174. package/src/drain3/Drain.test.ts +2 -2
  175. package/src/drain3/index.ts +2 -4
  176. package/src/fs/createWebDavFileSystem.ts +2 -7
  177. package/src/fs/createWebFileSystem.ts +1 -1
  178. package/src/fs/index.ts +4 -4
  179. package/src/fs/minio/createMinioFileSystem.ts +2 -2
  180. package/src/fs/minio/index.ts +1 -1
  181. package/src/fs/s3/createS3MiniFileSystem.ts +1 -1
  182. package/src/fs/server/createDatabaseFileSystem.ts +84 -120
  183. package/src/fs/server/dbfs.test.ts +14 -10
  184. package/src/fs/server/index.ts +1 -0
  185. package/src/fs/server/loadTestDatabase.ts +8 -119
  186. package/src/jsonschema/index.ts +1 -1
  187. package/src/meta/index.ts +2 -3
  188. package/src/orm/createSqliteDialect.ts +17 -0
  189. package/src/orm/index.ts +1 -0
  190. package/src/orpc/createOpenApiContractClient.ts +1 -1
  191. package/src/orpc/index.ts +1 -1
  192. package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
  193. package/src/password/index.ts +2 -2
  194. package/src/resource/index.ts +3 -3
  195. package/src/resource/schema/index.ts +4 -4
  196. package/src/s3/index.ts +1 -1
  197. package/src/schema/SchemaRegistry.ts +1 -1
  198. package/src/schema/createSchemaData.ts +1 -1
  199. package/src/schema/findJsonSchemaByPath.ts +1 -1
  200. package/src/schema/index.ts +5 -5
  201. package/src/schema/validate.ts +1 -1
  202. package/src/utils/buildRedactorFormSchema.ts +1 -1
  203. package/src/utils/formatNumber.ts +18 -0
  204. package/src/utils/formatPercent.ts +17 -0
  205. package/src/utils/index.ts +3 -3
  206. package/src/utils/resolveFeatureOptions.ts +1 -1
@@ -1,16 +1,22 @@
1
- import { describe, expect, it } from "vitest";
2
- import { UnifiedSocialCreditCode } from "./index.js";
3
- describe("UnifiedSocialCreditCode", function () {
4
- it("should parse", function () {
5
- for (var _i = 0, _iter = [
6
- //
7
- "91330106673959654P",
8
- "91330106MA2CFLDG4R"
9
- ]; _i < _iter.length; _i++) {
10
- var a = _iter[_i];
11
- var out = UnifiedSocialCreditCode.parse(a);
12
- expect(UnifiedSocialCreditCode.format(out)).toBe(a);
13
- expect(out).toMatchSnapshot();
14
- }
15
- });
1
+ import { describe, expect, it } from 'vitest';
2
+ import { UnifiedSocialCreditCode } from './index.js';
3
+
4
+ describe('UnifiedSocialCreditCode', () => {
5
+ it('should parse', () => {
6
+ for (
7
+ var _i = 0,
8
+ _iter = [
9
+ //
10
+ '91330106673959654P',
11
+ '91330106MA2CFLDG4R',
12
+ ];
13
+ _i < _iter.length;
14
+ _i++
15
+ ) {
16
+ var a = _iter[_i];
17
+ var out = UnifiedSocialCreditCode.parse(a);
18
+ expect(UnifiedSocialCreditCode.format(out)).toBe(a);
19
+ expect(out).toMatchSnapshot();
20
+ }
21
+ });
16
22
  });
@@ -2,76 +2,51 @@
2
2
  * @see https://gist.github.com/tonyc726/00c829a54a40cf80409f
3
3
  * @see https://github.com/Siykt/javascript-algorithms/blob/master/src/algorithms/string/getChinesePrice.ts 人民币金额转中文大写
4
4
  */ export function formatChineseAmount(price) {
5
- if (price === 0) return '零元整';
6
- if (price >= 1e12) return '整数位已超过最大值';
7
- const CHINESE_NUMBER_MAP = [
8
- '',
9
- '',
10
- '',
11
- '叁',
12
- '',
13
- '伍',
14
- '陆',
15
- '',
16
- '捌',
17
- '玖'
18
- ];
19
- const CHINESE_UNIT_MAP = [
20
- '',
21
- '拾',
22
- '佰',
23
- '仟'
24
- ];
25
- const CHINESE_BIG_UNIT_MAP = [
26
- '',
27
- '万',
28
- '亿'
29
- ];
30
- const CHINESE_SMALL_UNIT_MAP = [
31
- '角',
32
- '分',
33
- '厘',
34
- '毫'
35
- ];
36
- const priceStr = price.toString();
37
- const priceArr = priceStr.split('.');
38
- const integer = priceArr[0];
39
- const decimal = priceArr[1];
40
- let chineseIntegerPrice = '';
41
- let zeroCount = 0;
42
- for(let i = 0; i < integer.length; i++){
43
- const num = +integer[i];
44
- const unit = integer.length - i - 1; // 当前数字的单位
45
- const quotient = Math.floor(unit / 4); // 1w为进位单位, 除 4 即为 万 亿
46
- const remainder = unit % 4; // 1w为进位单位, 取模 4 即为 个 十 百 千
47
- if (num === 0) {
48
- zeroCount++;
49
- } else {
50
- // 处理前置的零
51
- if (zeroCount > 0) chineseIntegerPrice += CHINESE_NUMBER_MAP[0];
52
- zeroCount = 0;
53
- chineseIntegerPrice += CHINESE_NUMBER_MAP[num] + CHINESE_UNIT_MAP[remainder];
54
- }
55
- if (remainder === 0 && zeroCount < 4) {
56
- chineseIntegerPrice += CHINESE_BIG_UNIT_MAP[quotient];
57
- }
58
- }
59
- // 价格为小数时,整数部分不显示
60
- if (price < 1) chineseIntegerPrice = '';
61
- else chineseIntegerPrice += '元';
62
- let chineseDecimalPrice = '';
63
- if (!decimal) {
64
- chineseDecimalPrice = '整';
65
- } else {
66
- let hasZero = false;
67
- for(let i = 0; i < decimal.length; i++){
68
- const num = +decimal[i];
69
- if (num) chineseDecimalPrice += CHINESE_NUMBER_MAP[num] + CHINESE_SMALL_UNIT_MAP[i];
70
- else hasZero = true;
71
- }
72
- if (chineseIntegerPrice && hasZero) chineseIntegerPrice += '零';
73
- }
74
- return chineseIntegerPrice + chineseDecimalPrice;
5
+ if (price === 0) return '零元整';
6
+ if (price >= 1e12) return '整数位已超过最大值';
7
+ const CHINESE_NUMBER_MAP = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
8
+ const CHINESE_UNIT_MAP = ['', '拾', '佰', '仟'];
9
+ const CHINESE_BIG_UNIT_MAP = ['', '万', '亿'];
10
+ const CHINESE_SMALL_UNIT_MAP = ['', '分', '厘', '毫'];
11
+ const priceStr = price.toString();
12
+ const priceArr = priceStr.split('.');
13
+ const integer = priceArr[0];
14
+ const decimal = priceArr[1];
15
+ let chineseIntegerPrice = '';
16
+ let zeroCount = 0;
17
+ for (let i = 0; i < integer.length; i++) {
18
+ const num = +integer[i];
19
+ const unit = integer.length - i - 1; // 当前数字的单位
20
+ const quotient = Math.floor(unit / 4); // 1w为进位单位, 除 4 即为 万 亿
21
+ const remainder = unit % 4; // 1w为进位单位, 取模 4 即为 个 十 百 千
22
+ if (num === 0) {
23
+ zeroCount++;
24
+ } else {
25
+ // 处理前置的零
26
+ if (zeroCount > 0) chineseIntegerPrice += CHINESE_NUMBER_MAP[0];
27
+ zeroCount = 0;
28
+ chineseIntegerPrice += CHINESE_NUMBER_MAP[num] + CHINESE_UNIT_MAP[remainder];
29
+ }
30
+ if (remainder === 0 && zeroCount < 4) {
31
+ chineseIntegerPrice += CHINESE_BIG_UNIT_MAP[quotient];
32
+ }
33
+ }
34
+ // 价格为小数时,整数部分不显示
35
+ if (price < 1) chineseIntegerPrice = '';
36
+ else chineseIntegerPrice += '元';
37
+ let chineseDecimalPrice = '';
38
+ if (!decimal) {
39
+ chineseDecimalPrice = '整';
40
+ } else {
41
+ let hasZero = false;
42
+ for (let i = 0; i < decimal.length; i++) {
43
+ const num = +decimal[i];
44
+ if (num) chineseDecimalPrice += CHINESE_NUMBER_MAP[num] + CHINESE_SMALL_UNIT_MAP[i];
45
+ else hasZero = true;
46
+ }
47
+ if (chineseIntegerPrice && hasZero) chineseIntegerPrice += '零';
48
+ }
49
+ return chineseIntegerPrice + chineseDecimalPrice;
75
50
  }
76
51
 
77
- //# sourceMappingURL=formatChineseAmount.js.map
52
+ //# sourceMappingURL=formatChineseAmount.js.map
package/lib/cn/index.js CHANGED
@@ -1,7 +1,7 @@
1
- export { ChineseResidentIdNo } from "./ChineseResidentIdNo.js";
2
- export { UnifiedSocialCreditCode } from "./UnifiedSocialCreditCode.js";
3
- export { DivisionCode } from "./DivisionCode.js";
4
- export * from "./formatChineseAmount.js";
5
- export * from "./parseChineseNumber.js";
6
- export * from "./pinyin/toPinyinPure.js";
1
+ export { ChineseResidentIdNo } from './ChineseResidentIdNo.js';
2
+ export { DivisionCode } from './DivisionCode.js';
3
+ export * from './formatChineseAmount.js';
4
+ export * from './parseChineseNumber.js';
5
+ export * from './pinyin/toPinyinPure.js';
6
+ export { UnifiedSocialCreditCode } from './UnifiedSocialCreditCode.js';
7
7
  //# sourceMappingURL=index.js.map
package/lib/cn/mod.js CHANGED
@@ -1,6 +1,8 @@
1
- import * as _ChineseResidentIdNo from "./ChineseResidentIdNo.mod.js";
1
+ import * as _ChineseResidentIdNo from './ChineseResidentIdNo.mod.js';
2
2
  export { _ChineseResidentIdNo as ChineseResidentIdNo };
3
- import * as _UnifiedSocialCreditCode from "./UnifiedSocialCreditCode.mod.js";
3
+
4
+ import * as _UnifiedSocialCreditCode from './UnifiedSocialCreditCode.mod.js';
4
5
  export { _UnifiedSocialCreditCode as UnifiedSocialCreditCode };
5
- import * as _DivisionCode from "./DivisionCode.mod.js";
6
+
7
+ import * as _DivisionCode from './DivisionCode.mod.js';
6
8
  export { _DivisionCode as DivisionCode };
@@ -1,94 +1,90 @@
1
1
  const ToNumber = {
2
- 〇: 0,
3
- 一: 1,
4
- 二: 2,
5
- 三: 3,
6
- 四: 4,
7
- 五: 5,
8
- 六: 6,
9
- 七: 7,
10
- 八: 8,
11
- 九: 9,
12
- 十: 10,
13
- 百: 100,
14
- 千: 1000,
15
- 万: 10000,
16
- 零: 0,
17
- 壹: 1,
18
- 贰: 2,
19
- 叁: 3,
20
- 肆: 4,
21
- 伍: 5,
22
- 陆: 6,
23
- 柒: 7,
24
- 捌: 8,
25
- 玖: 9,
26
- 拾: 10,
27
- 佰: 100,
28
- 仟: 1000,
29
- 0: 0,
30
- 1: 1,
31
- 2: 2,
32
- 3: 3,
33
- 4: 4,
34
- 5: 5,
35
- 6: 6,
36
- 7: 7,
37
- 8: 8,
38
- 9: 9
2
+ 〇: 0,
3
+ 一: 1,
4
+ 二: 2,
5
+ 三: 3,
6
+ 四: 4,
7
+ 五: 5,
8
+ 六: 6,
9
+ 七: 7,
10
+ 八: 8,
11
+ 九: 9,
12
+ 十: 10,
13
+ 百: 100,
14
+ 千: 1000,
15
+ 万: 10000,
16
+ 零: 0,
17
+ 壹: 1,
18
+ 贰: 2,
19
+ 叁: 3,
20
+ 肆: 4,
21
+ 伍: 5,
22
+ 陆: 6,
23
+ 柒: 7,
24
+ 捌: 8,
25
+ 玖: 9,
26
+ 拾: 10,
27
+ 佰: 100,
28
+ 仟: 1000,
29
+ 0: 0,
30
+ 1: 1,
31
+ 2: 2,
32
+ 3: 3,
33
+ 4: 4,
34
+ 5: 5,
35
+ 6: 6,
36
+ 7: 7,
37
+ 8: 8,
38
+ 9: 9,
39
39
  };
40
40
  // 一万一 -> 10001
41
41
  // 一万一百一 -> 10101
42
42
  // 一万 -> 10000
43
43
  // 10000 -> 10000
44
44
  export function parseChineseNumber(s) {
45
- if (typeof s === 'number') {
46
- return s;
47
- }
48
- let n = 0;
49
- let c = 0;
50
- let base = 0;
51
- let shouldAddLast = false;
52
- for (const char of s.split('').reverse()){
53
- c = ToNumber[char];
54
- if (c === undefined) {
55
- throw new Error(`无法解析的数字: ${char}`);
56
- }
57
- switch(c){
58
- case 10:
59
- {
60
- base = 1;
61
- break;
62
- }
63
- case 100:
64
- {
65
- base = 2;
66
- break;
67
- }
68
- case 1000:
69
- {
70
- base = 3;
71
- break;
72
- }
73
- case 10000:
74
- {
75
- base = 4;
76
- break;
77
- }
78
- }
79
- //
80
- if (c < 10) {
81
- n += c * 10 ** base;
82
- base++;
83
- shouldAddLast = false;
84
- } else {
85
- shouldAddLast = true;
86
- }
87
- }
88
- if (shouldAddLast) {
89
- n += c;
90
- }
91
- return n;
45
+ if (typeof s === 'number') {
46
+ return s;
47
+ }
48
+ let n = 0;
49
+ let c = 0;
50
+ let base = 0;
51
+ let shouldAddLast = false;
52
+ for (const char of s.split('').reverse()) {
53
+ c = ToNumber[char];
54
+ if (c === undefined) {
55
+ throw new Error(`无法解析的数字: ${char}`);
56
+ }
57
+ switch (c) {
58
+ case 10: {
59
+ base = 1;
60
+ break;
61
+ }
62
+ case 100: {
63
+ base = 2;
64
+ break;
65
+ }
66
+ case 1000: {
67
+ base = 3;
68
+ break;
69
+ }
70
+ case 10000: {
71
+ base = 4;
72
+ break;
73
+ }
74
+ }
75
+ //
76
+ if (c < 10) {
77
+ n += c * 10 ** base;
78
+ base++;
79
+ shouldAddLast = false;
80
+ } else {
81
+ shouldAddLast = true;
82
+ }
83
+ }
84
+ if (shouldAddLast) {
85
+ n += c;
86
+ }
87
+ return n;
92
88
  }
93
89
 
94
- //# sourceMappingURL=parseChineseNumber.js.map
90
+ //# sourceMappingURL=parseChineseNumber.js.map