Skip to content

Commit 06110e8

Browse files
Merge pull request #1 from typescript-package/develop
v1.0.0
2 parents 01f8c3d + 3cf7196 commit 06110e8

17 files changed

+2507
-0
lines changed

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: [angular-package] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: angularpackage # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

.gitignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.
2+
3+
# Compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
/bazel-out
8+
9+
# Node
10+
/node_modules
11+
npm-debug.log
12+
yarn-error.log
13+
14+
# IDEs and editors
15+
.idea/
16+
.project
17+
.classpath
18+
.c9/
19+
*.launch
20+
.settings/
21+
*.sublime-workspace
22+
23+
# Visual Studio Code
24+
.vscode/*
25+
!.vscode/settings.json
26+
!.vscode/tasks.json
27+
!.vscode/launch.json
28+
!.vscode/extensions.json
29+
.history/*
30+
31+
# Miscellaneous
32+
/.angular/cache
33+
.sass-cache/
34+
/connect.lock
35+
/coverage
36+
/libpeerconnection.log
37+
testem.log
38+
/typings
39+
40+
# System files
41+
.DS_Store
42+
Thumbs.db
43+
44+
*.ignore*
45+
temp

README.md

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
2+
<a href="https://www.typescriptlang.org/">
3+
<img
4+
src="https://raw.githubusercontent.com/typescript-package/core/refs/heads/main/ts-package-barcode-logo-512.png"
5+
width="20%"
6+
title="@typescript-package/hooks"
7+
/>
8+
</a>
9+
10+
## @typescript-package/hooks
11+
12+
<!-- npm badge -->
13+
[![npm version][typescript-package-npm-badge-svg]][typescript-package-npm-badge]
14+
[![GitHub issues][typescript-package-badge-issues]][typescript-package-issues]
15+
[![GitHub license][typescript-package-badge-license]][typescript-package-license]
16+
17+
A **lightweight** TypeScript library for managing hooks.
18+
19+
## Table of contents
20+
21+
- [Installation](#installation)
22+
- [Api](#api)
23+
- [`HooksBase`](#hooksbase)
24+
- [`HooksCore`](#hookscore)
25+
- [`ObjectHooksBase`](#objecthooksbase)
26+
- [Contributing](#contributing)
27+
- [Code of Conduct](#code-of-conduct)
28+
- [Git](#git)
29+
- [Commit](#commit)
30+
- [Versioning](#versioning)
31+
- [License](#license)
32+
33+
## Installation
34+
35+
```bash
36+
npm install @typescript-package/hooks --save-peer
37+
```
38+
39+
## Api
40+
41+
```typescript
42+
import {
43+
// Abstract.
44+
// - Core.
45+
HooksCore,
46+
// - Base.
47+
HooksBase,
48+
ObjectHooksBase,
49+
} from '@typescript-package/hooks';
50+
```
51+
52+
## `HooksCore`
53+
54+
The core abstraction class for hooks functionality.
55+
56+
```typescript
57+
import { HooksCore } from '@typescript-package/hooks';
58+
```
59+
60+
[Source](https://github.com/typescript-package/hooks/blob/main/src/lib/hooks-core.abstract.ts)
61+
62+
## `HooksBase`
63+
64+
Base abstraction class for hooks functionality.
65+
66+
```typescript
67+
import { HooksBase } from '@typescript-package/hooks';
68+
```
69+
70+
[Source](https://github.com/typescript-package/hooks/blob/main/src/lib/hooks-base.abstract.ts)
71+
72+
## `ObjectHooksBase`
73+
74+
The base abstraction class for object hooks functionality.
75+
76+
```typescript
77+
import { ObjectHooksBase } from '@typescript-package/hooks';
78+
79+
class ReactiveObject<T extends object> extends ObjectHooksBase<T> {
80+
private data: T;
81+
82+
constructor(initial: T, options?: ConstructorParameters<typeof ObjectHooksBase<T>>[0]) {
83+
super(options || {});
84+
this.data = new Proxy(initial, {
85+
set: (target, key, value) => {
86+
if (typeof key === 'string' || typeof key === 'symbol') {
87+
const oldValue = (target as any)[key];
88+
(target as any)[key] = this.triggerOnSetProperty(key as keyof T, value, oldValue);
89+
this.triggerOnPropertyChange(key as keyof T, value, oldValue);
90+
this.triggerOnChange(target as T, this.data);
91+
}
92+
return true;
93+
},
94+
});
95+
}
96+
97+
get value(): T {
98+
return this.data;
99+
}
100+
}
101+
102+
// Usage
103+
const obj = new ReactiveObject({ count: 0 });
104+
obj.onPropertyChange((key, value, oldValue) => {
105+
console.log(`${key} changed from ${oldValue} to ${value}`);
106+
});
107+
108+
obj.value.count = 1; // Triggers onPropertyChange and onChange
109+
```
110+
111+
[Source](https://github.com/typescript-package/hooks/blob/main/src/lib/object-hooks-base.abstract.ts)
112+
113+
## Contributing
114+
115+
Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.
116+
117+
## Support
118+
119+
If you find this package useful and would like to support its and general development, you can contribute through one of the following payment methods. Your support helps maintain the packages and continue adding new.
120+
121+
Support via:
122+
123+
- [Stripe](https://donate.stripe.com/dR614hfDZcJE3wAcMM)
124+
- [Revolut](https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29)
125+
- [GitHub](https://github.com/sponsors/angular-package/sponsorships?sponsor=sciborrudnicki&tier_id=83618)
126+
- [DonorBox](https://donorbox.org/become-a-sponsor-to-the-angular-package?default_interval=o)
127+
- [Patreon](https://www.patreon.com/checkout/angularpackage?rid=0&fan_landing=true&view_as=public)
128+
129+
or via Trust Wallet
130+
131+
- [XLM](https://link.trustwallet.com/send?coin=148&address=GAFFFB7H3LG42O6JA63FJDRK4PP4JCNEOPHLGLLFH625X2KFYQ4UYVM4)
132+
- [USDT (BEP20)](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94&token_id=0x55d398326f99059fF775485246999027B3197955)
133+
- [ETH](https://link.trustwallet.com/send?coin=60&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
134+
- [BTC](https://link.trustwallet.com/send?coin=0&address=bc1qnf709336tfl57ta5mfkf4t9fndhx7agxvv9svn)
135+
- [BNB](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
136+
137+
Thanks for your support!
138+
139+
## Code of Conduct
140+
141+
By participating in this project, you agree to follow **[Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct/)**.
142+
143+
## GIT
144+
145+
### Commit
146+
147+
Please follow the following commit message conventions:
148+
149+
- [AngularJS Git Commit Message Conventions][git-commit-angular]
150+
- [Karma Git Commit Msg][git-commit-karma]
151+
- [Conventional Commits][git-commit-conventional]
152+
153+
### Versioning
154+
155+
The package follows [Semantic Versioning 2.0.0][git-semver] for all releases. The versioning format is:
156+
157+
**Given a version number MAJOR.MINOR.PATCH, increment the:**
158+
159+
- MAJOR version when you make incompatible API changes,
160+
- MINOR version when you add functionality in a backwards-compatible manner, and
161+
- PATCH version when you make backwards-compatible bug fixes.
162+
163+
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
164+
165+
**FAQ**
166+
How should I deal with revisions in the 0.y.z initial development phase?
167+
168+
> The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release.
169+
170+
How do I know when to release 1.0.0?
171+
172+
> If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backwards compatibility, you should probably already be 1.0.0.
173+
174+
## License
175+
176+
MIT © typescript-package ([license][typescript-package-license])
177+
178+
## 📦 Related Packages
179+
180+
| Package | Description |
181+
|---------------------------|---------------------------------------------------|
182+
| [`@typedly/callback`](https://github.com/typedly/callback) | A **TypeScript** type definitions package for managing hooks. |
183+
| [`@typedly/hooks`](https://github.com/typedly/hooks) | A **TypeScript** type definitions package for asynchronous and synchronous callback functions of various types. |
184+
185+
## Packages
186+
187+
- **[@typescript-package/affix](https://github.com/typescript-package/affix)**: A **lightweight TypeScript** library for the affix - prefix and suffix.
188+
- **[@typescript-package/are](https://github.com/typescript-package/are)**: Type-safe `are` checkers for validating value types in TypeScript.
189+
- **[@typescript-package/data](https://github.com/typescript-package/data)**: A **lightweight TypeScript** library for basic data management.
190+
- **[@typescript-package/descriptor](https://github.com/typescript-package/descriptor)**: A **lightweight TypeScript** library for property descriptor.
191+
- **[@typescript-package/guard](https://github.com/typescript-package/guard)**: Type-safe guards for guarding the value types in TypeScript.
192+
- **[@typescript-package/history](https://github.com/typescript-package/history)**: A **TypeScript** package for tracking history of values.
193+
- **[@typescript-package/is](https://github.com/typescript-package/is)**: Type-safe is checkers for validating value types in TypeScript.
194+
- **[@typescript-package/name](https://github.com/typescript-package/name)**: A **lightweight TypeScript** library for the name with prefix and suffix.
195+
- **[@typescript-package/property](https://github.com/typescript-package/property)**: A **lightweight TypeScript** package with features to handle object properties.
196+
- **[@typescript-package/queue](https://github.com/typescript-package/queue)**: A **lightweight TypeScript** library for managing various queue and stack structures.
197+
- **[@typescript-package/range](https://github.com/typescript-package/range)**: A **lightweight TypeScript** library for managing various types of ranges.
198+
- **[@typescript-package/regexp](https://github.com/typescript-package/regexp)**: A **lightweight TypeScript** library for **RegExp**.
199+
- **[@typescript-package/state](https://github.com/typescript-package/state)**: Simple state management for different types in **TypeScript**.
200+
- **[@typescript-package/type](https://github.com/typescript-package/type)**: Utility types to enhance and simplify **TypeScript** development.
201+
- **[@typescript-package/wrapper](https://github.com/typescript-package/wrapper)**: A **lightweight TypeScript** library to wrap the text with the opening and closing chars.
202+
203+
<!-- This package: typescript-package -->
204+
<!-- GitHub: badges -->
205+
[typescript-package-badge-issues]: https://img.shields.io/github/issues/typescript-package/hooks
206+
[typescript-package-badge-forks]: https://img.shields.io/github/forks/typescript-package/hooks
207+
[typescript-package-badge-stars]: https://img.shields.io/github/stars/typescript-package/hooks
208+
[typescript-package-badge-license]: https://img.shields.io/github/license/typescript-package/hooks
209+
<!-- GitHub: badges links -->
210+
[typescript-package-issues]: https://github.com/typescript-package/hooks/issues
211+
[typescript-package-forks]: https://github.com/typescript-package/hooks/network
212+
[typescript-package-license]: https://github.com/typescript-package/hooks/blob/master/LICENSE
213+
[typescript-package-stars]: https://github.com/typescript-package/hooks/stargazers
214+
<!-- This package -->
215+
216+
<!-- Package: typescript-package -->
217+
<!-- npm -->
218+
[typescript-package-npm-badge-svg]: https://badge.fury.io/js/@typescript-package%2Fhooks.svg
219+
[typescript-package-npm-badge]: https://badge.fury.io/js/@typescript-package%2Fhooks
220+
221+
<!-- GIT -->
222+
[git-semver]: http://semver.org/
223+
224+
<!-- GIT: commit -->
225+
[git-commit-angular]: https://gist.github.com/stephenparish/9941e89d80e2bc58a153
226+
[git-commit-karma]: http://karma-runner.github.io/0.10/dev/git-commit-msg.html
227+
[git-commit-conventional]: https://www.conventionalcommits.org/en/v1.0.0/

eslint.config.mts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import js from "@eslint/js";
2+
import globals from "globals";
3+
import tseslint from "typescript-eslint";
4+
import { defineConfig } from "eslint/config";
5+
6+
export default defineConfig([
7+
{
8+
...js.configs.recommended,
9+
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
10+
plugins: { js },
11+
languageOptions: { globals: globals.browser }
12+
},
13+
tseslint.configs.recommended,
14+
{
15+
files: ["**/*.{ts,tsx,mts,cts}"],
16+
plugins: { "@typescript-eslint": tseslint.plugin },
17+
languageOptions: {
18+
parser: tseslint.parser,
19+
parserOptions: { project: "./tsconfig.eslint.json" }
20+
},
21+
rules: {
22+
// ...tseslint.configs.recommended,
23+
"@typescript-eslint/no-unused-expressions": "off",
24+
"@typescript-eslint/member-ordering": [
25+
"error",
26+
{
27+
"default": [
28+
// Static fields
29+
"public-static-field",
30+
"protected-static-field",
31+
"private-static-field",
32+
// Static methods
33+
"public-static-method",
34+
"protected-static-method",
35+
"private-static-method",
36+
// Instance fields
37+
"public-instance-field",
38+
"protected-instance-field",
39+
"private-instance-field",
40+
// Constructor
41+
"public-constructor",
42+
// Instance methods
43+
"public-instance-method",
44+
"protected-instance-method",
45+
"private-instance-method"
46+
// Note: The rule does NOT distinguish JS #private fields/methods natively.
47+
// To check for #private ordering, use code review and consistent style.
48+
]
49+
}
50+
]
51+
}
52+
}
53+
]);

ng-package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3+
"dest": "../../dist/hooks",
4+
"lib": {
5+
"entryFile": "src/public-api.ts"
6+
},
7+
"keepLifecycleScripts": true
8+
}

0 commit comments

Comments
 (0)