{"id":15392811,"url":"https://github.com/kutyel/es6-emitter","last_synced_at":"2025-04-15T23:28:19.720Z","repository":{"id":57227114,"uuid":"98185394","full_name":"kutyel/es6-emitter","owner":"kutyel","description":"🚀 Smallest event emitter for JavaScript with all the power of ES6 Maps!","archived":false,"fork":false,"pushed_at":"2019-07-25T09:25:58.000Z","size":76,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-16T06:01:43.960Z","etag":null,"topics":["es6","es6-map","eventemitter","events","pubsub"],"latest_commit_sha":null,"homepage":"","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/kutyel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-24T11:52:27.000Z","updated_at":"2022-01-17T05:33:41.000Z","dependencies_parsed_at":"2022-09-04T16:01:29.595Z","dependency_job_id":null,"html_url":"https://github.com/kutyel/es6-emitter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kutyel%2Fes6-emitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kutyel%2Fes6-emitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kutyel%2Fes6-emitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kutyel%2Fes6-emitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kutyel","download_url":"https://codeload.github.com/kutyel/es6-emitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240351458,"owners_count":19787834,"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","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":["es6","es6-map","eventemitter","events","pubsub"],"created_at":"2024-10-01T15:16:16.580Z","updated_at":"2025-02-28T19:30:46.849Z","avatar_url":"https://github.com/kutyel.png","language":"JavaScript","funding_links":["https://paypal.me/flaviocorpa"],"categories":[],"sub_categories":[],"readme":"# es6-emitter\n\n[![Standard - JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\n[![Node version](https://img.shields.io/node/v/es6-emitter.svg?style=flat-square)](https://www.npmjs.org/package/es6-emitter)\n[![Build Status](https://img.shields.io/travis/kutyel/es6-emitter/master.svg?style=flat-square)](https://travis-ci.org/kutyel/es6-emitter)\n[![Coverage Status](https://img.shields.io/coveralls/kutyel/es6-emitter.svg?style=flat-square)](https://coveralls.io/github/kutyel/es6-emitter)\n[![Dependency status](https://img.shields.io/david/kutyel/es6-emitter.svg?style=flat-square)](https://david-dm.org/kutyel/es6-emitter)\n[![Dev Dependencies Status](https://img.shields.io/david/dev/kutyel/es6-emitter.svg?style=flat-square)](https://david-dm.org/kutyel/es6-emitter#info=devDependencies)\n[![NPM Status](https://img.shields.io/npm/dm/es6-emitter.svg?style=flat-square)](https://www.npmjs.org/package/es6-emitter)\n[![Donate](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square)](https://paypal.me/flaviocorpa)\n\n\u003e Smallest event emitter for JavaScript with all the power of ES6 Maps!\n\n## Install\n\n```bash\n$ npm install es6-emitter --save\n```\n\n## Usage\n\n```javascript\nimport Emitter from 'es6-emitter'\n\nconst em = new Emitter()\n```\n\n## API\n\n### subscribe (name, callback)\n\nAllows you to add subscriptions to your emitter given a certain name, **multiple subscriptions** under the same name are allowed!\n\n```js\nconst sub1 = em.subscribe('myEvent', foo =\u003e console.log('a callback!'));\n\nconst sub2 = em.subscribe('myEvent', (bar, baz) =\u003e console.log('another callback!'));\n\nsub1(); // releases the first subscription\n```\n\n**Returns** a function to release the subscription while the others remain intact.\n\n#### name\n\n*Required*\u003cbr\u003e\nType: `any`\n\nCan be literally [any](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) type, and corresponds to the name of the event that you want the Emitter to subscribe to.\n\n#### callback\n\n*Required*\u003cbr\u003e\nType: `function`\n\nSide effect that you want to associate with the name of the event.\n\n### emit (name[, args])\n\nAllows you to emit any subscription added to the emitter, with any number of arguments.\n\n```js\nem.emit('myEvent', 1, '2', null, () =\u003e 4);\n```\n\n**Returns** an array with every return value for each subscription callback.\n\n```js\nconst s1 = em.subscribe('otherEvent', () =\u003e 1);\nconst s2 = em.subscribe('otherEvent', () =\u003e 2);\nconst s3 = em.subscribe('otherEvent', () =\u003e true);\nconst result = em.emit('otherEvent'); // \u003e [1, 2, true]\n```\n\n#### name\n\n*Required*\u003cbr\u003e\nType: `any`\n\nJust as in the `subscribe` function, this is the `name` of the event you want to emit.\n\n#### args\n\nAny number of values of `any` type to be passed to the subscription functions.\n\n## ES6 Map Awesomeness ✨\n\nThanks to **ES Maps** goodness, the `name` of the event subscribed can be literally *anything*, even another function! 😱\n\n```js\nconst em = new Emitter();\n\nconst eventObject = { name: 'click', debounce: 300 };\nconst eventFunction = e =\u003e console.log(e);\n\nconst sub1 = em.subscribe(NaN, () =\u003e 'not a number');\nconst sub2 = em.subscribe(eventObject, () =\u003e 'called with an object!');\nconst sub3 = em.subscribe(eventFunction, () =\u003e 'called with a function!');\n\nem.emit(NaN); // \u003e ['not a number']\nem.emit(eventObject); // \u003e ['called with an object!']\nem.emit(eventFunction); // \u003e ['called with a function!']\n```\n\n## License\n\nMIT © [Flavio Corpa](https://github.com/kutyel).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkutyel%2Fes6-emitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkutyel%2Fes6-emitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkutyel%2Fes6-emitter/lists"}