有没有一个不糟糕的格式化 JavaScript 的工具?

发布于 2024-09-18 18:16:22 字数 1611 浏览 3 评论 0原文

我正在寻找一个可以为我格式化 javascript 的工具。很多时候,我希望我可以让一个工具格式化我的源代码,因为重组一些代码或者因为我想确保代码结构确实像我相信的那样。我的问题是我发现的所有格式化程序都会产生非常迟缓的结果。

如果我自己格式化源代码,我会像这样格式化它:

var structure = {
  key1: {
    subkey1: 3,
    subkey: 6,
    sublist: [
      {
         deep: "yes"
      },
      {
        deep: "yes",
        somekey: 4
      },
      5,
      10          
    ]
  },
  key2: [
    {
      key: 5,
      key2: 10
    },
    [1, 2, 3],
    [
      {
        nestedObj: "hello",
        siblingProp: 5
      },
      {}
    ]
  ]
}

无论我找到什么工具,都不必以完全相同的方式执行此操作,但看看 eclipse 内置格式化程序的功能:

var structure = {
    key1 : {
        subkey1 : 3,
        subkey : 6,
        sublist : [{
                    deep : "yes"
                }, {
                    deep : "yes",
                    somekey : 4
                }, 5, 10]
    },
    key2 : [{
                key : 5,
                key2 : 10
            }, [1, 2, 3], [{
                        nestedObj : "hello",
                        siblingProp : 5
                    }, {}]]
}

或者我使用 Aptana 插件(3.0 beta)获得的格式化程序

var structure = {
    key1: {
        subkey1: 3,
        subkey: 6,
        sublist: [
        {
            deep: "yes"
        },
        {
            deep: "yes",
            somekey: 4
        },
        5,
        10
        ]
    },
    key2: [
    {
        key: 5,
        key2: 10
    },
    [1, 2, 3],
    [
    {
        nestedObj: "hello",
        siblingProp: 5
    },
    {}
    ]
    ]
}

它们在可视化我的数据结构的结构方面提供零帮助。 有人知道一个不错的格式化程序吗?请。

I am looking for a tool that formats my javascript for me. There are many times when I wish I could just let a tool format my source code because of restructuring some code or because I want to make sure the code structure really is like I believe it to be. My problem is that all formatters I have found produce really retarded results.

If I format the source myself I would format it like this:

var structure = {
  key1: {
    subkey1: 3,
    subkey: 6,
    sublist: [
      {
         deep: "yes"
      },
      {
        deep: "yes",
        somekey: 4
      },
      5,
      10          
    ]
  },
  key2: [
    {
      key: 5,
      key2: 10
    },
    [1, 2, 3],
    [
      {
        nestedObj: "hello",
        siblingProp: 5
      },
      {}
    ]
  ]
}

Whatever tool I find doesn't have to do it exactly the same way but look at what eclipse's built in formatter does:

var structure = {
    key1 : {
        subkey1 : 3,
        subkey : 6,
        sublist : [{
                    deep : "yes"
                }, {
                    deep : "yes",
                    somekey : 4
                }, 5, 10]
    },
    key2 : [{
                key : 5,
                key2 : 10
            }, [1, 2, 3], [{
                        nestedObj : "hello",
                        siblingProp : 5
                    }, {}]]
}

Or the one I get with Aptana's plugin (3.0 beta)

var structure = {
    key1: {
        subkey1: 3,
        subkey: 6,
        sublist: [
        {
            deep: "yes"
        },
        {
            deep: "yes",
            somekey: 4
        },
        5,
        10
        ]
    },
    key2: [
    {
        key: 5,
        key2: 10
    },
    [1, 2, 3],
    [
    {
        nestedObj: "hello",
        siblingProp: 5
    },
    {}
    ]
    ]
}

They provide zero help in visualizing the structure of my datastructure.
Does anyone know of a decent formatter? Please.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦中的蝴蝶 2024-09-25 18:16:22

WebStorm / PHPStorm / Intellij IDEA

刚刚在我的 PHPStorm 中进行了快速检查:我已经粘贴了“Eclipse”示例中的代码,运行了 Code ->;重新格式化代码,它给了我代码,就像您手动执行的一样(唯一的区别是它用两边的空格包裹冒号)

WebStorm / PHPStorm / Intellij IDEA

Just made a quick check in my PHPStorm: i've pasted your code from "Eclipse" example, ran Code -> Reformat code and it gave me the code, like you would do it manually (the only difference is that it wraps colons with spaces from both sides)

木有鱼丸 2024-09-25 18:16:22

我认为 JS Beautifier 启用“大括号在自己的行”至少接近。

I think the JS Beautifier with "braces on own line" enabled comes at least close.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文