@idlebox/common 1.4.1 → 1.4.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.
Files changed (261) hide show
  1. package/lib/cjs/array/arrayUnique.cjs +2 -4
  2. package/lib/cjs/array/arrayUnique.cjs.map +1 -1
  3. package/lib/cjs/array/normalizeArray.cjs +2 -4
  4. package/lib/cjs/array/normalizeArray.cjs.map +1 -1
  5. package/lib/cjs/array/sortAlpha.cjs +2 -4
  6. package/lib/cjs/array/sortAlpha.cjs.map +1 -1
  7. package/lib/cjs/date/isInvalid.cjs +1 -1
  8. package/lib/cjs/date/isInvalid.cjs.map +1 -1
  9. package/lib/cjs/date/timeString.cjs +8 -10
  10. package/lib/cjs/date/timeString.cjs.map +1 -1
  11. package/lib/cjs/debugging/serializable.cjs +2 -2
  12. package/lib/cjs/debugging/serializable.cjs.map +1 -1
  13. package/lib/cjs/debugging/tryInspect.cjs +7 -9
  14. package/lib/cjs/debugging/tryInspect.cjs.map +1 -1
  15. package/lib/cjs/error/convertUnknown.cjs +2 -4
  16. package/lib/cjs/error/convertUnknown.cjs.map +1 -1
  17. package/lib/cjs/error/getFrame.cjs +2 -2
  18. package/lib/cjs/error/getFrame.cjs.map +1 -1
  19. package/lib/cjs/error/known.cjs.map +1 -1
  20. package/lib/cjs/error/pretty.cjs +22 -30
  21. package/lib/cjs/error/pretty.cjs.map +1 -1
  22. package/lib/cjs/function/asyncCallbackList.cjs.map +1 -1
  23. package/lib/cjs/function/callbackList.cjs.map +1 -1
  24. package/lib/cjs/function/delayCallbackList.cjs +3 -3
  25. package/lib/cjs/function/delayCallbackList.cjs.map +1 -1
  26. package/lib/cjs/lifecycle/dispose/disposableEvent.cjs +1 -3
  27. package/lib/cjs/lifecycle/dispose/disposableEvent.cjs.map +1 -1
  28. package/lib/cjs/lifecycle/dispose/lifecycle.async.cjs.map +1 -1
  29. package/lib/cjs/lifecycle/dispose/lifecycle.global.cjs +4 -8
  30. package/lib/cjs/lifecycle/dispose/lifecycle.global.cjs.map +1 -1
  31. package/lib/cjs/lifecycle/dispose/lifecycle.sync.cjs +1 -1
  32. package/lib/cjs/lifecycle/dispose/lifecycle.sync.cjs.map +1 -1
  33. package/lib/cjs/lifecycle/event/event.cjs +61 -6
  34. package/lib/cjs/lifecycle/event/event.cjs.map +1 -1
  35. package/lib/cjs/lifecycle/event/memorized.cjs +1 -1
  36. package/lib/cjs/lifecycle/event/memorized.cjs.map +1 -1
  37. package/lib/cjs/lifecycle/promise/cancellationToken/driver.common.cjs.map +1 -1
  38. package/lib/cjs/lifecycle/promise/deferredPromise.cjs +2 -2
  39. package/lib/cjs/lifecycle/promise/deferredPromise.cjs.map +1 -1
  40. package/lib/cjs/lifecycle/timeout/timeout.cjs +1 -3
  41. package/lib/cjs/lifecycle/timeout/timeout.cjs.map +1 -1
  42. package/lib/cjs/lifecycle/timeout/timeoutError.cjs.map +1 -1
  43. package/lib/cjs/log/logger.cjs +4 -6
  44. package/lib/cjs/log/logger.cjs.map +1 -1
  45. package/lib/cjs/mapSet/customSet.cjs +3 -7
  46. package/lib/cjs/mapSet/customSet.cjs.map +1 -1
  47. package/lib/cjs/mapSet/extendMap.cjs +5 -9
  48. package/lib/cjs/mapSet/extendMap.cjs.map +1 -1
  49. package/lib/cjs/misc/assertNotNull.cjs +1 -3
  50. package/lib/cjs/misc/assertNotNull.cjs.map +1 -1
  51. package/lib/cjs/misc/package.json.cjs +1 -1
  52. package/lib/cjs/misc/package.json.cjs.map +1 -1
  53. package/lib/cjs/object/initOnRead.cjs.map +1 -1
  54. package/lib/cjs/object/objectSame.cjs +2 -1
  55. package/lib/cjs/object/objectSame.cjs.map +1 -1
  56. package/lib/cjs/path/normalizePath.cjs +7 -9
  57. package/lib/cjs/path/normalizePath.cjs.map +1 -1
  58. package/lib/cjs/path/pathArray.cjs +1 -1
  59. package/lib/cjs/path/pathArray.cjs.map +1 -1
  60. package/lib/cjs/platform/globalSingleton.cjs +1 -1
  61. package/lib/cjs/platform/globalSymbol.cjs +6 -8
  62. package/lib/cjs/platform/globalSymbol.cjs.map +1 -1
  63. package/lib/cjs/promise/promiseCollection.cjs +3 -3
  64. package/lib/cjs/promise/promiseCollection.cjs.map +1 -1
  65. package/lib/cjs/reflection/classes/singleton.cjs +1 -3
  66. package/lib/cjs/reflection/classes/singleton.cjs.map +1 -1
  67. package/lib/cjs/reflection/methods/bind.cjs +1 -3
  68. package/lib/cjs/reflection/methods/bind.cjs.map +1 -1
  69. package/lib/cjs/reflection/methods/initOnRead.cjs +2 -2
  70. package/lib/cjs/reflection/methods/initOnRead.cjs.map +1 -1
  71. package/lib/cjs/string/castCase.cjs +5 -5
  72. package/lib/cjs/string/castCase.cjs.map +1 -1
  73. package/lib/cjs/string/pad2.cjs +2 -4
  74. package/lib/cjs/string/pad2.cjs.map +1 -1
  75. package/lib/cjs/string/sizeString.cjs +23 -27
  76. package/lib/cjs/string/sizeString.cjs.map +1 -1
  77. package/lib/esm/array/arrayUnique.d.ts +1 -3
  78. package/lib/esm/array/arrayUnique.d.ts.map +1 -1
  79. package/lib/esm/array/arrayUnique.js +2 -4
  80. package/lib/esm/array/arrayUnique.js.map +1 -1
  81. package/lib/esm/array/normalizeArray.js +2 -4
  82. package/lib/esm/array/normalizeArray.js.map +1 -1
  83. package/lib/esm/array/sortAlpha.js +2 -4
  84. package/lib/esm/array/sortAlpha.js.map +1 -1
  85. package/lib/esm/date/isInvalid.js +1 -1
  86. package/lib/esm/date/isInvalid.js.map +1 -1
  87. package/lib/esm/date/timeString.d.ts +1 -3
  88. package/lib/esm/date/timeString.d.ts.map +1 -1
  89. package/lib/esm/date/timeString.js +8 -10
  90. package/lib/esm/date/timeString.js.map +1 -1
  91. package/lib/esm/debugging/serializable.d.ts +1 -1
  92. package/lib/esm/debugging/serializable.d.ts.map +1 -1
  93. package/lib/esm/debugging/serializable.js +2 -2
  94. package/lib/esm/debugging/serializable.js.map +1 -1
  95. package/lib/esm/debugging/tryInspect.d.ts.map +1 -1
  96. package/lib/esm/debugging/tryInspect.js +7 -9
  97. package/lib/esm/debugging/tryInspect.js.map +1 -1
  98. package/lib/esm/error/convertUnknown.d.ts.map +1 -1
  99. package/lib/esm/error/convertUnknown.js +2 -4
  100. package/lib/esm/error/convertUnknown.js.map +1 -1
  101. package/lib/esm/error/getFrame.js +2 -2
  102. package/lib/esm/error/getFrame.js.map +1 -1
  103. package/lib/esm/error/known.d.ts.map +1 -1
  104. package/lib/esm/error/known.js.map +1 -1
  105. package/lib/esm/error/pretty.d.ts.map +1 -1
  106. package/lib/esm/error/pretty.js +22 -30
  107. package/lib/esm/error/pretty.js.map +1 -1
  108. package/lib/esm/function/asyncCallbackList.d.ts +1 -1
  109. package/lib/esm/function/asyncCallbackList.d.ts.map +1 -1
  110. package/lib/esm/function/asyncCallbackList.js.map +1 -1
  111. package/lib/esm/function/callbackList.d.ts.map +1 -1
  112. package/lib/esm/function/callbackList.js.map +1 -1
  113. package/lib/esm/function/delayCallbackList.d.ts.map +1 -1
  114. package/lib/esm/function/delayCallbackList.js +3 -3
  115. package/lib/esm/function/delayCallbackList.js.map +1 -1
  116. package/lib/esm/lifecycle/dispose/disposableEvent.d.ts +1 -1
  117. package/lib/esm/lifecycle/dispose/disposableEvent.d.ts.map +1 -1
  118. package/lib/esm/lifecycle/dispose/disposableEvent.js +1 -3
  119. package/lib/esm/lifecycle/dispose/disposableEvent.js.map +1 -1
  120. package/lib/esm/lifecycle/dispose/lifecycle.async.d.ts +2 -2
  121. package/lib/esm/lifecycle/dispose/lifecycle.async.d.ts.map +1 -1
  122. package/lib/esm/lifecycle/dispose/lifecycle.async.js.map +1 -1
  123. package/lib/esm/lifecycle/dispose/lifecycle.d.ts +1 -1
  124. package/lib/esm/lifecycle/dispose/lifecycle.d.ts.map +1 -1
  125. package/lib/esm/lifecycle/dispose/lifecycle.global.d.ts +1 -1
  126. package/lib/esm/lifecycle/dispose/lifecycle.global.d.ts.map +1 -1
  127. package/lib/esm/lifecycle/dispose/lifecycle.global.js +4 -8
  128. package/lib/esm/lifecycle/dispose/lifecycle.global.js.map +1 -1
  129. package/lib/esm/lifecycle/dispose/lifecycle.sync.d.ts +2 -2
  130. package/lib/esm/lifecycle/dispose/lifecycle.sync.d.ts.map +1 -1
  131. package/lib/esm/lifecycle/dispose/lifecycle.sync.js +1 -1
  132. package/lib/esm/lifecycle/dispose/lifecycle.sync.js.map +1 -1
  133. package/lib/esm/lifecycle/event/event.d.ts +15 -7
  134. package/lib/esm/lifecycle/event/event.d.ts.map +1 -1
  135. package/lib/esm/lifecycle/event/event.js +61 -6
  136. package/lib/esm/lifecycle/event/event.js.map +1 -1
  137. package/lib/esm/lifecycle/event/memorized.d.ts +2 -2
  138. package/lib/esm/lifecycle/event/memorized.d.ts.map +1 -1
  139. package/lib/esm/lifecycle/event/memorized.js +1 -1
  140. package/lib/esm/lifecycle/event/memorized.js.map +1 -1
  141. package/lib/esm/lifecycle/promise/cancellationToken/driver.common.js.map +1 -1
  142. package/lib/esm/lifecycle/promise/cancellationToken/source.d.ts +2 -2
  143. package/lib/esm/lifecycle/promise/cancellationToken/source.d.ts.map +1 -1
  144. package/lib/esm/lifecycle/promise/deferredPromise.js +2 -2
  145. package/lib/esm/lifecycle/promise/deferredPromise.js.map +1 -1
  146. package/lib/esm/lifecycle/timeout/timeout.js +1 -3
  147. package/lib/esm/lifecycle/timeout/timeout.js.map +1 -1
  148. package/lib/esm/lifecycle/timeout/timeoutError.d.ts.map +1 -1
  149. package/lib/esm/lifecycle/timeout/timeoutError.js.map +1 -1
  150. package/lib/esm/log/logger.d.ts.map +1 -1
  151. package/lib/esm/log/logger.js +4 -6
  152. package/lib/esm/log/logger.js.map +1 -1
  153. package/lib/esm/mapSet/customSet.d.ts +1 -3
  154. package/lib/esm/mapSet/customSet.d.ts.map +1 -1
  155. package/lib/esm/mapSet/customSet.js +3 -7
  156. package/lib/esm/mapSet/customSet.js.map +1 -1
  157. package/lib/esm/mapSet/extendMap.d.ts.map +1 -1
  158. package/lib/esm/mapSet/extendMap.js +5 -9
  159. package/lib/esm/mapSet/extendMap.js.map +1 -1
  160. package/lib/esm/misc/assertNotNull.d.ts.map +1 -1
  161. package/lib/esm/misc/assertNotNull.js +1 -3
  162. package/lib/esm/misc/assertNotNull.js.map +1 -1
  163. package/lib/esm/misc/package.json.js +1 -1
  164. package/lib/esm/misc/package.json.js.map +1 -1
  165. package/lib/esm/object/initOnRead.d.ts +1 -3
  166. package/lib/esm/object/initOnRead.d.ts.map +1 -1
  167. package/lib/esm/object/initOnRead.js.map +1 -1
  168. package/lib/esm/object/objectSame.js +2 -1
  169. package/lib/esm/object/objectSame.js.map +1 -1
  170. package/lib/esm/path/normalizePath.d.ts.map +1 -1
  171. package/lib/esm/path/normalizePath.js +7 -9
  172. package/lib/esm/path/normalizePath.js.map +1 -1
  173. package/lib/esm/path/pathArray.js +1 -1
  174. package/lib/esm/path/pathArray.js.map +1 -1
  175. package/lib/esm/platform/globalSingleton.js +1 -1
  176. package/lib/esm/platform/globalSymbol.d.ts.map +1 -1
  177. package/lib/esm/platform/globalSymbol.js +6 -8
  178. package/lib/esm/platform/globalSymbol.js.map +1 -1
  179. package/lib/esm/promise/promiseCollection.js +3 -3
  180. package/lib/esm/promise/promiseCollection.js.map +1 -1
  181. package/lib/esm/reflection/classes/hookClass.d.ts +1 -1
  182. package/lib/esm/reflection/classes/hookClass.d.ts.map +1 -1
  183. package/lib/esm/reflection/classes/singleton.d.ts.map +1 -1
  184. package/lib/esm/reflection/classes/singleton.js +1 -3
  185. package/lib/esm/reflection/classes/singleton.js.map +1 -1
  186. package/lib/esm/reflection/methods/bind.d.ts.map +1 -1
  187. package/lib/esm/reflection/methods/bind.js +1 -3
  188. package/lib/esm/reflection/methods/bind.js.map +1 -1
  189. package/lib/esm/reflection/methods/initOnRead.d.ts +1 -1
  190. package/lib/esm/reflection/methods/initOnRead.d.ts.map +1 -1
  191. package/lib/esm/reflection/methods/initOnRead.js +2 -2
  192. package/lib/esm/reflection/methods/initOnRead.js.map +1 -1
  193. package/lib/esm/string/castCase.js +5 -5
  194. package/lib/esm/string/castCase.js.map +1 -1
  195. package/lib/esm/string/pad2.d.ts.map +1 -1
  196. package/lib/esm/string/pad2.js +2 -4
  197. package/lib/esm/string/pad2.js.map +1 -1
  198. package/lib/esm/string/sizeString.d.ts.map +1 -1
  199. package/lib/esm/string/sizeString.js +23 -27
  200. package/lib/esm/string/sizeString.js.map +1 -1
  201. package/lib/esm/typingHelper/deep.partial.d.ts +1 -1
  202. package/lib/esm/typingHelper/deep.partial.d.ts.map +1 -1
  203. package/lib/esm/typingHelper/deep.readonly.d.ts +1 -1
  204. package/lib/esm/typingHelper/deep.readonly.d.ts.map +1 -1
  205. package/lib/esm/typingHelper/deep.required.d.ts +1 -1
  206. package/lib/esm/typingHelper/deep.required.d.ts.map +1 -1
  207. package/lib/esm/typingHelper/deep.writable.d.ts +1 -1
  208. package/lib/esm/typingHelper/deep.writable.d.ts.map +1 -1
  209. package/package.json +3 -3
  210. package/src/array/arrayUnique.ts +3 -6
  211. package/src/array/normalizeArray.ts +3 -3
  212. package/src/array/sortAlpha.ts +3 -3
  213. package/src/date/isInvalid.ts +1 -1
  214. package/src/date/timeString.ts +9 -15
  215. package/src/debugging/serializable.ts +8 -8
  216. package/src/debugging/tryInspect.ts +12 -8
  217. package/src/error/convertUnknown.ts +2 -3
  218. package/src/error/getFrame.ts +2 -2
  219. package/src/error/known.ts +2 -2
  220. package/src/error/pretty.ts +29 -34
  221. package/src/function/asyncCallbackList.ts +3 -3
  222. package/src/function/callbackList.ts +2 -2
  223. package/src/function/delayCallbackList.ts +4 -4
  224. package/src/lifecycle/dispose/disposableEvent.ts +2 -3
  225. package/src/lifecycle/dispose/disposedError.ts +1 -1
  226. package/src/lifecycle/dispose/lifecycle.async.ts +2 -2
  227. package/src/lifecycle/dispose/lifecycle.global.ts +6 -7
  228. package/src/lifecycle/dispose/lifecycle.sync.ts +3 -3
  229. package/src/lifecycle/dispose/lifecycle.ts +1 -1
  230. package/src/lifecycle/event/event.ts +66 -13
  231. package/src/lifecycle/event/memorized.ts +4 -4
  232. package/src/lifecycle/promise/cancellationToken/driver.browser.ts +1 -1
  233. package/src/lifecycle/promise/cancellationToken/driver.common.ts +2 -2
  234. package/src/lifecycle/promise/cancellationToken/source.ts +2 -2
  235. package/src/lifecycle/promise/deferredPromise.ts +2 -2
  236. package/src/lifecycle/timeout/timeout.ts +1 -2
  237. package/src/lifecycle/timeout/timeoutError.ts +1 -1
  238. package/src/log/logger.ts +8 -9
  239. package/src/mapSet/customSet.ts +4 -8
  240. package/src/mapSet/extendMap.ts +6 -7
  241. package/src/misc/assertNotNull.ts +1 -2
  242. package/src/misc/package.json.ts +1 -1
  243. package/src/object/initOnRead.ts +1 -3
  244. package/src/object/objectSame.ts +2 -2
  245. package/src/path/normalizePath.ts +14 -17
  246. package/src/path/pathArray.ts +2 -2
  247. package/src/platform/globalSingleton.ts +1 -1
  248. package/src/platform/globalSymbol.ts +8 -9
  249. package/src/promise/promiseCollection.ts +3 -3
  250. package/src/reflection/classes/hookClass.ts +1 -1
  251. package/src/reflection/classes/singleton.ts +3 -4
  252. package/src/reflection/methods/bind.ts +1 -2
  253. package/src/reflection/methods/initOnRead.ts +3 -3
  254. package/src/string/castCase.ts +5 -5
  255. package/src/string/pad2.ts +2 -3
  256. package/src/string/sizeString.ts +33 -25
  257. package/src/tsconfig.json +1 -1
  258. package/src/typingHelper/deep.partial.ts +7 -7
  259. package/src/typingHelper/deep.readonly.ts +7 -7
  260. package/src/typingHelper/deep.required.ts +7 -7
  261. package/src/typingHelper/deep.writable.ts +7 -7
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idlebox/common",
3
3
  "type": "module",
4
- "version": "1.4.1",
4
+ "version": "1.4.3",
5
5
  "license": "MIT",
6
6
  "main": "./lib/cjs/__create_index.generated.cjs",
7
7
  "module": "./lib/esm/__create_index.generated.js",
@@ -18,8 +18,8 @@
18
18
  "repository": "https://github.com/GongT/baobao",
19
19
  "devDependencies": {
20
20
  "@rushstack/heft": "^0.68.2",
21
- "@build-script/single-dog-asset": "^1.0.31",
22
- "@idlebox/itypes": "^1.0.5",
21
+ "@idlebox/itypes": "^1.0.6",
22
+ "@build-script/single-dog-asset": "^1.0.33",
23
23
  "@internal/local-rig": "^1.0.1"
24
24
  },
25
25
  "scripts": {
@@ -20,9 +20,7 @@ export function arrayUniqueReference(arr: any[]): void {
20
20
  }
21
21
  }
22
22
 
23
- export interface IUniqueIdFactory<T> {
24
- (item: T): string;
25
- }
23
+ export type IUniqueIdFactory<T> = (item: T) => string;
26
24
 
27
25
  function defaultFactory(t: any) {
28
26
  return t as string;
@@ -42,9 +40,8 @@ export function uniqueFilter<T>(idFactory: IUniqueIdFactory<T> = defaultFactory)
42
40
  const id = idFactory(item);
43
41
  if (seen[id]) {
44
42
  return false;
45
- } else {
46
- seen[id] = true;
47
- return true;
48
43
  }
44
+ seen[id] = true;
45
+ return true;
49
46
  };
50
47
  }
@@ -5,9 +5,9 @@
5
5
  export function normalizeArray<T>(input: T | T[]): T[] {
6
6
  if (input && Array.isArray(input)) {
7
7
  return input;
8
- } else if (typeof input !== undefined) {
8
+ }
9
+ if (typeof input !== 'undefined') {
9
10
  return [input];
10
- } else {
11
- return [];
12
11
  }
12
+ return [];
13
13
  }
@@ -7,9 +7,9 @@
7
7
  export function sortByString(a: string, b: string): number {
8
8
  if (a === b) {
9
9
  return 0;
10
- } else if (a > b) {
10
+ }
11
+ if (a > b) {
11
12
  return 1;
12
- } else {
13
- return -1;
14
13
  }
14
+ return -1;
15
15
  }
@@ -2,5 +2,5 @@
2
2
  * Check if a date is NaN
3
3
  */
4
4
  export function isDateInvalid(date: Date) {
5
- return isNaN(date.getTime());
5
+ return Number.isNaN(date.getTime());
6
6
  }
@@ -6,7 +6,7 @@ export namespace humanDate {
6
6
  */
7
7
  export function time(date: Date | string | number) {
8
8
  if (typeof date === 'string') {
9
- date = parseInt(date);
9
+ date = Number.parseInt(date);
10
10
  }
11
11
  date = new Date(date as number);
12
12
  return `${pad2(date.getHours())}:${pad2(date.getMinutes())}:${pad2(date.getSeconds())}`;
@@ -19,7 +19,7 @@ export namespace humanDate {
19
19
  */
20
20
  export function date(date: Date | string | number, sp = '-') {
21
21
  if (typeof date === 'string') {
22
- date = parseInt(date);
22
+ date = Number.parseInt(date);
23
23
  }
24
24
  date = new Date(date as number);
25
25
  return `${date.getFullYear()}${sp}${pad2(date.getMonth() + 1)}${sp}${pad2(date.getDate())}`;
@@ -30,19 +30,13 @@ export namespace humanDate {
30
30
  */
31
31
  export function datetime(date: Date | string | number) {
32
32
  if (typeof date === 'string') {
33
- date = parseInt(date);
33
+ date = Number.parseInt(date);
34
34
  }
35
35
  date = new Date(date as number);
36
- return (
37
- `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}` +
38
- ' ' +
39
- `${pad2(date.getHours())}:${pad2(date.getMinutes())}:${pad2(date.getSeconds())}`
40
- );
36
+ return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} ${pad2(date.getHours())}:${pad2(date.getMinutes())}:${pad2(date.getSeconds())}`;
41
37
  }
42
38
 
43
- export interface ITimeFormatter {
44
- (s: number): string;
45
- }
39
+ export type ITimeFormatter = (s: number) => string;
46
40
 
47
41
  export interface IFormatters {
48
42
  s: ITimeFormatter;
@@ -53,16 +47,16 @@ export namespace humanDate {
53
47
 
54
48
  const formatters: IFormatters = {
55
49
  s(v: number) {
56
- return v + 's';
50
+ return `${v}s`;
57
51
  },
58
52
  m(v: number) {
59
- return v + 'm';
53
+ return `${v}m`;
60
54
  },
61
55
  h(v: number) {
62
- return v + 'h';
56
+ return `${v}h`;
63
57
  },
64
58
  d(v: number) {
65
- return v + 'd';
59
+ return `${v}d`;
66
60
  },
67
61
  };
68
62
 
@@ -5,11 +5,11 @@ declare const Element: any;
5
5
  type ScalarTypes =
6
6
  | bigint
7
7
  | number
8
- | Number
8
+ | number
9
+ | boolean
9
10
  | boolean
10
- | Boolean
11
11
  | string
12
- | String
12
+ | string
13
13
  | symbol
14
14
  | undefined
15
15
  | null
@@ -43,9 +43,9 @@ export function isScalar(value: any): value is ScalarTypes {
43
43
 
44
44
  export enum SerializableKind {
45
45
  Invalid = 0,
46
- Primitive,
47
- Manual,
48
- Other,
46
+ Primitive = 1,
47
+ Manual = 2,
48
+ Other = 3,
49
49
  }
50
50
 
51
51
  export function isSerializable(value: any): SerializableKind {
@@ -54,7 +54,7 @@ export function isSerializable(value: any): SerializableKind {
54
54
  case 'bigint':
55
55
  // @ts-expect-error
56
56
  case 'number':
57
- if (isNaN(value) || Infinity === value || -Infinity === value) {
57
+ if (Number.isNaN(value) || Number.POSITIVE_INFINITY === value || Number.NEGATIVE_INFINITY === value) {
58
58
  return SerializableKind.Invalid;
59
59
  }
60
60
  case 'boolean':
@@ -84,7 +84,7 @@ export function isSerializable(value: any): SerializableKind {
84
84
  return SerializableKind.Invalid;
85
85
  }
86
86
  }
87
- if ('then' in value && typeof value['then'] === 'function') {
87
+ if ('then' in value && typeof value.then === 'function') {
88
88
  return SerializableKind.Invalid;
89
89
  }
90
90
 
@@ -23,17 +23,21 @@ export function tryInspect(object: any) {
23
23
 
24
24
  if (object[inspect]) {
25
25
  return object[inspect]();
26
- } else if (inspectOld && object[inspectOld]) {
26
+ }
27
+ if (inspectOld && object[inspectOld]) {
27
28
  return object[inspectOld]();
28
- } else if (object['inspect']) {
29
- return object['inspect']();
30
- } else if (object[Symbol.toStringTag]) {
29
+ }
30
+ if (object.inspect) {
31
+ return object.inspect();
32
+ }
33
+ if (object[Symbol.toStringTag]) {
31
34
  return object[Symbol.toStringTag]();
32
- } else if (object.toJSON) {
35
+ }
36
+ if (object.toJSON) {
33
37
  return object.toJSON();
34
- } else if (object.constructor?.name) {
38
+ }
39
+ if (object.constructor?.name) {
35
40
  return `unknown: ${object.constructor.name}`;
36
- } else {
37
- return 'unknown: ' + object;
38
41
  }
42
+ return `unknown: ${object}`;
39
43
  }
@@ -3,8 +3,7 @@ import { getErrorFrame } from './getFrame.js';
3
3
  export function convertCatchedError(e: unknown): Error {
4
4
  if (e instanceof Error) {
5
5
  return e;
6
- } else {
7
- console.error('Catched invalid error at %s, type %s, value %s.', getErrorFrame(new Error(), 1), typeof e, e);
8
- return new Error('Invalid: ' + e);
9
6
  }
7
+ console.error('Catched invalid error at %s, type %s, value %s.', getErrorFrame(new Error(), 1), typeof e, e);
8
+ return new Error(`Invalid: ${e}`);
10
9
  }
@@ -3,10 +3,10 @@
3
3
  * @returns {string} if frame greater than max, return ''
4
4
  */
5
5
  export function getErrorFrame(e: Error, frame: number): string {
6
- if (e && e.stack) {
6
+ if (e?.stack) {
7
7
  const stackArr = e.stack.split('\n');
8
8
  if (stackArr.length > frame + 1) {
9
- return stackArr[frame + 1]!.trim();
9
+ return stackArr[frame + 1]?.trim();
10
10
  }
11
11
  }
12
12
  return '';
@@ -5,8 +5,8 @@ interface ErrorOptions {
5
5
  }
6
6
 
7
7
  abstract class KnownErrorAbstract extends Error {
8
- protected static debugMode: boolean = false;
9
- static debug(enabled: boolean = true) {
8
+ protected static debugMode = false;
9
+ static debug(enabled = true) {
10
10
  KnownErrorAbstract.debugMode = enabled;
11
11
  }
12
12
  static is(e: any): e is KnownErrorAbstract {
@@ -74,8 +74,8 @@ function addLoc(ret: IStructreStackLine, m: Record<TypeMatchFileOnly, string>) {
74
74
  ret.location = {
75
75
  schema: m.schema?.replace(/\/+$/, '') ?? '',
76
76
  path: path,
77
- line: parseInt(m.line),
78
- column: parseInt(m.column),
77
+ line: Number.parseInt(m.line),
78
+ column: Number.parseInt(m.column),
79
79
  isAbsolute: isAbsolute(path),
80
80
  };
81
81
  }
@@ -126,12 +126,13 @@ export function parseStackLine(line: string): IStructreStackLine {
126
126
  addLoc(ret, mEval);
127
127
 
128
128
  ret.eval = {
129
- eval_column: parseInt(mEval.eval_column),
129
+ eval_column: Number.parseInt(mEval.eval_column),
130
130
  eval_func: mEval.eval_func,
131
- eval_line: parseInt(mEval.eval_line),
131
+ eval_line: Number.parseInt(mEval.eval_line),
132
132
  funcs: [],
133
133
  };
134
134
  for (const item of line.matchAll(regEvalItem)) {
135
+ // biome-ignore lint/style/noNonNullAssertion: 有匹配必然有 groups
135
136
  ret.eval.funcs.push(item.groups!.func_name);
136
137
  }
137
138
  ret.eval.funcs.push(mEval.eval_func);
@@ -161,7 +162,7 @@ export function prettyPrintError(type: string, e: Error) {
161
162
  // console.log(JSON.stringify(e.stack), JSON.stringify(e.message));
162
163
  notify_printed = true;
163
164
  console.error(
164
- '\x1B[2muse env.DISABLE_PRETTY_ERROR=yes / window.DISABLE_PRETTY_ERROR=true to see original error stack\x1B[0m',
165
+ '\x1B[2muse env.DISABLE_PRETTY_ERROR=yes / window.DISABLE_PRETTY_ERROR=true to see original error stack\x1B[0m'
165
166
  );
166
167
  }
167
168
  }
@@ -197,12 +198,7 @@ export function prettyFormatStack(stackLines: readonly string[]) {
197
198
  if (fn_name) {
198
199
  ret += ' (';
199
200
  }
200
- ret += formatFileLine(
201
- line.location.schema,
202
- line.location.path,
203
- line.location.line,
204
- line.location.column,
205
- );
201
+ ret += formatFileLine(line.location.schema, line.location.path, line.location.line, line.location.column);
206
202
  if (fn_name) {
207
203
  ret += ')';
208
204
  }
@@ -216,7 +212,7 @@ export function prettyFormatStack(stackLines: readonly string[]) {
216
212
  const color = fn_name ? (isNodeModule ? '14;2' : '14') : '8';
217
213
  ret = `\x1b[0m at \x1b[38;5;${color}m`;
218
214
  if (fn_alias && fn_name && fn_name.startsWith('Object.')) {
219
- ret += fn_alias + ' [export]';
215
+ ret += `${fn_alias} [export]`;
220
216
  } else {
221
217
  ret += formatFunctionName(fn_name, fn_alias);
222
218
  }
@@ -232,7 +228,7 @@ export function prettyFormatStack(stackLines: readonly string[]) {
232
228
  } else {
233
229
  color = '\x1b[38;5;2m';
234
230
  }
235
- ret += ' (' + color;
231
+ ret += ` (${color}`;
236
232
  const file = formatFileLine(line.location.schema, path, line.location.line, line.location.column);
237
233
  const lastNmPos = file.lastIndexOf('/node_modules/');
238
234
  if (lastNmPos >= 0) {
@@ -266,15 +262,14 @@ interface IError {
266
262
  export function prettyFormatError(e: IError, withMessage = true) {
267
263
  if (!e || !e.stack) {
268
264
  if (withMessage) {
269
- let msg = e?.message || 'Unknown Error';
265
+ const msg = e?.message || 'Unknown Error';
270
266
 
271
- return red(msg + '\n No stack trace');
272
- } else {
273
- return red(' No stack trace');
267
+ return red(`${msg}\n No stack trace`);
274
268
  }
269
+ return red(' No stack trace');
275
270
  }
276
271
 
277
- let stackLines = e.stack.split(/\n/g);
272
+ const stackLines = e.stack.split(/\n/g);
278
273
 
279
274
  let first = 'Unknown Error';
280
275
  if (/^\S/.test(stackLines[0])) {
@@ -286,10 +281,9 @@ export function prettyFormatError(e: IError, withMessage = true) {
286
281
  first = first.replace(/^(\S+):/, `$1(code ${e.code}):`);
287
282
  }
288
283
 
289
- return first + '\n' + prettyFormatStack(stackLines).join('\n');
290
- } else {
291
- return prettyFormatStack(stackLines).join('\n');
284
+ return `${first}\n${prettyFormatStack(stackLines).join('\n')}`;
292
285
  }
286
+ return prettyFormatStack(stackLines).join('\n');
293
287
  }
294
288
 
295
289
  let alert = false;
@@ -300,7 +294,7 @@ function formatFileLine(schema: string | undefined, file: string, row?: number,
300
294
  try {
301
295
  rel = relativePath(root, file);
302
296
  if (rel[0] !== '.') {
303
- rel = './' + rel;
297
+ rel = `./${rel}`;
304
298
  } else if (rel[1] === '.') {
305
299
  if (file.length < rel.length) {
306
300
  rel = file;
@@ -311,13 +305,12 @@ function formatFileLine(schema: string | undefined, file: string, row?: number,
311
305
  }
312
306
  } catch (e: any) {
313
307
  if (!alert) {
314
- debugger;
315
308
  alert = true;
316
309
  console.error(
317
310
  'pretty print error: failed calc relative path ("%s" to "%s"):\n\x1B[2mFormat%s\x1B[0m',
318
311
  root,
319
312
  file,
320
- e.stack,
313
+ e.stack
321
314
  );
322
315
  }
323
316
  rel = file;
@@ -331,12 +324,10 @@ function formatFunctionName(fn?: string, as?: string) {
331
324
  if (fn) {
332
325
  if (as) {
333
326
  return `${fn} [as ${as}]`;
334
- } else {
335
- return fn;
336
327
  }
337
- } else {
338
- return '<anonymous>';
328
+ return fn;
339
329
  }
330
+ return '<anonymous>';
340
331
  }
341
332
 
342
333
  function translateFunction(data: IStructreStackLine): IStructreStackLine {
@@ -353,8 +344,8 @@ function translateFunction(data: IStructreStackLine): IStructreStackLine {
353
344
  data.func.name = 'process.nextTick';
354
345
  }
355
346
  if (data.func.name.startsWith('Timeout.') && data.func.alias === '_onTimeout') {
356
- data.func.name = 'setTimeout->' + data.func.name.slice(8);
357
- delete data.func.alias;
347
+ data.func.name = `setTimeout->${data.func.name.slice(8)}`;
348
+ data.func.alias = undefined;
358
349
  }
359
350
  return data;
360
351
  }
@@ -370,13 +361,17 @@ function skipSomeFrame({ location }: IStructreStackLine): boolean {
370
361
  if (location.schema === 'node:') {
371
362
  if (location.path.startsWith('internal/timers')) {
372
363
  return false;
373
- } else if (location.path === 'internal/modules/cjs/loader') {
364
+ }
365
+ if (location.path === 'internal/modules/cjs/loader') {
374
366
  return false;
375
- } else if (location.path === 'internal/modules/esm/loader') {
367
+ }
368
+ if (location.path === 'internal/modules/esm/loader') {
376
369
  return false;
377
- } else if (location.path === 'internal/modules/run_main') {
370
+ }
371
+ if (location.path === 'internal/modules/run_main') {
378
372
  return false;
379
- } else if (location.path === 'internal/modules/esm/module_job') {
373
+ }
374
+ if (location.path === 'internal/modules/esm/module_job') {
380
375
  return false;
381
376
  }
382
377
  }
@@ -3,7 +3,7 @@ import { nameFunction } from './functionName.js';
3
3
  export interface MyAsyncCallback<Argument extends unknown[]> {
4
4
  displayName?: string;
5
5
 
6
- (...param: Argument): Promise<void | undefined | boolean> | void | undefined | boolean;
6
+ (...param: Argument): Promise<undefined | undefined | boolean> | undefined | undefined | boolean;
7
7
  }
8
8
 
9
9
  /**
@@ -11,7 +11,7 @@ export interface MyAsyncCallback<Argument extends unknown[]> {
11
11
  */
12
12
  export class AsyncCallbackList<Argument extends unknown[]> {
13
13
  protected list: MyAsyncCallback<Argument>[] = [];
14
- protected running: boolean = false;
14
+ protected running = false;
15
15
 
16
16
  constructor() {
17
17
  this.run = (this.run as any).bind(this);
@@ -62,7 +62,7 @@ export class AsyncCallbackList<Argument extends unknown[]> {
62
62
  */
63
63
  async run(...argument: Argument): Promise<boolean> {
64
64
  this.running = true;
65
- let ret: boolean | undefined | void;
65
+ let ret: boolean | undefined | undefined;
66
66
  for (const cb of this.list) {
67
67
  ret = await cb(...argument);
68
68
  if (ret === true) {
@@ -11,8 +11,8 @@ export interface MyCallback<Argument extends unknown[]> {
11
11
  */
12
12
  export class CallbackList<Argument extends unknown[]> {
13
13
  protected list: MyCallback<Argument>[] = [];
14
- protected running: boolean = false;
15
- protected stop: boolean = false;
14
+ protected running = false;
15
+ protected stop = false;
16
16
 
17
17
  constructor() {
18
18
  this.run = (this.run as any).bind(this);
@@ -12,7 +12,7 @@ export interface MyDelayCallback<Argument extends unknown[]> {
12
12
  */
13
13
  export class DelayCallbackList<Argument extends unknown[]> {
14
14
  private delayArgument?: Argument;
15
- private delayComplete: boolean = false;
15
+ private delayComplete = false;
16
16
 
17
17
  protected list?: MyDelayCallback<Argument>[] = [];
18
18
 
@@ -27,7 +27,7 @@ export class DelayCallbackList<Argument extends unknown[]> {
27
27
  if (this.delayComplete) {
28
28
  item(...this.delayArgument!);
29
29
  } else {
30
- this.list!.push(item);
30
+ this.list?.push(item);
31
31
  }
32
32
  }
33
33
 
@@ -37,9 +37,9 @@ export class DelayCallbackList<Argument extends unknown[]> {
37
37
  }
38
38
  this.delayComplete = true;
39
39
  this.delayArgument = argument;
40
- this.list!.forEach((cb) => {
40
+ this.list?.forEach((cb) => {
41
41
  cb(...argument);
42
42
  });
43
- delete this.list;
43
+ this.list = undefined;
44
44
  }
45
45
  }
@@ -1,4 +1,4 @@
1
- import { IDisposable } from './lifecycle.js';
1
+ import type { IDisposable } from './lifecycle.js';
2
2
 
3
3
  declare const AbortController: new () => any;
4
4
 
@@ -86,9 +86,8 @@ function check(options: IEventListenerOptions = {}): [{ abort(): void } | undefi
86
86
  const controller = new AbortController();
87
87
  (options as any).signal = controller.signal;
88
88
  return [controller, options];
89
- } else {
90
- return [undefined, options];
91
89
  }
90
+ return [undefined, options];
92
91
  }
93
92
 
94
93
  function checkAllSupport(ele: IEventHostObject<any>) {
@@ -9,7 +9,7 @@ export class DisposedError extends Error {
9
9
  public readonly inspectString: string;
10
10
  constructor(
11
11
  object: any,
12
- public readonly previous: Error,
12
+ public readonly previous: Error
13
13
  ) {
14
14
  const insp = tryInspect(object);
15
15
  super(`Object [${insp}] has already disposed ${getErrorFrame(previous, 2)}.`);
@@ -1,7 +1,7 @@
1
1
  import { convertCatchedError } from '../../error/convertUnknown.js';
2
- import { Emitter, EventRegister } from '../event/event.js';
2
+ import { Emitter, type EventRegister } from '../event/event.js';
3
3
  import { DisposedError } from './disposedError.js';
4
- import { IAsyncDisposable, IDisposableEvents } from './lifecycle.js';
4
+ import type { IAsyncDisposable, IDisposableEvents } from './lifecycle.js';
5
5
 
6
6
  /**
7
7
  * Async version of Disposable
@@ -1,6 +1,6 @@
1
1
  import { globalSingletonStrong } from '../../platform/globalSingleton.js';
2
2
  import { createSymbol } from '../../platform/globalSymbol.js';
3
- import { IDisposable } from './lifecycle.js';
3
+ import type { IDisposable } from './lifecycle.js';
4
4
  import { AsyncDisposable } from './lifecycle.async.js';
5
5
 
6
6
  const symbol = createSymbol('lifecycle', 'application');
@@ -23,9 +23,8 @@ export function ensureDisposeGlobal() {
23
23
  const obj = globalSingletonStrong<AsyncDisposable>(symbol);
24
24
  if (obj && !obj.hasDisposed) {
25
25
  return Promise.resolve(obj.dispose());
26
- } else {
27
- return Promise.resolve();
28
26
  }
27
+ return Promise.resolve();
29
28
  }
30
29
 
31
30
  /**
@@ -36,13 +35,13 @@ export function ensureDisposeGlobal() {
36
35
  */
37
36
  export function disposeGlobal() {
38
37
  const obj = globalSingletonStrong<AsyncDisposable>(symbol);
39
- if (obj && obj.hasDisposed) {
38
+ if (obj?.hasDisposed) {
40
39
  throw new Error('global already disposed.');
41
- } else if (obj) {
40
+ }
41
+ if (obj) {
42
42
  return Promise.resolve(obj.dispose());
43
- } else {
44
- return Promise.resolve();
45
43
  }
44
+ return Promise.resolve();
46
45
  }
47
46
 
48
47
  /**
@@ -1,6 +1,6 @@
1
- import { Emitter, EventRegister } from '../event/event.js';
1
+ import { Emitter, type EventRegister } from '../event/event.js';
2
2
  import { DisposedError } from './disposedError.js';
3
- import { IDisposable, IDisposableEvents } from './lifecycle.js';
3
+ import type { IDisposable, IDisposableEvents } from './lifecycle.js';
4
4
 
5
5
  export abstract class DisposableOnce implements IDisposable {
6
6
  private _disposed?: Error;
@@ -85,7 +85,7 @@ export class Disposable implements IDisposable, IDisposableEvents {
85
85
  this._onDisposeError.fire(e);
86
86
  } else {
87
87
  console.error('error during dispose, throw:', e);
88
- this._onDisposeError.fire(new Error('' + e));
88
+ this._onDisposeError.fire(new Error(`${e}`));
89
89
  }
90
90
  }
91
91
  }
@@ -1,4 +1,4 @@
1
- import { EventRegister } from '../event/event.js';
1
+ import type { EventRegister } from '../event/event.js';
2
2
 
3
3
  /**
4
4
  * @private