# extra-aspect

> ```sh npm install --save extra-aspect # or yarn add extra-aspect ```

Latest version **0.2.6** (published 2022-12-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install extra-aspect
pnpm add extra-aspect
yarn add extra-aspect
bun add extra-aspect
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.6 |
| Published | 2022-12-12 |
| First published | 2021-10-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | BlackGlory |
| Maintainers | black_glory |

## Links

- npm: https://www.npmjs.com/package/extra-aspect
- Repository: https://github.com/BlackGlory/extra-aspect
- Homepage: https://github.com/BlackGlory/extra-aspect#readme
- Issues: https://github.com/BlackGlory/extra-aspect/issues
- npm.io page: https://npm.io/package/extra-aspect

## Dependencies (4)

- [justypes](https://npm.io/package/justypes.md) ^3.1.2
- [extra-promise](https://npm.io/package/extra-promise.md) ^4.4.0
- [@blackglory/types](https://npm.io/package/@blackglory/types.md) ^1.4.0
- [iterable-operator](https://npm.io/package/iterable-operator.md) ^2.5.0

## Recent versions

- 0.2.6 (latest) — 2022-12-12
- 0.2.5 — 2022-10-18
- 0.2.4 — 2022-03-23
- 0.2.3 — 2022-02-27
- 0.2.2 — 2022-01-06
- 0.2.1 — 2021-12-17
- 0.2.0 — 2021-12-16
- 0.1.0 — 2021-10-08

## README

# extra-aspect
## Install
```sh
npm install --save extra-aspect
# or
yarn add extra-aspect
```

## Usage
```ts
import { aspect } from 'extra-aspect'

const fn = aspect(
  () => {
    console.log('called')
    return 'return'
  }
, {
    before: () => console.log('before')
  , returning: () => console.log('returning')
  }
)

console.log(fn())
// before
// called
// returning
// return
```

## API
```ts
type IHooks<T> = {
  before?: Arrayable<() => unknown>
  returning?: Arrayable<(result: T) => unknown>
  throwing?: Arrayable<(err: unknown) => unknown>
  finally?: Arrayable<() => unknown>
}

type IAsyncHooks<T> = {
  before?: Arrayable<() => unknown | PromiseLike<unknown>>
  returning?: Arrayable<(result: T) => unknown | PromiseLike<unknown>>
  throwing?: Arrayable<(err: unknown) => unknown | PromiseLike<unknown>>
  finally?: Arrayable<() => unknown | PromiseLike<unknown>>
}
```

### aspect
```ts
function aspect<T, Args extends any[]>(
  fn: (...args: Args) => T
, hooks: IHooks<T>
): (...args: Args) => T
function aspect<T, Args extends any[]>(
  hooks: IHooks<T>
, fn: (...args: Args) => T
): (...args: Args) => T
```

### aspectAsync
```ts
function aspectAsync<T, Args extends any[]>(
  fn: (...args: Args) => PromiseLike<T>
, hooks: IAsyncHooks<T>
, concurrency: number = 1
): (...args: Args) => Promise<T>
function aspectAsync<T, Args extends any[]>(
  hooks: IAsyncHooks<T>
, fn: (...args: Args) => PromiseLike<T>
, concurrency: number = 1
): (...args: Args) => Promise<T>
```

### compose
```ts
function compose<T>(...hooks: Array<IHooks<T>>): IHooks<T>
function compose<T>(...hooks: Array<IAsyncHooks<T>>): IAsyncHooks<T>
function compose<T>(...hooks: Array<IHooks<T> | IAsyncHooks<T>>): IAsyncHooks<T>
```

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