Skip to content

Commit 2ef153e

Browse files
committed
Migrate utility/replace.js to typescript
1 parent 02983ae commit 2ef153e

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/utility/replace.js

-9
This file was deleted.

src/utility/replace.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Replace a property of an object with a new function
3+
*
4+
* @param obj The object containing the property to replace
5+
* @param name The name of the property to replace
6+
* @param replacement A function that takes the original value and returns the replacement
7+
* @param replacements Optional object to store replacement history
8+
* @param type Optional string indicating the type of replacement
9+
*/
10+
export default function replace(
11+
obj: Record<string, any>,
12+
name: string,
13+
replacement: (orig: any) => any,
14+
replacements?: { [key: string]: Array<[Record<string, any>, string, any]> },
15+
type?: string,
16+
): void {
17+
const orig = obj[name];
18+
obj[name] = replacement(orig);
19+
if (replacements && type) {
20+
replacements[type].push([obj, name, orig]);
21+
}
22+
}

0 commit comments

Comments
 (0)