|
@@ -66,14 +66,17 @@ export function renameFunction<T extends Function> (fn: T, newName: string): T {
|
|
|
}
|
|
|
|
|
|
// change the name of an event
|
|
|
-export function event (emitter: NodeJS.EventEmitter, oldName: string, newName: string) {
|
|
|
+export function event (emitter: NodeJS.EventEmitter, oldName: string, newName: string, transformer: (...args: any[]) => any[] | undefined = (...args) => args) {
|
|
|
const warn = newName.startsWith('-') /* internal event */
|
|
|
? warnOnce(`${oldName} event`)
|
|
|
: warnOnce(`${oldName} event`, `${newName} event`);
|
|
|
return emitter.on(newName, function (this: NodeJS.EventEmitter, ...args) {
|
|
|
if (this.listenerCount(oldName) !== 0) {
|
|
|
warn();
|
|
|
- this.emit(oldName, ...args);
|
|
|
+ const transformedArgs = transformer(...args);
|
|
|
+ if (transformedArgs) {
|
|
|
+ this.emit(oldName, ...transformedArgs);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}
|