Skip to content

Instantly share code, notes, and snippets.

@makeusabrew
Created January 4, 2013 09:41
Show Gist options
  • Save makeusabrew/4451255 to your computer and use it in GitHub Desktop.
Save makeusabrew/4451255 to your computer and use it in GitHub Desktop.
Various object key / val alignment styles
// 1) colon aligned, no spaces where possible
var Foo = {
host :"foo",
db :"bar",
details:"baz"
};
// 2) colon aligned, space after key
var Foo = {
host : "foo",
db : "bar",
details: "baz"
};
// 3) colon aligned, space before & after key
var Foo = {
host : "foo",
db : "bar",
details : "baz"
};
// 4) space aligned, no spaces where possible
var Foo = {
host: "foo",
db: "bar",
details:"baz"
};
// 5) space aligned, space after key
var Foo = {
host: "foo",
db: "bar",
details: "baz"
};
// 6) space aligned, space before & after key
var Foo = {
host : "foo",
db : "bar",
details : "baz"
};
// or something else entirely?
@glenjamin
Copy link

Same as steve for this, the real question is where to put the newlines and how much to indent when passing an object literal as a function argument!

@stephenmelrose
Copy link

@CyberStrike
Copy link

CyberStrike commented Jul 12, 2017

Wow, this is 4-year-old thread. But this how I align things.

Right align keys on colon. Values left aligned with space after colon.

{
           key: 1,
        string: "value",
    object_key: {
                   string_key: "string",
                  integer_key: 2
                },
  function_key: () => {

                }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment