@idlebox/common 1.4.2 → 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 (259) 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.map +1 -1
  34. package/lib/cjs/lifecycle/event/memorized.cjs +1 -1
  35. package/lib/cjs/lifecycle/event/memorized.cjs.map +1 -1
  36. package/lib/cjs/lifecycle/promise/cancellationToken/driver.common.cjs.map +1 -1
  37. package/lib/cjs/lifecycle/promise/deferredPromise.cjs +2 -2
  38. package/lib/cjs/lifecycle/promise/deferredPromise.cjs.map +1 -1
  39. package/lib/cjs/lifecycle/timeout/timeout.cjs +1 -3
  40. package/lib/cjs/lifecycle/timeout/timeout.cjs.map +1 -1
  41. package/lib/cjs/lifecycle/timeout/timeoutError.cjs.map +1 -1
  42. package/lib/cjs/log/logger.cjs +4 -6
  43. package/lib/cjs/log/logger.cjs.map +1 -1
  44. package/lib/cjs/mapSet/customSet.cjs +3 -7
  45. package/lib/cjs/mapSet/customSet.cjs.map +1 -1
  46. package/lib/cjs/mapSet/extendMap.cjs +5 -9
  47. package/lib/cjs/mapSet/extendMap.cjs.map +1 -1
  48. package/lib/cjs/misc/assertNotNull.cjs +1 -3
  49. package/lib/cjs/misc/assertNotNull.cjs.map +1 -1
  50. package/lib/cjs/misc/package.json.cjs +1 -1
  51. package/lib/cjs/misc/package.json.cjs.map +1 -1
  52. package/lib/cjs/object/initOnRead.cjs.map +1 -1
  53. package/lib/cjs/object/objectSame.cjs +2 -1
  54. package/lib/cjs/object/objectSame.cjs.map +1 -1
  55. package/lib/cjs/path/normalizePath.cjs +7 -9
  56. package/lib/cjs/path/normalizePath.cjs.map +1 -1
  57. package/lib/cjs/path/pathArray.cjs +1 -1
  58. package/lib/cjs/path/pathArray.cjs.map +1 -1
  59. package/lib/cjs/platform/globalSingleton.cjs +1 -1
  60. package/lib/cjs/platform/globalSymbol.cjs +6 -8
  61. package/lib/cjs/platform/globalSymbol.cjs.map +1 -1
  62. package/lib/cjs/promise/promiseCollection.cjs +3 -3
  63. package/lib/cjs/promise/promiseCollection.cjs.map +1 -1
  64. package/lib/cjs/reflection/classes/singleton.cjs +1 -3
  65. package/lib/cjs/reflection/classes/singleton.cjs.map +1 -1
  66. package/lib/cjs/reflection/methods/bind.cjs +1 -3
  67. package/lib/cjs/reflection/methods/bind.cjs.map +1 -1
  68. package/lib/cjs/reflection/methods/initOnRead.cjs +2 -2
  69. package/lib/cjs/reflection/methods/initOnRead.cjs.map +1 -1
  70. package/lib/cjs/string/castCase.cjs +5 -5
  71. package/lib/cjs/string/castCase.cjs.map +1 -1
  72. package/lib/cjs/string/pad2.cjs +2 -4
  73. package/lib/cjs/string/pad2.cjs.map +1 -1
  74. package/lib/cjs/string/sizeString.cjs +23 -27
  75. package/lib/cjs/string/sizeString.cjs.map +1 -1
  76. package/lib/esm/array/arrayUnique.d.ts +1 -3
  77. package/lib/esm/array/arrayUnique.d.ts.map +1 -1
  78. package/lib/esm/array/arrayUnique.js +2 -4
  79. package/lib/esm/array/arrayUnique.js.map +1 -1
  80. package/lib/esm/array/normalizeArray.js +2 -4
  81. package/lib/esm/array/normalizeArray.js.map +1 -1
  82. package/lib/esm/array/sortAlpha.js +2 -4
  83. package/lib/esm/array/sortAlpha.js.map +1 -1
  84. package/lib/esm/date/isInvalid.js +1 -1
  85. package/lib/esm/date/isInvalid.js.map +1 -1
  86. package/lib/esm/date/timeString.d.ts +1 -3
  87. package/lib/esm/date/timeString.d.ts.map +1 -1
  88. package/lib/esm/date/timeString.js +8 -10
  89. package/lib/esm/date/timeString.js.map +1 -1
  90. package/lib/esm/debugging/serializable.d.ts +1 -1
  91. package/lib/esm/debugging/serializable.d.ts.map +1 -1
  92. package/lib/esm/debugging/serializable.js +2 -2
  93. package/lib/esm/debugging/serializable.js.map +1 -1
  94. package/lib/esm/debugging/tryInspect.d.ts.map +1 -1
  95. package/lib/esm/debugging/tryInspect.js +7 -9
  96. package/lib/esm/debugging/tryInspect.js.map +1 -1
  97. package/lib/esm/error/convertUnknown.d.ts.map +1 -1
  98. package/lib/esm/error/convertUnknown.js +2 -4
  99. package/lib/esm/error/convertUnknown.js.map +1 -1
  100. package/lib/esm/error/getFrame.js +2 -2
  101. package/lib/esm/error/getFrame.js.map +1 -1
  102. package/lib/esm/error/known.d.ts.map +1 -1
  103. package/lib/esm/error/known.js.map +1 -1
  104. package/lib/esm/error/pretty.d.ts.map +1 -1
  105. package/lib/esm/error/pretty.js +22 -30
  106. package/lib/esm/error/pretty.js.map +1 -1
  107. package/lib/esm/function/asyncCallbackList.d.ts +1 -1
  108. package/lib/esm/function/asyncCallbackList.d.ts.map +1 -1
  109. package/lib/esm/function/asyncCallbackList.js.map +1 -1
  110. package/lib/esm/function/callbackList.d.ts.map +1 -1
  111. package/lib/esm/function/callbackList.js.map +1 -1
  112. package/lib/esm/function/delayCallbackList.d.ts.map +1 -1
  113. package/lib/esm/function/delayCallbackList.js +3 -3
  114. package/lib/esm/function/delayCallbackList.js.map +1 -1
  115. package/lib/esm/lifecycle/dispose/disposableEvent.d.ts +1 -1
  116. package/lib/esm/lifecycle/dispose/disposableEvent.d.ts.map +1 -1
  117. package/lib/esm/lifecycle/dispose/disposableEvent.js +1 -3
  118. package/lib/esm/lifecycle/dispose/disposableEvent.js.map +1 -1
  119. package/lib/esm/lifecycle/dispose/lifecycle.async.d.ts +2 -2
  120. package/lib/esm/lifecycle/dispose/lifecycle.async.d.ts.map +1 -1
  121. package/lib/esm/lifecycle/dispose/lifecycle.async.js.map +1 -1
  122. package/lib/esm/lifecycle/dispose/lifecycle.d.ts +1 -1
  123. package/lib/esm/lifecycle/dispose/lifecycle.d.ts.map +1 -1
  124. package/lib/esm/lifecycle/dispose/lifecycle.global.d.ts +1 -1
  125. package/lib/esm/lifecycle/dispose/lifecycle.global.d.ts.map +1 -1
  126. package/lib/esm/lifecycle/dispose/lifecycle.global.js +4 -8
  127. package/lib/esm/lifecycle/dispose/lifecycle.global.js.map +1 -1
  128. package/lib/esm/lifecycle/dispose/lifecycle.sync.d.ts +2 -2
  129. package/lib/esm/lifecycle/dispose/lifecycle.sync.d.ts.map +1 -1
  130. package/lib/esm/lifecycle/dispose/lifecycle.sync.js +1 -1
  131. package/lib/esm/lifecycle/dispose/lifecycle.sync.js.map +1 -1
  132. package/lib/esm/lifecycle/event/event.d.ts +3 -7
  133. package/lib/esm/lifecycle/event/event.d.ts.map +1 -1
  134. package/lib/esm/lifecycle/event/event.js.map +1 -1
  135. package/lib/esm/lifecycle/event/memorized.d.ts +2 -2
  136. package/lib/esm/lifecycle/event/memorized.d.ts.map +1 -1
  137. package/lib/esm/lifecycle/event/memorized.js +1 -1
  138. package/lib/esm/lifecycle/event/memorized.js.map +1 -1
  139. package/lib/esm/lifecycle/promise/cancellationToken/driver.common.js.map +1 -1
  140. package/lib/esm/lifecycle/promise/cancellationToken/source.d.ts +2 -2
  141. package/lib/esm/lifecycle/promise/cancellationToken/source.d.ts.map +1 -1
  142. package/lib/esm/lifecycle/promise/deferredPromise.js +2 -2
  143. package/lib/esm/lifecycle/promise/deferredPromise.js.map +1 -1
  144. package/lib/esm/lifecycle/timeout/timeout.js +1 -3
  145. package/lib/esm/lifecycle/timeout/timeout.js.map +1 -1
  146. package/lib/esm/lifecycle/timeout/timeoutError.d.ts.map +1 -1
  147. package/lib/esm/lifecycle/timeout/timeoutError.js.map +1 -1
  148. package/lib/esm/log/logger.d.ts.map +1 -1
  149. package/lib/esm/log/logger.js +4 -6
  150. package/lib/esm/log/logger.js.map +1 -1
  151. package/lib/esm/mapSet/customSet.d.ts +1 -3
  152. package/lib/esm/mapSet/customSet.d.ts.map +1 -1
  153. package/lib/esm/mapSet/customSet.js +3 -7
  154. package/lib/esm/mapSet/customSet.js.map +1 -1
  155. package/lib/esm/mapSet/extendMap.d.ts.map +1 -1
  156. package/lib/esm/mapSet/extendMap.js +5 -9
  157. package/lib/esm/mapSet/extendMap.js.map +1 -1
  158. package/lib/esm/misc/assertNotNull.d.ts.map +1 -1
  159. package/lib/esm/misc/assertNotNull.js +1 -3
  160. package/lib/esm/misc/assertNotNull.js.map +1 -1
  161. package/lib/esm/misc/package.json.js +1 -1
  162. package/lib/esm/misc/package.json.js.map +1 -1
  163. package/lib/esm/object/initOnRead.d.ts +1 -3
  164. package/lib/esm/object/initOnRead.d.ts.map +1 -1
  165. package/lib/esm/object/initOnRead.js.map +1 -1
  166. package/lib/esm/object/objectSame.js +2 -1
  167. package/lib/esm/object/objectSame.js.map +1 -1
  168. package/lib/esm/path/normalizePath.d.ts.map +1 -1
  169. package/lib/esm/path/normalizePath.js +7 -9
  170. package/lib/esm/path/normalizePath.js.map +1 -1
  171. package/lib/esm/path/pathArray.js +1 -1
  172. package/lib/esm/path/pathArray.js.map +1 -1
  173. package/lib/esm/platform/globalSingleton.js +1 -1
  174. package/lib/esm/platform/globalSymbol.d.ts.map +1 -1
  175. package/lib/esm/platform/globalSymbol.js +6 -8
  176. package/lib/esm/platform/globalSymbol.js.map +1 -1
  177. package/lib/esm/promise/promiseCollection.js +3 -3
  178. package/lib/esm/promise/promiseCollection.js.map +1 -1
  179. package/lib/esm/reflection/classes/hookClass.d.ts +1 -1
  180. package/lib/esm/reflection/classes/hookClass.d.ts.map +1 -1
  181. package/lib/esm/reflection/classes/singleton.d.ts.map +1 -1
  182. package/lib/esm/reflection/classes/singleton.js +1 -3
  183. package/lib/esm/reflection/classes/singleton.js.map +1 -1
  184. package/lib/esm/reflection/methods/bind.d.ts.map +1 -1
  185. package/lib/esm/reflection/methods/bind.js +1 -3
  186. package/lib/esm/reflection/methods/bind.js.map +1 -1
  187. package/lib/esm/reflection/methods/initOnRead.d.ts +1 -1
  188. package/lib/esm/reflection/methods/initOnRead.d.ts.map +1 -1
  189. package/lib/esm/reflection/methods/initOnRead.js +2 -2
  190. package/lib/esm/reflection/methods/initOnRead.js.map +1 -1
  191. package/lib/esm/string/castCase.js +5 -5
  192. package/lib/esm/string/castCase.js.map +1 -1
  193. package/lib/esm/string/pad2.d.ts.map +1 -1
  194. package/lib/esm/string/pad2.js +2 -4
  195. package/lib/esm/string/pad2.js.map +1 -1
  196. package/lib/esm/string/sizeString.d.ts.map +1 -1
  197. package/lib/esm/string/sizeString.js +23 -27
  198. package/lib/esm/string/sizeString.js.map +1 -1
  199. package/lib/esm/typingHelper/deep.partial.d.ts +1 -1
  200. package/lib/esm/typingHelper/deep.partial.d.ts.map +1 -1
  201. package/lib/esm/typingHelper/deep.readonly.d.ts +1 -1
  202. package/lib/esm/typingHelper/deep.readonly.d.ts.map +1 -1
  203. package/lib/esm/typingHelper/deep.required.d.ts +1 -1
  204. package/lib/esm/typingHelper/deep.required.d.ts.map +1 -1
  205. package/lib/esm/typingHelper/deep.writable.d.ts +1 -1
  206. package/lib/esm/typingHelper/deep.writable.d.ts.map +1 -1
  207. package/package.json +3 -3
  208. package/src/array/arrayUnique.ts +3 -6
  209. package/src/array/normalizeArray.ts +3 -3
  210. package/src/array/sortAlpha.ts +3 -3
  211. package/src/date/isInvalid.ts +1 -1
  212. package/src/date/timeString.ts +9 -15
  213. package/src/debugging/serializable.ts +8 -8
  214. package/src/debugging/tryInspect.ts +12 -8
  215. package/src/error/convertUnknown.ts +2 -3
  216. package/src/error/getFrame.ts +2 -2
  217. package/src/error/known.ts +2 -2
  218. package/src/error/pretty.ts +29 -34
  219. package/src/function/asyncCallbackList.ts +3 -3
  220. package/src/function/callbackList.ts +2 -2
  221. package/src/function/delayCallbackList.ts +4 -4
  222. package/src/lifecycle/dispose/disposableEvent.ts +2 -3
  223. package/src/lifecycle/dispose/disposedError.ts +1 -1
  224. package/src/lifecycle/dispose/lifecycle.async.ts +2 -2
  225. package/src/lifecycle/dispose/lifecycle.global.ts +6 -7
  226. package/src/lifecycle/dispose/lifecycle.sync.ts +3 -3
  227. package/src/lifecycle/dispose/lifecycle.ts +1 -1
  228. package/src/lifecycle/event/event.ts +4 -8
  229. package/src/lifecycle/event/memorized.ts +4 -4
  230. package/src/lifecycle/promise/cancellationToken/driver.browser.ts +1 -1
  231. package/src/lifecycle/promise/cancellationToken/driver.common.ts +2 -2
  232. package/src/lifecycle/promise/cancellationToken/source.ts +2 -2
  233. package/src/lifecycle/promise/deferredPromise.ts +2 -2
  234. package/src/lifecycle/timeout/timeout.ts +1 -2
  235. package/src/lifecycle/timeout/timeoutError.ts +1 -1
  236. package/src/log/logger.ts +8 -9
  237. package/src/mapSet/customSet.ts +4 -8
  238. package/src/mapSet/extendMap.ts +6 -7
  239. package/src/misc/assertNotNull.ts +1 -2
  240. package/src/misc/package.json.ts +1 -1
  241. package/src/object/initOnRead.ts +1 -3
  242. package/src/object/objectSame.ts +2 -2
  243. package/src/path/normalizePath.ts +14 -17
  244. package/src/path/pathArray.ts +2 -2
  245. package/src/platform/globalSingleton.ts +1 -1
  246. package/src/platform/globalSymbol.ts +8 -9
  247. package/src/promise/promiseCollection.ts +3 -3
  248. package/src/reflection/classes/hookClass.ts +1 -1
  249. package/src/reflection/classes/singleton.ts +3 -4
  250. package/src/reflection/methods/bind.ts +1 -2
  251. package/src/reflection/methods/initOnRead.ts +3 -3
  252. package/src/string/castCase.ts +5 -5
  253. package/src/string/pad2.ts +2 -3
  254. package/src/string/sizeString.ts +33 -25
  255. package/src/tsconfig.json +1 -1
  256. package/src/typingHelper/deep.partial.ts +7 -7
  257. package/src/typingHelper/deep.readonly.ts +7 -7
  258. package/src/typingHelper/deep.required.ts +7 -7
  259. package/src/typingHelper/deep.writable.ts +7 -7
@@ -10,12 +10,12 @@ const winLetter = /^[a-z]:[\/\\]/i;
10
10
  const doubleSlash = /^[\/\\]{2}[^\/\\]/i;
11
11
 
12
12
  export enum PathKind {
13
- url,
14
- unc,
15
- win,
16
- cifs,
17
- unix,
18
- relative,
13
+ url = 0,
14
+ unc = 1,
15
+ win = 2,
16
+ cifs = 3,
17
+ unix = 4,
18
+ relative = 5,
19
19
  }
20
20
  export interface IPathInfo {
21
21
  kind: PathKind;
@@ -31,18 +31,18 @@ export function analyzePath(p: string) {
31
31
  const u = new URL(p);
32
32
  r = {
33
33
  kind: PathKind.url,
34
- prefix: u.protocol + '//' + u.host,
34
+ prefix: `${u.protocol}//${u.host}`,
35
35
  path: u.pathname.slice(1),
36
36
  url: u,
37
37
  };
38
38
  } else if (unc.test(p)) {
39
39
  p = p.replace(unc, '').replace(/^[\/\\]+/, '');
40
40
  const i = /[\///]/.exec(p)?.index ?? -1;
41
- if (i <= 0) throw new Error('invalid unc path: ' + inp);
41
+ if (i <= 0) throw new Error(`invalid unc path: ${inp}`);
42
42
 
43
43
  r = {
44
44
  kind: PathKind.unc,
45
- prefix: '//?/UNC/' + p.slice(0, i),
45
+ prefix: `//?/UNC/${p.slice(0, i)}`,
46
46
  path: p.slice(i + 1),
47
47
  };
48
48
  } else if (winSp.test(p) || winLetter.test(p)) {
@@ -56,11 +56,11 @@ export function analyzePath(p: string) {
56
56
  } else if (doubleSlash.test(p)) {
57
57
  p = p.replace(/^[\/\\]+/, '');
58
58
  const i = /[\///]/.exec(p)?.index ?? -1;
59
- if (i <= 0) throw new Error('invalid cifs url: ' + inp);
59
+ if (i <= 0) throw new Error(`invalid cifs url: ${inp}`);
60
60
 
61
61
  r = {
62
62
  kind: PathKind.cifs,
63
- prefix: '//' + p.slice(0, i),
63
+ prefix: `//${p.slice(0, i)}`,
64
64
  path: p.slice(i + 1),
65
65
  };
66
66
  } else if (p.startsWith('/')) {
@@ -103,9 +103,8 @@ export function normalizePath(p: string) {
103
103
 
104
104
  if (r.prefix === undefined) {
105
105
  return r.path;
106
- } else {
107
- return `${r.prefix}/${r.path}`;
108
106
  }
107
+ return `${r.prefix}/${r.path}`;
109
108
  }
110
109
 
111
110
  export function relativePath(from: string, to: string) {
@@ -113,9 +112,7 @@ export function relativePath(from: string, to: string) {
113
112
  const r2 = analyzePath(to);
114
113
  if (r1.kind !== r2.kind)
115
114
  throw new Error(
116
- `cannot relative path between different kind: "${PathKind[r1.kind]}::${from}" * "${
117
- PathKind[r2.kind]
118
- }::${to}"`,
115
+ `cannot relative path between different kind: "${PathKind[r1.kind]}::${from}" * "${PathKind[r2.kind]}::${to}"`
119
116
  );
120
117
 
121
118
  if (r1.prefix !== r2.prefix) return to;
@@ -132,7 +129,7 @@ export function relativePath(from: string, to: string) {
132
129
  p2arr.splice(0, i);
133
130
 
134
131
  // add ..
135
- const p1 = p1arr.length > 0 ? p1arr.map(() => '..').join('/') + '/' : '';
132
+ const p1 = p1arr.length > 0 ? `${p1arr.map(() => '..').join('/')}/` : '';
136
133
  const p2 = p2arr.join('/');
137
134
 
138
135
  return p1 + p2;
@@ -10,7 +10,7 @@ const isAbsolute = /^[a-z]:[/\\]/i;
10
10
  abstract class PathArrayAbstract extends Set<string> {
11
11
  constructor(
12
12
  init: string,
13
- private readonly sep: ':' | ';' = isWindows ? ';' : ':',
13
+ private readonly sep: ':' | ';' = isWindows ? ';' : ':'
14
14
  ) {
15
15
  super();
16
16
  if (init) this.add(init);
@@ -44,7 +44,7 @@ abstract class PathArrayAbstract extends Set<string> {
44
44
  * @returns an array with `part` append to every element
45
45
  */
46
46
  join(part: string) {
47
- return [...this.values()].map((p) => normalizePath(p + '/' + part));
47
+ return [...this.values()].map((p) => normalizePath(`${p}/${part}`));
48
48
  }
49
49
  }
50
50
 
@@ -1,7 +1,7 @@
1
1
  import { functionName } from '../function/functionName.js';
2
2
  import { ensureGlobalObject } from './globalObject.js';
3
3
 
4
- const singletonRegistry = ensureGlobalObject(`@@idlebox/global-singleton`, () => {
4
+ const singletonRegistry = ensureGlobalObject('@@idlebox/global-singleton', () => {
5
5
  return new Map<string | symbol, any>();
6
6
  });
7
7
 
@@ -1,6 +1,6 @@
1
1
  import { ensureGlobalObject } from './globalObject.js';
2
2
 
3
- const symbolRegistry = ensureGlobalObject(`@@idlebox/global-symbol`, () => {
3
+ const symbolRegistry = ensureGlobalObject('@@idlebox/global-symbol', () => {
4
4
  return {} as Record<string, Record<string, symbol>>;
5
5
  });
6
6
 
@@ -12,15 +12,14 @@ const symbolRegistry = ensureGlobalObject(`@@idlebox/global-symbol`, () => {
12
12
  */
13
13
  export function createSymbol(category: string, name: string): symbol {
14
14
  if (symbolRegistry[category]?.[name]) {
15
- return symbolRegistry[category]![name]!;
16
- } else {
17
- if (!symbolRegistry[category]) {
18
- symbolRegistry[category] = {};
19
- }
20
- const c = symbolRegistry[category]!;
21
-
22
- return (c[name] = Symbol(name));
15
+ return symbolRegistry[category]?.[name]!;
23
16
  }
17
+ if (!symbolRegistry[category]) {
18
+ symbolRegistry[category] = {};
19
+ }
20
+ const c = symbolRegistry[category]!;
21
+
22
+ return (c[name] = Symbol(name));
24
23
  }
25
24
 
26
25
  /**
@@ -10,7 +10,7 @@ export class PromiseCollection {
10
10
 
11
11
  create(id: string) {
12
12
  if (this.promiseList[id]) {
13
- throw new Error('duplicate promise with id ' + id);
13
+ throw new Error(`duplicate promise with id ${id}`);
14
14
  }
15
15
  const dfd = new DeferredPromise<any>();
16
16
  this.promiseList[id] = dfd;
@@ -22,12 +22,12 @@ export class PromiseCollection {
22
22
  }
23
23
 
24
24
  done(id: string, data: any) {
25
- this.promiseList[id]!.complete(data);
25
+ this.promiseList[id]?.complete(data);
26
26
  delete this.promiseList[id];
27
27
  }
28
28
 
29
29
  error(id: string, e: Error) {
30
- this.promiseList[id]!.error(e);
30
+ this.promiseList[id]?.error(e);
31
31
  delete this.promiseList[id];
32
32
  }
33
33
 
@@ -6,7 +6,7 @@ interface IConstructorOf<T> extends Object {
6
6
 
7
7
  interface IHooks<T, TC> {
8
8
  afterConstruct?: ((obj: T) => void)[];
9
- beforeConstruct?: ((obj: TC) => T | void)[];
9
+ beforeConstruct?: ((obj: TC) => T | undefined)[];
10
10
  }
11
11
 
12
12
  export function hookClass<TC extends IConstructorOf<T>, T>(target: TC): IHooks<T, TC> {
@@ -3,8 +3,8 @@ import { hookClass } from './hookClass.js';
3
3
  export const singletonSymbol = Symbol('@gongt/singleton');
4
4
 
5
5
  export enum SingletonType {
6
- Throw,
7
- Return,
6
+ Throw = 0,
7
+ Return = 1,
8
8
  }
9
9
 
10
10
  export function singleton(type: SingletonType = SingletonType.Return): ClassDecorator {
@@ -21,9 +21,8 @@ export function singleton(type: SingletonType = SingletonType.Return): ClassDeco
21
21
  if (cls[singletonSymbol]) {
22
22
  if (type === SingletonType.Return) {
23
23
  return cls[singletonSymbol];
24
- } else {
25
- throw new Error(`Duplicate new singleton class [${target.name}]`);
26
24
  }
25
+ throw new Error(`Duplicate new singleton class [${target.name}]`);
27
26
  }
28
27
  });
29
28
  hook.afterConstruct.push((obj) => {
@@ -24,7 +24,6 @@ export const bindThis: MethodDecorator = <T>(
24
24
  return fn;
25
25
  },
26
26
  };
27
- } else {
28
- throw new TypeError('@bindThis can only use with method, but not property.');
29
27
  }
28
+ throw new TypeError('@bindThis can only use with method, but not property.');
30
29
  };
@@ -1,11 +1,11 @@
1
- import { InitFunc, initOnRead } from '../../object/initOnRead.js';
1
+ import { type InitFunc, initOnRead } from '../../object/initOnRead.js';
2
2
 
3
3
  /**
4
4
  * Decorater version of `initOnRead`
5
5
  * @see initOnRead
6
6
  */
7
7
  export function init<O, T extends keyof O>(init: InitFunc<O, O[T]>): PropertyDecorator {
8
- return function (target: O, propertyKey: T) {
8
+ return ((target: O, propertyKey: T) => {
9
9
  initOnRead<O, T>(target, propertyKey, init);
10
- } as any;
10
+ }) as any;
11
11
  }
@@ -2,7 +2,7 @@
2
2
  export function camelCase(str: string) {
3
3
  return str
4
4
  .replace(/[-.\/_]+[a-z]/g, (s) => {
5
- return s[1]!.toUpperCase();
5
+ return s[1]?.toUpperCase();
6
6
  })
7
7
  .replace(/[-.\/_]+/g, '');
8
8
  }
@@ -12,7 +12,7 @@ export function camelCase(str: string) {
12
12
  * @public
13
13
  */
14
14
  export function ucfirst<T extends string>(str: T): Capitalize<T> {
15
- return <any>(str[0]!.toUpperCase() + str.slice(1));
15
+ return <any>(str[0]?.toUpperCase() + str.slice(1));
16
16
  }
17
17
 
18
18
  /**
@@ -20,7 +20,7 @@ export function ucfirst<T extends string>(str: T): Capitalize<T> {
20
20
  * @public
21
21
  */
22
22
  export function lcfirst<T extends string>(str: T): Uncapitalize<T> {
23
- return <any>(str[0]!.toLowerCase() + str.slice(1));
23
+ return <any>(str[0]?.toLowerCase() + str.slice(1));
24
24
  }
25
25
 
26
26
  /** @public */
@@ -30,7 +30,7 @@ export function linux_case(str: string) {
30
30
  return s.toLowerCase();
31
31
  })
32
32
  .replace(/[A-Z]+/g, (s) => {
33
- return '_' + s.toLowerCase();
33
+ return `_${s.toLowerCase()}`;
34
34
  })
35
35
  .replace(/[-.\/_]+/g, '_');
36
36
  }
@@ -42,7 +42,7 @@ export function linux_case_hyphen(str: string) {
42
42
  return s.toLowerCase();
43
43
  })
44
44
  .replace(/[A-Z]+/g, (s) => {
45
- return '-' + s.toLowerCase();
45
+ return `-${s.toLowerCase()}`;
46
46
  })
47
47
  .replace(/[-.\/_]+/g, '-');
48
48
  }
@@ -4,8 +4,7 @@
4
4
  */
5
5
  export function pad2(s: number) {
6
6
  if (s < 10) {
7
- return '0' + s;
8
- } else {
9
- return '' + s;
7
+ return `0${s}`;
10
8
  }
9
+ return `${s}`;
11
10
  }
@@ -5,19 +5,23 @@
5
5
  export function humanSizeSI(bytes: number, fixed = 2) {
6
6
  if (bytes < 0) {
7
7
  return '<0B';
8
- } else if (bytes < 1000) {
9
- return bytes + 'B';
10
- } else if (bytes < 1000000) {
11
- return (bytes / 1000).toFixed(fixed) + 'KiB';
12
- } else if (bytes < 1000000000) {
13
- return (bytes / 1000000).toFixed(fixed) + 'MiB';
14
- } else if (bytes < 1000000000000) {
15
- return (bytes / 1000000000).toFixed(fixed) + 'GiB';
16
- } else if (bytes < 1000000000000000) {
17
- return (bytes / 1000000000000).toFixed(fixed) + 'TiB';
18
- } else {
19
- return (bytes / 1000000000000000).toFixed(fixed) + 'PiB';
20
8
  }
9
+ if (bytes < 1000) {
10
+ return `${bytes}B`;
11
+ }
12
+ if (bytes < 1000000) {
13
+ return `${(bytes / 1000).toFixed(fixed)}KiB`;
14
+ }
15
+ if (bytes < 1000000000) {
16
+ return `${(bytes / 1000000).toFixed(fixed)}MiB`;
17
+ }
18
+ if (bytes < 1000000000000) {
19
+ return `${(bytes / 1000000000).toFixed(fixed)}GiB`;
20
+ }
21
+ if (bytes < 1000000000000000) {
22
+ return `${(bytes / 1000000000000).toFixed(fixed)}TiB`;
23
+ }
24
+ return `${(bytes / 1000000000000000).toFixed(fixed)}PiB`;
21
25
  }
22
26
 
23
27
  /**
@@ -27,26 +31,30 @@ export function humanSizeSI(bytes: number, fixed = 2) {
27
31
  export function humanSize(bytes: number, fixed = 2) {
28
32
  if (bytes < 0) {
29
33
  return '<0B';
30
- } else if (bytes < 1024) {
31
- return bytes + 'B';
32
- } else if (bytes < 1048576) {
34
+ }
35
+ if (bytes < 1024) {
36
+ return `${bytes}B`;
37
+ }
38
+ if (bytes < 1048576) {
33
39
  // 1024 * 1024
34
- return (bytes / 1024).toFixed(fixed) + 'KiB';
35
- } else if (bytes < 1073741824) {
40
+ return `${(bytes / 1024).toFixed(fixed)}KiB`;
41
+ }
42
+ if (bytes < 1073741824) {
36
43
  // 1024 * 1024 * 1024
37
- return (bytes / 1048576).toFixed(fixed) + 'MiB';
38
- } else if (bytes < 1099511627776) {
44
+ return `${(bytes / 1048576).toFixed(fixed)}MiB`;
45
+ }
46
+ if (bytes < 1099511627776) {
39
47
  // 1024 * 1024 * 1024 * 1024
40
- return (bytes / 1073741824).toFixed(fixed) + 'GiB';
41
- } else if (bytes < 1125899906842624) {
48
+ return `${(bytes / 1073741824).toFixed(fixed)}GiB`;
49
+ }
50
+ if (bytes < 1125899906842624) {
42
51
  // 1024 * 1024 * 1024 * 1024 * 1024
43
- return (bytes / 1099511627776).toFixed(fixed) + 'TiB';
44
- } else {
45
- return (bytes / 1125899906842624).toFixed(fixed) + 'PiB';
52
+ return `${(bytes / 1099511627776).toFixed(fixed)}TiB`;
46
53
  }
54
+ return `${(bytes / 1125899906842624).toFixed(fixed)}PiB`;
47
55
  }
48
56
 
49
57
  /** @deprecated */
50
58
  export function humanSpeed(bps: number) {
51
- return humanSize(bps) + '/s';
59
+ return `${humanSize(bps)}/s`;
52
60
  }
package/src/tsconfig.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "outDir": "../lib/esm",
6
6
  "rootDir": "./",
7
7
  },
8
- "exclude": ["**/*.generator.ts"]
8
+ "exclude": ["**/*.generator.ts"],
9
9
  }
@@ -1,14 +1,14 @@
1
- import { Primitive } from './literal.js';
1
+ import type { Primitive } from './literal.js';
2
2
 
3
3
  export type DeepPartial<T> = T extends Primitive
4
4
  ? T
5
5
  : T extends ReadonlyArray<infer U>
6
- ? DeepPartialArray<U>
7
- : T extends ReadonlyMap<infer K, infer V>
8
- ? DeepPartialMap<K, V>
9
- : T extends ReadonlySet<infer M>
10
- ? DeepPartialSet<M>
11
- : DeepPartialObject<T>;
6
+ ? DeepPartialArray<U>
7
+ : T extends ReadonlyMap<infer K, infer V>
8
+ ? DeepPartialMap<K, V>
9
+ : T extends ReadonlySet<infer M>
10
+ ? DeepPartialSet<M>
11
+ : DeepPartialObject<T>;
12
12
 
13
13
  type DeepPartialArray<T> = Array<DeepPartial<T>>;
14
14
  type DeepPartialMap<K, V> = Map<DeepPartial<K>, DeepPartial<V>>;
@@ -1,14 +1,14 @@
1
- import { Primitive } from './literal.js';
1
+ import type { Primitive } from './literal.js';
2
2
 
3
3
  export type DeepReadonly<T> = T extends Primitive
4
4
  ? T
5
5
  : T extends Array<infer U>
6
- ? DeepReadonlyArray<U>
7
- : T extends Map<infer K, infer V>
8
- ? DeepReadonlyMap<K, V>
9
- : T extends Set<infer M>
10
- ? DeepReadonlySet<M>
11
- : DeepReadonlyObject<T>;
6
+ ? DeepReadonlyArray<U>
7
+ : T extends Map<infer K, infer V>
8
+ ? DeepReadonlyMap<K, V>
9
+ : T extends Set<infer M>
10
+ ? DeepReadonlySet<M>
11
+ : DeepReadonlyObject<T>;
12
12
 
13
13
  type DeepReadonlyArray<T> = ReadonlyArray<DeepReadonly<T>>;
14
14
  type DeepReadonlyMap<K, V> = ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>;
@@ -1,14 +1,14 @@
1
- import { Primitive } from './literal.js';
1
+ import type { Primitive } from './literal.js';
2
2
 
3
3
  export type DeepNonNullable<T> = T extends Primitive
4
4
  ? T
5
5
  : T extends ReadonlyArray<infer U> | Array<infer U>
6
- ? DeepNonNullableArray<U>
7
- : T extends ReadonlyMap<infer K, infer V> | Map<infer K, infer V>
8
- ? DeepNonNullableMap<K, V>
9
- : T extends ReadonlySet<infer M>
10
- ? DeepNonNullableSet<M>
11
- : DeepNonNullableObject<T>;
6
+ ? DeepNonNullableArray<U>
7
+ : T extends ReadonlyMap<infer K, infer V> | Map<infer K, infer V>
8
+ ? DeepNonNullableMap<K, V>
9
+ : T extends ReadonlySet<infer M>
10
+ ? DeepNonNullableSet<M>
11
+ : DeepNonNullableObject<T>;
12
12
 
13
13
  type DeepNonNullableArray<T> = Array<DeepNonNullable<T>>;
14
14
  type DeepNonNullableMap<K, V> = Map<DeepNonNullable<K>, DeepNonNullable<V>>;
@@ -1,14 +1,14 @@
1
- import { Primitive } from './literal.js';
1
+ import type { Primitive } from './literal.js';
2
2
 
3
3
  export type DeepWriteable<T> = T extends Primitive
4
4
  ? T
5
5
  : T extends ReadonlyArray<infer U>
6
- ? DeepWriteableArray<U>
7
- : T extends ReadonlyMap<infer K, infer V>
8
- ? DeepWriteableMap<K, V>
9
- : T extends ReadonlySet<infer M>
10
- ? DeepWriteableSet<M>
11
- : DeepWriteableObject<T>;
6
+ ? DeepWriteableArray<U>
7
+ : T extends ReadonlyMap<infer K, infer V>
8
+ ? DeepWriteableMap<K, V>
9
+ : T extends ReadonlySet<infer M>
10
+ ? DeepWriteableSet<M>
11
+ : DeepWriteableObject<T>;
12
12
 
13
13
  type DeepWriteableArray<T> = Array<DeepWriteable<T>>;
14
14
  type DeepWriteableMap<K, V> = Map<DeepWriteable<K>, DeepWriteable<V>>;