sorted-object

WebJar for sorted-object

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

sorted-object
Last Version

Last Version

2.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

sorted-object
WebJar for sorted-object
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/domenic/sorted-object

Download sorted-object

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/sorted-object/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>sorted-object</artifactId>
    <version>2.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/sorted-object/
implementation 'org.webjars.npm:sorted-object:2.0.1'
// https://jarcasting.com/artifacts/org.webjars.npm/sorted-object/
implementation ("org.webjars.npm:sorted-object:2.0.1")
'org.webjars.npm:sorted-object:jar:2.0.1'
<dependency org="org.webjars.npm" name="sorted-object" rev="2.0.1">
  <artifact name="sorted-object" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='sorted-object', version='2.0.1')
)
libraryDependencies += "org.webjars.npm" % "sorted-object" % "2.0.1"
[org.webjars.npm/sorted-object "2.0.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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.

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));

Versions

Version
2.0.1