Socket
Socket
Sign inDemoInstall

small-emitter

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.8 to 0.1.9

README.zh.md

0

dist/index.d.ts

@@ -0,0 +0,0 @@ export declare class Emitter {

8

package.json
{
"name": "small-emitter",
"version": "0.1.8",
"version": "0.1.9",
"license": "MIT",

@@ -48,3 +48,3 @@ "author": "Lv Heng",

"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^8.3.0",
"@rollup/plugin-typescript": "^11.1.6",
"@types/jest": "^27.0.3",

@@ -55,6 +55,6 @@ "@types/node": "^20.10.1",

"rollup": "^4.6.0",
"rollup-plugin-esbuild": "^4.7.2",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-typescript2": "^0.36.0",
"tslib": "^2.3.1",
"typescript": "^4.4.4",
"typescript": "^5.3.3",
"vite": "^2.7.0"

@@ -61,0 +61,0 @@ },

# Emitter
简体中文 | [English](./README.en.md)
English | [简体中文](./README.zh.md)
一个很小的 event emitter 库。
A small event emitter library.
## 安装
## Install
使用 npm 安装
Install with npm
```sh
npm i small-emitter
# or yarn add small-emitter
# or pnpm add small-emitter
```
在项目中导入
Import in the project
```js
// ES6 modules
import Emitter from 'small-emitter'
import { Emitter } from 'small-emitter'
// CommonJS modules
const Emitter = require('small-emitter')
const { Emitter } = require('small-emitter')
```
## 用法
## Usage
```js
import Emitter from 'small-emitter'
import { Emitter } from 'small-emitter'
const emitter = new Emitter();
// 订阅事件
// subscribe to events
emitter.on('foo', function (p1, p2, p3) {

@@ -37,3 +37,3 @@ // ...

// 只订阅一次事件
// subscribe the event only once
emitter.once('foo', function (p1, p2, p3) {

@@ -43,9 +43,9 @@ // ...

// 发布事件
// publish events
emitter.emit('foo', 'p1', 'p2', 'p3');
// 清空所有事件
// clearing all events
emitter.clear()
// 使用函数引用
// use reference functions
function fn() {}

@@ -60,8 +60,8 @@ emitter.on('foo', fn)

**参数**
**Arguments**
- `name` 事件名
- `callback` 事件的回调函数
- `name` name of the event
- `callback` event's callback function
**示例**
**Example**

@@ -81,8 +81,8 @@ ```js

**参数**
**Arguments**
- `name` 事件名
- `callback` 事件的回调函数
- `name` name of the event
- `callback` event's callback function
**示例**
**Example**

@@ -93,3 +93,3 @@ ```js

emitter.once('foo', (data) => {
// 这个函数只会执行一次
// The function will only be executed once
console.log(data)

@@ -104,8 +104,8 @@ })

**参数**
**Arguments**
- `name` 事件名
- `...args (optional)` 执行事件时传入的参数
- `name` name of the event
- `...args (optional)` parameters passed in by the execution event
**示例**
**Example**

@@ -124,8 +124,8 @@ ```js

**参数**
**Arguments**
- `name` 事件名
- `callback (optional)` 需要清除的函数或函数引用
- `name` name of the event
- `callback (optional)` functions that need to be cleared or function reference
**示例**
**Example**

@@ -147,5 +147,5 @@ ```js

调用此方法将清除所有事件
Calling this method will clear all events
**示例**
**Example**

@@ -170,4 +170,4 @@ ```js

## 开源协议
## License
[MIT License](https://opensource.org/licenses/MIT)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc