# inspectable

> Make the output of a class instance in the console meaningful

Latest version **3.0.2** (published 2024-06-16) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2024-06-16 |
| First published | 2020-04-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20.0.0 |
| Dependencies | 0 |
| Unpacked size | 14 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Vladlen |
| Maintainers | negezor |
| Keywords | inspect, inspectable, console, typescript |

## Links

- npm: https://www.npmjs.com/package/inspectable
- Repository: https://github.com/negezor/inspectable
- Homepage: https://github.com/negezor/inspectable#readme
- Issues: https://github.com/negezor/inspectable/issues
- npm.io page: https://npm.io/package/inspectable

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 3.0.2 (latest) — 2024-06-16
- 2.1.1 — 2024-04-18
- 3.0.1 — 2024-04-18
- 3.0.0 — 2024-02-25
- 2.1.0 — 2023-04-25
- 2.0.0 — 2023-03-13
- 1.2.2 — 2022-09-20
- 1.2.1 — 2021-12-14
- 1.2.0 — 2021-05-26
- 1.1.1 — 2021-03-28
- 1.1.0 — 2021-01-11
- 1.0.0 — 2020-05-20
- 0.0.1 — 2020-04-24

## README

<p align="center">
<a href="https://www.npmjs.com/package/inspectable"><img src="https://img.shields.io/npm/v/inspectable.svg?style=flat-square" alt="NPM version"></a>
<a href="https://github.com/negezor/inspectable/actions/workflows/tests.yml"><img src="https://img.shields.io/github/actions/workflow/status/negezor/inspectable/tests.yml?style=flat-square" alt="Build Status"></a>
<a href="https://www.npmjs.com/package/inspectable"><img src="https://img.shields.io/npm/dt/inspectable.svg?style=flat-square" alt="NPM downloads"></a>
</p>

**Inspectable** - Make the output of a class instance in the console meaningful

| 📖 [Documentation](docs/) |
|---------------------------|

## Features

1. **Self-Sufficient.** The library has zero dependencies.
2. **Reliable.** The library is written in **TypeScript** and covered by tests.
3. **Modern.** The library comes with native ESM support

## Installation
> **[Node.js](https://nodejs.org/) 20.0.0 or newer is required**

- **Using `npm`** (recommended)
    ```shell
    npm i inspectable
    ```
- **Using `Yarn`**
  ```shell
  yarn add inspectable
  ```
- **Using `pnpm`**
  ```shell
  pnpm add inspectable
  ```

## Example usage
```ts
import { inspectable } from 'inspectable';

class APIRequest {
    public method = 'pay';

    private token = 'super-private';
}

const request = new APIRequest();

console.log(request);
// APIRequest { method: 'pay', token: 'super-private' }

inspectable(APIRequest, {
    serialize(instance) {
        return {
            method: instance.method
        };
    }
});

console.log(request);
// APIRequest {
//   method: 'pay'
// }
```

### Decorators
```ts
import { Inspectable, Inspect } from 'inspectable';

// INFO: Temp polyfill, more info https://github.com/microsoft/TypeScript/issues/55453#issuecomment-1687496648
(Symbol as any).metadata ??= Symbol("Symbol.metadata");

@Inspectable({/* options */})
class APIRequest {
    @Inspect()
    public method = 'pay';

    private token = 'super-private';

    @Inspect({ nullable: false })
    private signal = null;

    @Inspect({ as: 'firstName' })
    private name = 'john';

    @Inspect({ compute: true })
    public canRequest() {
        return Boolean(this.token);
    }
}

const request = new APIRequest();

console.log(request);
// APIRequest {
//   method: 'pay',
//   firstName: 'john',
//   canRequest: true
// }
```

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