# dtor

> Very small library which adds a deconstructor to classes in typescript

Latest version **0.1.2** (published 2023-08-30) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2023-08-30 |
| First published | 2023-07-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Berend Sliedrecht |
| Maintainers | blu3beri |

## Links

- npm: https://www.npmjs.com/package/dtor
- Repository: https://github.com/blu3beri/dtor
- Issues: https://github.com/blu3beri/dtor/issues
- npm.io page: https://npm.io/package/dtor

## Recent versions

- 0.1.2 (latest) — 2023-08-30
- 0.1.1 — 2023-08-30
- 0.1.0 — 2023-08-30
- 0.0.2 — 2023-07-01
- 0.0.1 — 2023-07-01
- 0.0.0 — 2023-07-01

## README

# Experimental TypeScript Deconstructor

Requires TypeScript 0.5.2 or newer

## Example tsconfig.json

```json
{
    "compilerOptions": {
        "lib": ["esnext", "dom"],
        "target": "es2015",
        "module": "commonjs",
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "strict": true,
        "outDir": "build",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "declaration": true
    }
}
```

## Example using with async deconstructors

```typescript
import type { AsyncDeconstructable } from 'dtor'
import { Deconstructor } from "dtor";

class SomeExample {
    public constructor() {
        console.log("constructed");
    }

    @Deconstructor()
    public async asyncDeconstructor() {
        await new Promise((r) => setTimeout(r, 2000));
        console.log("deconstructed");
    }
}

void (async () => {
  await using cls = new SomeExample() as AsyncDeconstructable<SomeExample>;
})()

```

## Example using with sync deconstructors

```typescript
import type { Deconstructable } from 'dtor'
import { Deconstructor } from "dtor";

class SomeExample {
    public constructor() {
        console.log("constructed");
    }

    @Deconstructor()
    public deconstructor() {
        console.log("deconstructed");
    }
}

using cls = new SomeExample() as Deconstructable<SomeExample>;
```

## Without this library

```typescript
class SomeExample {
    public constructor() {
        console.log("constructed");
    }

    [Symbol.dispose]() {
        console.log("deconstructed");
    }
}

using cls = new SomeExample() as Deconstructable<SomeExample>;
```

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