# obj-repr

> Package which generates code for a JavaScript expression that evaluates to the provided input value

Latest version **1.0.0** (published 2024-05-01) · EUPL-1.2 license · 0 weekly downloads

## Install

```sh
npm install obj-repr
pnpm add obj-repr
yarn add obj-repr
bun add obj-repr
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-05-01 |
| First published | 2023-04-18 |
| Weekly downloads | 0 |
| License | EUPL-1.2 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | slietar |

## Links

- npm: https://www.npmjs.com/package/obj-repr
- Repository: https://github.com/slietar/obj-repr
- Homepage: https://github.com/slietar/obj-repr#readme
- Issues: https://github.com/slietar/obj-repr/issues
- npm.io page: https://npm.io/package/obj-repr

## Recent versions

- 1.0.0 (latest) — 2024-05-01
- 0.1.0 — 2023-04-18

## README

# obj-repr

This package generates code for a JavaScript expression that evaluates to the provided input value, similar to the `repr()` function in Python. Compared to JSON and similar serialization solutions, `obj-repr` has support for the following:

- repeated and circular references
- typed arrays and `ArrayBuffer`
- bigints
- symbols; symbols with a description are recreated using `Symbol.for()`
- `Map`, `Set`
- `Date`, `RegExp`, `URL`

Under the hood, `obj-repr` returns code that creates an IIFE which resolves all references and recreates complex objects. It is meant to be used with JavaScript code generators, such as bundlers, when passing data from input options to output files.

The output string is guaranteed to be constant for a given input value in the absence of symbols.


## Installation

```sh
$ npm install obj-repr
```


## Usage

```js
import repr from 'obj-repr';

let obj = {
  a: 4,
  b: 'hello',
  c: new Set([5, 6])
};

obj.self = obj;

let output = repr(obj);
// => an opaque string of JavaScript

eval(output);
// => <ref *1> {
//   a: 4,
//   b: 'hello',
//   c: Set(2) { 5, 6 },
//   self: [Circular *1]
// }
```

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