Standardize

Standardize a package.json object.

Usage

var standardize = require( '@stdlib/_tools/package-json/standardize' );

standardize( pkg[, keys] )

Standardizes a package.json object.

var pkg = {
    'license': 'MIT',
    'name': 'beep'
};

var out = standardize( pkg );
// returns {'name':'beep','license':'MIT'}

To specify an alternative key order, provide an array of keys.

var pkg = {
    'c': 1,
    'b': 2,
    'a': 3
};

var keys = [ 'b', 'a', 'c' ];

var out = standardize( pkg, keys );
// returns {'b':2,'a':3,'c':1}

Notes

  • The implementation relies on engines using insertion order for key ordering. This is not specified by the ECMAScript specification; however, most engines order keys according to insertion order.

Examples

var standardize = require( '@stdlib/_tools/package-json/standardize' );
var pkg = require( './../package.json' );

var out = standardize( pkg );
console.dir( out );

CLI

Usage

Usage: standardize-json [options] [json]

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.
         --keys k1,k2,k3,...   Keys in order of insertion.

Examples

$ standardize-json '{"license":"MIT","name":"beep"}'
{"name":"beep","license":"MIT"}

To use as a standard stream,

$ echo '{"license":"MIT","name":"beep"}' | standardize-json
{"name":"beep","license":"MIT"}