utilium 1.3.1 → 1.3.2
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 +2 -0
- package/dist/objects.js +10 -2
- package/package.json +1 -1
- package/src/buffer.ts +1 -1
- package/src/objects.ts +11 -2
package/dist/buffer.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
2
2
|
/**
|
3
3
|
* Grows a buffer if it isn't large enough
|
4
4
|
* @returns The original buffer if resized successfully, or a newly created buffer
|
package/dist/objects.d.ts
CHANGED
@@ -32,3 +32,5 @@ export interface ConstMap<T extends Partial<Record<keyof any, any>>, K extends k
|
|
32
32
|
export declare function map<const T extends Partial<Record<any, any>>>(items: T): Map<keyof T, T[keyof T]>;
|
33
33
|
export declare function getByString(object: Record<string, any>, path: string, separator?: RegExp): Record<string, any>;
|
34
34
|
export declare function setByString(object: Record<string, any>, path: string, value: unknown, separator?: RegExp): Record<string, any>;
|
35
|
+
/** Binds a class member to the instance */
|
36
|
+
export declare function bound(value: unknown, { name, addInitializer }: ClassMethodDecoratorContext): void;
|
package/dist/objects.js
CHANGED
@@ -18,7 +18,7 @@ export function assignWithDefaults(to, from, defaults = to) {
|
|
18
18
|
try {
|
19
19
|
to[key] = from[key] ?? defaults[key] ?? to[key];
|
20
20
|
}
|
21
|
-
catch
|
21
|
+
catch {
|
22
22
|
// Do nothing
|
23
23
|
}
|
24
24
|
}
|
@@ -28,7 +28,7 @@ export function isJSON(str) {
|
|
28
28
|
JSON.parse(str);
|
29
29
|
return true;
|
30
30
|
}
|
31
|
-
catch
|
31
|
+
catch {
|
32
32
|
return false;
|
33
33
|
}
|
34
34
|
}
|
@@ -56,3 +56,11 @@ export function setByString(object, path, value, separator = /[.[\]'"]/) {
|
|
56
56
|
.filter(p => p)
|
57
57
|
.reduce((o, p, i) => (o[p] = path.split(separator).filter(p => p).length === ++i ? value : o[p] || {}), object);
|
58
58
|
}
|
59
|
+
/** Binds a class member to the instance */
|
60
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
61
|
+
export function bound(value, { name, addInitializer }) {
|
62
|
+
addInitializer(function () {
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
64
|
+
this[name] = this[name].bind(this);
|
65
|
+
});
|
66
|
+
}
|
package/package.json
CHANGED
package/src/buffer.ts
CHANGED
package/src/objects.ts
CHANGED
@@ -26,7 +26,7 @@ export function assignWithDefaults<To extends Record<keyof any, any>, From exten
|
|
26
26
|
for (const key of keys) {
|
27
27
|
try {
|
28
28
|
to[key] = from[key] ?? defaults[key] ?? to[key];
|
29
|
-
} catch
|
29
|
+
} catch {
|
30
30
|
// Do nothing
|
31
31
|
}
|
32
32
|
}
|
@@ -46,7 +46,7 @@ export function isJSON(str: string) {
|
|
46
46
|
try {
|
47
47
|
JSON.parse(str);
|
48
48
|
return true;
|
49
|
-
} catch
|
49
|
+
} catch {
|
50
50
|
return false;
|
51
51
|
}
|
52
52
|
}
|
@@ -89,3 +89,12 @@ export function setByString(object: Record<string, any>, path: string, value: un
|
|
89
89
|
.filter(p => p)
|
90
90
|
.reduce((o, p, i) => (o[p] = path.split(separator).filter(p => p).length === ++i ? value : o[p] || {}), object);
|
91
91
|
}
|
92
|
+
|
93
|
+
/** Binds a class member to the instance */
|
94
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
95
|
+
export function bound(value: unknown, { name, addInitializer }: ClassMethodDecoratorContext) {
|
96
|
+
addInitializer(function (this: any) {
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
98
|
+
this[name] = this[name].bind(this);
|
99
|
+
});
|
100
|
+
}
|