# poproxy

> Proxy factory for preserving insertion order of object keys

Latest version **0.1.0** (published 2021-06-16) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2021-06-16 |
| First published | 2021-06-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 18.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Matt Miller |
| Maintainers | mmiller42 |

## Links

- npm: https://www.npmjs.com/package/poproxy
- Repository: https://github.com/mmiller42/poproxy
- npm.io page: https://npm.io/package/poproxy

## Recent versions

- 0.1.0 (latest) — 2021-06-16

## README

# poproxy

> Preserved Order Proxy

poproxy is a [`Proxy`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) constructor that preserves the original order of properties as they are assigned to the object, ignoring the [exceptions that apply to numbers and symbols](https://2ality.com/2015/10/property-traversal-order-es6.html).

## Example

```ts
import { preserveOrder } from "poproxy";

interface Foo {
  a: string;
  b: string;
  "0": string;
  "1": string;
}

const foo: Partial<Foo> = {};
const proxy = preserveOrder<Foo>(foo);

proxy.b = "b";
proxy[1] = "1";
proxy["0"] = "0";
proxy.a = "a";

Object.keys(foo); // ["0", "1", "b", "a"]
JSON.stringify(foo); // {"0":"0","1":"1","b":"b","a":"a"}

Object.keys(proxy); // ["b", "1", "0", "a"]
JSON.stringify(proxy); // {"b":"b","1":"1","0":"0","a":"a"}
```

Just like normal objects, if a property is deleted and then assigned, it will be appended rather than returning to its previous position:

```ts
delete proxy.b;
proxy.b = "B";

Object.keys(foo); // ["0", "1", "a", "b"]
JSON.stringify(foo); // {"0":"0","1":"1","a":"a","b":"B"}

Object.keys(proxy); // ["1", "0", "a", "b"]
JSON.stringify(proxy); // {"1":"1","0":"0","a":"a","b":"B"}
```

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