# levent

> A better solution of distributing events in TS and JS. [![Test](https://github.com/zsh2401/eventx/actions/workflows/test.yml/badge.svg)](https://github.com/zsh2401/eventx/actions/workflows/test.yml) [![Publish](https://github.com/zsh2401/eventx/action

Latest version **0.3.12** (published 2025-08-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install levent
pnpm add levent
yarn add levent
bun add levent
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.12 |
| Published | 2025-08-16 |
| First published | 2022-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 60.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Seymour Zhang |
| Maintainers | zsh2401 |

## Links

- npm: https://www.npmjs.com/package/levent
- npm.io page: https://npm.io/package/levent

## Recent versions

- 0.3.12 (latest) — 2025-08-16
- 0.3.8 — 2022-07-27
- 0.3.7 — 2022-06-04
- 0.3.6 — 2022-06-04
- 0.3.0 — 2022-05-26
- 0.2.1 — 2022-05-21
- 0.1.1 — 2022-05-21

## README

# 🚌 Levent
A better solution of distributing events in TS and JS.    
[![Test](https://github.com/zsh2401/eventx/actions/workflows/test.yml/badge.svg)](https://github.com/zsh2401/eventx/actions/workflows/test.yml)
[![Publish](https://github.com/zsh2401/eventx/actions/workflows/publish.yml/badge.svg)](https://github.com/zsh2401/eventx/actions/workflows/publish.yml)
    
🌟 High performance   
🌟 Async supported   
🌟 Sticky event   
🌟 Preventable   
🌟 Lightful (Minified + Gzipped = 1kB)   

## Getting Started
```
pnpm add levent
yarn add levent
npm install --save levent
```

### Quick Start
```typescript
import levent from "levent"

//subscribe event
levent.on("test",(arg:string)=>{
    return arg
})

//publish event.
const values = levent.emit("test","I love you.")

console.log(values) // ['I love you.']
```
### Strict event types.
```typescript
import { Levent } from "levent"

// create your own event bus instance
const bus : Levent<{
    "example-event":[string,number]
}>

//define the handler
function handler(arg:string){
    return arg.length;
}

//subscribe
bus.on("example-event",handler)

// publish event
const values = bus.emit( "example-event","I Love You")

//desubscribe
bus.off("example-event",handler)
```


### Async☘️
```typescript
bus.on("example-event",async (arg)=>{
    return await someAsyncOperation(arg)
})

// emit event and wait all handler returns.
const values = await bus.emit("example-event",null,{ async:true })

```
### Hooks
```typescript
eventx.emit("example-event",null,{
    afterEach:(r:any)=>{
        console.log("last handler's result: " + r)
    }
})


```
## Join in development!🏋🏻‍♂️
### 1. Get the source
```sh
git clone https://github.com/zsh2401/levent && cd levent
```
### 2. Go
```sh
# Download dependencies
pnpm
# Build it
pnpm build
# Or run unit test
pnpm test
```

All pull requests are welcomed!🧑‍💻

---
_Source: https://npm.io/package/levent · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
