Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MichielvdVelde committed Sep 18, 2023
0 parents commit 3df6922
Show file tree
Hide file tree
Showing 13 changed files with 4,304 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/ci.yaml
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist
node_modules
*.tsbuildinfo
.coverage
types
browser
20 changes: 20 additions & 0 deletions LICENSE
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.
73 changes: 73 additions & 0 deletions README.md
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).
21 changes: 21 additions & 0 deletions jest.config.ts
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;
Loading

0 comments on commit 3df6922

Please sign in to comment.