Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: [angular-package] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: angularpackage # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
45 changes: 45 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.

# Compiled output
/dist
/tmp
/out-tsc
/bazel-out

# Node
/node_modules
npm-debug.log
yarn-error.log

# IDEs and editors
.idea/
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# Miscellaneous
/.angular/cache
.sass-cache/
/connect.lock
/coverage
/libpeerconnection.log
testem.log
/typings

# System files
.DS_Store
Thumbs.db

*.ignore*
temp
227 changes: 227 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@

<a href="https://www.typescriptlang.org/">
<img
src="https://raw.githubusercontent.com/typescript-package/core/refs/heads/main/ts-package-barcode-logo-512.png"
width="20%"
title="@typescript-package/hooks"
/>
</a>

## @typescript-package/hooks

<!-- npm badge -->
[![npm version][typescript-package-npm-badge-svg]][typescript-package-npm-badge]
[![GitHub issues][typescript-package-badge-issues]][typescript-package-issues]
[![GitHub license][typescript-package-badge-license]][typescript-package-license]

A **lightweight** TypeScript library for managing hooks.

## Table of contents

- [Installation](#installation)
- [Api](#api)
- [`HooksBase`](#hooksbase)
- [`HooksCore`](#hookscore)
- [`ObjectHooksBase`](#objecthooksbase)
- [Contributing](#contributing)
- [Code of Conduct](#code-of-conduct)
- [Git](#git)
- [Commit](#commit)
- [Versioning](#versioning)
- [License](#license)

## Installation

```bash
npm install @typescript-package/hooks --save-peer
```

## Api

```typescript
import {
// Abstract.
// - Core.
HooksCore,
// - Base.
HooksBase,
ObjectHooksBase,
} from '@typescript-package/hooks';
```

## `HooksCore`

The core abstraction class for hooks functionality.

```typescript
import { HooksCore } from '@typescript-package/hooks';
```

[Source](https://github.com/typescript-package/hooks/blob/main/src/lib/hooks-core.abstract.ts)

## `HooksBase`

Base abstraction class for hooks functionality.

```typescript
import { HooksBase } from '@typescript-package/hooks';
```

[Source](https://github.com/typescript-package/hooks/blob/main/src/lib/hooks-base.abstract.ts)

## `ObjectHooksBase`

The base abstraction class for object hooks functionality.

```typescript
import { ObjectHooksBase } from '@typescript-package/hooks';

class ReactiveObject<T extends object> extends ObjectHooksBase<T> {
private data: T;

constructor(initial: T, options?: ConstructorParameters<typeof ObjectHooksBase<T>>[0]) {
super(options || {});
this.data = new Proxy(initial, {
set: (target, key, value) => {
if (typeof key === 'string' || typeof key === 'symbol') {
const oldValue = (target as any)[key];
(target as any)[key] = this.triggerOnSetProperty(key as keyof T, value, oldValue);
this.triggerOnPropertyChange(key as keyof T, value, oldValue);
this.triggerOnChange(target as T, this.data);
}
return true;
},
});
}

get value(): T {
return this.data;
}
}

// Usage
const obj = new ReactiveObject({ count: 0 });
obj.onPropertyChange((key, value, oldValue) => {
console.log(`${key} changed from ${oldValue} to ${value}`);
});

obj.value.count = 1; // Triggers onPropertyChange and onChange
```

[Source](https://github.com/typescript-package/hooks/blob/main/src/lib/object-hooks-base.abstract.ts)

## Contributing

Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.

## Support

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.

Support via:

- [Stripe](https://donate.stripe.com/dR614hfDZcJE3wAcMM)
- [Revolut](https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29)
- [GitHub](https://github.com/sponsors/angular-package/sponsorships?sponsor=sciborrudnicki&tier_id=83618)
- [DonorBox](https://donorbox.org/become-a-sponsor-to-the-angular-package?default_interval=o)
- [Patreon](https://www.patreon.com/checkout/angularpackage?rid=0&fan_landing=true&view_as=public)

or via Trust Wallet

- [XLM](https://link.trustwallet.com/send?coin=148&address=GAFFFB7H3LG42O6JA63FJDRK4PP4JCNEOPHLGLLFH625X2KFYQ4UYVM4)
- [USDT (BEP20)](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94&token_id=0x55d398326f99059fF775485246999027B3197955)
- [ETH](https://link.trustwallet.com/send?coin=60&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
- [BTC](https://link.trustwallet.com/send?coin=0&address=bc1qnf709336tfl57ta5mfkf4t9fndhx7agxvv9svn)
- [BNB](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)

Thanks for your support!

## Code of Conduct

By participating in this project, you agree to follow **[Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct/)**.

## GIT

### Commit

Please follow the following commit message conventions:

- [AngularJS Git Commit Message Conventions][git-commit-angular]
- [Karma Git Commit Msg][git-commit-karma]
- [Conventional Commits][git-commit-conventional]

### Versioning

The package follows [Semantic Versioning 2.0.0][git-semver] for all releases. The versioning format is:

**Given a version number MAJOR.MINOR.PATCH, increment the:**

- MAJOR version when you make incompatible API changes,
- MINOR version when you add functionality in a backwards-compatible manner, and
- PATCH version when you make backwards-compatible bug fixes.

Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

**FAQ**
How should I deal with revisions in the 0.y.z initial development phase?

> 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.

How do I know when to release 1.0.0?

> 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.

## License

MIT © typescript-package ([license][typescript-package-license])

## 📦 Related Packages

| Package | Description |
|---------------------------|---------------------------------------------------|
| [`@typedly/callback`](https://github.com/typedly/callback) | A **TypeScript** type definitions package for managing hooks. |
| [`@typedly/hooks`](https://github.com/typedly/hooks) | A **TypeScript** type definitions package for asynchronous and synchronous callback functions of various types. |

## Packages

- **[@typescript-package/affix](https://github.com/typescript-package/affix)**: A **lightweight TypeScript** library for the affix - prefix and suffix.
- **[@typescript-package/are](https://github.com/typescript-package/are)**: Type-safe `are` checkers for validating value types in TypeScript.
- **[@typescript-package/data](https://github.com/typescript-package/data)**: A **lightweight TypeScript** library for basic data management.
- **[@typescript-package/descriptor](https://github.com/typescript-package/descriptor)**: A **lightweight TypeScript** library for property descriptor.
- **[@typescript-package/guard](https://github.com/typescript-package/guard)**: Type-safe guards for guarding the value types in TypeScript.
- **[@typescript-package/history](https://github.com/typescript-package/history)**: A **TypeScript** package for tracking history of values.
- **[@typescript-package/is](https://github.com/typescript-package/is)**: Type-safe is checkers for validating value types in TypeScript.
- **[@typescript-package/name](https://github.com/typescript-package/name)**: A **lightweight TypeScript** library for the name with prefix and suffix.
- **[@typescript-package/property](https://github.com/typescript-package/property)**: A **lightweight TypeScript** package with features to handle object properties.
- **[@typescript-package/queue](https://github.com/typescript-package/queue)**: A **lightweight TypeScript** library for managing various queue and stack structures.
- **[@typescript-package/range](https://github.com/typescript-package/range)**: A **lightweight TypeScript** library for managing various types of ranges.
- **[@typescript-package/regexp](https://github.com/typescript-package/regexp)**: A **lightweight TypeScript** library for **RegExp**.
- **[@typescript-package/state](https://github.com/typescript-package/state)**: Simple state management for different types in **TypeScript**.
- **[@typescript-package/type](https://github.com/typescript-package/type)**: Utility types to enhance and simplify **TypeScript** development.
- **[@typescript-package/wrapper](https://github.com/typescript-package/wrapper)**: A **lightweight TypeScript** library to wrap the text with the opening and closing chars.

<!-- This package: typescript-package -->
<!-- GitHub: badges -->
[typescript-package-badge-issues]: https://img.shields.io/github/issues/typescript-package/hooks
[typescript-package-badge-forks]: https://img.shields.io/github/forks/typescript-package/hooks
[typescript-package-badge-stars]: https://img.shields.io/github/stars/typescript-package/hooks
[typescript-package-badge-license]: https://img.shields.io/github/license/typescript-package/hooks
<!-- GitHub: badges links -->
[typescript-package-issues]: https://github.com/typescript-package/hooks/issues
[typescript-package-forks]: https://github.com/typescript-package/hooks/network
[typescript-package-license]: https://github.com/typescript-package/hooks/blob/master/LICENSE
[typescript-package-stars]: https://github.com/typescript-package/hooks/stargazers
<!-- This package -->

<!-- Package: typescript-package -->
<!-- npm -->
[typescript-package-npm-badge-svg]: https://badge.fury.io/js/@typescript-package%2Fhooks.svg
[typescript-package-npm-badge]: https://badge.fury.io/js/@typescript-package%2Fhooks

<!-- GIT -->
[git-semver]: http://semver.org/

<!-- GIT: commit -->
[git-commit-angular]: https://gist.github.com/stephenparish/9941e89d80e2bc58a153
[git-commit-karma]: http://karma-runner.github.io/0.10/dev/git-commit-msg.html
[git-commit-conventional]: https://www.conventionalcommits.org/en/v1.0.0/
53 changes: 53 additions & 0 deletions eslint.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import js from "@eslint/js";
import globals from "globals";
import tseslint from "typescript-eslint";
import { defineConfig } from "eslint/config";

export default defineConfig([
{
...js.configs.recommended,
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
plugins: { js },
languageOptions: { globals: globals.browser }
},
tseslint.configs.recommended,
{
files: ["**/*.{ts,tsx,mts,cts}"],
plugins: { "@typescript-eslint": tseslint.plugin },
languageOptions: {
parser: tseslint.parser,
parserOptions: { project: "./tsconfig.eslint.json" }
},
rules: {
// ...tseslint.configs.recommended,
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/member-ordering": [
"error",
{
"default": [
// Static fields
"public-static-field",
"protected-static-field",
"private-static-field",
// Static methods
"public-static-method",
"protected-static-method",
"private-static-method",
// Instance fields
"public-instance-field",
"protected-instance-field",
"private-instance-field",
// Constructor
"public-constructor",
// Instance methods
"public-instance-method",
"protected-instance-method",
"private-instance-method"
// Note: The rule does NOT distinguish JS #private fields/methods natively.
// To check for #private ordering, use code review and consistent style.
]
}
]
}
}
]);
8 changes: 8 additions & 0 deletions ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/hooks",
"lib": {
"entryFile": "src/public-api.ts"
},
"keepLifecycleScripts": true
}
Loading