https://github.com/dotupnet/dotup-ts-interceptor-proxy
Create proxy of any object and add interceptors.
https://github.com/dotupnet/dotup-ts-interceptor-proxy
interceptor logging proxy typescript
Last synced: 4 months ago
JSON representation
Create proxy of any object and add interceptors.
- Host: GitHub
- URL: https://github.com/dotupnet/dotup-ts-interceptor-proxy
- Owner: dotupNET
- License: mit
- Created: 2019-03-08T16:30:32.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T17:16:25.000Z (over 2 years ago)
- Last Synced: 2025-02-12T11:46:12.038Z (4 months ago)
- Topics: interceptor, logging, proxy, typescript
- Language: TypeScript
- Homepage:
- Size: 475 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/dotupNET/dotup-ts-interceptor-proxy)
# dotup-ts-interceptor-proxy
Create proxy of any object and add interceptors.## USAGE
```typescript
import { logMethodCallInterceptor } from './BuildInInterceptor';
import { ICallInterceptor } from './ICallInterceptor';
import { intercept } from './Interceptor';
import { Model } from './test/Model';
import { MethodInterceptor } from './types';const callInterceptor: ICallInterceptor = {
kind: 'ICallInterceptor',
callback(typeOfKey: string, target: Model, key: keyof Model, value: Model[keyof Model]): void {
console.log(`callInterceptor for "${key}" value: ${value}`);
}
};const mi: MethodInterceptor = {
getCount: () => {
console.log('MethodInterceptor for getCount');return 4;
}
};const nameInterceptor: MethodInterceptor = {
setName: (name: string) => {
console.log(`name changed to ${name}`);
}
};const myIntercepter = [nameInterceptor, logMethodCallInterceptor, callInterceptor, mi];
// @ts-ignore
// tslint:disable-next-line: no-unsafe-any
Model = intercept(Model, myIntercepter);const model = new Model();
model.count = 7;
const count = model.getCount();
model.setName('oha');
console.log(model.name);```
## Docs:
https://dotupnet.github.io/dotup-ts-interceptor-proxy/index.html## repository:
https://github.com/dotupNET/dotup-ts-interceptor-proxy