bitspook / js-sort-object-properties

A small npm module for sorting object properties in javascript code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

js-sort-object-properties

It’s a small npm module for sorting object properties in javascript code.

Status: Very alpha

Demo (in Emacs)

https://i.imgur.com/X4f17dr.gif

Installation

npm install js-sort-object-properties -g

Usage

Installing/linking this package will expose a single command named jsop. jsop accepts no arguments. It takes input from stdin and provides output to stdout. If your code is correct, you’ll get same code as output with all the objects’ properties sorted. Else it’ll fail in your face, so keep an eye for a quick jab.

echo "var o = {c: 'c', a: 'a', b: 'b'}" | jsop
cat myJsFile.js | jsop > myJsFile.js

Warning

Currently if you pass it an object (e.g {a: 'a'}), it fails. That one is on esprima. I’ll fix it in the future. Just watch out for now. Make sure you pass it the object with the indentifier you bind it to. e.g var o = {a: 'a'};

Editor plugins

My real intention to create this package is to use it from within my text-editor. I wanted to just select an object, and sort its properties with a key combination. ./editor-plugins directory has plugins for following editors:

Emacs

Emacs is the only supported editor as of now (because it’s the only editor I use these days).

Install

Just put the ./editor-plugins/emacs/jsop.el somewhere on your load-path and you’re good to go.

Usage

  • Install the npm package
  • Select a javascript object
  • `M-x` and select `jsop`

About

A small npm module for sorting object properties in javascript code


Languages

Language:JavaScript 56.5%Language:Emacs Lisp 43.5%