-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3df6922
Showing
13 changed files
with
4,304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Code Coverage | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
nodejs: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [18.x,20.x] | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Run the tests | ||
run: npm run test:coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dist | ||
node_modules | ||
*.tsbuildinfo | ||
.coverage | ||
types | ||
browser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 We Can Do Better | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# @wecandobetter/propeller | ||
|
||
![npm](https://img.shields.io/npm/v/@wecandobetter/propeller) | ||
![GitHub](https://img.shields.io/github/license/wecandobetter/propeller) | ||
|
||
A flexible and extensible hook system for JavaScript/TypeScript applications. | ||
Empower your projects with the ability to register, execute, and manage hooks | ||
for customized behavior and context management. | ||
|
||
## Features π£ | ||
|
||
- π Register hooks with unique names for different purposes. | ||
- π Execute hooks in a specified order, allowing customization of behavior. | ||
- π Hooks can modify context and return updated context, providing versatility. | ||
- π Type-safe hooks and context management for robust applications. | ||
- π Extensible and reusable for various projects and use cases. | ||
|
||
## Installation π¦ | ||
|
||
Install the package via npm: | ||
|
||
```bash | ||
npm install @wecandobetter/propeller | ||
``` | ||
|
||
## Usage π | ||
|
||
```typescript | ||
import { | ||
createHookCollection, | ||
type Hook, | ||
type HookCollection, | ||
} from "@wecandobetter/propeller"; | ||
|
||
// Define context interfaces for testing | ||
interface BeforeExecuteContext { | ||
a: number; | ||
} | ||
|
||
interface AfterExecuteContext { | ||
b: number; | ||
} | ||
|
||
// Create a hook collection | ||
const hooks = createHookCollection<{ | ||
beforeExecute: BeforeExecuteContext; | ||
afterExecute: AfterExecuteContext; | ||
}>(); | ||
|
||
// Register a hook | ||
hooks.register("beforeExecute", async (ctx) => { | ||
ctx.a = 42; // Modify the context | ||
}); | ||
|
||
// Execute a hook | ||
const context: BeforeExecuteContext = { a: 10 }; | ||
const updatedContext = await hooks.execute("beforeExecute", context); | ||
|
||
// Output: The context is updated with a = 42 | ||
console.log(updatedContext); | ||
``` | ||
|
||
## License π | ||
|
||
This project is licensed under the [MIT License](LICENSE). | ||
|
||
## Contributing πββοΈ | ||
|
||
Contributions are welcome! Feel free to open issues and submit pull requests. | ||
|
||
## Credits π | ||
|
||
Made with β€οΈβπ₯ by [We Can Do Better](https://wcdb.life). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { JestConfigWithTsJest } from "ts-jest"; | ||
|
||
const jestConfig: JestConfigWithTsJest = { | ||
preset: "ts-jest/presets/default-esm", // or other ESM presets | ||
moduleNameMapper: { | ||
"^(\\.{1,2}/.*)\\.js$": "$1", | ||
}, | ||
testMatch: ["<rootDir>/tests/*.ts"], | ||
transform: { | ||
// '^.+\\.[tj]sx?$' to process js/ts with `ts-jest` | ||
// '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest` | ||
"^.+\\.tsx?$": [ | ||
"ts-jest", | ||
{ | ||
useESM: true, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export default jestConfig; |
Oops, something went wrong.