Skip to content

Commit 0fcf6b2

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

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/utility/replace.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/utility/replace.ts

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

0 commit comments

Comments
 (0)