{"_id":"@2k/signal","_rev":"1-d66fe8371519dc2914f493307b603372","name":"@2k/signal","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@2k/signal","version":"0.0.1","description":"Tiny, typed signal utility for Node.js and browsers.","author":{"name":"scriptpower"},"keywords":["signal","events","micro","tiny","nodejs","browser","typescript"],"type":"module","types":"./lib/index.d.ts","main":"./lib/index.cjs","module":"lib/index.js","unpkg":"lib/index.iife.js","jsdelivr":"lib/index.iife.js","exports":{".":{"import":{"types":"./lib/index.d.ts","default":"./lib/index.js"},"require":{"types":"./lib/index.d.ts","default":"./lib/index.cjs"}}},"scripts":{},"publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"},"license":"MIT","_id":"@2k/signal@0.0.1","gitHead":"c4b01c2d1dde580ec50f430ac5b29e72ad346250","_nodeVersion":"20.6.1","_npmVersion":"10.2.0","dist":{"integrity":"sha512-WpBJksY3i/cgsi/U+Rkv5dcpXCb+gmL9Nf+etEcddblzex1bnLh73IkrBYecVLy26XoESTuJli4BEbn5vko/9g==","shasum":"7fd28ea88248ef665a9a03c3fc386f43dba4603e","tarball":"https://registry.npmjs.org/@2k/signal/-/signal-0.0.1.tgz","fileCount":6,"unpackedSize":3671,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDitTlBkO2+Z5o0OBa3mHRZUsFVewDPjiwvHwAM26dDrAIhAIpwuXbWFSABAP5+gVM99yyzFs2G4m3Ja2cKKtswzSQw"}]},"_npmUser":{"name":"scriptpower","email":"scriptpower@qq.com"},"directories":{},"maintainers":[{"name":"scriptpower","email":"scriptpower@qq.com"},{"name":"leiyl","email":"leiyl@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/signal_0.0.1_1699142373461_0.3959716227620296"},"_hasShrinkwrap":false}},"time":{"created":"2023-11-04T23:59:33.368Z","0.0.1":"2023-11-04T23:59:33.724Z","modified":"2023-11-05T00:00:54.659Z"},"maintainers":[{"email":"scriptpower@qq.com","name":"scriptpower"}],"description":"Tiny, typed signal utility for Node.js and browsers.","keywords":["signal","events","micro","tiny","nodejs","browser","typescript"],"author":{"name":"scriptpower"},"license":"MIT","readme":"# Signal\n\n> Tiny, typed signal utility for Node.js and browsers.\n\n_Need multiple dynamic events and types? Use [EE (Event Emitter)](https://www.npmjs.com/package/@2k/ee) instead_\n\n## Installation\n\n```sh\nnpm install @2k/signal --save\n```\n\n## Usage (TypeScript)\n\n```ts\nimport { Signal } from '@2k/signal';\n\n// specify callback param type\nconst signal = new Signal<number>();\nconst cb = (num: number) => console.log('signal', num);\nsignal.on(cb);\nsignal.emit(123);\nsignal.off(cb);\n```\n\n## Methods\n\n### `on(fn)`\n\nAttaches a signal handler to be called whenever the signal fires.\n\n### `once(fn)`\n\nAttaches a one-time handler which is unbound after it fires the first time.\n\n### `off(fn?)`\n\nDetaches one instance of a given handler from the signal. If no handler is provided, detaches all handlers.\n\n### `emit(arg)`\n\nFires the signal synchronously, triggering any attached handlers with the given `arg`.\n\n### `event(arg)`\n\nFires the signal asynchronously, triggering any attached handlers with the given `arg`. Useful when attaching handlers later in the same event loop turn.\n","readmeFilename":"readme.md"}