Comparing version 1.2.1 to 1.3.0
{ | ||
"name": "hookified", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Event and Middleware Hooks", | ||
"type": "module", | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"main": "dist/node/index.cjs", | ||
"module": "dist/node/index.js", | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.js" | ||
"import": "./dist/node/index.js", | ||
"require": "./dist/node/index.cjs" | ||
}, | ||
"./browser": { | ||
"import": "./dist/browser/index.js", | ||
"default": "./dist/browser/index.global.js" | ||
} | ||
}, | ||
"engines": { | ||
"node": ">=20" | ||
}, | ||
"types": "dist/node/index.d.ts", | ||
"scripts": { | ||
@@ -22,3 +23,3 @@ "test": "xo --fix && vitest run --coverage", | ||
"clean": "rimraf ./dist ./coverage ./site/dist", | ||
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean", | ||
"build": "rimraf ./dist && tsup", | ||
"website:build": "docula build", | ||
@@ -60,3 +61,3 @@ "website:serve": "docula serve", | ||
"devDependencies": { | ||
"@vitest/coverage-v8": "^2.1.2", | ||
"@vitest/coverage-v8": "^2.1.3", | ||
"docula": "^0.9.3", | ||
@@ -66,3 +67,3 @@ "rimraf": "^6.0.1", | ||
"typescript": "^5.6.3", | ||
"vitest": "^2.1.2", | ||
"vitest": "^2.1.3", | ||
"xo": "^0.59.3" | ||
@@ -69,0 +70,0 @@ }, |
@@ -11,3 +11,3 @@ ![site/logo.svg](site/logo.svg) | ||
## Features | ||
# Features | ||
- Simple replacement for EventEmitter | ||
@@ -18,3 +18,3 @@ - Async Middleware Hooks for Your Methods | ||
## Installation | ||
# Installation | ||
```bash | ||
@@ -24,3 +24,3 @@ npm install hookified --save | ||
## Usage | ||
# Usage | ||
This was built because we constantly wanted hooks and events extended on libraires we are building such as [Keyv](https://keyv.org) and [Cacheable](https://cacheable.org). This is a simple way to add hooks and events to your classes. | ||
@@ -72,35 +72,88 @@ | ||
## API | ||
# Using it in the Browser | ||
### .onHook(eventName, handler) | ||
```html | ||
<script type="module"> | ||
import { Hookified } from 'https://cdn.jsdelivr.net/npm/hookified/dist/browser/index.js'; | ||
class MyClass extends Hookified { | ||
constructor() { | ||
super(); | ||
} | ||
async myMethodEmittingEvent() { | ||
this.emit('message', 'Hello World'); //using Emittery | ||
} | ||
//with hooks you can pass data in and if they are subscribed via onHook they can modify the data | ||
async myMethodWithHooks() Promise<any> { | ||
let data = { some: 'data' }; | ||
// do something | ||
await this.hook('before:myMethod2', data); | ||
return data; | ||
} | ||
} | ||
</script> | ||
``` | ||
if you are not using ESM modules, you can use the following: | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/hookified/dist/browser/index.global.js"></script> | ||
<script> | ||
class MyClass extends Hookified { | ||
constructor() { | ||
super(); | ||
} | ||
async myMethodEmittingEvent() { | ||
this.emit('message', 'Hello World'); //using Emittery | ||
} | ||
//with hooks you can pass data in and if they are subscribed via onHook they can modify the data | ||
async myMethodWithHooks() Promise<any> { | ||
let data = { some: 'data' }; | ||
// do something | ||
await this.hook('before:myMethod2', data); | ||
return data; | ||
} | ||
} | ||
</script> | ||
``` | ||
# API | ||
## .onHook(eventName, handler) | ||
Subscribe to a hook event. | ||
### .removeHook(eventName) | ||
## .removeHook(eventName) | ||
Unsubscribe from a hook event. | ||
### .hook(eventName, ...args) | ||
## .hook(eventName, ...args) | ||
Run a hook event. | ||
### .hooks | ||
## .hooks | ||
Get all hooks. | ||
### .getHooks(eventName) | ||
## .getHooks(eventName) | ||
Get all hooks for an event. | ||
### .clearHooks(eventName) | ||
## .clearHooks(eventName) | ||
### .on(eventName, handler) | ||
## .on(eventName, handler) | ||
Subscribe to an event. | ||
### .off(eventName, handler) | ||
## .off(eventName, handler) | ||
Unsubscribe from an event. | ||
### .emit(eventName, ...args) | ||
## .emit(eventName, ...args) | ||
@@ -121,3 +174,3 @@ Emit an event. | ||
## Development and Testing | ||
# Development and Testing | ||
@@ -134,3 +187,3 @@ Hookified is written in TypeScript and tests are written in `vitest`. To run the tests, use the following command: | ||
## License | ||
# License | ||
@@ -137,0 +190,0 @@ [MIT & © Jared Wray](LICENSE) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33739
11
319
189
1