UNPKG

626 BJavaScriptView Raw
1/**
2 * Extracts event handlers from a given object.
3 * A prop is considered an event handler if it is a function and its name starts with `on`.
4 *
5 * @param object An object to extract event handlers from.
6 * @param excludeKeys An array of keys to exclude from the returned object.
7 */
8export function extractEventHandlers(object, excludeKeys = []) {
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' && !excludeKeys.includes(prop)).forEach(prop => {
14 result[prop] = object[prop];
15 });
16 return result;
17}
\No newline at end of file