{"id":15497491,"url":"https://github.com/bcomnes/dom-event-handler","last_synced_at":"2026-03-16T19:31:45.714Z","repository":{"id":30495052,"uuid":"124609152","full_name":"bcomnes/dom-event-handler","owner":"bcomnes","description":"A generic DOM event handler implementing the EventListener interface for class methods.","archived":false,"fork":false,"pushed_at":"2025-01-10T17:32:35.000Z","size":111,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-09T04:48:09.404Z","etag":null,"topics":["dom","eventhandler","eventlistener","events"],"latest_commit_sha":null,"homepage":"https://npmjs.com/dom-event-handler","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bcomnes.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["bcomnes"],"custom":["https://bret.io"]}},"created_at":"2018-03-10T00:55:54.000Z","updated_at":"2025-01-10T17:32:38.000Z","dependencies_parsed_at":"2023-01-14T17:04:36.940Z","dependency_job_id":"477d887d-6786-4cb2-85e2-769e7469773e","html_url":"https://github.com/bcomnes/dom-event-handler","commit_stats":{"total_commits":97,"total_committers":4,"mean_commits":24.25,"dds":"0.44329896907216493","last_synced_commit":"426c8743d649e2bda01a46946265bc078347d5a3"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/bcomnes/dom-event-handler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcomnes%2Fdom-event-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcomnes%2Fdom-event-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcomnes%2Fdom-event-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcomnes%2Fdom-event-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bcomnes","download_url":"https://codeload.github.com/bcomnes/dom-event-handler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcomnes%2Fdom-event-handler/sbom","scorecard":{"id":228716,"data":{"date":"2025-08-11","repo":{"name":"github.com/bcomnes/dom-event-handler","commit":"3fe91a3be47410b582248cacdbe4b42d5f23efd4"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/1 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/bcomnes/dom-event-handler/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/bcomnes/dom-event-handler/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/bcomnes/dom-event-handler/test.yml/master?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/test.yml:24","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   0 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: jobLevel 'contents' permission set to 'write': .github/workflows/test.yml:31","Warn: no topLevel permission defined: .github/workflows/test.yml:1"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 29 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T04:23:16.523Z","repository_id":30495052,"created_at":"2025-08-17T04:23:16.524Z","updated_at":"2025-08-17T04:23:16.524Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274046000,"owners_count":25212982,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dom","eventhandler","eventlistener","events"],"created_at":"2024-10-02T08:38:40.829Z","updated_at":"2026-03-16T19:31:45.681Z","avatar_url":"https://github.com/bcomnes.png","language":"JavaScript","funding_links":["https://github.com/sponsors/bcomnes","https://bret.io"],"categories":[],"sub_categories":[],"readme":"# dom-event-handler\n[![npm version][npmimg]][npm] [![build status][travisimg]][travis] [![coverage][coverallsimg]][coveralls]\n[![downloads][downloadsimg]][downloads] [![js-standard-style][standardimg]][standard]\n\nA generic DOM event handler implementing the [EventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventListener) interface for class methods.  Works great in the browser.  Does't work great in the Node.js ecosystem.\n\n## Installation\n```console\n$ npm install dom-event-handler\n```\n\n## Usage\n\n```js\nconst DOMEventHandler = require(\"dom-event-handler\")\n\nclass MyWSController extends SomeOtherClass {\n  constructor () {\n    this.ws = new WebSocket('ws://localhost:8080')\n    this.handler = new DOMEventHandler(this, this.ws)\n  }\n\n  // These methods handle the websocket events\n  onmessage (ev) {}\n  onopen (ev) {}\n  onerror (ev) {}\n  onclose (ev) {}\n}\n```\n\nIsn't that nicer than this?\n\n```js\nconst ws = new WebSocket('ws://localhost:8080')\n\nclass VerboseWSController {\n  constructor () {\n    this.foo = 'bar'\n\n    // You have to bind since you don't pass a full context.\n    // Static class properties assigned to arrow functions are less verbose\n    // but are structurally similar to binding, and have poor env support still.\n    // They don't reside on the prototype.  That may or may not matter to the use case.\n    this.onmessage = this.onmessage.bind(this)\n    this.onopen = this.onopen.bind(this)s\n    this.onerror = this.onerror.bind(this)\n    this.onclose = this.onclose.bind(this)\n  }\n\n  onmessage (ev) {}\n  onopen (ev) {}\n  onerror (ev) {}\n  onclose (ev) {}\n}\n\nconst c = new VerboseWSController()\n\nws.addEventListener('message', c.onmessage)\nws.addEventListener('open', c.onopen)\nws.addEventListener('error', c.onerror)\nws.addEventListener('close', c.onclose)\n```\n\n## API\n\n### `handler = new DOMEventHandler(ctx, [node])`\n\nCreate a new instance of `DOMEventHandler` passing in a context `ctx` (often `this` when created within a class) and optionally a [DOM event target][domtarget] `node` (e.g. an event emitting DOM node) to attach listeners to on instantiation.\n\nThe `ctx` should be an object who's prototype contains event handler methods.  Event handler methods must take the form of `on{eventname}` where `eventname` is the name of the event you want to listen on and handle (the name you would pass to `node.addEventListener`).  In practice, you can pass a class instance as a `ctx`, or `this` when the instance owns the `DOMEventHanlder` instance.\n\n### `handler.addEventListeners(node)`\n\nAttach all `event` handler methods on `ctx` to the [DOM event target][domtarget] `node`.\n\n### `handler.removeEventListeners(node)`\n\nRemove all `event` handler event names on `ctx` from the [DOM event target][domtarget] `node`.\n\n### Internal Methods\n\nYou don't need to call these, but they are there.\n\n#### `handler.handleEvent(event)`\n\nImplements the [`eventListener.handleEvent`](https://developer.mozilla.org/en-US/docs/Web/API/EventListener/handleEvent) method for the  `events` found on the `ctx` prototype.  This is where the magic happens.\n\n#### `handler.events`\n\nA getter that returns all events found on the `ctx` the handler is bound to.  The events returned from this getter are what get attached and detached in the above methods.\n\n## See also\n\nThis module was inspired by a @webreflection [article](https://medium.com/@WebReflection/dom-handleevent-a-cross-platform-standard-since-year-2000-5bf17287fd38).\n\n This is a slick API, but has poor support in the Node.js ecosystem due to poor support for the [EventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventListener) interface ([Node.js style events](https://nodejs.org/api/events.html) do not support [handleEvent](https://developer.mozilla.org/en-US/docs/Web/API/EventListener/handleEvent) or similar).  For a similar API see [node-event-handler](https://github.com/bcomnes/node-event-handler), which lacks the bind free benefits of this approach, but can provide a stand-in api when writing universal Node.js code.\n\n## License\n[MIT](https://tldrlegal.com/license/mit-license)\n\n[stabilityimg]: https://img.shields.io/badge/stability-experimental-orange.svg\n[stability]: https://nodejs.org/api/documentation.html#documentation_stability_index\n[npmimg]: https://img.shields.io/npm/v/dom-event-handler.svg\n[npm]: https://npmjs.org/package/dom-event-handler\n[travisimg]: https://img.shields.io/travis/bcomnes/dom-event-handler/master.svg\n[travis]: https://travis-ci.org/bcomnes/dom-event-handler\n[downloadsimg]: http://img.shields.io/npm/dm/dom-event-handler.svg\n[downloads]: https://npmjs.org/package/dom-event-handler\n[standardimg]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg\n[standard]: https://github.com/feross/standard\n[coverallsimg]: https://img.shields.io/coveralls/bcomnes/dom-event-handler/master.svg\n[coveralls]: https://coveralls.io/github/bcomnes/dom-event-handler\n\n\n[domtarget]: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbcomnes%2Fdom-event-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbcomnes%2Fdom-event-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbcomnes%2Fdom-event-handler/lists"}