UNPKG

@hoover-institution/hubspot-lib

Version:

A toolkit for deep integration with HubSpot's Marketing Events API with a plugin-based architecture.

36 lines (33 loc) 956 B
/** @type {Record<string, number>} */ const HOOKS = {}; let nextBit = 0; /** * Defines named hooks and assigns each a unique bitmask (power of 2). * If a hook has already been defined, it will be skipped. * * This function is idempotent and safe to call multiple times. * * @param {string[]} names - List of hook/plugin names to register * @returns {Record<string, number>} A map of hook names to assigned bitmask values * * @example * defineHooks(["MONGO_SYNC", "CUSTOM_PLUGIN"]); * // => { MONGO_SYNC: 1, CUSTOM_PLUGIN: 2 } */ export function defineHooks(names = []) { for (const name of names) { if (!HOOKS[name]) { HOOKS[name] = 1 << nextBit++; } } return HOOKS; } /** * Returns a shallow copy of the current hook/bitmask map. * Useful for debugging or inspection. * * @returns {Record<string, number>} A map of all registered hooks and their bit values */ export function getHookMap() { return { ...HOOKS }; }