hookified 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,7 +20,7 @@ npm install hookified --save
20
20
  ```
21
21
 
22
22
  ## Usage
23
- this is primarily a library for creating hooks and middleware for your own libraries. Here is an example of a class that is extended using hookified.
23
+ This was built because we constantly wanted hooks and events extended on libraires we are building such as [Keyv](https://keyv.org). This is a simple way to add hooks and events (via [emittery](https://npmjs.com/package/emittery)) to your libraries.
24
24
 
25
25
  ```javascript
26
26
  import { Hookified } from 'hookified';
@@ -30,18 +30,16 @@ class MyClass extends Hookified {
30
30
  super();
31
31
  }
32
32
 
33
- async myMethod() {
34
- await this.emit('before:myMethod');
35
- // do something
36
- await this.emit('after:myMethod');
33
+ async myMethodEmittingEvent() {
34
+ await this.emit('message', 'Hello World');
37
35
  }
38
36
 
39
- async myMethod2() Promise<any> {
37
+ //with hooks you can pass data in and if they are subscribed via onHook they can modify the data
38
+ async myMethodWithHooks() Promise<any> {
40
39
  let data = { some: 'data' };
41
40
  // do something
42
41
  await this.hook('before:myMethod2', data);
43
- // do something
44
- await this.hook('after:myMethod2', data);
42
+
45
43
  return data;
46
44
  }
47
45
  }
package/dist/index.d.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import Emittery from 'emittery';
2
- type HookHandler = (...arguments_: any[]) => Promise<void> | void;
2
+ export type Hook = (...arguments_: any[]) => Promise<void> | void;
3
3
  export declare class Hookified extends Emittery {
4
- _hookHandlers: Map<string, HookHandler[]>;
4
+ _hooks: Map<string, Hook[]>;
5
5
  constructor();
6
- onHook(event: string, handler: HookHandler): Promise<void>;
7
- removeHook(event: string, handler: HookHandler): Promise<void>;
6
+ onHook(event: string, handler: Hook): Promise<void>;
7
+ removeHook(event: string, handler: Hook): Promise<void>;
8
8
  hook(event: string, data: any): Promise<void>;
9
- get hookHandlers(): Map<string, HookHandler[]>;
9
+ get hooks(): Map<string, Hook[]>;
10
10
  }
11
- export {};
package/dist/index.js CHANGED
@@ -1,23 +1,23 @@
1
1
  import Emittery from 'emittery';
2
2
  export class Hookified extends Emittery {
3
- _hookHandlers;
3
+ _hooks;
4
4
  constructor() {
5
5
  super();
6
- this._hookHandlers = new Map();
6
+ this._hooks = new Map();
7
7
  }
8
8
  // Adds a handler function for a specific event
9
9
  async onHook(event, handler) {
10
- const eventHandlers = this._hookHandlers.get(event);
10
+ const eventHandlers = this._hooks.get(event);
11
11
  if (eventHandlers) {
12
12
  eventHandlers.push(handler);
13
13
  }
14
14
  else {
15
- this._hookHandlers.set(event, [handler]);
15
+ this._hooks.set(event, [handler]);
16
16
  }
17
17
  }
18
18
  // Removes a specific handler function for a specific event
19
19
  async removeHook(event, handler) {
20
- const eventHandlers = this._hookHandlers.get(event);
20
+ const eventHandlers = this._hooks.get(event);
21
21
  if (eventHandlers) {
22
22
  const index = eventHandlers.indexOf(handler);
23
23
  if (index !== -1) {
@@ -27,7 +27,7 @@ export class Hookified extends Emittery {
27
27
  }
28
28
  // Triggers all handlers for a specific event with provided data
29
29
  async hook(event, data) {
30
- const eventHandlers = this._hookHandlers.get(event);
30
+ const eventHandlers = this._hooks.get(event);
31
31
  if (eventHandlers) {
32
32
  for (const handler of eventHandlers) {
33
33
  try {
@@ -42,9 +42,9 @@ export class Hookified extends Emittery {
42
42
  }
43
43
  }
44
44
  // Provides read-only access to the current handlers
45
- get hookHandlers() {
45
+ get hooks() {
46
46
  // Creating a new map to prevent external modifications to the original map
47
- return new Map(this._hookHandlers);
47
+ return this._hooks;
48
48
  }
49
49
  }
50
50
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAIhC,MAAM,OAAO,SAAU,SAAQ,QAAQ;IACtC,aAAa,CAA6B;IAE1C;QACC,KAAK,EAAE,CA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;IAChE,KAAK,CAAC,IAAI,CAAC,KAAa,EAAE,IAAS;QAClC,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC7C,IAAI,aAAa,EAAE,CAAC;YACnB,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE,CAAC;gBACrC,IAAI,CAAC;oBACJ,4CAA4C;oBAC5C,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;gBACrB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBAChB,4CAA4C;oBAC5C,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,KAAK,CAAC,oCAAoC,KAAK,MAAO,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBAChH,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAED,oDAAoD;IACpD,IAAI,KAAK;QACR,2EAA2E;QAC3E,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD"}
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "hookified",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Event and Middleware Hooks",
5
5
  "type": "module",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
6
+ "main": "./dist/index.js",
7
+ "exports": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "engines": {
10
+ "node": ">=20"
11
+ },
8
12
  "scripts": {
9
13
  "test": "xo --fix && vitest run --coverage",
10
14
  "test:ci": "xo && vitest run --coverage",
@@ -57,5 +61,9 @@
57
61
  "typescript": "^5.5.4",
58
62
  "vitest": "^2.0.5",
59
63
  "xo": "^0.59.3"
60
- }
64
+ },
65
+ "files": [
66
+ "dist",
67
+ "LICENSE"
68
+ ]
61
69
  }
@@ -1,14 +0,0 @@
1
- ---
2
- name: Bug report
3
- about: Create a report to help us improve
4
- title: ''
5
- labels: bug
6
- assignees: ''
7
-
8
- ---
9
-
10
- **Describe the bug**
11
- A clear and concise description of what the bug is.
12
-
13
- **How To Reproduce (best to provide workable code or tests!)**
14
- Please provide code or unit test example that will reproduce the error. If you can't provide code, please provide a detailed description of how to reproduce the error.
@@ -1,14 +0,0 @@
1
- ---
2
- name: Feature request
3
- about: Suggest an idea for this project
4
- title: ''
5
- labels: enhancement
6
- assignees: ''
7
-
8
- ---
9
-
10
- **Is your feature request related to a problem? Please describe.**
11
- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
-
13
- **Describe the solution you'd like**
14
- A clear and concise description of what you want to happen.
@@ -1,6 +0,0 @@
1
- **Please check if the PR fulfills these requirements**
2
- - [ ] Followed the [Contributing](https://github.com/jaredwray/hookified/blob/main/CONTRIBUTING.md) guidelines.
3
- - [ ] Tests for the changes have been added (for bug fixes/features) with 100% code coverage.
4
- - [ ] Docs have been added / updated (for bug fixes / features)
5
-
6
- **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...)
@@ -1,39 +0,0 @@
1
- name: code-coverage
2
-
3
- on:
4
- workflow_dispatch:
5
- push:
6
- branches: [ main ]
7
- pull_request:
8
- branches: [ main ]
9
-
10
- jobs:
11
- build:
12
-
13
- runs-on: ubuntu-latest
14
-
15
- strategy:
16
- matrix:
17
- node-version: ['20']
18
-
19
- steps:
20
- - uses: actions/checkout@v4
21
- - name: Use Node.js ${{ matrix.node-version }}
22
- uses: actions/setup-node@v4
23
- with:
24
- node-version: ${{ matrix.node-version }}
25
-
26
- - name: Install Dependencies
27
- run: npm install
28
-
29
- - name: Build
30
- run: npm run build
31
-
32
- - name: Testing
33
- run: npm run test
34
-
35
- - name: Code Coverage
36
- uses: codecov/codecov-action@v3
37
- with:
38
- token: ${{ secrets.CODECOV_KEY }}
39
-
@@ -1,72 +0,0 @@
1
- # For most projects, this workflow file will not need changing; you simply need
2
- # to commit it to your repository.
3
- #
4
- # You may wish to alter this file to override the set of languages analyzed,
5
- # or to provide custom queries or build logic.
6
- #
7
- # ******** NOTE ********
8
- # We have attempted to detect the languages in your repository. Please check
9
- # the `language` matrix defined below to confirm you have the correct set of
10
- # supported CodeQL languages.
11
- #
12
- name: "codeql"
13
-
14
- on:
15
- push:
16
- branches: [ "main" ]
17
- pull_request:
18
- # The branches below must be a subset of the branches above
19
- branches: [ "main" ]
20
-
21
- jobs:
22
- analyze:
23
- name: Analyze
24
- runs-on: ubuntu-latest
25
- permissions:
26
- actions: read
27
- contents: read
28
- security-events: write
29
-
30
- strategy:
31
- fail-fast: false
32
- matrix:
33
- language: [ 'javascript' ]
34
- # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
35
- # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
36
-
37
- steps:
38
- - name: Checkout repository
39
- uses: actions/checkout@v3
40
-
41
- # Initializes the CodeQL tools for scanning.
42
- - name: Initialize CodeQL
43
- uses: github/codeql-action/init@v2
44
- with:
45
- languages: ${{ matrix.language }}
46
- # If you wish to specify custom queries, you can do so here or in a config file.
47
- # By default, queries listed here will override any specified in a config file.
48
- # Prefix the list here with "+" to use these queries and those in the config file.
49
-
50
- # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
51
- # queries: security-extended,security-and-quality
52
-
53
-
54
- # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
55
- # If this step fails, then you should remove it and run the build manually (see below)
56
- - name: Autobuild
57
- uses: github/codeql-action/autobuild@v2
58
-
59
- # ℹ️ Command-line programs to run using the OS shell.
60
- # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
61
-
62
- # If the Autobuild fails above, remove it and uncomment the following three lines.
63
- # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
64
-
65
- # - run: |
66
- # echo "Run, Build Application using script"
67
- # ./location_of_script_within_repo/buildscript.sh
68
-
69
- - name: Perform CodeQL Analysis
70
- uses: github/codeql-action/analyze@v2
71
- with:
72
- category: "/language:${{matrix.language}}"
@@ -1,41 +0,0 @@
1
- name: deploy-site
2
-
3
- on:
4
- workflow_dispatch:
5
- release:
6
- types: [released]
7
-
8
- jobs:
9
- setup-build-deploy:
10
- name: Deploy Website
11
- runs-on: ubuntu-latest
12
-
13
- strategy:
14
- matrix:
15
- node-version: ['20']
16
-
17
- steps:
18
- - uses: actions/checkout@v4
19
- - name: Use Node.js ${{ matrix.node-version }}
20
- uses: actions/setup-node@v4
21
- with:
22
- node-version: ${{ matrix.node-version }}
23
-
24
- - name: Install Dependencies
25
- run: npm install
26
-
27
- - name: Build
28
- run: npm run build
29
-
30
- - name: Build Website
31
- run: npm run website:build
32
-
33
- - name: Publish to Cloudflare Pages
34
- uses: cloudflare/pages-action@1
35
- with:
36
- apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
37
- accountId: b09b24c345713c704e71dea8bd81f713
38
- projectName: hookified
39
- directory: site/dist
40
- branch: main
41
- gitHubToken: ${{ secrets.GH_TOKEN }}
@@ -1,39 +0,0 @@
1
- name: release
2
-
3
- on:
4
- workflow_dispatch:
5
- release:
6
- types: [released]
7
-
8
- jobs:
9
- build:
10
-
11
- runs-on: ubuntu-latest
12
-
13
- strategy:
14
- matrix:
15
- node-version: ['20']
16
-
17
- steps:
18
- - uses: actions/checkout@v4
19
- - name: Use Node.js ${{ matrix.node-version }}
20
- uses: actions/setup-node@v4
21
- with:
22
- node-version: ${{ matrix.node-version }}
23
-
24
- - name: Install Dependencies
25
- run: npm install
26
-
27
- - name: Build
28
- run: npm run build
29
-
30
- - name: Testing
31
- run: npm run test
32
-
33
- - name: Publish
34
- run: |
35
- npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
36
- npm publish --ignore-scripts
37
- env:
38
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
39
-
@@ -1,34 +0,0 @@
1
- name: tests
2
-
3
- on:
4
- workflow_dispatch:
5
- push:
6
- branches: [ main ]
7
- pull_request:
8
- branches: [ main ]
9
-
10
- jobs:
11
- build:
12
-
13
- runs-on: ubuntu-latest
14
-
15
- strategy:
16
- matrix:
17
- node-version: ['20', '22']
18
-
19
- steps:
20
- - uses: actions/checkout@v4
21
- - name: Use Node.js ${{ matrix.node-version }}
22
- uses: actions/setup-node@v4
23
- with:
24
- node-version: ${{ matrix.node-version }}
25
-
26
- - name: Install Dependencies
27
- run: npm install
28
-
29
- - name: Build
30
- run: npm run build
31
-
32
- - name: Testing
33
- run: npm run test
34
-
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- 20
@@ -1,128 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our
6
- community a harassment-free experience for everyone, regardless of age, body
7
- size, visible or invisible disability, ethnicity, sex characteristics, gender
8
- identity and expression, level of experience, education, socio-economic status,
9
- nationality, personal appearance, race, religion, or sexual identity
10
- and orientation.
11
-
12
- We pledge to act and interact in ways that contribute to an open, welcoming,
13
- diverse, inclusive, and healthy community.
14
-
15
- ## Our Standards
16
-
17
- Examples of behavior that contributes to a positive environment for our
18
- community include:
19
-
20
- * Demonstrating empathy and kindness toward other people
21
- * Being respectful of differing opinions, viewpoints, and experiences
22
- * Giving and gracefully accepting constructive feedback
23
- * Accepting responsibility and apologizing to those affected by our mistakes,
24
- and learning from the experience
25
- * Focusing on what is best not just for us as individuals, but for the
26
- overall community
27
-
28
- Examples of unacceptable behavior include:
29
-
30
- * The use of sexualized language or imagery, and sexual attention or
31
- advances of any kind
32
- * Trolling, insulting or derogatory comments, and personal or political attacks
33
- * Public or private harassment
34
- * Publishing others' private information, such as a physical or email
35
- address, without their explicit permission
36
- * Other conduct which could reasonably be considered inappropriate in a
37
- professional setting
38
-
39
- ## Enforcement Responsibilities
40
-
41
- Community leaders are responsible for clarifying and enforcing our standards of
42
- acceptable behavior and will take appropriate and fair corrective action in
43
- response to any behavior that they deem inappropriate, threatening, offensive,
44
- or harmful.
45
-
46
- Community leaders have the right and responsibility to remove, edit, or reject
47
- comments, commits, code, wiki edits, issues, and other contributions that are
48
- not aligned to this Code of Conduct, and will communicate reasons for moderation
49
- decisions when appropriate.
50
-
51
- ## Scope
52
-
53
- This Code of Conduct applies within all community spaces, and also applies when
54
- an individual is officially representing the community in public spaces.
55
- Examples of representing our community include using an official e-mail address,
56
- posting via an official social media account, or acting as an appointed
57
- representative at an online or offline event.
58
-
59
- ## Enforcement
60
-
61
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
- reported to the community leaders responsible for enforcement at
63
- me@jaredwray.com.
64
- All complaints will be reviewed and investigated promptly and fairly.
65
-
66
- All community leaders are obligated to respect the privacy and security of the
67
- reporter of any incident.
68
-
69
- ## Enforcement Guidelines
70
-
71
- Community leaders will follow these Community Impact Guidelines in determining
72
- the consequences for any action they deem in violation of this Code of Conduct:
73
-
74
- ### 1. Correction
75
-
76
- **Community Impact**: Use of inappropriate language or other behavior deemed
77
- unprofessional or unwelcome in the community.
78
-
79
- **Consequence**: A private, written warning from community leaders, providing
80
- clarity around the nature of the violation and an explanation of why the
81
- behavior was inappropriate. A public apology may be requested.
82
-
83
- ### 2. Warning
84
-
85
- **Community Impact**: A violation through a single incident or series
86
- of actions.
87
-
88
- **Consequence**: A warning with consequences for continued behavior. No
89
- interaction with the people involved, including unsolicited interaction with
90
- those enforcing the Code of Conduct, for a specified period of time. This
91
- includes avoiding interactions in community spaces as well as external channels
92
- like social media. Violating these terms may lead to a temporary or
93
- permanent ban.
94
-
95
- ### 3. Temporary Ban
96
-
97
- **Community Impact**: A serious violation of community standards, including
98
- sustained inappropriate behavior.
99
-
100
- **Consequence**: A temporary ban from any sort of interaction or public
101
- communication with the community for a specified period of time. No public or
102
- private interaction with the people involved, including unsolicited interaction
103
- with those enforcing the Code of Conduct, is allowed during this period.
104
- Violating these terms may lead to a permanent ban.
105
-
106
- ### 4. Permanent Ban
107
-
108
- **Community Impact**: Demonstrating a pattern of violation of community
109
- standards, including sustained inappropriate behavior, harassment of an
110
- individual, or aggression toward or disparagement of classes of individuals.
111
-
112
- **Consequence**: A permanent ban from any sort of public interaction within
113
- the community.
114
-
115
- ## Attribution
116
-
117
- This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
- version 2.0, available at
119
- https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
-
121
- Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
- enforcement ladder](https://github.com/mozilla/diversity).
123
-
124
- [homepage]: https://www.contributor-covenant.org
125
-
126
- For answers to common questions about this code of conduct, see the FAQ at
127
- https://www.contributor-covenant.org/faq. Translations are available at
128
- https://www.contributor-covenant.org/translations.
package/CONTRIBUTING.md DELETED
@@ -1,27 +0,0 @@
1
- # Contributing
2
- When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.
3
-
4
- Please note we have a [Code of Conduct](CODE_OF_CONDUCT.md), please follow it in all your interactions with the project.
5
-
6
- We release new versions of this project (maintenance/features) on a monthly cadence so please be aware that some items will not get released right away.
7
-
8
- # Pull Request Process
9
- You can contribute changes to this repo by opening a pull request:
10
-
11
- 1) After forking this repository to your Git account, make the proposed changes on your forked branch.
12
- 2) Run tests and linting locally.
13
- - Run `npm install`.
14
- - Run `npm test`.
15
- 3) Commit your changes and push them to your forked repository.
16
- 4) Navigate to the main `Hookified` repository and select the *Pull Requests* tab.
17
- 5) Click the *New pull request* button, then select the option "Compare across forks"
18
- 6) Leave the base branch set to main. Set the compare branch to your forked branch, and open the pull request.
19
- 7) Once your pull request is created, ensure that all checks have passed and that your branch has no conflicts with the base branch. If there are any issues, resolve these changes in your local repository, and then commit and push them to git.
20
- 8) Similarly, respond to any reviewer comments or requests for changes by making edits to your local repository and pushing them to Git.
21
- 9) Once the pull request has been reviewed, those with write access to the branch will be able to merge your changes into the `Hookified` repository.
22
-
23
- If you need more information on the steps to create a pull request, you can find a detailed walkthrough in the [Github documentation](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork)
24
-
25
-
26
- # Code of Conduct
27
- Please refer to our [Code of Conduct](https://github.com/jaredwray/hookified/blob/main/CODE_OF_CONDUCT.md) readme for how to contribute to this open source project and work within the community.
@@ -1,20 +0,0 @@
1
- const fs = require('node:fs');
2
- const path = require('node:path');
3
- const process = require('node:process');
4
-
5
- module.exports.options = {
6
- githubPath: 'jaredwray/hookified',
7
- outputPath: './site/dist',
8
- siteTitle: 'Hookified',
9
- siteDescription: 'Event and Middleware Hooks for Node.js',
10
- siteUrl: 'https://hookified.org',
11
- };
12
-
13
- module.exports.onPrepare = async config => {
14
- const readmePath = path.join(process.cwd(), './README.md');
15
- const readmeSitePath = path.join(config.sitePath, 'README.md');
16
- const readme = await fs.promises.readFile(readmePath, 'utf8');
17
- const updatedReadme = readme.replace('<img src="site/logo.svg" alt="Hookified" height="400" align="center">\n\n', '');
18
- console.log('writing updated readme to', readmeSitePath);
19
- await fs.promises.writeFile(readmeSitePath, updatedReadme);
20
- };
package/site/favicon.ico DELETED
Binary file
package/site/logo.svg DELETED
@@ -1,25 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 160.14 223.57">
3
- <defs>
4
- <style>
5
- .cls-1 {
6
- fill: #fff;
7
- }
8
- </style>
9
- </defs>
10
- <!-- Generator: Adobe Illustrator 28.6.0, SVG Export Plug-In . SVG Version: 1.2.0 Build 709) -->
11
- <g>
12
- <g id="Layer_1">
13
- <g id="Layer_1-2" data-name="Layer_1">
14
- <g id="Layer_1-2">
15
- <g id="Layer_1-2-2" data-name="Layer_1-2">
16
- <g id="Layer_1-2-2">
17
- <rect class="cls-1" width="160.14" height="226.52"/>
18
- <path d="M119.62,160.92c0-30.59-20.69-51.13-20.69-102.26,0-5.47.77-9.28,2.63-14.66.32-.93.68-1.91,1.06-2.95,0,0,0-.02,0-.03,0-.02.02-.05.03-.08h0c.14-.39.29-.81.47-1.26.56-1.47.82-3.09.74-4.68-.22-4.35-3.7-7.63-8.09-7.63s-7.86,3.28-8.09,7.63c-.08,1.59.17,3.2.74,4.68.33.86.6,1.59.8,2.19.29.74.54,1.44.76,2.11,2.43,7.13,2.12,11.22,2.12,14.65h0c0,51.13,20.69,71.68,20.69,102.26v.3c0,18.93-15.41,34.35-34.35,34.35s-34.35-15.41-34.35-34.35v-.37c1.6.57,3.25,1.02,4.94,1.34-1.57-4.04-2.43-8.41-2.43-12.99,0-7.49,2.3-14.45,6.23-20.21-8.62,6.85-14.42,17.07-15.42,28.68-.1,1.18-.16,2.37-.16,3.56,0,22.73,18.43,41.16,41.15,41.16s41.16-18.43,41.16-41.16v-.3h.03l.02.02ZM96.18,37.56c-.43,1.12-.98,2.63-1.36,3.92h0c-.06.21-.11.41-.17.59,0,0,0,.03,0,.04-.1.35-.2.71-.3,1.07-.19-1.38-1.11-3.94-1.75-5.62-.27-.71-.39-1.49-.35-2.24.14-2.65,4.14-2.65,4.29,0,.04.75-.08,1.53-.35,2.24h0Z"/>
19
- </g>
20
- </g>
21
- </g>
22
- </g>
23
- </g>
24
- </g>
25
- </svg>
@@ -1,21 +0,0 @@
1
- :root {
2
- --font-family: 'Open Sans', sans-serif;
3
-
4
- --color-primary: #322d3c;
5
- --color-secondary: #8cdc00;
6
- --color-secondary-dark: #8cdc00;
7
- --color-text: #322d3c;
8
-
9
- --background: #ffffff;
10
- --home-background: #ffffff;
11
- --header-background: #ffffff;
12
-
13
- --sidebar-background: #ffffff;
14
- --sidebar-text: #322d3c;
15
- --sidebar-text-active: var(--color-secondary);
16
-
17
- --border: rgba(238,238,245,1);
18
-
19
- --code: rgba(238,238,245,1);
20
-
21
- }
package/src/index.ts DELETED
@@ -1,55 +0,0 @@
1
- import Emittery from 'emittery';
2
-
3
- type HookHandler = (...arguments_: any[]) => Promise<void> | void;
4
-
5
- export class Hookified extends Emittery {
6
- _hookHandlers: Map<string, HookHandler[]>;
7
-
8
- constructor() {
9
- super();
10
- this._hookHandlers = new Map();
11
- }
12
-
13
- // Adds a handler function for a specific event
14
- async onHook(event: string, handler: HookHandler) {
15
- const eventHandlers = this._hookHandlers.get(event);
16
- if (eventHandlers) {
17
- eventHandlers.push(handler);
18
- } else {
19
- this._hookHandlers.set(event, [handler]);
20
- }
21
- }
22
-
23
- // Removes a specific handler function for a specific event
24
- async removeHook(event: string, handler: HookHandler) {
25
- const eventHandlers = this._hookHandlers.get(event);
26
- if (eventHandlers) {
27
- const index = eventHandlers.indexOf(handler);
28
- if (index !== -1) {
29
- eventHandlers.splice(index, 1);
30
- }
31
- }
32
- }
33
-
34
- // Triggers all handlers for a specific event with provided data
35
- async hook(event: string, data: any) {
36
- const eventHandlers = this._hookHandlers.get(event);
37
- if (eventHandlers) {
38
- for (const handler of eventHandlers) {
39
- try {
40
- // eslint-disable-next-line no-await-in-loop
41
- await handler(data);
42
- } catch (error) {
43
- // eslint-disable-next-line no-await-in-loop
44
- await this.emit('error', new Error(`Error in hook handler for event "${event}": ${(error as Error).message}`));
45
- }
46
- }
47
- }
48
- }
49
-
50
- // Provides read-only access to the current handlers
51
- get hookHandlers() {
52
- // Creating a new map to prevent external modifications to the original map
53
- return new Map(this._hookHandlers);
54
- }
55
- }
@@ -1,83 +0,0 @@
1
- import {describe, test, expect} from 'vitest';
2
- import {Hookified} from '../src/index.js';
3
-
4
- describe('Hookified', () => {
5
- test('initialization', () => {
6
- const hookified = new Hookified();
7
- expect(hookified.hookHandlers).toEqual(new Map());
8
- });
9
-
10
- test('onHook', async () => {
11
- const hookified = new Hookified();
12
- // eslint-disable-next-line @typescript-eslint/no-empty-function
13
- const handler = () => {};
14
- // eslint-disable-next-line @typescript-eslint/no-empty-function
15
- const handler2 = () => {};
16
- await hookified.onHook('event', handler);
17
- await hookified.onHook('event2', handler2);
18
- expect(hookified.hookHandlers.get('event')).toEqual([handler]);
19
- expect(hookified.hookHandlers.get('event2')).toEqual([handler2]);
20
- expect(hookified.hookHandlers.size).toBe(2);
21
- });
22
-
23
- test('onHook multiple handlers', async () => {
24
- const hookified = new Hookified();
25
- // eslint-disable-next-line @typescript-eslint/no-empty-function
26
- const handler = () => {};
27
- // eslint-disable-next-line @typescript-eslint/no-empty-function
28
- const handler2 = () => {};
29
- await hookified.onHook('event', handler);
30
- await hookified.onHook('event', handler2);
31
- expect(hookified.hookHandlers.get('event')).toEqual([handler, handler2]);
32
- expect(hookified.hookHandlers.size).toBe(1);
33
- });
34
-
35
- test('removeHook', async () => {
36
- const hookified = new Hookified();
37
- // eslint-disable-next-line @typescript-eslint/no-empty-function
38
- const handler = () => {};
39
- // eslint-disable-next-line @typescript-eslint/no-empty-function
40
- const handler2 = () => {};
41
- await hookified.onHook('event', handler);
42
- await hookified.onHook('event', handler2);
43
- await hookified.removeHook('event', handler);
44
- expect(hookified.hookHandlers.get('event')).toEqual([handler2]);
45
- expect(hookified.hookHandlers.size).toBe(1);
46
- });
47
-
48
- test('execute hook and manipulate data', async () => {
49
- const hookified = new Hookified();
50
- const data = {key: 'value'};
51
- let handlerData;
52
-
53
- const handler = (data: any) => {
54
- data.key = 'modified';
55
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
56
- handlerData = data;
57
- };
58
-
59
- await hookified.onHook('event', handler);
60
- await hookified.hook('event', data);
61
- expect(handlerData.key).toBe('modified');
62
- });
63
-
64
- test('hook with error emitted', async () => {
65
- const hookified = new Hookified();
66
- let errorMessage;
67
- hookified.on('error', (error: Error) => {
68
- errorMessage = error.message;
69
- expect(error.message).toBe('Error in hook handler for event "event": error');
70
- });
71
-
72
- const data = {key: 'value'};
73
- let handlerData;
74
-
75
- const handler = (data: any) => {
76
- throw new Error('error');
77
- };
78
-
79
- await hookified.onHook('event', handler);
80
- await hookified.hook('event', data);
81
- expect(errorMessage).toBe('Error in hook handler for event "event": error');
82
- });
83
- });
package/tsconfig.json DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "ESNext",
5
- "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
6
- "baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */
7
-
8
- /* Emit */
9
- "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
10
- "sourceMap": true, /* Create source map files for emitted JavaScript files. */
11
- "outDir": "./dist", /* Specify an output folder for all emitted files. */
12
-
13
- /* Interop Constraints */
14
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
15
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
16
-
17
- /* Type Checking */
18
- "strict": true, /* Enable all strict type-checking options. */
19
-
20
- /* Completeness */
21
- "skipLibCheck": true, /* Skip type checking all .d.ts files. */
22
- "lib": [
23
- "ESNext", "DOM"
24
- ]
25
- },
26
- "include": [
27
- "src/**/*.ts"
28
- ]
29
- }
package/vitest.config.ts DELETED
@@ -1,15 +0,0 @@
1
- import {defineConfig} from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- include: ['test/*.ts'],
6
- coverage: {
7
- exclude: [
8
- 'site/**',
9
- 'vitest.config.ts',
10
- 'dist/**',
11
- 'test/**',
12
- ],
13
- },
14
- },
15
- });