@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.
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/fluent/FluentArray.d.ts +48 -0
- package/dist/fluent/FluentArray.js +48 -0
- package/dist/fluent/FluentArray.js.map +1 -0
- package/dist/fluent/FluentObject.d.ts +16 -0
- package/dist/fluent/FluentObject.js +45 -0
- package/dist/fluent/FluentObject.js.map +1 -0
- package/dist/fluent/FluentString.d.ts +21 -0
- package/dist/fluent/FluentString.js +28 -0
- package/dist/fluent/FluentString.js.map +1 -0
- package/dist/fluent/facade.d.ts +17 -0
- package/dist/fluent/facade.js +45 -0
- package/dist/fluent/facade.js.map +1 -0
- package/dist/fluent/index.d.ts +29 -0
- package/dist/fluent/index.js +41 -0
- package/dist/fluent/index.js.map +1 -0
- package/dist/fluent/invade.d.ts +6 -0
- package/dist/fluent/invade.js +8 -0
- package/dist/fluent/invade.js.map +1 -0
- package/dist/fluent/lazyFacade.d.ts +16 -0
- package/dist/fluent/lazyFacade.js +67 -0
- package/dist/fluent/lazyFacade.js.map +1 -0
- package/dist/fluent/noop.d.ts +4 -0
- package/dist/fluent/noop.js +6 -0
- package/dist/fluent/noop.js.map +1 -0
- package/dist/fluent/required.d.ts +5 -0
- package/dist/fluent/required.js +32 -0
- package/dist/fluent/required.js.map +1 -0
- package/dist/fluent/tap.d.ts +7 -0
- package/dist/fluent/tap.js +22 -0
- package/dist/fluent/tap.js.map +1 -0
- package/dist/fluent/value.d.ts +5 -0
- package/dist/fluent/value.js +8 -0
- package/dist/fluent/value.js.map +1 -0
- package/dist/fluent/when.d.ts +6 -0
- package/dist/fluent/when.js +11 -0
- package/dist/fluent/when.js.map +1 -0
- package/dist/helpers/InMemoryStorageService.d.ts +8 -0
- package/dist/helpers/InMemoryStorageService.js +16 -0
- package/dist/helpers/InMemoryStorageService.js.map +1 -0
- package/dist/helpers/IndexedDBMap.d.ts +17 -0
- package/dist/helpers/IndexedDBMap.js +52 -0
- package/dist/helpers/IndexedDBMap.js.map +1 -0
- package/dist/helpers/JSError.d.ts +14 -0
- package/dist/helpers/JSError.js +14 -0
- package/dist/helpers/JSError.js.map +1 -0
- package/dist/helpers/ListenersManager.d.ts +15 -0
- package/dist/helpers/ListenersManager.js +23 -0
- package/dist/helpers/ListenersManager.js.map +1 -0
- package/dist/helpers/MagicObject.d.ts +29 -0
- package/dist/helpers/MagicObject.js +77 -0
- package/dist/helpers/MagicObject.js.map +1 -0
- package/dist/helpers/ObjectsMap.d.ts +28 -0
- package/dist/helpers/ObjectsMap.js +86 -0
- package/dist/helpers/ObjectsMap.js.map +1 -0
- package/dist/helpers/PromisedValue.d.ts +32 -0
- package/dist/helpers/PromisedValue.js +68 -0
- package/dist/helpers/PromisedValue.js.map +1 -0
- package/dist/helpers/Semaphore.d.ts +14 -0
- package/dist/helpers/Semaphore.js +45 -0
- package/dist/helpers/Semaphore.js.map +1 -0
- package/dist/helpers/Storage.d.ts +17 -0
- package/dist/helpers/Storage.js +39 -0
- package/dist/helpers/Storage.js.map +1 -0
- package/dist/helpers/array_helpers.d.ts +57 -0
- package/dist/helpers/array_helpers.js +208 -0
- package/dist/helpers/array_helpers.js.map +1 -0
- package/dist/helpers/boolean_helpers.d.ts +4 -0
- package/dist/helpers/boolean_helpers.js +10 -0
- package/dist/helpers/boolean_helpers.js.map +1 -0
- package/dist/helpers/caching_helpers.d.ts +17 -0
- package/dist/helpers/caching_helpers.js +55 -0
- package/dist/helpers/caching_helpers.js.map +1 -0
- package/dist/helpers/chaos_helpers.d.ts +6 -0
- package/dist/helpers/chaos_helpers.js +11 -0
- package/dist/helpers/chaos_helpers.js.map +1 -0
- package/dist/helpers/date_helpers.d.ts +4 -0
- package/dist/helpers/date_helpers.js +15 -0
- package/dist/helpers/date_helpers.js.map +1 -0
- package/dist/helpers/deprecated.d.ts +24 -0
- package/dist/helpers/env.d.ts +9 -0
- package/dist/helpers/env.js +42 -0
- package/dist/helpers/env.js.map +1 -0
- package/dist/helpers/error_helpers.d.ts +12 -0
- package/dist/helpers/error_helpers.js +20 -0
- package/dist/helpers/error_helpers.js.map +1 -0
- package/dist/helpers/escape_helpers.d.ts +5 -0
- package/dist/helpers/escape_helpers.js +11 -0
- package/dist/helpers/escape_helpers.js.map +1 -0
- package/dist/helpers/file_helpers.d.ts +4 -0
- package/dist/helpers/file_helpers.js +16 -0
- package/dist/helpers/file_helpers.js.map +1 -0
- package/dist/helpers/format_helpers.d.ts +7 -0
- package/dist/helpers/format_helpers.js +28 -0
- package/dist/helpers/format_helpers.js.map +1 -0
- package/dist/helpers/hash_helpers.d.ts +4 -0
- package/dist/helpers/hash_helpers.js +156 -0
- package/dist/helpers/hash_helpers.js.map +1 -0
- package/dist/helpers/identity_helpers.d.ts +5 -0
- package/dist/helpers/identity_helpers.js +15 -0
- package/dist/helpers/identity_helpers.js.map +1 -0
- package/dist/helpers/location_helpers.d.ts +8 -0
- package/dist/helpers/location_helpers.js +37 -0
- package/dist/helpers/location_helpers.js.map +1 -0
- package/dist/helpers/logical_helpers.d.ts +4 -0
- package/dist/helpers/logical_helpers.js +13 -0
- package/dist/helpers/logical_helpers.js.map +1 -0
- package/dist/helpers/math_helpers.d.ts +5 -0
- package/dist/helpers/math_helpers.js +12 -0
- package/dist/helpers/math_helpers.js.map +1 -0
- package/dist/helpers/mixin_helpers.d.ts +20 -0
- package/dist/helpers/mixin_helpers.js +43 -0
- package/dist/helpers/mixin_helpers.js.map +1 -0
- package/dist/helpers/network_helpers.d.ts +4 -0
- package/dist/helpers/network_helpers.js +8 -0
- package/dist/helpers/network_helpers.js.map +1 -0
- package/dist/helpers/object_helpers.d.ts +58 -0
- package/dist/helpers/object_helpers.js +179 -0
- package/dist/helpers/object_helpers.js.map +1 -0
- package/dist/helpers/promise_helpers.d.ts +10 -0
- package/dist/helpers/promise_helpers.js +25 -0
- package/dist/helpers/promise_helpers.js.map +1 -0
- package/dist/helpers/replacements-scope.js +21 -0
- package/dist/helpers/replacements-scope.js.map +1 -0
- package/dist/helpers/replacements.d.ts +5 -0
- package/dist/helpers/replacements.js +34 -0
- package/dist/helpers/replacements.js.map +1 -0
- package/dist/helpers/runtime_helpers.d.ts +4 -0
- package/dist/helpers/runtime_helpers.js +8 -0
- package/dist/helpers/runtime_helpers.js.map +1 -0
- package/dist/helpers/string_helpers.d.ts +17 -0
- package/dist/helpers/string_helpers.js +42 -0
- package/dist/helpers/string_helpers.js.map +1 -0
- package/dist/helpers/time_constants.d.ts +15 -0
- package/dist/helpers/time_constants.js +17 -0
- package/dist/helpers/time_constants.js.map +1 -0
- package/dist/helpers/time_helpers.d.ts +24 -0
- package/dist/helpers/time_helpers.js +57 -0
- package/dist/helpers/time_helpers.js.map +1 -0
- package/dist/helpers/url_helpers.d.ts +24 -0
- package/dist/helpers/url_helpers.js +90 -0
- package/dist/helpers/url_helpers.js.map +1 -0
- package/dist/helpers/value_helpers.d.ts +7 -0
- package/dist/helpers/value_helpers.js +11 -0
- package/dist/helpers/value_helpers.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +49 -0
- package/dist/types/arrays.d.ts +12 -0
- package/dist/types/classes.d.ts +12 -0
- package/dist/types/helpers.d.ts +36 -0
- package/dist/types/helpers.js +6 -0
- package/dist/types/helpers.js.map +1 -0
- package/dist/types/objects.d.ts +8 -0
- package/package.json +38 -52
- package/src/fluent/FluentArray.test.ts +2 -9
- package/src/fluent/FluentArray.ts +6 -5
- package/src/fluent/FluentObject.ts +2 -4
- package/src/fluent/FluentString.test.ts +1 -8
- package/src/fluent/FluentString.ts +0 -2
- package/src/fluent/facade.test.ts +16 -4
- package/src/fluent/facade.ts +6 -4
- package/src/fluent/index.test.ts +3 -8
- package/src/fluent/index.ts +3 -3
- package/src/fluent/invade.test.ts +1 -5
- package/src/fluent/invade.ts +1 -1
- package/src/fluent/lazyFacade.test.ts +191 -0
- package/src/fluent/lazyFacade.ts +115 -0
- package/src/fluent/required.test.ts +1 -5
- package/src/fluent/required.ts +2 -4
- package/src/fluent/tap.test.ts +2 -9
- package/src/fluent/tap.ts +4 -3
- package/src/fluent/value.test.ts +1 -4
- package/src/fluent/when.test.ts +1 -6
- package/src/fluent/when.ts +2 -2
- package/src/helpers/InMemoryStorageService.ts +13 -0
- package/src/helpers/IndexedDBMap.ts +0 -2
- package/src/helpers/JSError.test.ts +1 -6
- package/src/helpers/JSError.ts +0 -2
- package/src/helpers/ListenersManager.test.ts +3 -7
- package/src/helpers/ListenersManager.ts +2 -4
- package/src/helpers/MagicObject.test.ts +14 -8
- package/src/helpers/MagicObject.ts +12 -3
- package/src/helpers/ObjectsMap.test.ts +1 -3
- package/src/helpers/ObjectsMap.ts +1 -5
- package/src/helpers/PromisedValue.test.ts +1 -3
- package/src/helpers/PromisedValue.ts +5 -6
- package/src/helpers/Semaphore.test.ts +6 -10
- package/src/helpers/Semaphore.ts +0 -2
- package/src/helpers/Storage.test.ts +47 -0
- package/src/helpers/Storage.ts +11 -19
- package/src/helpers/array_helpers.test.ts +127 -38
- package/src/helpers/array_helpers.ts +137 -78
- package/src/helpers/caching_helpers.test.ts +1 -3
- package/src/helpers/caching_helpers.ts +2 -2
- package/src/helpers/date_helpers.test.ts +1 -4
- package/src/helpers/date_helpers.ts +1 -1
- package/src/helpers/env.ts +5 -1
- package/src/helpers/error_helpers.test.ts +9 -8
- package/src/helpers/error_helpers.ts +11 -11
- package/src/helpers/format_helpers.test.ts +2 -4
- package/src/helpers/hash_helpers.test.ts +1 -4
- package/src/helpers/hash_helpers.ts +3 -3
- package/src/helpers/identity_helpers.test.ts +1 -3
- package/src/helpers/index.ts +3 -0
- package/src/helpers/logical_helpers.test.ts +1 -3
- package/src/helpers/logical_helpers.ts +1 -1
- package/src/helpers/math_helpers.test.ts +1 -3
- package/src/helpers/mixin_helpers.stubs.ts +1 -13
- package/src/helpers/mixin_helpers.test.ts +2 -7
- package/src/helpers/mixin_helpers.ts +6 -9
- package/src/helpers/object_helpers.test.ts +32 -19
- package/src/helpers/object_helpers.ts +43 -21
- package/src/helpers/promise_helpers.test.ts +1 -4
- package/src/helpers/promise_helpers.ts +9 -9
- package/src/helpers/replacements-scope.ts +15 -0
- package/src/helpers/replacements.test.ts +23 -0
- package/src/helpers/replacements.ts +52 -0
- package/src/helpers/runtime_helpers.ts +3 -3
- package/src/helpers/string_helpers.test.ts +3 -5
- package/src/helpers/time_constants.ts +13 -0
- package/src/helpers/time_helpers.ts +35 -0
- package/src/helpers/url_helpers.test.ts +12 -4
- package/src/helpers/url_helpers.ts +9 -15
- package/src/helpers/value_helpers.test.ts +12 -0
- package/src/helpers/value_helpers.ts +6 -0
- package/src/types/arrays.test.ts +1 -4
- package/src/types/classes.ts +1 -0
- package/src/types/helpers.test.ts +1 -6
- package/src/types/helpers.ts +6 -5
- package/src/types/objects.test.ts +1 -4
- package/src/types/objects.ts +3 -3
- package/dist/noeldemartin-utils.d.ts +0 -901
- package/dist/noeldemartin-utils.js +0 -1473
- 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
|
-
/*
|
|
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
|
-
/*
|
|
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
|
-
/*
|
|
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?:
|
|
37
|
-
...params: ConstructorParameters<
|
|
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?:
|
|
41
|
-
...params: ConstructorParameters<
|
|
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
|
-
/*
|
|
48
|
+
/* oxlint-enable typescript/no-explicit-any */
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { describe, expect, it } from '
|
|
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
|
-
|
|
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
|
-
/*
|
|
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 '
|
|
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
|
});
|
package/src/helpers/index.ts
CHANGED
|
@@ -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 '
|
|
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
|
-
//
|
|
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 '
|
|
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
|
-
//
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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:
|
|
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<
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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') {
|