# xaop

> Typescript 的Aop实现. 有关AOP编程,其实就是在函数的运行时注入相应的代码,以达到分离实现的目的.(简单的说就是这样...)

Latest version **2.1.0** (published 2023-04-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install xaop
pnpm add xaop
yarn add xaop
bun add xaop
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2023-04-12 |
| First published | 2017-07-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 23.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | xcad |
| Maintainers | xcad |

## Links

- npm: https://www.npmjs.com/package/xaop
- Repository: https://github.com/FishOrBear/xaop
- npm.io page: https://npm.io/package/xaop

## Recent versions

- 2.1.0 (latest) — 2023-04-12
- 2.0.0 — 2022-04-24
- 1.3.3 — 2019-08-16
- 1.3.2 — 2018-02-23
- 1.3.1 — 2018-02-23
- 1.1.9 — 2017-09-26
- 1.1.8 — 2017-09-21
- 1.1.7 — 2017-09-18
- 1.1.6 — 2017-09-18
- 1.1.5 — 2017-07-08
- 1.1.4 — 2017-07-08
- 1.1.2 — 2017-07-08
- 1.1.1 — 2017-07-07
- 1.1.0 — 2017-07-05
- 1.0.4 — 2017-07-05
- … 4 more at https://npm.io/package/xaop/versions

## README

# xaop

Typescript 的Aop实现.
有关AOP编程,其实就是在函数的运行时注入相应的代码,以达到分离实现的目的.(简单的说就是这样...)

所以现在这个库用装饰器实现了一个注入工具.可以直接通过 obj.func 直接输入起始和结束,并且可以得到参数和返回结果.
下面这个例子简单的描述了这个库的使用


##安装
```
npm i xaop
```
##升级
```
npm publish
```

##注意:
默认构造参数无法捕获初始化参数.
```ts
function add(a,b=1) //这里的b是无法捕获到的
{

}
```

##全局注入
```ts
class E
{
    @iaop
    exec()
    {
        console.log("hello e");
    }
}

let e = new E();
let remove1 = xaop.begin(e.exec, () =>
{
    console.log("begin");
})

let remove2 = xaop.end(e.exec, function()
{
    //如果你不使用箭头函数 你可以捕获到this.
    console.log("end");
})

e.exec();
//begin
//hello e
//end
remove1();//清除注入
remove2();//清除注入
e.exec();
//hello e
```



##对象注入
```ts
class E
{
    exec()
    {
        console.log("hello e");
    }
}

let e=new E()
let e2=new E();
xaop.begin(e,e.exec,()=>{
    console.log("hello begin");
})

e.exec();
/*
hello begin
hello e
*/

//不影响e2的响应
e2.exec()
/*
hello e
*/
```

---
_Source: https://npm.io/package/xaop · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
