Skip to content

Commit

Permalink
feat: publish to JSR!
Browse files Browse the repository at this point in the history
  • Loading branch information
eliassjogreen committed Mar 3, 2024
1 parent 31dec9c commit d8e466e
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
run: deno fmt --check

- name: Run deno lint
run: deno lint --unstable
run: deno lint

test:
runs-on: ubuntu-latest
Expand Down
21 changes: 0 additions & 21 deletions .github/workflows/depsbot.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Publish

on:
push:
branches:
- main

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
- run: deno publish
5 changes: 5 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@denosaurs/event",
"version": "2.0.1",
"exports": "./mod.ts"
}
71 changes: 71 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,74 @@
/**
* # Event
*
* Strictly typed event emitter with asynciterator support.
*
* Events should be defined as a literal object type where the key is the event
* name, and the value is a tuple with any amount of elements of any type.
*
* The constructor takes an optional argument which defines the maximum amount of
* listeners per event, which defaults to 10. If this limit is surpassed, an error
* is thrown.
*
* ---
*
* > ⚠️ Events must be a type, and can't be an interface due to their design
* > differences.
*
* ---
*
* @example
*
* ```ts
* type Events = {
* foo: [string];
* bar: [number, boolean];
* };
*
* class MyClass extends EventEmitter<Events> {}
* const MyClassInstance = new MyClass();
*
* function listener(num, bool) {}
*
* // add a listener to the bar event
* MyClassInstance.on("bar", listener);
*
* // remove a listener from the bar event
* MyClassInstance.off("bar", listener);
*
* // remove all listeners from the bar event
* MyClassInstance.off("bar");
*
* // remove all listeners from the event emitter
* MyClassInstance.off();
*
* // add a one-time listener to the bar event
* MyClassInstance.once("bar", listener);
*
* // on, once, and off are chainable
* MyClassInstance.on("bar", listener).off("bar", listener);
*
* // emit the bar event with the wanted data
* MyClassInstance.emit("bar", 42, true);
*
* // listen to all events with an async iterator
* for await (const event of MyClassInstance) {
* if (event.name === "bar") {
* // event.value is of type [number, boolean]
* }
* }
*
* // listen to a specific event with an async iterator
* for await (const [num, bool] of MyClassInstance.on("bar")) {
* }
*
* // removes all listeners and closes async iterators
* MyClassInstance.close("bar");
* ```
*
* @module
*/

// Copyright 2020-present the denosaurs team. All rights reserved. MIT license.

type Entry<E, K extends keyof E> = {
Expand Down
6 changes: 1 addition & 5 deletions test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
assertEquals,
assertThrows,
fail,
} from "https://deno.land/[email protected]/testing/asserts.ts";
import { assertEquals, assertThrows, fail } from "jsr:@std/[email protected]";
import { EventEmitter } from "./mod.ts";

type Events = {
Expand Down

0 comments on commit d8e466e

Please sign in to comment.