{"version":3,"file":"createHasHook.cjs","names":[],"sources":["../src/createHasHook.ts"],"sourcesContent":["import type { Hooks, StoreKey } from './types';\n/**\n *\n * Returns whether any handlers are attached for the given hookName and optional namespace.\n */\nexport type HasHook = (\n\t/**\n\t * The name of the hook to check for.\n\t */\n\thookname: string,\n\t/**\n\t * The unique namespace identifying the callback in the form `vendor/plugin/function`.\n\t */\n\tnamespace?: string\n) => boolean;\n\n/**\n * Returns a function which, when invoked, will return whether any handlers are\n * attached to a particular hook.\n *\n * @param hooks    Hooks instance.\n * @param storeKey\n *\n * @return  Function that returns whether any handlers are\n *                   attached to a particular hook and optional namespace.\n */\nfunction createHasHook( hooks: Hooks, storeKey: StoreKey ): HasHook {\n\treturn function hasHook( hookName, namespace ) {\n\t\tconst hooksStore = hooks[ storeKey ];\n\n\t\t// Use the namespace if provided.\n\t\tif ( 'undefined' !== typeof namespace ) {\n\t\t\treturn (\n\t\t\t\thookName in hooksStore &&\n\t\t\t\thooksStore[ hookName ].handlers.some(\n\t\t\t\t\t( hook ) => hook.namespace === namespace\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn hookName in hooksStore;\n\t};\n}\n\nexport default createHasHook;\n"],"mappings":";;;;;;;;;;;;;;;;AA0BA,SAAS,cAAe,OAAc,UAA8B;CACnE,OAAO,SAAS,QAAS,UAAU,WAAY;EAC9C,MAAM,aAAa,MAAO;EAG1B,IAAK,gBAAgB,OAAO,WAC3B,OACC,YAAY,cACZ,WAAY,SAAU,CAAC,SAAS,MAC7B,SAAU,KAAK,cAAc,SAChC;EAIF,OAAO,YAAY;CACpB;AACD"}