Returns a copy of a JavaScript object with the keys arranged in a specified order. Useful for formatting JSON files.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
source
.editorconfig
.eslintrc.js
.gitignore
.npmignore
.travis.yml
CONTRIBUTING.md
HISTORY.md
LICENSE.md
README.md
index.js
package.json

README.md

Arrange Keys

Travis CI Build Status NPM version NPM downloads Dependency Status Dev Dependency Status
Slack community badge Patreon donate button Gratipay donate button Flattr donate button PayPal donate button Bitcoin donate button Wishlist browse button

Returns a copy of a JavaScript object with the keys arranged in a specified order. Useful for formatting JSON files.

Install

NPM

  • Install: npm install --save arrangekeys
  • Module: require('arrangekeys')

Browserify

  • Install: npm install --save arrangekeys
  • Module: require('arrangekeys')
  • CDN URL: //wzrd.in/bundle/arrangekeys@1.2.0

Ender

  • Install: ender add arrangekeys
  • Module: require('arrangekeys')

Editions

This package is published with the following editions:

  • arrangekeys aliases arrangekeys/index.js which uses Editions to automatically select the correct edition for the consumers environment
  • arrangekeys/source/index.js is Source + ESNext + Require
  • arrangekeys/es2015/index.js is Babel Compiled + ES2015 + Require

Older environments may need Babel's Polyfill or something similar.

Usage

// Arrange the keys of the input so that keys "b" and "c" are first
console.log(
	require('arrangekeys')({
		z: 1,
		a: 2,
		b: 3,
		c: 4
	}, 'b c')
) /* {
	b: 3,
	c: 4,
	z: 1,
	a: 2
} */

// Arrange the keys of the input so that keys "b" and "c" are first, with the rest alphabetically sorted
console.log(
	require('arrangekeys')({
		z: 1,
		a: 2,
		b: 3,
		c: 4
	}, 'b c', true)
) /* {
	b: 3,
	c: 4,
	a: 2,
	z: 1
} */

// Arrange the keys to be alphabetically sorted
console.log(
	require('arrangekeys')({
		z: 1,
		a: 2,
		b: 3,
		c: 4
	})
) /* {
	a: 2,
	b: 3,
	c: 4,
	z: 1
} */

History

Discover the release history by heading on over to the HISTORY.md file.

Contribute

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

Patreon donate button Gratipay donate button Flattr donate button PayPal donate button Bitcoin donate button Wishlist browse button

Contributors

These amazing people have contributed code to this project:

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

License

Unless stated otherwise all works are:

and licensed under: