@nomicfoundation/hardhat-utils 3.0.0-next.30 → 3.0.0-next.32
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/src/lang.d.ts +7 -0
- package/dist/src/lang.d.ts.map +1 -1
- package/dist/src/lang.js +30 -0
- package/dist/src/lang.js.map +1 -1
- package/package.json +2 -2
- package/src/lang.ts +36 -0
package/dist/src/lang.d.ts
CHANGED
|
@@ -46,4 +46,11 @@ export declare function isObject(value: unknown): value is Record<string | symbo
|
|
|
46
46
|
* @returns A promise that resolves after the specified number of seconds.
|
|
47
47
|
*/
|
|
48
48
|
export declare function sleep(seconds: number): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Binds all methods of an object to the object itself, so that they can be
|
|
51
|
+
* assigned to an independent variable and still work.
|
|
52
|
+
*
|
|
53
|
+
* @param obj The object, which can be an instance of a class.
|
|
54
|
+
*/
|
|
55
|
+
export declare function bindAllMethods<ObjectT extends object>(obj: ObjectT): void;
|
|
49
56
|
//# sourceMappingURL=lang.d.ts.map
|
package/dist/src/lang.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lang.d.ts","sourceRoot":"","sources":["../../src/lang.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAIvD;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAI/D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAC1D,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,GACR,CAAC,GAAG,CAAC,CAEP;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAE3C;AAED;;;;;GAKG;AACH,wBAAsB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1D"}
|
|
1
|
+
{"version":3,"file":"lang.d.ts","sourceRoot":"","sources":["../../src/lang.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAIvD;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAI/D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAC1D,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,GACR,CAAC,GAAG,CAAC,CAEP;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAE3C;AAED;;;;;GAKG;AACH,wBAAsB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAS,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI,CA4BzE"}
|
package/dist/src/lang.js
CHANGED
|
@@ -59,4 +59,34 @@ export function isObject(value) {
|
|
|
59
59
|
export async function sleep(seconds) {
|
|
60
60
|
await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Binds all methods of an object to the object itself, so that they can be
|
|
64
|
+
* assigned to an independent variable and still work.
|
|
65
|
+
*
|
|
66
|
+
* @param obj The object, which can be an instance of a class.
|
|
67
|
+
*/
|
|
68
|
+
export function bindAllMethods(obj) {
|
|
69
|
+
const prototype = Object.getPrototypeOf(obj);
|
|
70
|
+
const prototypeKeys = prototype !== null ? Object.getOwnPropertyNames(prototype) : [];
|
|
71
|
+
const keys = [...prototypeKeys, ...Object.getOwnPropertyNames(obj)];
|
|
72
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions --
|
|
73
|
+
typescript can't express this in a safe way, so we use any here */
|
|
74
|
+
const objAsAny = obj;
|
|
75
|
+
// Exclude methods that should not be rebound (constructor, Object.prototype methods, etc.)
|
|
76
|
+
const EXCLUDED_METHODS = [
|
|
77
|
+
"constructor",
|
|
78
|
+
"hasOwnProperty",
|
|
79
|
+
"isPrototypeOf",
|
|
80
|
+
"propertyIsEnumerable",
|
|
81
|
+
"toLocaleString",
|
|
82
|
+
"toString",
|
|
83
|
+
"valueOf",
|
|
84
|
+
];
|
|
85
|
+
for (const key of keys) {
|
|
86
|
+
const val = objAsAny[key];
|
|
87
|
+
if (typeof val === "function" && !EXCLUDED_METHODS.includes(key)) {
|
|
88
|
+
objAsAny[key] = val.bind(obj);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
62
92
|
//# sourceMappingURL=lang.js.map
|
package/dist/src/lang.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lang.js","sourceRoot":"","sources":["../../src/lang.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAI,KAAQ;IACzC,MAAM,UAAU,GAAG,MAAM,oBAAoB,EAAE,CAAC;IAEhD,OAAO,UAAU,CAAI,KAAK,CAAC,CAAC;AAC9B,CAAC;A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AAI,OAAO,GAAG,KAAK,UAAU,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACjE,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nomicfoundation/hardhat-utils",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.32",
|
|
4
4
|
"description": "Utilities for Hardhat and its plugins",
|
|
5
5
|
"homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-utils",
|
|
6
6
|
"repository": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"README.md"
|
|
49
49
|
],
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@nomicfoundation/hardhat-node-test-reporter": "^3.0.0-next.
|
|
51
|
+
"@nomicfoundation/hardhat-node-test-reporter": "^3.0.0-next.32",
|
|
52
52
|
"@types/bn.js": "^5.1.5",
|
|
53
53
|
"@types/debug": "^4.1.7",
|
|
54
54
|
"@types/node": "^20.14.9",
|
package/src/lang.ts
CHANGED
|
@@ -71,3 +71,39 @@ export function isObject(
|
|
|
71
71
|
export async function sleep(seconds: number): Promise<void> {
|
|
72
72
|
await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
|
|
73
73
|
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Binds all methods of an object to the object itself, so that they can be
|
|
77
|
+
* assigned to an independent variable and still work.
|
|
78
|
+
*
|
|
79
|
+
* @param obj The object, which can be an instance of a class.
|
|
80
|
+
*/
|
|
81
|
+
export function bindAllMethods<ObjectT extends object>(obj: ObjectT): void {
|
|
82
|
+
const prototype = Object.getPrototypeOf(obj);
|
|
83
|
+
const prototypeKeys =
|
|
84
|
+
prototype !== null ? Object.getOwnPropertyNames(prototype) : [];
|
|
85
|
+
|
|
86
|
+
const keys = [...prototypeKeys, ...Object.getOwnPropertyNames(obj)];
|
|
87
|
+
|
|
88
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions --
|
|
89
|
+
typescript can't express this in a safe way, so we use any here */
|
|
90
|
+
const objAsAny = obj as any;
|
|
91
|
+
|
|
92
|
+
// Exclude methods that should not be rebound (constructor, Object.prototype methods, etc.)
|
|
93
|
+
const EXCLUDED_METHODS = [
|
|
94
|
+
"constructor",
|
|
95
|
+
"hasOwnProperty",
|
|
96
|
+
"isPrototypeOf",
|
|
97
|
+
"propertyIsEnumerable",
|
|
98
|
+
"toLocaleString",
|
|
99
|
+
"toString",
|
|
100
|
+
"valueOf",
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
for (const key of keys) {
|
|
104
|
+
const val = objAsAny[key];
|
|
105
|
+
if (typeof val === "function" && !EXCLUDED_METHODS.includes(key)) {
|
|
106
|
+
objAsAny[key] = val.bind(obj);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|