Converts between object literal notation and function statement (constructor) notation.
JS object notation converter
An atom package that converts the syntax between object literal notation and function statement notation (sometimes called constructor).
Normally, when you convert a JS object you need to complete two steps:
- Convert the syntax (e.g. convert equals signs to colons)
- 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
- Select the object you want converted
- Press ctrl-alt-o (win/linux) / cmd-alt-o (mac)
or
- Select the object you want converted
- Then press shift-ctrl-p (win) / shift-cmd-p (mac) / ctrl-shift-p (linux) to open the atom command palette
- Start typing
"js-object-notation-converter:convert"
- Select the command from the list of choices
- 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:
- Open Atom, or click the green Install button at the top of this page
- Click
File
in the menubar at the top in Atom - Click
Settings
in the dropdown menu or press ctrl-, (win/linux) / cmd-, (mac) - Select
Install
in the left menu - Type
"js-object-notation-converter"
in the input field - Find the package in the results and click Install
Command Line
-
Install Atom
-
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.)