-
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
Sergey Krasnov
committed
Feb 24, 2024
1 parent
f90522d
commit 3929ff3
Showing
24 changed files
with
4,965 additions
and
2 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,2 @@ | ||
node_modules/ | ||
dist/ |
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,18 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"project": "./tsconfig.lint.json" | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended-type-checked", | ||
"prettier" | ||
], | ||
"plugins": ["simple-import-sort", "@typescript-eslint"], | ||
"env": { "browser": true }, | ||
"rules": { | ||
"simple-import-sort/imports": "warn", | ||
"simple-import-sort/exports": "warn" | ||
} | ||
} |
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,26 @@ | ||
name: Install pnpm | ||
description: Install dependencies and pnpm cache | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- uses: pnpm/action-setup@v2 | ||
with: | ||
standalone: true | ||
run_install: false | ||
|
||
- name: Cache node_modules | ||
uses: actions/cache@v3 | ||
id: node-modules | ||
with: | ||
path: node_modules | ||
key: node-modules-${{ hashFiles('pnpm-lock.yaml') }} | ||
|
||
- name: Set publishing config | ||
run: pnpm config set '//npm.pkg.github.com/:_authToken' "${NODE_AUTH_TOKEN}" | ||
shell: bash | ||
|
||
- name: Install dependencies | ||
if: steps.node-modules.cache-hit != 'true' | ||
run: pnpm install --frozen-lockfile | ||
shell: bash |
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,16 @@ | ||
name: Publish | ||
on: | ||
workflow_dispatch: | ||
release: | ||
types: [published] | ||
|
||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: ./.github/actions/install | ||
- run: pnpm run publish |
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,18 @@ | ||
name: Validate | ||
|
||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
jobs: | ||
validate: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: ./.github/actions/install | ||
- run: pnpm lint | ||
- run: pnpm test | ||
- run: pnpm build |
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,3 @@ | ||
node_modules/ | ||
dist/ | ||
.DS_Store |
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 @@ | ||
pnpm -- commitlint --edit $1 |
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,2 @@ | ||
pnpm lint | ||
pnpm test |
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 @@ | ||
use-node-version=20.11.1 |
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,3 @@ | ||
node_modules/ | ||
dist/ | ||
pnpm-lock.yaml |
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 |
---|---|---|
@@ -1,2 +1,72 @@ | ||
# event-notifier | ||
typed event emitter | ||
# event-notifier pack | ||
|
||
### **typed event emitter** | ||
|
||
### to install, use the following (or similar package managers) | ||
|
||
```sh | ||
npm install event-notifier | ||
``` | ||
|
||
### after that you can use | ||
|
||
```ts | ||
type Data = { | ||
balance: { value: number }; | ||
test: undefined; | ||
}; | ||
|
||
const eventNotifier = new EventNotifier<Data>(); | ||
|
||
eventNotifier.on('balance', ({ value }) => { | ||
// your code | ||
}); | ||
|
||
eventNotifier.notify({ type: 'test' }); | ||
|
||
eventNotifier.notify({ type: 'balance', value: 42 }); | ||
``` | ||
|
||
### data object | ||
|
||
```ts | ||
type Data = { | ||
balance: { value: number }; | ||
test: undefined; | ||
}; | ||
|
||
const eventNotifier = new EventNotifier<Data>(); | ||
|
||
eventNotifier.on('test', (data) => { | ||
// Object.entries(data).length === 0; | ||
}); | ||
|
||
eventNotifier.on('balance', (data) => { | ||
// Object.entries(data).length === 1; | ||
// 'value' in data === true; | ||
// typeof data.value === 'number' | ||
}); | ||
``` | ||
|
||
### erroneous statements | ||
|
||
```ts | ||
type Data = { | ||
balance: { value: number }; | ||
test: undefined; | ||
}; | ||
|
||
const eventNotifier = new EventNotifier<Data>(); | ||
|
||
// An argument of type ""asd" cannot be assigned to a parameter of type "keyof Data".ts(2345) | ||
eventNotifier.on('asd', () => {}); | ||
|
||
// The "value" property is missing in the type "{ type: "balance"; }" and is required in the type "{ value: number; }".ts(2345) | ||
eventNotifier.notify({ type: 'balance' }); | ||
|
||
// An object literal can only use unique properties. "data" does not exist in type "{ type: "test"; }.ts(2353) | ||
eventNotifier.notify({ type: 'test', data: 42 }); | ||
|
||
// Type ""asd"" cannot be assigned to type "keyof Data".ts(2322) | ||
eventNotifier.notify({ type: 'asd' }); | ||
``` |
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,5 @@ | ||
const config = { | ||
extends: ['@commitlint/config-conventional'], | ||
}; | ||
|
||
export default config; |
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,57 @@ | ||
{ | ||
"name": "event-notifier", | ||
"version": "0.0.1", | ||
"description": "typed event emitter", | ||
"main": "dist", | ||
"type": "module", | ||
"files": [ | ||
"/dist" | ||
], | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs", | ||
"types": "./dist/index.d.ts" | ||
}, | ||
"scripts": { | ||
"build": "vite build", | ||
"dev": "vite build --watch", | ||
"lint": "eslint .", | ||
"test": "pnpm test:unit & pnpm test:type", | ||
"test:unit": "vitest --run", | ||
"test:bench": "vitest bench --run", | ||
"test:type": "vitest --typecheck --run", | ||
"test:browser": "vitest --browser=chrome", | ||
"prepare": "husky", | ||
"prepublish": "pnpm run build" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^18.6.1", | ||
"@commitlint/config-conventional": "^18.6.2", | ||
"@types/node": "^20.11.20", | ||
"@typescript-eslint/eslint-plugin": "^7.0.2", | ||
"@typescript-eslint/parser": "^7.0.2", | ||
"@vitest/browser": "^1.3.1", | ||
"eslint": "^8.56.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-simple-import-sort": "^12.0.0", | ||
"husky": "^9.0.11", | ||
"prettier": "^3.2.5", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.1.4", | ||
"vite-plugin-dts": "^3.7.3", | ||
"vitest": "^1.3.1", | ||
"webdriverio": "^8.32.3" | ||
}, | ||
"keywords": [ | ||
"event notifier", | ||
"event emitter" | ||
], | ||
"author": "Krasnov Sergei", | ||
"license": "ISC", | ||
"engines": { | ||
"node": ">=20.0.0", | ||
"pnpm": ">=8.0.0" | ||
}, | ||
"packageManager": "[email protected]", | ||
"homepage": "https://github.com/ksv90/event-notifier" | ||
} |
Oops, something went wrong.