@noeldemartin/utils 0.7.3 → 0.8.0

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 (234) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +13 -0
  2. package/dist/fluent/FluentArray.d.ts +48 -0
  3. package/dist/fluent/FluentArray.js +48 -0
  4. package/dist/fluent/FluentArray.js.map +1 -0
  5. package/dist/fluent/FluentObject.d.ts +16 -0
  6. package/dist/fluent/FluentObject.js +45 -0
  7. package/dist/fluent/FluentObject.js.map +1 -0
  8. package/dist/fluent/FluentString.d.ts +21 -0
  9. package/dist/fluent/FluentString.js +28 -0
  10. package/dist/fluent/FluentString.js.map +1 -0
  11. package/dist/fluent/facade.d.ts +17 -0
  12. package/dist/fluent/facade.js +45 -0
  13. package/dist/fluent/facade.js.map +1 -0
  14. package/dist/fluent/index.d.ts +29 -0
  15. package/dist/fluent/index.js +41 -0
  16. package/dist/fluent/index.js.map +1 -0
  17. package/dist/fluent/invade.d.ts +6 -0
  18. package/dist/fluent/invade.js +8 -0
  19. package/dist/fluent/invade.js.map +1 -0
  20. package/dist/fluent/lazyFacade.d.ts +16 -0
  21. package/dist/fluent/lazyFacade.js +67 -0
  22. package/dist/fluent/lazyFacade.js.map +1 -0
  23. package/dist/fluent/noop.d.ts +4 -0
  24. package/dist/fluent/noop.js +6 -0
  25. package/dist/fluent/noop.js.map +1 -0
  26. package/dist/fluent/required.d.ts +5 -0
  27. package/dist/fluent/required.js +32 -0
  28. package/dist/fluent/required.js.map +1 -0
  29. package/dist/fluent/tap.d.ts +7 -0
  30. package/dist/fluent/tap.js +22 -0
  31. package/dist/fluent/tap.js.map +1 -0
  32. package/dist/fluent/value.d.ts +5 -0
  33. package/dist/fluent/value.js +8 -0
  34. package/dist/fluent/value.js.map +1 -0
  35. package/dist/fluent/when.d.ts +6 -0
  36. package/dist/fluent/when.js +11 -0
  37. package/dist/fluent/when.js.map +1 -0
  38. package/dist/helpers/InMemoryStorageService.d.ts +8 -0
  39. package/dist/helpers/InMemoryStorageService.js +16 -0
  40. package/dist/helpers/InMemoryStorageService.js.map +1 -0
  41. package/dist/helpers/IndexedDBMap.d.ts +17 -0
  42. package/dist/helpers/IndexedDBMap.js +52 -0
  43. package/dist/helpers/IndexedDBMap.js.map +1 -0
  44. package/dist/helpers/JSError.d.ts +14 -0
  45. package/dist/helpers/JSError.js +14 -0
  46. package/dist/helpers/JSError.js.map +1 -0
  47. package/dist/helpers/ListenersManager.d.ts +15 -0
  48. package/dist/helpers/ListenersManager.js +23 -0
  49. package/dist/helpers/ListenersManager.js.map +1 -0
  50. package/dist/helpers/MagicObject.d.ts +29 -0
  51. package/dist/helpers/MagicObject.js +77 -0
  52. package/dist/helpers/MagicObject.js.map +1 -0
  53. package/dist/helpers/ObjectsMap.d.ts +28 -0
  54. package/dist/helpers/ObjectsMap.js +86 -0
  55. package/dist/helpers/ObjectsMap.js.map +1 -0
  56. package/dist/helpers/PromisedValue.d.ts +32 -0
  57. package/dist/helpers/PromisedValue.js +68 -0
  58. package/dist/helpers/PromisedValue.js.map +1 -0
  59. package/dist/helpers/Semaphore.d.ts +14 -0
  60. package/dist/helpers/Semaphore.js +45 -0
  61. package/dist/helpers/Semaphore.js.map +1 -0
  62. package/dist/helpers/Storage.d.ts +17 -0
  63. package/dist/helpers/Storage.js +39 -0
  64. package/dist/helpers/Storage.js.map +1 -0
  65. package/dist/helpers/array_helpers.d.ts +57 -0
  66. package/dist/helpers/array_helpers.js +208 -0
  67. package/dist/helpers/array_helpers.js.map +1 -0
  68. package/dist/helpers/boolean_helpers.d.ts +4 -0
  69. package/dist/helpers/boolean_helpers.js +10 -0
  70. package/dist/helpers/boolean_helpers.js.map +1 -0
  71. package/dist/helpers/caching_helpers.d.ts +17 -0
  72. package/dist/helpers/caching_helpers.js +55 -0
  73. package/dist/helpers/caching_helpers.js.map +1 -0
  74. package/dist/helpers/chaos_helpers.d.ts +6 -0
  75. package/dist/helpers/chaos_helpers.js +11 -0
  76. package/dist/helpers/chaos_helpers.js.map +1 -0
  77. package/dist/helpers/date_helpers.d.ts +4 -0
  78. package/dist/helpers/date_helpers.js +15 -0
  79. package/dist/helpers/date_helpers.js.map +1 -0
  80. package/dist/helpers/deprecated.d.ts +24 -0
  81. package/dist/helpers/env.d.ts +9 -0
  82. package/dist/helpers/env.js +42 -0
  83. package/dist/helpers/env.js.map +1 -0
  84. package/dist/helpers/error_helpers.d.ts +12 -0
  85. package/dist/helpers/error_helpers.js +20 -0
  86. package/dist/helpers/error_helpers.js.map +1 -0
  87. package/dist/helpers/escape_helpers.d.ts +5 -0
  88. package/dist/helpers/escape_helpers.js +11 -0
  89. package/dist/helpers/escape_helpers.js.map +1 -0
  90. package/dist/helpers/file_helpers.d.ts +4 -0
  91. package/dist/helpers/file_helpers.js +16 -0
  92. package/dist/helpers/file_helpers.js.map +1 -0
  93. package/dist/helpers/format_helpers.d.ts +7 -0
  94. package/dist/helpers/format_helpers.js +28 -0
  95. package/dist/helpers/format_helpers.js.map +1 -0
  96. package/dist/helpers/hash_helpers.d.ts +4 -0
  97. package/dist/helpers/hash_helpers.js +156 -0
  98. package/dist/helpers/hash_helpers.js.map +1 -0
  99. package/dist/helpers/identity_helpers.d.ts +5 -0
  100. package/dist/helpers/identity_helpers.js +15 -0
  101. package/dist/helpers/identity_helpers.js.map +1 -0
  102. package/dist/helpers/location_helpers.d.ts +8 -0
  103. package/dist/helpers/location_helpers.js +37 -0
  104. package/dist/helpers/location_helpers.js.map +1 -0
  105. package/dist/helpers/logical_helpers.d.ts +4 -0
  106. package/dist/helpers/logical_helpers.js +13 -0
  107. package/dist/helpers/logical_helpers.js.map +1 -0
  108. package/dist/helpers/math_helpers.d.ts +5 -0
  109. package/dist/helpers/math_helpers.js +12 -0
  110. package/dist/helpers/math_helpers.js.map +1 -0
  111. package/dist/helpers/mixin_helpers.d.ts +20 -0
  112. package/dist/helpers/mixin_helpers.js +43 -0
  113. package/dist/helpers/mixin_helpers.js.map +1 -0
  114. package/dist/helpers/network_helpers.d.ts +4 -0
  115. package/dist/helpers/network_helpers.js +8 -0
  116. package/dist/helpers/network_helpers.js.map +1 -0
  117. package/dist/helpers/object_helpers.d.ts +58 -0
  118. package/dist/helpers/object_helpers.js +179 -0
  119. package/dist/helpers/object_helpers.js.map +1 -0
  120. package/dist/helpers/promise_helpers.d.ts +10 -0
  121. package/dist/helpers/promise_helpers.js +25 -0
  122. package/dist/helpers/promise_helpers.js.map +1 -0
  123. package/dist/helpers/replacements-scope.js +21 -0
  124. package/dist/helpers/replacements-scope.js.map +1 -0
  125. package/dist/helpers/replacements.d.ts +5 -0
  126. package/dist/helpers/replacements.js +34 -0
  127. package/dist/helpers/replacements.js.map +1 -0
  128. package/dist/helpers/runtime_helpers.d.ts +4 -0
  129. package/dist/helpers/runtime_helpers.js +8 -0
  130. package/dist/helpers/runtime_helpers.js.map +1 -0
  131. package/dist/helpers/string_helpers.d.ts +17 -0
  132. package/dist/helpers/string_helpers.js +42 -0
  133. package/dist/helpers/string_helpers.js.map +1 -0
  134. package/dist/helpers/time_constants.d.ts +15 -0
  135. package/dist/helpers/time_constants.js +17 -0
  136. package/dist/helpers/time_constants.js.map +1 -0
  137. package/dist/helpers/time_helpers.d.ts +24 -0
  138. package/dist/helpers/time_helpers.js +57 -0
  139. package/dist/helpers/time_helpers.js.map +1 -0
  140. package/dist/helpers/url_helpers.d.ts +24 -0
  141. package/dist/helpers/url_helpers.js +90 -0
  142. package/dist/helpers/url_helpers.js.map +1 -0
  143. package/dist/helpers/value_helpers.d.ts +7 -0
  144. package/dist/helpers/value_helpers.js +11 -0
  145. package/dist/helpers/value_helpers.js.map +1 -0
  146. package/dist/index.d.ts +53 -0
  147. package/dist/index.js +49 -0
  148. package/dist/types/arrays.d.ts +12 -0
  149. package/dist/types/classes.d.ts +12 -0
  150. package/dist/types/helpers.d.ts +36 -0
  151. package/dist/types/helpers.js +6 -0
  152. package/dist/types/helpers.js.map +1 -0
  153. package/dist/types/objects.d.ts +8 -0
  154. package/package.json +38 -52
  155. package/src/fluent/FluentArray.test.ts +2 -9
  156. package/src/fluent/FluentArray.ts +6 -5
  157. package/src/fluent/FluentObject.ts +2 -4
  158. package/src/fluent/FluentString.test.ts +1 -8
  159. package/src/fluent/FluentString.ts +0 -2
  160. package/src/fluent/facade.test.ts +16 -4
  161. package/src/fluent/facade.ts +6 -4
  162. package/src/fluent/index.test.ts +3 -8
  163. package/src/fluent/index.ts +3 -3
  164. package/src/fluent/invade.test.ts +1 -5
  165. package/src/fluent/invade.ts +1 -1
  166. package/src/fluent/lazyFacade.test.ts +191 -0
  167. package/src/fluent/lazyFacade.ts +115 -0
  168. package/src/fluent/required.test.ts +1 -5
  169. package/src/fluent/required.ts +2 -4
  170. package/src/fluent/tap.test.ts +2 -9
  171. package/src/fluent/tap.ts +4 -3
  172. package/src/fluent/value.test.ts +1 -4
  173. package/src/fluent/when.test.ts +1 -6
  174. package/src/fluent/when.ts +2 -2
  175. package/src/helpers/InMemoryStorageService.ts +13 -0
  176. package/src/helpers/IndexedDBMap.ts +0 -2
  177. package/src/helpers/JSError.test.ts +1 -6
  178. package/src/helpers/JSError.ts +0 -2
  179. package/src/helpers/ListenersManager.test.ts +3 -7
  180. package/src/helpers/ListenersManager.ts +2 -4
  181. package/src/helpers/MagicObject.test.ts +14 -8
  182. package/src/helpers/MagicObject.ts +12 -3
  183. package/src/helpers/ObjectsMap.test.ts +1 -3
  184. package/src/helpers/ObjectsMap.ts +1 -5
  185. package/src/helpers/PromisedValue.test.ts +1 -3
  186. package/src/helpers/PromisedValue.ts +5 -6
  187. package/src/helpers/Semaphore.test.ts +6 -10
  188. package/src/helpers/Semaphore.ts +0 -2
  189. package/src/helpers/Storage.test.ts +47 -0
  190. package/src/helpers/Storage.ts +11 -19
  191. package/src/helpers/array_helpers.test.ts +127 -38
  192. package/src/helpers/array_helpers.ts +137 -78
  193. package/src/helpers/caching_helpers.test.ts +1 -3
  194. package/src/helpers/caching_helpers.ts +2 -2
  195. package/src/helpers/date_helpers.test.ts +1 -4
  196. package/src/helpers/date_helpers.ts +1 -1
  197. package/src/helpers/env.ts +5 -1
  198. package/src/helpers/error_helpers.test.ts +9 -8
  199. package/src/helpers/error_helpers.ts +11 -11
  200. package/src/helpers/format_helpers.test.ts +2 -4
  201. package/src/helpers/hash_helpers.test.ts +1 -4
  202. package/src/helpers/hash_helpers.ts +3 -3
  203. package/src/helpers/identity_helpers.test.ts +1 -3
  204. package/src/helpers/index.ts +3 -0
  205. package/src/helpers/logical_helpers.test.ts +1 -3
  206. package/src/helpers/logical_helpers.ts +1 -1
  207. package/src/helpers/math_helpers.test.ts +1 -3
  208. package/src/helpers/mixin_helpers.stubs.ts +1 -13
  209. package/src/helpers/mixin_helpers.test.ts +2 -7
  210. package/src/helpers/mixin_helpers.ts +6 -9
  211. package/src/helpers/object_helpers.test.ts +32 -19
  212. package/src/helpers/object_helpers.ts +43 -21
  213. package/src/helpers/promise_helpers.test.ts +1 -4
  214. package/src/helpers/promise_helpers.ts +9 -9
  215. package/src/helpers/replacements-scope.ts +15 -0
  216. package/src/helpers/replacements.test.ts +23 -0
  217. package/src/helpers/replacements.ts +52 -0
  218. package/src/helpers/runtime_helpers.ts +3 -3
  219. package/src/helpers/string_helpers.test.ts +3 -5
  220. package/src/helpers/time_constants.ts +13 -0
  221. package/src/helpers/time_helpers.ts +35 -0
  222. package/src/helpers/url_helpers.test.ts +12 -4
  223. package/src/helpers/url_helpers.ts +9 -15
  224. package/src/helpers/value_helpers.test.ts +12 -0
  225. package/src/helpers/value_helpers.ts +6 -0
  226. package/src/types/arrays.test.ts +1 -4
  227. package/src/types/classes.ts +1 -0
  228. package/src/types/helpers.test.ts +1 -6
  229. package/src/types/helpers.ts +6 -5
  230. package/src/types/objects.test.ts +1 -4
  231. package/src/types/objects.ts +3 -3
  232. package/dist/noeldemartin-utils.d.ts +0 -901
  233. package/dist/noeldemartin-utils.js +0 -1473
  234. package/dist/noeldemartin-utils.js.map +0 -1
@@ -1,10 +1,10 @@
1
1
  import type { Constructor } from '@noeldemartin/utils/types';
2
2
 
3
- import { evaluate } from './value_helpers';
4
3
  import type JSError from './JSError';
4
+ import { evaluate } from './value_helpers';
5
5
  import type { EvaluatesTo } from './value_helpers';
6
6
 
7
- /* eslint-disable @typescript-eslint/no-explicit-any, max-len */
7
+ /* oxlint-disable typescript/no-explicit-any */
8
8
  export function assert(assertion: EvaluatesTo<boolean>, message?: string): void;
9
9
  export function assert<E extends Error = Error>(
10
10
  assertion: EvaluatesTo<boolean>,
@@ -18,7 +18,7 @@ export function assert(
18
18
  ): void {
19
19
  evaluate(assertion) || fail(messageOrClass as any, ...params);
20
20
  }
21
- /* eslint-enable @typescript-eslint/no-explicit-any, max-len */
21
+ /* oxlint-enable typescript/no-explicit-any */
22
22
 
23
23
  export function catchError(callback: () => unknown): Error | null {
24
24
  try {
@@ -30,19 +30,19 @@ export function catchError(callback: () => unknown): Error | null {
30
30
  }
31
31
  }
32
32
 
33
- /* eslint-disable @typescript-eslint/no-explicit-any, max-len */
33
+ /* oxlint-disable typescript/no-explicit-any */
34
34
  export function fail<T = any>(message?: string): T;
35
- export function fail<T = any, E extends Error = Error>(
36
- errorClass?: Constructor<E>,
37
- ...params: ConstructorParameters<Constructor<E>>
35
+ export function fail<T = any, E extends Constructor<Error> = Constructor<Error>>(
36
+ errorClass?: E,
37
+ ...params: ConstructorParameters<E>
38
38
  ): T;
39
- export function fail<T = any, E extends JSError = JSError>(
40
- errorClass?: Constructor<E>,
41
- ...params: ConstructorParameters<Constructor<E>>
39
+ export function fail<T = any, E extends Constructor<JSError> = Constructor<JSError>>(
40
+ errorClass?: E,
41
+ ...params: ConstructorParameters<E>
42
42
  ): T;
43
43
  export function fail(messageOrClass: string | Constructor<Error> = 'Something went wrong', ...params: any[]): any {
44
44
  const errorClass = typeof messageOrClass === 'string' ? Error : messageOrClass;
45
45
 
46
46
  throw new errorClass(...(typeof messageOrClass === 'string' ? [messageOrClass] : params));
47
47
  }
48
- /* eslint-enable @typescript-eslint/no-explicit-any, max-len */
48
+ /* oxlint-enable typescript/no-explicit-any */
@@ -1,9 +1,8 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, it } from 'vite-plus/test';
2
2
 
3
3
  import { formatCodeBlock } from './format_helpers';
4
4
 
5
5
  describe('Format helpers', () => {
6
-
7
6
  it('Formats code blocks', () => {
8
7
  // Arrange
9
8
  const raw = `
@@ -16,7 +15,7 @@ describe('Format helpers', () => {
16
15
 
17
16
  `;
18
17
  const formatted = [
19
- 'const foo = \'bar\';', //
18
+ "const foo = 'bar';", //
20
19
  '', //
21
20
  'if (foo) {', //
22
21
  ' doSomething();', //
@@ -29,5 +28,4 @@ describe('Format helpers', () => {
29
28
  // Assert
30
29
  expect(actual).toEqual(formatted);
31
30
  });
32
-
33
31
  });
@@ -1,9 +1,7 @@
1
- import { describe, expect, it } from 'vitest';
2
-
3
1
  import { md5 } from '@noeldemartin/utils/helpers/hash_helpers';
2
+ import { describe, expect, it } from 'vite-plus/test';
4
3
 
5
4
  describe('Hash helpers', () => {
6
-
7
5
  it('calculates md5 hashes', () => {
8
6
  expect(md5('foobar')).toEqual('3858f62230ac3c915f300c664312c63f');
9
7
  expect(
@@ -19,5 +17,4 @@ describe('Hash helpers', () => {
19
17
  ),
20
18
  ).toEqual('e789ad95b7fa0ee666a5c80df0bf1ba1');
21
19
  });
22
-
23
20
  });
@@ -7,7 +7,7 @@ export function md5(message: string): string {
7
7
  * @see http://www.myersdaily.org/joseph/javascript/md5-text.html
8
8
  */
9
9
 
10
- /* eslint-disable @typescript-eslint/no-explicit-any */
10
+ /* oxlint-disable typescript/no-explicit-any */
11
11
 
12
12
  function md5cycle(x: any, k: any) {
13
13
  let a = x[0],
@@ -122,8 +122,8 @@ function md51(s: any) {
122
122
  }
123
123
  s = s.substring(i - 64);
124
124
  const tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
125
- for (i = 0; i < s.length; i++) tail[i >> 2] |= s.charCodeAt(i) << (i % 4 << 3);
126
- tail[i >> 2] |= 0x80 << (i % 4 << 3);
125
+ for (i = 0; i < s.length; i++) tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3);
126
+ tail[i >> 2] |= 0x80 << ((i % 4) << 3);
127
127
  if (i > 55) {
128
128
  md5cycle(state, tail);
129
129
  for (i = 0; i < 16; i++) tail[i] = 0;
@@ -1,13 +1,11 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, it } from 'vite-plus/test';
2
2
 
3
3
  import { shortId, uuid } from './identity_helpers';
4
4
 
5
5
  describe('Identity helpers', () => {
6
-
7
6
  it('works', () => {
8
7
  expect(uuid()).toHaveLength(36);
9
8
  expect(shortId()).toHaveLength(9);
10
9
  expect(shortId(6)).toHaveLength(6);
11
10
  });
12
-
13
11
  });
@@ -1,4 +1,5 @@
1
1
  export { default as IndexedDBMap } from './IndexedDBMap';
2
+ export { default as InMemoryStorageService } from './InMemoryStorageService';
2
3
  export { default as JSError } from './JSError';
3
4
  export { default as ListenersManager } from './ListenersManager';
4
5
  export { default as MagicObject } from './MagicObject';
@@ -32,10 +33,12 @@ export * from './object_helpers';
32
33
  export * from './ObjectsMap';
33
34
  export * from './promise_helpers';
34
35
  export * from './PromisedValue';
36
+ export * from './replacements';
35
37
  export * from './runtime_helpers';
36
38
  export * from './Semaphore';
37
39
  export * from './Storage';
38
40
  export * from './string_helpers';
41
+ export * from './time_constants';
39
42
  export * from './time_helpers';
40
43
  export * from './url_helpers';
41
44
  export * from './value_helpers';
@@ -1,9 +1,8 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, it } from 'vite-plus/test';
2
2
 
3
3
  import { compare } from './logical_helpers';
4
4
 
5
5
  describe('Logical helpers', () => {
6
-
7
6
  it('compares numbers', () => {
8
7
  expect(compare(5, 1)).toBe(1);
9
8
  expect(compare(1, 5)).toBe(-1);
@@ -35,5 +34,4 @@ describe('Logical helpers', () => {
35
34
  expect(compare(null, null)).toBe(0);
36
35
  expect(compare(undefined, undefined)).toBe(0);
37
36
  });
38
-
39
37
  });
@@ -1,4 +1,4 @@
1
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1
+ // oxlint-disable-next-line typescript/no-explicit-any
2
2
  function normalizeCompareValues<T>(a: T, b: T): [any, any] {
3
3
  if ((a === undefined || a === null) && (b === null || b === undefined)) {
4
4
  return [a === null ? 1 : 0, b === null ? 1 : 0];
@@ -1,9 +1,8 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, it } from 'vite-plus/test';
2
2
 
3
3
  import { clamp, round } from './math_helpers';
4
4
 
5
5
  describe('Math helpers', () => {
6
-
7
6
  it('clamps values', () => {
8
7
  expect(clamp(50, 0, 100)).toBe(50);
9
8
  expect(clamp(500, 0, 100)).toBe(100);
@@ -17,5 +16,4 @@ describe('Math helpers', () => {
17
16
  expect(round(1.23456, 3)).toBe(1.235);
18
17
  expect(round(1 / 3, 2)).toBe(0.33);
19
18
  });
20
-
21
19
  });
@@ -2,7 +2,6 @@ import { mixed } from '@noeldemartin/utils/helpers/mixin_helpers';
2
2
  import type { Use } from '@noeldemartin/utils/types';
3
3
 
4
4
  export abstract class BaseClass<Secret> {
5
-
6
5
  public static planet = 'Earth';
7
6
 
8
7
  public baseSecret?: Secret;
@@ -14,22 +13,18 @@ export abstract class BaseClass<Secret> {
14
13
  }
15
14
 
16
15
  public abstract concrete(): void;
17
-
18
16
  }
19
17
 
20
18
  export class MixinA {
21
-
22
19
  public name: string = 'John';
23
20
 
24
21
  public getName(): string {
25
22
  return `name: ${this.name}`;
26
23
  }
27
-
28
24
  }
29
25
 
30
26
  export interface MixinAA<BaseSecret> extends MixinA, BaseClass<BaseSecret> {}
31
27
  export class MixinAA<BaseSecret> extends MixinA implements Use<BaseSecret> {
32
-
33
28
  public surname: string = 'Doe';
34
29
 
35
30
  public identifyWithName(): string {
@@ -39,12 +34,10 @@ export class MixinAA<BaseSecret> extends MixinA implements Use<BaseSecret> {
39
34
  public getSurname(): string {
40
35
  return `surname: ${this.surname}`;
41
36
  }
42
-
43
37
  }
44
38
 
45
39
  export interface MixinB<Secret, BaseSecret> extends BaseClass<BaseSecret>, Use<Secret> {}
46
40
  export class MixinB<Secret, BaseSecret> implements Use<BaseSecret> {
47
-
48
41
  public age: number = 42;
49
42
 
50
43
  public mixinSecret?: Secret;
@@ -56,17 +49,13 @@ export class MixinB<Secret, BaseSecret> implements Use<BaseSecret> {
56
49
  public getAge(): string {
57
50
  return `age: ${this.age}`;
58
51
  }
59
-
60
52
  }
61
53
 
62
54
  export const TargetMixedBase = mixed(BaseClass, [MixinAA, MixinB]) as typeof BaseClass;
63
55
 
64
56
  export default interface TargetClass<BaseSecret, MixinSecret>
65
- extends BaseClass<BaseSecret>,
66
- MixinAA<BaseSecret>,
67
- MixinB<MixinSecret, BaseSecret> {}
57
+ extends BaseClass<BaseSecret>, MixinAA<BaseSecret>, MixinB<MixinSecret, BaseSecret> {}
68
58
  export default class TargetClass<BaseSecret, MixinSecret> extends TargetMixedBase<BaseSecret> {
69
-
70
59
  public specificId: number = 32;
71
60
 
72
61
  public static getPlanet(): string {
@@ -99,5 +88,4 @@ export default class TargetClass<BaseSecret, MixinSecret> extends TargetMixedBas
99
88
  this.static().getPlanet(),
100
89
  ].join(', ');
101
90
  }
102
-
103
91
  }
@@ -1,14 +1,12 @@
1
- import { describe, expect, it } from 'vitest';
2
1
  import { tt } from '@noeldemartin/testing';
3
2
  import type { Expect } from '@noeldemartin/testing';
4
-
5
3
  import type { Equals } from '@noeldemartin/utils/types';
4
+ import { describe, expect, it } from 'vite-plus/test';
6
5
 
7
- import TargetClass, { BaseClass, MixinAA } from './mixin_helpers.stubs';
8
6
  import { usesMixin } from './mixin_helpers';
7
+ import TargetClass, { BaseClass, MixinAA } from './mixin_helpers.stubs';
9
8
 
10
9
  describe('Inheritance helpers', () => {
11
-
12
10
  it('mixes methods', () => {
13
11
  const instance = new TargetClass<string, number>();
14
12
 
@@ -70,11 +68,9 @@ describe('Inheritance helpers', () => {
70
68
  });
71
69
 
72
70
  it.todo('disallows using mixins for unsupported classes');
73
-
74
71
  });
75
72
 
76
73
  describe('Inheritance helpers types', () => {
77
-
78
74
  let instance: TargetClass<string, number>;
79
75
 
80
76
  it(
@@ -88,5 +84,4 @@ describe('Inheritance helpers types', () => {
88
84
  | true
89
85
  >(),
90
86
  );
91
-
92
87
  });
@@ -6,7 +6,6 @@ const OBJECT_PROTOTYPE = Object.getPrototypeOf(Object);
6
6
 
7
7
  function createMixedClass(baseClass: Constructor, mixinClasses: Constructor[]): Constructor {
8
8
  class MixedClass extends baseClass {
9
-
10
9
  public static __mixins = mixinClasses;
11
10
 
12
11
  constructor(...args: any[]) {
@@ -20,7 +19,6 @@ function createMixedClass(baseClass: Constructor, mixinClasses: Constructor[]):
20
19
 
21
20
  return this;
22
21
  }
23
-
24
22
  }
25
23
 
26
24
  applyMixins(MixedClass, mixinClasses);
@@ -52,7 +50,6 @@ export function applyMixins<Base extends Constructor>(baseClass: Base, mixinClas
52
50
  }
53
51
  }
54
52
 
55
- /* eslint-disable max-len */
56
53
  export type Cr<T> = Constructor<T>;
57
54
 
58
55
  export function mixed<A>(mixins: [Cr<A>]): Cr<A>;
@@ -64,21 +61,20 @@ export function mixed<Base, A, B>(baseClass: Base, mixins: [Cr<A>, Cr<B>]): Base
64
61
  export function mixed<Base, A, B, C>(baseClass: Base, mixins: [Cr<A>, Cr<B>, Cr<C>]): Base & Cr<A & B & C>;
65
62
  export function mixed<Base, A, B, C, D>(
66
63
  baseClass: Base,
67
- mixins: [Cr<A>, Cr<B>, Cr<C>, Cr<D>]
64
+ mixins: [Cr<A>, Cr<B>, Cr<C>, Cr<D>],
68
65
  ): Base & Cr<A & B & C & D>;
69
66
  export function mixed<Base, A, B, C, D, E>(
70
67
  baseClass: Base,
71
- mixins: [Cr<A>, Cr<B>, Cr<C>, Cr<D>, Cr<E>]
68
+ mixins: [Cr<A>, Cr<B>, Cr<C>, Cr<D>, Cr<E>],
72
69
  ): Base & Cr<A & B & C & D & E>;
73
70
  export function mixed<Base, A, B, C, D, E, F>(
74
71
  baseClass: Base,
75
- mixins: [Cr<A>, Cr<B>, Cr<C>, Cr<D>, Cr<E>, Cr<F>]
72
+ mixins: [Cr<A>, Cr<B>, Cr<C>, Cr<D>, Cr<E>, Cr<F>],
76
73
  ): Base & Cr<A & B & C & D & E & F>;
77
74
  export function mixed<Base, A, B, C, D, E, F, G>(
78
75
  baseClass: Base,
79
- mixins: [Cr<A>, Cr<B>, Cr<C>, Cr<D>, Cr<E>, Cr<F>, Cr<G>]
76
+ mixins: [Cr<A>, Cr<B>, Cr<C>, Cr<D>, Cr<E>, Cr<F>, Cr<G>],
80
77
  ): Base & Cr<A & B & C & D & E & F & G>;
81
- /* eslint-enable max-len */
82
78
 
83
79
  export function mixed(
84
80
  baseClassOrMixinClasses: Constructor | Constructor[],
@@ -90,13 +86,14 @@ export function mixed(
90
86
  return createMixedClass(baseClass, mixinClasses);
91
87
  }
92
88
 
89
+ // oxlint-disable-next-line typescript/no-wrapper-object-types
93
90
  export function mixedWithoutTypes(mixins: Constructor[]): Object;
94
91
  export function mixedWithoutTypes<Base>(baseClass: Base, mixins: Constructor[]): Base;
95
92
  export function mixedWithoutTypes(...args: any[]): unknown {
96
93
  return (mixed as Function)(...args);
97
94
  }
98
95
 
99
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
96
+ // oxlint-disable-next-line typescript/no-explicit-any, typescript/explicit-module-boundary-types
100
97
  export function usesMixin(target: any, mixin: Constructor): boolean {
101
98
  return (target?.__mixins ?? target?.__proto__?.constructor?.__mixins ?? []).includes(mixin);
102
99
  }
@@ -1,13 +1,14 @@
1
- import { describe, expect, expectTypeOf, it, vi } from 'vitest';
2
1
  import { tt } from '@noeldemartin/testing';
3
2
  import type { Expect } from '@noeldemartin/testing';
4
-
5
3
  import type { Equals, GetOptionalKeys, GetRequiredKeys } from '@noeldemartin/utils/types/helpers';
4
+ import { describe, expect, expectTypeOf, it, vi } from 'vite-plus/test';
6
5
 
7
6
  import {
8
7
  deepGet,
9
8
  deepSet,
10
9
  getClassMethods,
10
+ invert,
11
+ isSubclassOf,
11
12
  monkeyPatch,
12
13
  objectDeepClone,
13
14
  objectEntries,
@@ -17,23 +18,18 @@ import {
17
18
  } from './object_helpers';
18
19
 
19
20
  describe('Object helpers', () => {
20
-
21
21
  it('gets class methods', () => {
22
22
  // Arrange
23
23
  class Foo {
24
-
25
24
  public hello(): void {
26
25
  //
27
26
  }
28
-
29
27
  }
30
28
 
31
29
  class Bar extends Foo {
32
-
33
30
  public goodbye(): void {
34
31
  //
35
32
  }
36
-
37
33
  }
38
34
 
39
35
  // Act
@@ -50,15 +46,11 @@ describe('Object helpers', () => {
50
46
  it('patches methods', () => {
51
47
  // Arrange
52
48
  class Computer {
53
-
54
49
  public foo: string = '';
55
50
 
56
- public run(question: string): number {
57
- question;
58
-
51
+ public run(_: string): number {
59
52
  return 42;
60
53
  }
61
-
62
54
  }
63
55
 
64
56
  const computer = new Computer();
@@ -67,11 +59,11 @@ describe('Object helpers', () => {
67
59
  monkeyPatch(computer, 'run', (question) => callback(`Question: ${question}`));
68
60
 
69
61
  // Act
70
- const result = computer.run('What\'s the meaning of life?');
62
+ const result = computer.run("What's the meaning of life?");
71
63
 
72
64
  // Assert
73
65
  expect(result).toEqual(42);
74
- expect(callback).toHaveBeenCalledWith('Question: What\'s the meaning of life?');
66
+ expect(callback).toHaveBeenCalledWith("Question: What's the meaning of life?");
75
67
  });
76
68
 
77
69
  it('removes keys', () => {
@@ -96,10 +88,8 @@ describe('Object helpers', () => {
96
88
 
97
89
  it('gets subset', () => {
98
90
  class Stub {
99
-
100
91
  public foo = true;
101
92
  public bar = false;
102
-
103
93
  }
104
94
 
105
95
  expect(objectOnly({ foo: true, bar: false }, 'foo')).toEqual({ foo: true });
@@ -158,7 +148,6 @@ describe('Object helpers', () => {
158
148
  author: { id: 1, name: 'Jane Doe' },
159
149
  });
160
150
  });
161
-
162
151
  });
163
152
 
164
153
  type Original = {
@@ -176,7 +165,6 @@ const originalWithoutFoo = objectWithout(original, ['foo']);
176
165
  const originalWithoutEmpty = objectWithoutEmpty(original);
177
166
 
178
167
  describe('Object helpers types', () => {
179
-
180
168
  it('gets typed entries', () => {
181
169
  const partialObject = {} as Partial<Record<'a' | 'b', number>>;
182
170
  const objectWithUndefined = {} as Record<'a' | 'b', number | undefined>;
@@ -189,6 +177,32 @@ describe('Object helpers types', () => {
189
177
  expectTypeOf(objectEntries(objectWithOptionalAndRequired)).toEqualTypeOf<['a' | 'b', number | undefined][]>();
190
178
  });
191
179
 
180
+ it('inverts objects', () => {
181
+ const genres = { 'Science Fiction': 878, Animation: 16 } as const;
182
+ const duplicates = { a: 'x', b: 'x', c: 'y' } as const;
183
+ const record = {} as Record<string, string>;
184
+
185
+ expect(invert(genres)).toEqual({ 878: 'Science Fiction', 16: 'Animation' });
186
+ expect(invert(duplicates)).toEqual({ x: 'b', y: 'c' });
187
+
188
+ expectTypeOf(invert(genres)).toEqualTypeOf<{ readonly 878: 'Science Fiction'; readonly 16: 'Animation' }>();
189
+ expectTypeOf(invert(duplicates)).toEqualTypeOf<{ readonly x: 'a' | 'b'; readonly y: 'c' }>();
190
+ expectTypeOf(invert(record)).toEqualTypeOf<Record<string, string>>();
191
+ });
192
+
193
+ it('checks subclasses', () => {
194
+ class A {}
195
+ class B extends A {}
196
+ class C extends B {}
197
+
198
+ expect(isSubclassOf(B, A)).toBe(true);
199
+ expect(isSubclassOf(C, A)).toBe(true);
200
+ expect(isSubclassOf(C, B)).toBe(true);
201
+ expect(isSubclassOf(A, A)).toBe(false);
202
+ expect(isSubclassOf(A, B)).toBe(false);
203
+ expect(isSubclassOf(A, C)).toBe(false);
204
+ });
205
+
192
206
  it(
193
207
  'has correct types',
194
208
  tt<
@@ -200,5 +214,4 @@ describe('Object helpers types', () => {
200
214
  | true
201
215
  >(),
202
216
  );
203
-
204
217
  });
@@ -1,3 +1,5 @@
1
+ import type { DeepKeyOf, DeepValue } from '@noeldemartin/utils/types';
2
+ import type { Constructor } from '@noeldemartin/utils/types/classes';
1
3
  import type {
2
4
  Closure,
3
5
  ClosureArgs,
@@ -8,15 +10,13 @@ import type {
8
10
  TypeGuard,
9
11
  VoidClosure,
10
12
  } from '@noeldemartin/utils/types/helpers';
11
- import type { Constructor } from '@noeldemartin/utils/types/classes';
12
- import type { DeepKeyOf, DeepValue } from '@noeldemartin/utils/types';
13
13
 
14
14
  export type Obj = Record<string, unknown>;
15
15
 
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ // oxlint-disable-next-line typescript/no-explicit-any
17
17
  export type GetObjectKeys<T> = T extends Record<infer Key, any> ? Key : keyof T;
18
18
 
19
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ // oxlint-disable-next-line typescript/no-explicit-any
20
20
  export type GetObjectValues<T> = T extends Record<any, infer Value> ? Value : never;
21
21
 
22
22
  export type ValueWithout<TValue, TExclude> = TValue extends TExclude ? never : TValue;
@@ -58,6 +58,10 @@ export type ObjectWithout<TObj, TExclude> = Pretty<
58
58
  }
59
59
  >;
60
60
 
61
+ export type Inverted<T extends { [K in keyof T]: PropertyKey }> = {
62
+ [K in keyof T as T[K]]: `${K & (string | number)}`;
63
+ };
64
+
61
65
  export function deepEquals(a: unknown, b: unknown): boolean {
62
66
  if (a === b) return true;
63
67
 
@@ -99,7 +103,7 @@ export function deepAssign<T extends object>(target: T, ...sources: T[]): T {
99
103
  }
100
104
 
101
105
  export function deepGet<T extends object, K extends DeepKeyOf<T>>(object: T, key: K): DeepValue<T, K> {
102
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
106
+ // oxlint-disable-next-line typescript/no-explicit-any, typescript/no-unsafe-assignment
103
107
  let value = object as any;
104
108
  const objectKeys = key.split('.');
105
109
 
@@ -121,7 +125,7 @@ export function deepGet<T extends object, K extends DeepKeyOf<T>>(object: T, key
121
125
  }
122
126
 
123
127
  export function deepSet<T extends object, K extends DeepKeyOf<T>>(object: T, key: K, value: DeepValue<T, K>): void {
124
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
128
+ // oxlint-disable-next-line typescript/no-explicit-any, typescript/no-unsafe-assignment
125
129
  let wrapper = object as any;
126
130
  const objectKeys = key.split('.');
127
131
  const lastKey = objectKeys.pop();
@@ -138,7 +142,7 @@ export function deepSet<T extends object, K extends DeepKeyOf<T>>(object: T, key
138
142
  wrapper = wrapper[deepKey];
139
143
  }
140
144
 
141
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
145
+ // oxlint-disable-next-line typescript/no-unsafe-member-access
142
146
  wrapper[lastKey] = value;
143
147
  }
144
148
 
@@ -158,15 +162,15 @@ export function getClassMethods(target: object): string[] {
158
162
  return Array.from(properties);
159
163
  }
160
164
 
161
- export function invert(map: Record<string, string>): Record<string, string> {
162
- return Object.entries(map).reduce(
165
+ export function invert<T extends { [K in keyof T]: PropertyKey }>(map: T): Inverted<T> {
166
+ return Object.entries(map as Record<string, PropertyKey>).reduce(
163
167
  (invertedMap, [key, value]) => {
164
168
  invertedMap[value] = key;
165
169
 
166
170
  return invertedMap;
167
171
  },
168
- {} as Record<string, string>,
169
- );
172
+ {} as Record<PropertyKey, string>,
173
+ ) as Inverted<T>;
170
174
  }
171
175
 
172
176
  export const isArray = Array.isArray.bind(Array);
@@ -201,6 +205,7 @@ export function isPlainObject(value: unknown): value is object {
201
205
  return isObject(value) && Object.getPrototypeOf(value) === Object.prototype;
202
206
  }
203
207
 
208
+ // oxlint-disable-next-line typescript/no-wrapper-object-types
204
209
  export function isString(value: unknown): value is string | String {
205
210
  return typeof value === 'string' || value instanceof String;
206
211
  }
@@ -209,6 +214,25 @@ export function isNullable(value: unknown): value is undefined | null {
209
214
  return typeof value === 'undefined' || value === null;
210
215
  }
211
216
 
217
+ export function isPromiseLike(value: unknown): value is PromiseLike<unknown> {
218
+ // oxlint-disable-next-line typescript/no-explicit-any
219
+ return (isObject(value) || typeof value === 'function') && typeof (value as any)?.then === 'function';
220
+ }
221
+
222
+ export function isSubclassOf(value: Constructor, baseClass: Constructor): boolean {
223
+ let prototype = Object.getPrototypeOf(value);
224
+
225
+ while (prototype !== null && prototype !== Object) {
226
+ if (prototype === baseClass) {
227
+ return true;
228
+ }
229
+
230
+ prototype = Object.getPrototypeOf(prototype);
231
+ }
232
+
233
+ return false;
234
+ }
235
+
212
236
  export function monkeyPatch<T, K extends GetObjectMethods<T>>(object: T, method: K, callback: VoidClosure<T[K]>): void {
213
237
  const originalMethod = object[method] as unknown as Closure;
214
238
 
@@ -232,21 +256,21 @@ export function objectDeepClone<T extends Obj>(object: T): T {
232
256
  }
233
257
 
234
258
  export const objectEntries = Object.entries.bind(Object) as <T extends Parameters<typeof Object.entries>[0]>(
235
- obj: T
259
+ obj: T,
236
260
  ) => [GetObjectKeys<T>, GetObjectValues<T>][];
237
261
 
238
262
  export const objectFromEntries = Object.fromEntries.bind(Object) as <K extends string | number | symbol, V>(
239
- value: Iterable<readonly [K, V]>
263
+ value: Iterable<readonly [K, V]>,
240
264
  ) => Record<K, V>;
241
265
 
242
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
266
+ // oxlint-disable-next-line typescript/no-explicit-any
243
267
  export const objectValues = Object.values.bind(Object) as <T extends { [k: string]: any } | ArrayLike<any>>(
244
- object: T
268
+ object: T,
245
269
  ) => GetObjectValues<T>[];
246
270
 
247
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
271
+ // oxlint-disable-next-line typescript/no-explicit-any
248
272
  export const objectKeys = Object.keys.bind(Object) as <T extends { [k: string]: any } | ArrayLike<any>>(
249
- object: T
273
+ object: T,
250
274
  ) => GetObjectKeys<T>[];
251
275
 
252
276
  export function objectHasOwnProperty(object: Obj, property: string): boolean {
@@ -293,20 +317,18 @@ export function objectPull<T extends Obj, K extends keyof T>(obj: T, key: K): T[
293
317
  return value;
294
318
  }
295
319
 
296
- /* eslint-disable max-len */
297
320
  export function objectWithout<TObj extends Obj, TKey extends keyof TObj>(obj: TObj, key: TKey): Omit<TObj, TKey>;
298
321
  export function objectWithout<TObj extends object, TKey extends keyof TObj>(obj: TObj, key: TKey): Omit<TObj, TKey>;
299
322
  export function objectWithout<TObj extends Obj, TKey extends keyof TObj>(obj: TObj, keys: TKey[]): Omit<TObj, TKey>;
300
323
  export function objectWithout<TObj extends object, TKey extends keyof TObj>(obj: TObj, keys: TKey[]): Omit<TObj, TKey>;
301
324
  export function objectWithout<TObj extends Obj, TExclude>(
302
325
  obj: TObj,
303
- exclude: TypeGuard<TExclude>
326
+ exclude: TypeGuard<TExclude>,
304
327
  ): ObjectWithout<TObj, TExclude>;
305
328
  export function objectWithout<TObj extends object, TExclude>(
306
329
  obj: TObj,
307
- exclude: TypeGuard<TExclude>
330
+ exclude: TypeGuard<TExclude>,
308
331
  ): ObjectWithout<TObj, TExclude>;
309
- /* eslint-enable max-len */
310
332
 
311
333
  export function objectWithout(obj: Obj, keysOrExclude: string | string[] | TypeGuard): unknown {
312
334
  if (typeof keysOrExclude === 'function') {