@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,179 +1,79 @@
1
- import { describe, expect, test } from "vitest";
2
- import { cartesianProduct } from "./cartesianProduct.js";
3
- describe("cartesianProduct", function () {
4
- test("combines two arrays with multiple elements", function () {
5
- expect(cartesianProduct([
6
- [
7
- 1,
8
- 2
9
- ],
10
- [
11
- 3,
12
- 4
13
- ]
14
- ])).toEqual([
15
- [
16
- 1,
17
- 3
18
- ],
19
- [
20
- 1,
21
- 4
22
- ],
23
- [
24
- 2,
25
- 3
26
- ],
27
- [
28
- 2,
29
- 4
30
- ]
31
- ]);
32
- });
33
- test("combines multiple arrays", function () {
34
- expect(cartesianProduct([
35
- [
36
- 1,
37
- 2
38
- ],
39
- [
40
- 3
41
- ],
42
- [
43
- 4,
44
- 5
45
- ]
46
- ])).toEqual([
47
- [
48
- 1,
49
- 3,
50
- 4
51
- ],
52
- [
53
- 1,
54
- 3,
55
- 5
56
- ],
57
- [
58
- 2,
59
- 3,
60
- 4
61
- ],
62
- [
63
- 2,
64
- 3,
65
- 5
66
- ]
67
- ]);
68
- });
69
- test("handles an empty array input correctly", function () {
70
- expect(cartesianProduct([])).toEqual([]);
71
- });
72
- test("handles one array being empty", function () {
73
- expect(cartesianProduct([
74
- [
75
- 1,
76
- 2
77
- ],
78
- [],
79
- [
80
- 3
81
- ]
82
- ])).toEqual([]);
83
- });
84
- test("works with arrays of different types", function () {
85
- expect(cartesianProduct([
86
- [
87
- "a",
88
- "b"
89
- ],
90
- [
91
- 1,
92
- 2
93
- ]
94
- ])).toEqual([
95
- [
96
- "a",
97
- 1
98
- ],
99
- [
100
- "a",
101
- 2
102
- ],
103
- [
104
- "b",
105
- 1
106
- ],
107
- [
108
- "b",
109
- 2
110
- ]
111
- ]);
112
- });
113
- test("handles single-element arrays", function () {
114
- expect(cartesianProduct([
115
- [
116
- 1
117
- ],
118
- [
119
- 2
120
- ],
121
- [
122
- 3
123
- ]
124
- ])).toEqual([
125
- [
126
- 1,
127
- 2,
128
- 3
129
- ]
130
- ]);
131
- });
132
- test("works with more complex objects", function () {
133
- expect(cartesianProduct([
134
- [
135
- {
136
- id: 1
137
- },
138
- {
139
- id: 2
140
- }
141
- ],
142
- [
143
- "a"
144
- ]
145
- ])).toEqual([
146
- [
147
- {
148
- id: 1
149
- },
150
- "a"
151
- ],
152
- [
153
- {
154
- id: 2
155
- },
156
- "a"
157
- ]
158
- ]);
159
- });
160
- test("handles an array containing a single array", function () {
161
- expect(cartesianProduct([
162
- [
163
- 1,
164
- 2,
165
- 3
166
- ]
167
- ])).toEqual([
168
- [
169
- 1
170
- ],
171
- [
172
- 2
173
- ],
174
- [
175
- 3
176
- ]
177
- ]);
178
- });
1
+ import { describe, expect, test } from 'vitest';
2
+ import { cartesianProduct } from './cartesianProduct.js';
3
+
4
+ describe('cartesianProduct', () => {
5
+ test('combines two arrays with multiple elements', () => {
6
+ expect(
7
+ cartesianProduct([
8
+ [1, 2],
9
+ [3, 4],
10
+ ]),
11
+ ).toEqual([
12
+ [1, 3],
13
+ [1, 4],
14
+ [2, 3],
15
+ [2, 4],
16
+ ]);
17
+ });
18
+ test('combines multiple arrays', () => {
19
+ expect(cartesianProduct([[1, 2], [3], [4, 5]])).toEqual([
20
+ [1, 3, 4],
21
+ [1, 3, 5],
22
+ [2, 3, 4],
23
+ [2, 3, 5],
24
+ ]);
25
+ });
26
+ test('handles an empty array input correctly', () => {
27
+ expect(cartesianProduct([])).toEqual([]);
28
+ });
29
+ test('handles one array being empty', () => {
30
+ expect(cartesianProduct([[1, 2], [], [3]])).toEqual([]);
31
+ });
32
+ test('works with arrays of different types', () => {
33
+ expect(
34
+ cartesianProduct([
35
+ ['a', 'b'],
36
+ [1, 2],
37
+ ]),
38
+ ).toEqual([
39
+ ['a', 1],
40
+ ['a', 2],
41
+ ['b', 1],
42
+ ['b', 2],
43
+ ]);
44
+ });
45
+ test('handles single-element arrays', () => {
46
+ expect(cartesianProduct([[1], [2], [3]])).toEqual([[1, 2, 3]]);
47
+ });
48
+ test('works with more complex objects', () => {
49
+ expect(
50
+ cartesianProduct([
51
+ [
52
+ {
53
+ id: 1,
54
+ },
55
+ {
56
+ id: 2,
57
+ },
58
+ ],
59
+ ['a'],
60
+ ]),
61
+ ).toEqual([
62
+ [
63
+ {
64
+ id: 1,
65
+ },
66
+ 'a',
67
+ ],
68
+ [
69
+ {
70
+ id: 2,
71
+ },
72
+ 'a',
73
+ ],
74
+ ]);
75
+ });
76
+ test('handles an array containing a single array', () => {
77
+ expect(cartesianProduct([[1, 2, 3]])).toEqual([[1], [2], [3]]);
78
+ });
179
79
  });
@@ -1,14 +1,16 @@
1
- import { setCharToPinyinTable } from "./toPinyinPure.js";
2
- import { transformData } from "./transform.js";
1
+ import { setCharToPinyinTable } from './toPinyinPure.js';
2
+ import { transformData } from './transform.js';
3
3
  export function loadCharToPinyinTable() {
4
- return import("./data.json", {
5
- with: {
6
- type: "json"
7
- }
8
- }).then((v) => v.default).then((data) => {
9
- let out = transformData(data);
10
- setCharToPinyinTable(out);
11
- return out;
12
- });
4
+ return import('./data.json', {
5
+ with: {
6
+ type: 'json',
7
+ },
8
+ })
9
+ .then((v) => v.default)
10
+ .then((data) => {
11
+ let out = transformData(data);
12
+ setCharToPinyinTable(out);
13
+ return out;
14
+ });
13
15
  }
14
16
  //# sourceMappingURL=loader.js.map
@@ -1,3 +1,4 @@
1
- import { loadCharToPinyinTable } from "./loader.js";
1
+ import { loadCharToPinyinTable } from './loader.js';
2
+
2
3
  await loadCharToPinyinTable();
3
4
  //# sourceMappingURL=preload.js.map
@@ -1,167 +1,155 @@
1
1
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- }
6
- catch (error) {
7
- reject(error);
8
- return;
9
- }
10
- if (info.done) {
11
- resolve(value);
12
- }
13
- else {
14
- Promise.resolve(value).then(_next, _throw);
15
- }
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
16
14
  }
17
15
  function _async_to_generator(fn) {
18
- return function () {
19
- var self = this, args = arguments;
20
- return new Promise(function (resolve, reject) {
21
- var gen = fn.apply(self, args);
22
- function _next(value) {
23
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
24
- }
25
- function _throw(err) {
26
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
27
- }
28
- _next(undefined);
29
- });
30
- };
16
+ return function () {
17
+ var args = arguments;
18
+ return new Promise((resolve, reject) => {
19
+ var gen = fn.apply(this, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'next', value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'throw', err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
31
29
  }
32
30
  function _ts_generator(thisArg, body) {
33
- var f, y, t, _ = {
34
- label: 0,
35
- sent: function () {
36
- if (t[0] & 1)
37
- throw t[1];
38
- return t[1];
39
- },
40
- trys: [],
41
- ops: []
42
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
43
- return d(g, "next", {
44
- value: verb(0)
45
- }), d(g, "throw", {
46
- value: verb(1)
47
- }), d(g, "return", {
48
- value: verb(2)
49
- }), typeof Symbol === "function" && d(g, Symbol.iterator, {
50
- value: function () {
51
- return this;
52
- }
53
- }), g;
54
- function verb(n) {
55
- return function (v) {
56
- return step([
57
- n,
58
- v
59
- ]);
60
- };
61
- }
62
- function step(op) {
63
- if (f)
64
- throw new TypeError("Generator is already executing.");
65
- while (g && (g = 0, op[0] && (_ = 0)), _)
66
- try {
67
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
68
- return t;
69
- if (y = 0, t)
70
- op = [
71
- op[0] & 2,
72
- t.value
73
- ];
74
- switch (op[0]) {
75
- case 0:
76
- case 1:
77
- t = op;
78
- break;
79
- case 4:
80
- _.label++;
81
- return {
82
- value: op[1],
83
- done: false
84
- };
85
- case 5:
86
- _.label++;
87
- y = op[1];
88
- op = [
89
- 0
90
- ];
91
- continue;
92
- case 7:
93
- op = _.ops.pop();
94
- _.trys.pop();
95
- continue;
96
- default:
97
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
98
- _ = 0;
99
- continue;
100
- }
101
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
102
- _.label = op[1];
103
- break;
104
- }
105
- if (op[0] === 6 && _.label < t[1]) {
106
- _.label = t[1];
107
- t = op;
108
- break;
109
- }
110
- if (t && _.label < t[2]) {
111
- _.label = t[2];
112
- _.ops.push(op);
113
- break;
114
- }
115
- if (t[2])
116
- _.ops.pop();
117
- _.trys.pop();
118
- continue;
119
- }
120
- op = body.call(thisArg, _);
121
- }
122
- catch (e) {
123
- op = [
124
- 6,
125
- e
126
- ];
127
- y = 0;
128
- }
129
- finally {
130
- f = t = 0;
131
- }
132
- if (op[0] & 5)
133
- throw op[1];
134
- return {
135
- value: op[0] ? op[1] : void 0,
136
- done: true
137
- };
138
- }
31
+ var f,
32
+ y,
33
+ t,
34
+ _ = {
35
+ label: 0,
36
+ sent: () => {
37
+ if (t[0] & 1) throw t[1];
38
+ return t[1];
39
+ },
40
+ trys: [],
41
+ ops: [],
42
+ },
43
+ g = Object.create((typeof Iterator === 'function' ? Iterator : Object).prototype),
44
+ d = Object.defineProperty;
45
+ return (
46
+ d(g, 'next', {
47
+ value: verb(0),
48
+ }),
49
+ d(g, 'throw', {
50
+ value: verb(1),
51
+ }),
52
+ d(g, 'return', {
53
+ value: verb(2),
54
+ }),
55
+ typeof Symbol === 'function' &&
56
+ d(g, Symbol.iterator, {
57
+ value: function () {
58
+ return this;
59
+ },
60
+ }),
61
+ g
62
+ );
63
+ function verb(n) {
64
+ return (v) => step([n, v]);
65
+ }
66
+ function step(op) {
67
+ if (f) throw new TypeError('Generator is already executing.');
68
+ while ((g && ((g = 0), op[0] && (_ = 0)), _))
69
+ try {
70
+ if (
71
+ ((f = 1),
72
+ y &&
73
+ (t = op[0] & 2 ? y['return'] : op[0] ? y['throw'] || ((t = y['return']) && t.call(y), 0) : y.next) &&
74
+ !(t = t.call(y, op[1])).done)
75
+ )
76
+ return t;
77
+ if (((y = 0), t)) op = [op[0] & 2, t.value];
78
+ switch (op[0]) {
79
+ case 0:
80
+ case 1:
81
+ t = op;
82
+ break;
83
+ case 4:
84
+ _.label++;
85
+ return {
86
+ value: op[1],
87
+ done: false,
88
+ };
89
+ case 5:
90
+ _.label++;
91
+ y = op[1];
92
+ op = [0];
93
+ continue;
94
+ case 7:
95
+ op = _.ops.pop();
96
+ _.trys.pop();
97
+ continue;
98
+ default:
99
+ if (!((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && (op[0] === 6 || op[0] === 2)) {
100
+ _ = 0;
101
+ continue;
102
+ }
103
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
104
+ _.label = op[1];
105
+ break;
106
+ }
107
+ if (op[0] === 6 && _.label < t[1]) {
108
+ _.label = t[1];
109
+ t = op;
110
+ break;
111
+ }
112
+ if (t && _.label < t[2]) {
113
+ _.label = t[2];
114
+ _.ops.push(op);
115
+ break;
116
+ }
117
+ if (t[2]) _.ops.pop();
118
+ _.trys.pop();
119
+ continue;
120
+ }
121
+ op = body.call(thisArg, _);
122
+ } catch (e) {
123
+ op = [6, e];
124
+ y = 0;
125
+ } finally {
126
+ f = t = 0;
127
+ }
128
+ if (op[0] & 5) throw op[1];
129
+ return {
130
+ value: op[0] ? op[1] : void 0,
131
+ done: true,
132
+ };
133
+ }
139
134
  }
140
- import { assert, test } from "vitest";
141
- import { loadCharToPinyinTable } from "./loader.js";
142
- import { toPinyinPure } from "./toPinyinPure.js";
143
- test("toPinyin", function () {
144
- return _async_to_generator(function () {
145
- return _ts_generator(this, function (_state) {
146
- switch (_state.label) {
147
- case 0:
148
- return [
149
- 4,
150
- loadCharToPinyinTable()
151
- ];
152
- case 1:
153
- _state.sent();
154
- assert.deepEqual(toPinyinPure("\u771F\u601D"), [
155
- "zhen,sai",
156
- "zhen,si"
157
- ]);
158
- return [
159
- 2
160
- ];
161
- }
162
- });
163
- // char to py -> 350k
164
- // py to char -> 145k
165
- // csv -> 96k
166
- })();
167
- });
135
+
136
+ import { assert, test } from 'vitest';
137
+ import { loadCharToPinyinTable } from './loader.js';
138
+ import { toPinyinPure } from './toPinyinPure.js';
139
+
140
+ test('toPinyin', () =>
141
+ _async_to_generator(function () {
142
+ return _ts_generator(this, (_state) => {
143
+ switch (_state.label) {
144
+ case 0:
145
+ return [4, loadCharToPinyinTable()];
146
+ case 1:
147
+ _state.sent();
148
+ assert.deepEqual(toPinyinPure('\u771F\u601D'), ['zhen,sai', 'zhen,si']);
149
+ return [2];
150
+ }
151
+ });
152
+ // char to py -> 350k
153
+ // py to char -> 145k
154
+ // csv -> 96k
155
+ })());
@@ -1,32 +1,37 @@
1
- import { cartesianProduct } from "./cartesianProduct.js";
1
+ import { cartesianProduct } from './cartesianProduct.js';
2
+
2
3
  let CharToPinyinTable;
3
4
  export function setCharToPinyinTable(table) {
4
- CharToPinyinTable = table;
5
+ CharToPinyinTable = table;
5
6
  }
6
7
  export function getCharToPinyinTable() {
7
- if (!CharToPinyinTable) {
8
- return {};
9
- }
10
- return CharToPinyinTable;
8
+ if (!CharToPinyinTable) {
9
+ return {};
10
+ }
11
+ return CharToPinyinTable;
11
12
  }
12
- export function toPinyinPureFirst(s, sep = ",") {
13
- let tab = getCharToPinyinTable();
14
- return s.split("").map((c) => tab[c]?.[0]).filter(Boolean).join(sep);
13
+ export function toPinyinPureFirst(s, sep = ',') {
14
+ let tab = getCharToPinyinTable();
15
+ return s
16
+ .split('')
17
+ .map((c) => tab[c]?.[0])
18
+ .filter(Boolean)
19
+ .join(sep);
15
20
  }
16
- export function toPinyinPure(s, sep = ",") {
17
- let tab = getCharToPinyinTable();
18
- // ensure order
19
- return cartesianProduct(s.split("").map((c) => tab[c] || "")).sort((a, b) => {
20
- for (let i = 0; i < a.length; i++) {
21
- let x = a[i];
22
- let y = b[i];
23
- if (x < y)
24
- return -1;
25
- if (x > y)
26
- return 1;
27
- }
28
- return 0;
29
- }).map((v) => v.filter(Boolean).join(sep));
21
+ export function toPinyinPure(s, sep = ',') {
22
+ let tab = getCharToPinyinTable();
23
+ // ensure order
24
+ return cartesianProduct(s.split('').map((c) => tab[c] || ''))
25
+ .sort((a, b) => {
26
+ for (let i = 0; i < a.length; i++) {
27
+ let x = a[i];
28
+ let y = b[i];
29
+ if (x < y) return -1;
30
+ if (x > y) return 1;
31
+ }
32
+ return 0;
33
+ })
34
+ .map((v) => v.filter(Boolean).join(sep));
30
35
  } // export function lookupPinyinPure(s: string): Array<Array<string>> {
31
36
  // return cartesianProductOfArray(s.split('').map(c => Lookup[c]));
32
37
  // }