# sixth-sense

> Gives functions a sixth sense

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

## Install

```sh
npm install sixth-sense
pnpm add sixth-sense
yarn add sixth-sense
bun add sixth-sense
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-09-12 |
| First published | 2022-09-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Alistair Smith |
| Maintainers | aabbccsmith |

## Links

- npm: https://www.npmjs.com/package/sixth-sense
- Repository: git@github.com:alii/sixth-sense
- Homepage: https://github.com/alii/sixth-sense#readme
- Issues: https://github.com/alii/sixth-sense/issues
- npm.io page: https://npm.io/package/sixth-sense

## Recent versions

- 1.0.1 (latest) — 2022-09-12
- 1.0.0 — 2022-09-12

## README

# sixth-sense

This library gives functions a sixth sense. It allows them to know when they're called, when they throw, and can even modify return values (_EVEN_ after the function has executed).

## Installation

```bash
npm install sixth-sense
```

## Usage

```javascript
import { aware } from "sixth-sense";

const add = aware(function (a, b) {
	// Listen for if the function throws
	this.onThrow(error => {
		this.return(-1);
	});

	// You can add as many .onThrow listeners as you want
	this.onThrow(error => {
		console.log(error);
	});

	// Listen for when the function has executed
	// Again, you can add as many .after listeners as you want
	this.after(result => {
		if (result === 30) {
			this.return(99);
		}
	});

	// Business logic below

	if (Math.random() > 0.5) {
		throw new Error("Math exists");
	}

	return a + b;
});
```

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