homebrew-core/Formula/json5.rb

40 lines
1.1 KiB
Ruby

require "language/node"
class Json5 < Formula
desc "JSON enhanced with usability features"
homepage "https://json5.org/"
url "https://github.com/json5/json5/archive/v2.2.1.tar.gz"
sha256 "2ad1be22d6138825a712411fac53086a8710b7d987e9aa81c59ee370b5a57030"
license "MIT"
bottle do
sha256 cellar: :any_skip_relocation, all: "b78db2e75223abf02b70379e741be320cc35f26190b7907035d694735b44253c"
end
depends_on "node"
def install
system "npm", "install", *Language::Node.std_npm_install_args(libexec)
bin.install_symlink Dir["#{libexec}/bin/*"]
end
test do
# Example taken from the official README
(testpath/"test.json5").write <<~EOF
{
// comments
unquoted: 'and you can quote me on that',
singleQuotes: 'I can use "double quotes" here',
lineBreaks: "Look, Mom! \
No \\n's!",
hexadecimal: 0xdecaf,
leadingDecimalPoint: .8675309, andTrailing: 8675309.,
positiveSign: +1,
trailingComma: 'in objects', andIn: ['arrays',],
"backwardsCompatible": "with JSON",
}
EOF
system bin/"json5", "--validate", "test.json5"
end
end