{"id":25971091,"url":"https://github.com/elijah-bodden/know","last_synced_at":"2025-07-22T04:04:38.443Z","repository":{"id":56763982,"uuid":"523947358","full_name":"Elijah-Bodden/kNow","owner":"Elijah-Bodden","description":"Plug-and-play, faster-than-native promise/callback event emitter","archived":false,"fork":false,"pushed_at":"2022-08-22T11:45:41.000Z","size":180,"stargazers_count":26,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-14T02:04:18.806Z","etag":null,"topics":["async","emitters","event-management","events","javascript","js","mit-license","node","node-module","node-modules","nodejs","npm-module","npm-package","open-source","opensource","promise"],"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/Elijah-Bodden.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-12T03:50:21.000Z","updated_at":"2024-10-13T04:58:39.000Z","dependencies_parsed_at":"2022-08-16T02:10:28.530Z","dependency_job_id":null,"html_url":"https://github.com/Elijah-Bodden/kNow","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Elijah-Bodden/kNow","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elijah-Bodden%2FkNow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elijah-Bodden%2FkNow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elijah-Bodden%2FkNow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elijah-Bodden%2FkNow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Elijah-Bodden","download_url":"https://codeload.github.com/Elijah-Bodden/kNow/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elijah-Bodden%2FkNow/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266424026,"owners_count":23926124,"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-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":["async","emitters","event-management","events","javascript","js","mit-license","node","node-module","node-modules","nodejs","npm-module","npm-package","open-source","opensource","promise"],"created_at":"2025-03-04T23:31:05.740Z","updated_at":"2025-07-22T04:04:38.418Z","avatar_url":"https://github.com/Elijah-Bodden.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cimg src=\"./Assets/logo.svg\" width=\"128\" height=\"128\"\u003e\u003c/img\u003e\u003cbr\u003e\n  kNow\n\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\nBlazing-fast callback/promise-based events with a tiny footprint\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/bundlephobia/minzip/@elijah-bodden/know/latest?label=Minzipped%20size\u0026style=flat-square\"/\u003e\n  \u003cimg src=\"https://img.shields.io/github/license/Elijah-Bodden/kNow?style=flat-square\"/\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@elijah-bodden/know\"\u003e\u003cimg src=\"https://img.shields.io/npm/dt/@elijah-bodden/know?color=%23009eb0\u0026label=NPM%20downloads\u0026style=flat-square\"/\u003e\u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/maintenance/yes/2022?label=Maintained\u0026style=flat-square\"/\u003e\n  \u003ca href=\"https://twitter.com/intent/tweet?text=A+tiny+event+emitter+that+packs+a+punch.\u0026url=https%3A%2F%2Fgithub.com%2FElijah-Bodden%2FkNow\u0026hashtags=javascript+js+opensource+javascriptdev+eventhandler+emitter+github\u0026original_referer=http%3A%2F%2Fgithub.com%2F\u0026tw_p=tweetbutton\" target=\"_blank\"\u003e\n  \u003cimg src=\"http://jpillora.com/github-twitter-button/img/tweet.png\" title=\"A tiny event emitter that packs a punch.\"\u003e\u003c/img\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## What is this?\nWith kNow (pronounced \"*now*\"—the k's silent), JavaScript event management has never been more intuitive—or lighter-weight. Want to append custom actions to functions on-the-fly? To use awaitable timers to pause and resume execution at any time? To create large numbers of listeners without worrying about performance degradation? If so, you want kNow.  \n| \u003cimg src=\"./Assets/jsben.ch.jpg\"/\u003e |\n|:--:|\n| \u003cp align=\"center\"\u003e\u003ci\u003eVia https://jsben.ch/ZESbj (Avg. over 25 runs)\u003c/i\u003e\u003c/p\u003e |  \n\nOriginally developed for use in [Membrane](https://github.com/Elijah-Bodden/Membrane), kNow is a fully functional, if lightweight, native event-management utility for any use-case.\n\n## Getting Started\n### Node.js + npm\n#### Installation:\nTo install in the root of your node project:\n```bash\nnpm i @elijah-bodden/know\n```\nOr else globally:\n```bash\nnpm i @elijah-bodden/know -g\n```\n#### Use in-script\nTo import the module into your node script, simply paste the following line at the very top:\n```JavaScript\nconst kNow = require('@elijah-bodden/know')\n```\nThen, to create a usable intance, add `const someVariable = new kNow()` anywhere, where 'someVariable' is the name you wish to access it by.\n### HTML `script` tag\n#### Inclusion\nTo include the script in your HTML, add the following tag to the top of your document:\n```HTML\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/@elijah-bodden/know/index.min.js\"\u003e\n```\n#### Use in-script\nJust as with node, simply drop in `const someVariable = new kNow()` anywhere in your script, changing 'someVariable' to the name you want to reference the instance with.\n## Examples\n### Pause function execution for n milliseconds\n```JavaScript\n  const kNow = require(\"@elijah-bodden/know\");\n  const know = new kNow()\n  \n  async function test() {\n    console.log(\"foo\")\n    console.log(\"bar\")\n    //Creates and awaits a promise that resolves in 3000ms or 3 seconds\n    await know.in(3000)\n    console.log(\"baz\")\n  }\n  \n  test()\n  \n  /* Expected Output:\n    1. \"foo\"\n    2. \"bar\"\n    *Three-second pause*\n    3. \"baz\"\n  */\n```\n\n### Track changes to a variable\n```JavaScript\n  const kNow = require(\"@elijah-bodden/know\");\n  const know = new kNow()\n  \n  var variable\n  \n  function setVariable(newVal) {\n    variable = newVal\n    know.dispatch(\"variableChanged\", variable)\n  }\n  \n  setInterval(() =\u003e setVariable(Math.random()), 1000)\n  \n  //Listener callbacks can be created and destroyed at any time, on-the-fly.\n  const changeListener = know.when(\"variableChanged\", (newVal) =\u003e console.log(`Variable \"variable\" was changed to ${newVal}.`))\n\n  setTimeout(() =\u003e know.clearWhen(changeListener), 5000)\n  /* Expected Output:\n    *1 second pause* \"Variable was changed to (some value)\" x 4\n  */\n\n```\n### Call function X next time Y completes\n```JavaScript\n  const kNow = require(\"@elijah-bodden/know\");\n  const know = new kNow()\n\n  function unpredictableFunction() {\n    for (let i = 0; i \u003c 10000000; i++) {\n      //Doing some valuable operations\n    }\n    console.log(\"Alerting that task was completed.\")\n    know.dispatch(\"taskCompleted\")\n    setTimeout(unpredictableFunction, Math.floor(Math.random()*10000))\n  }\n  \n  setTimeout(unpredictableFunction, Math.floor(Math.random()*10000))\n  \n  know.next(\"taskCompleted\").then(() =\u003e console.log(\"Task completed!\"))\n  \n  /* Expected Output:\n    *Indefinite pause*\n    1. \"Alerting that task was completed.\"\n    2. \"Task completed!\"\n  */\n```\n\n## Methods\nUse any of the following functions on a kNow instance to implement powerful, high-speed event handling in a snap.\n| Command | Description |\n| --- | --- |\n| **constructor**(number) | When you initialize kNow, you can optionally pass a single argument, the length of time, in milliseconds, after which each `next` listener automatically expires. |\n| **when**(number \\| string, function) | Automatically attatches a callback, its second argument, which will run every time the first argument's value is `dispatched`. The function returns an `instanceID` object which can be passed into `clearWhen` to destroy the listener. |\n| **clearWhen**(object \\| string \\| number \\| undefined) | Accepts either a string or a number, an `instanceID` object, or no value. If it recieves a string or a number, kNow will unregister all `when` callbacks bound to that dispatch value; if it instead gets an `instanceID` created by `when`, only the callback created by this call will be destroyed. Otherwise, if the value is `undefined`, all callbacks registered to all `ID`'s will be destroyed simultaneously. |\n| **dispatch**(number \\| string, any) | Immediately resolves all promises bound through `next` to the first parameter, and invokes all callbacks attatched to it by `when`. All promises will resolve to the second argument, which will also be passed to all callback functions.|\n| **forceReject**(number \\| string, any) | `forceReject` does the exact opposite of `dispatch`, batch-rejecting all promises attatched to the first argument and setting the `reason`s to the second. |\n| **next**(number \\| string, number \\| undefined) | `next` returns a promise which may either be resolved by `dispatching` the value provided as the first parameter, or rejected through `clearNext` or `forceReject`. Optionally, a second argument, a timeout, may be specified, after which to automatically reject to promise. If this argument is omited, it will default to the value provided to the constructor, and if this too is undefined, there will be no timeout. |\n| **clearnext**(...string \\| number \\| undefined) | Accepts a list of dispatch ID's; if none are provided, it defaults to every registered ID. Each promise registered to each of these ID's is `forceReject`ed with the reason \"flushed\". |\n| **in**(number) | Returns a promise which will resolve to `undefined` in the specified number of milliseconds. |\n| **clearIn**() | Immediately `forceReject`s every promise created by `in` |\n\n## License\nkNow is distributed under the MIT license. See the `LICENSE` file for more information.  \n\n## Contributing\nAny and all contributions are greatly appreciated. If you want to see this project grow as much as I do, there are several ways to help. Firstly, if you see something you think you can improve within the code, please `fork` the repository and make a `pull` request once you have made any changes you'd like to see. If you just have an idea, or spot a bug, that's great too! In this case, please file an `issue` with a corresponding `bug` or `enhancement` tag. Oh, and if you like what you see here, please feel free to leave a star on the project, it would mean a ton to me.\n\n## Contact\nElijah Bodden - elijahbodden@protonmail.com  \nProject - https://github.com/Elijah-Bodden/kNow  \nnpm - https://www.npmjs.com/package/@elijah-bodden/know\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felijah-bodden%2Fknow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felijah-bodden%2Fknow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felijah-bodden%2Fknow/lists"}