# serialize-closures

> Serializes closures processed by the ts-closure-transform package.

Latest version **1.0.0-RC2** (published 2025-03-21) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install serialize-closures
pnpm add serialize-closures
yarn add serialize-closures
bun add serialize-closures
```

## Health

**Score 50/100 (C)** — status: stable.

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

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.0.0-RC2 |
| Published | 2025-03-21 |
| First published | 2019-08-19 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 39.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 51 |
| Author | Jonathan Van der Cruysse |
| Maintainers | rhumbertgz, lhoste-bell |
| Keywords | typescript, transform, modules |

## Links

- npm: https://www.npmjs.com/package/serialize-closures
- Repository: https://github.com/nokia/ts-serialize-closures
- Homepage: https://github.com/nokia/ts-serialize-closures/blob/master/README.md
- Issues: https://github.com/nokia/ts-serialize-closures/issues
- npm.io page: https://npm.io/package/serialize-closures

## 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

- 1.0.0-RC2 (latest) — 2025-03-21
- 1.0.0-RC1 — 2025-03-20
- 0.3.2 — 2025-02-20
- 0.3.1 — 2025-02-20
- 0.3.0 — 2024-01-03
- 0.2.9 — 2024-01-03
- 0.2.8 — 2023-01-20
- 0.2.7 — 2021-03-11
- 0.2.6 — 2020-10-15
- 0.2.5 — 2020-05-23
- 0.2.5-next.0 — 2020-04-22
- 0.2.4 — 2019-09-25
- 0.2.4-next.0 — 2019-09-13
- 0.2.3 — 2019-08-19

## README

# serialize-closures

This package is a runtime library for that allows for arbitrary object graphs to be serialized, including variable-capturing functions. **Be aware** that only functions whose code has first been processed by `ts-closure-transform` are eligible for serialization. 

 ‼️ IMPORTANT ‼️ starting from version 1.0 this library is ESM. If you want to use serialize-closures in a CJS-based project, you will probably want to use a version < 1.0.

`serialize-closures` defines the `serialize` and `deserialize` functions. These should work for any object graph as long as all source code has first been processed by `ts-closure-transform`.

Here's some example usage of `serialize` and `deserialize`:

```typescript
import { serialize, deserialize } from 'serialize-closures';

// Just about anything can be serialized by calling `serialize`.
let capturedVariable = 5;
let serialized = serialize(() => capturedVariable);

// Serialized representations can be stringified and parsed.
let text = JSON.stringify(serialized);
let parsed = JSON.parse(text);

// Serialized representations can be deserialized by calling `deserialize`.
console.log(deserialize(serialized)()); // Prints '5'.
```

If you want to attach some data to an object that don't want to see serialized, then you can assign that property a name that starts with two underscores. The serializer will ignore those when serializing.

```typescript
deserialize(serialize({ __dont_include_this: 10 })); // Produces '{ }'.
```

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