Skip to content

RikhartBekkevold/js-object-notation-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JS object notation converter

An atom package that converts the syntax between object literal notation and function statement notation (sometimes called constructor).

Demo gif

Normally, when you convert a JS object you need to complete two steps:

  1. Convert the syntax (e.g. convert equals signs to colons)
  2. Convert legal code in one notation that is illegal in the other

This package helps with the tedious work of the first step by automating it. The decisions of the second step still needs to be done manually by you.

How to

  1. Select the object you want converted
  2. Press ctrl-alt-o (win/linux) / cmd-alt-o (mac)

or

  1. Select the object you want converted
  2. Then press shift-ctrl-p (win) / shift-cmd-p (mac) / ctrl-shift-p (linux) to open the atom command palette
  3. Start typing "js-object-notation-converter:convert"
  4. Select the command from the list of choices
  5. Press Enter to execute

Additionally, you can access the convert command through the Packages option in the menu bar, or the text editor's contextmenu.

Install

In Atom Editor

Install the package through the Atom Editor itself:

  1. Open Atom, or click the green Install button at the top of this page
  2. Click File in the menubar at the top in Atom
  3. Click Settings in the dropdown menu or press ctrl-, (win/linux) / cmd-, (mac)
  4. Select Install in the left menu
  5. Type "js-object-notation-converter" in the input field
  6. Find the package in the results and click Install

Command Line

  1. Install Atom

  2. In your terminal of choice, type:

    apm install js-object-notation-converter

    to install the latest version.

NB!

This package will not auto-correct syntax for you. If the syntax is wrong, the output will (most likely), be wrong also.

As mentioned above, code that is legal in one notation, but not the other (e.g. comparison expressions in the objects root scope), will be ignored. You must manually decide what to do with this code. This package only converts syntax.

The exception to the above is private functions which will be made public in the "constructor -> literal" conversion (thats how object literals work after all).

function calc() {}   ->   calc: function() {}

(NB! running the conversion again after converting from constructor to literal will not make previous private functions private again - use ctrl-z (undo) instead; to achieve this.)

About

Converts between object literal notation and function statement (constructor) notation.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published