utilium 2.2.3 → 2.3.1
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/buffer.js +1 -1
- package/dist/objects.d.ts +15 -4
- package/dist/objects.js +36 -0
- package/package.json +1 -1
package/dist/buffer.js
CHANGED
@@ -48,7 +48,7 @@ export function initView(view, buffer, byteOffset, byteLength) {
|
|
48
48
|
|| buffer instanceof ArrayBuffer
|
49
49
|
|| (globalThis.SharedArrayBuffer && buffer instanceof SharedArrayBuffer)) {
|
50
50
|
const size = byteLength
|
51
|
-
?? view.constructor?.
|
51
|
+
?? view.constructor?.size // Memium types
|
52
52
|
?? buffer?.byteLength
|
53
53
|
?? 0;
|
54
54
|
view.buffer = buffer ?? new ArrayBuffer(size);
|
package/dist/objects.d.ts
CHANGED
@@ -1,10 +1,21 @@
|
|
1
|
-
import type { UnionToTuple } from './types.js';
|
1
|
+
import type { Expand, UnionToTuple } from './types.js';
|
2
2
|
export declare function filterObject<O extends object, R extends object>(object: O, predicate: (key: keyof O, value: O[keyof O]) => boolean): R;
|
3
3
|
export declare function pick<T extends object, K extends keyof T>(object: T, ...keys: readonly K[]): Pick<T, K>;
|
4
4
|
export declare function pick<T extends object, K extends keyof T>(object: T, ...keys: readonly (readonly K[])[]): Pick<T, K>;
|
5
5
|
export declare function omit<T extends object, K extends keyof T>(object: T, ...keys: readonly K[]): Omit<T, K>;
|
6
6
|
export declare function omit<T extends object, K extends keyof T>(object: T, ...keys: readonly (readonly K[])[]): Omit<T, K>;
|
7
7
|
export declare function assignWithDefaults<To extends Record<keyof any, any>, From extends Partial<To>>(to: To, from: From, defaults?: Partial<To>): void;
|
8
|
+
/**
|
9
|
+
* Returns whether `value` is not a primitive.
|
10
|
+
*
|
11
|
+
* This function is only useful for the type check,
|
12
|
+
* you can do `Object(v) === v` otherwise.
|
13
|
+
*/
|
14
|
+
export declare function isObject(value: unknown): value is object;
|
15
|
+
export type DeepAssign<To extends object, From extends object> = {
|
16
|
+
[K in keyof To | keyof From]: K extends keyof To ? K extends keyof From ? To[K] extends object ? From[K] extends object ? Expand<DeepAssign<To[K], From[K]>> : never : From[K] extends object ? never : From[K] : To[K] : From[K & keyof From];
|
17
|
+
};
|
18
|
+
export declare function deepAssign<To extends object, From extends object>(to: To, from: From): DeepAssign<To, From>;
|
8
19
|
/**
|
9
20
|
* Entries of T
|
10
21
|
*/
|
@@ -34,9 +45,9 @@ export declare function map<const T extends Partial<Record<any, any>>>(items: T)
|
|
34
45
|
export declare function getByString(object: Record<string, any>, path: string, separator?: RegExp): Record<string, any>;
|
35
46
|
export declare function setByString(object: Record<string, any>, path: string, value: unknown, separator?: RegExp): Record<string, any>;
|
36
47
|
export type JSONPrimitive = null | string | number | boolean;
|
37
|
-
export
|
38
|
-
[K
|
39
|
-
}
|
48
|
+
export interface JSONObject {
|
49
|
+
[K: string]: JSONValue | undefined;
|
50
|
+
}
|
40
51
|
export type JSONValue = JSONPrimitive | JSONObject | JSONValue[];
|
41
52
|
/**
|
42
53
|
* An object `T` with all of its functions bound to a `This` value
|
package/dist/objects.js
CHANGED
@@ -23,6 +23,42 @@ export function assignWithDefaults(to, from, defaults = to) {
|
|
23
23
|
}
|
24
24
|
}
|
25
25
|
}
|
26
|
+
/**
|
27
|
+
* Returns whether `value` is not a primitive.
|
28
|
+
*
|
29
|
+
* This function is only useful for the type check,
|
30
|
+
* you can do `Object(v) === v` otherwise.
|
31
|
+
*/
|
32
|
+
export function isObject(value) {
|
33
|
+
return Object(value) === value;
|
34
|
+
}
|
35
|
+
export function deepAssign(to, from) {
|
36
|
+
const keys = new Set([
|
37
|
+
...Object.keys(to),
|
38
|
+
...Object.keys(from),
|
39
|
+
]);
|
40
|
+
for (const key of keys) {
|
41
|
+
if (!(key in from))
|
42
|
+
continue;
|
43
|
+
const value = from[key];
|
44
|
+
if (!(key in to)) {
|
45
|
+
to[key] = value;
|
46
|
+
continue;
|
47
|
+
}
|
48
|
+
if (!isObject(to[key]) && Object(value) !== value) {
|
49
|
+
to[key] = value;
|
50
|
+
continue;
|
51
|
+
}
|
52
|
+
if (isObject(to[key]) && Object(value) === value) {
|
53
|
+
deepAssign(to[key], value);
|
54
|
+
continue;
|
55
|
+
}
|
56
|
+
throw new TypeError(!isObject(to[key])
|
57
|
+
? 'Can not deeply assign an object to a primitive'
|
58
|
+
: 'Can not deeply assign a primitive to an object');
|
59
|
+
}
|
60
|
+
return to;
|
61
|
+
}
|
26
62
|
export function isJSON(str) {
|
27
63
|
try {
|
28
64
|
JSON.parse(str);
|