UNPKG

739 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = extractEventHandlers;
7/**
8 * Extracts event handlers from a given object.
9 * A prop is considered an event handler if it is a function and its name starts with `on`.
10 *
11 * @param object An object to extract event handlers from.
12 * @param excludeKeys An array of keys to exclude from the returned object.
13 */
14function extractEventHandlers(object, excludeKeys = []) {
15 if (object === undefined) {
16 return {};
17 }
18 const result = {};
19 Object.keys(object).filter(prop => prop.match(/^on[A-Z]/) && typeof object[prop] === 'function' && !excludeKeys.includes(prop)).forEach(prop => {
20 result[prop] = object[prop];
21 });
22 return result;
23}
\No newline at end of file