# sorted-object

> Returns a copy of an object with its keys sorted

Latest version **2.0.1** (published 2016-09-10) · (WTFPL OR MIT) license · 0 weekly downloads

## Install

```sh
npm install sorted-object
pnpm add sorted-object
yarn add sorted-object
bun add sorted-object
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2016-09-10 |
| First published | 2014-02-17 |
| Weekly downloads | 0 |
| License | (WTFPL OR MIT) |
| TypeScript types | separate (@types/sorted-object) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 36 |
| Author | Domenic Denicola |
| Maintainers | domenic |
| Keywords | sort, keys, object |

## Links

- npm: https://www.npmjs.com/package/sorted-object
- Repository: https://github.com/domenic/sorted-object
- Homepage: https://github.com/domenic/sorted-object#readme
- Issues: https://github.com/domenic/sorted-object/issues
- npm.io page: https://npm.io/package/sorted-object

## Recent versions

- 2.0.1 (latest) — 2016-09-10
- 2.0.0 — 2016-03-13
- 1.0.0 — 2014-02-17

## README

# Get a Version of an Object with Sorted Keys

Although objects in JavaScript are theoretically unsorted, in practice most engines use insertion order—at least, ignoring numeric keys. This manifests itself most prominently when dealing with an object's JSON serialization.

So, for example, you might be trying to serialize some object to a JSON file. But every time you write it, it ends up being output in a different order, depending on how you created it in the first place! This makes for some ugly diffs.

**sorted-object** gives you the answer. Just use this package to create a version of your object with its keys sorted before serializing, and you'll get a consistent order every time.

```js
var sortedObject = require("sorted-object");

var objectToSerialize = generateStuffNondeterministically();

// Before:
fs.writeFileSync("dest.json", JSON.stringify(objectToSerialize));

// After:
var sortedVersion = sortedObject(objectToSerialize);
fs.writeFileSync("dest.json", JSON.stringify(sortedVersion));
```

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