UNPKG

549 BJavaScriptView Raw
1/**
2 * Removes event handlers from the given object.
3 * A field is considered an event handler if it is a function with a name beginning with `on`.
4 *
5 * @param object Object to remove event handlers from.
6 * @returns Object with event handlers removed.
7 */
8export function omitEventHandlers(object) {
9 if (object === undefined) {
10 return {};
11 }
12 const result = {};
13 Object.keys(object).filter(prop => !(prop.match(/^on[A-Z]/) && typeof object[prop] === 'function')).forEach(prop => {
14 result[prop] = object[prop];
15 });
16 return result;
17}
\No newline at end of file