json_minify 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/json_minify +2 -2
- data/lib/json_minify/version.rb +1 -1
- data/lib/json_minify.rb +6 -12
- data/spec/minify_spec.rb +42 -14
- metadata +30 -41
- checksums.yaml +0 -7
data/bin/json_minify
CHANGED
@@ -32,8 +32,8 @@ end
|
|
32
32
|
opt_parser.parse!
|
33
33
|
if (input = ARGF.read)
|
34
34
|
if options[:pretty]
|
35
|
-
puts
|
35
|
+
puts MultiJson.dump(MultiJson.load(input, minify: true), pretty: true)
|
36
36
|
else
|
37
|
-
puts
|
37
|
+
puts MultiJson.minify(input)
|
38
38
|
end
|
39
39
|
end
|
data/lib/json_minify/version.rb
CHANGED
data/lib/json_minify.rb
CHANGED
@@ -3,6 +3,7 @@ require 'multi_json'
|
|
3
3
|
require "json_minify/version"
|
4
4
|
|
5
5
|
module JsonMinify
|
6
|
+
|
6
7
|
def minify(str)
|
7
8
|
ss, buf = StringScanner.new(str), ''
|
8
9
|
|
@@ -41,20 +42,13 @@ module JsonMinify
|
|
41
42
|
end
|
42
43
|
buf
|
43
44
|
end
|
44
|
-
|
45
|
-
def minify_parse(buf)
|
46
|
-
MultiJson.load(minify(buf))
|
47
|
-
end
|
48
|
-
|
49
|
-
def minify_pretty(buf)
|
50
|
-
MultiJson.dump(minify_parse(buf), pretty: true)
|
51
|
-
end
|
52
45
|
end
|
53
46
|
|
54
|
-
MultiJson.
|
47
|
+
MultiJson.module_eval do
|
55
48
|
extend JsonMinify
|
56
|
-
end
|
57
49
|
|
58
|
-
|
59
|
-
|
50
|
+
def self.load(string, options={})
|
51
|
+
options.fetch(:minify, false) && string = minify(string)
|
52
|
+
super(string, options)
|
53
|
+
end
|
60
54
|
end
|
data/spec/minify_spec.rb
CHANGED
@@ -1,23 +1,51 @@
|
|
1
1
|
require 'json_minify'
|
2
2
|
require 'rspec/autorun'
|
3
3
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
describe MultiJson do
|
5
|
+
describe "::minify" do
|
6
|
+
it "removes whitespace from JSON" do
|
7
|
+
expect(MultiJson.minify("{ }")).to eql("{}")
|
8
|
+
expect(MultiJson.minify(%Q<{"foo": "bar"\n}\n>)).to eql(%Q<{"foo":"bar"}>)
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
it "removes comments from JSON" do
|
12
|
+
expect(MultiJson.minify("{ /* foo */ } /* bar */")).to eql("{}")
|
13
|
+
expect(MultiJson.minify(%Q<{"foo": "bar"\n}\n // this is a comment>)).to eql(%Q<{"foo":"bar"}>)
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
it "throws a SyntaxError on invalid JSON" do
|
17
|
+
expect { MultiJson.minify("{ /* foo */ } /* bar ") }.to raise_error(SyntaxError)
|
18
|
+
expect { MultiJson.minify(%Q<{ "foo": new Date(1023) }>) }.to raise_error(SyntaxError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "copes with the example from https://github.com/getify/JsonMinify.minify" do
|
22
|
+
expect(MultiJson.minify( %Q'{ /* comment */ "foo": 42 \n }' )).to eql('{"foo":42}')
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
|
-
|
21
|
-
|
26
|
+
|
27
|
+
describe "::load" do
|
28
|
+
context "with :minify option" do
|
29
|
+
let(:opts) { {minify: true, symbolize_keys: true} }
|
30
|
+
|
31
|
+
it "removes whitespace from JSON" do
|
32
|
+
expect(MultiJson.load("{ }", opts)).to eq({})
|
33
|
+
expect(MultiJson.load(%Q<{"foo": "bar"\n}\n>, opts)).to eq({foo:"bar"})
|
34
|
+
end
|
35
|
+
|
36
|
+
it "removes comments from JSON" do
|
37
|
+
expect(MultiJson.load("{ /* foo */ } /* bar */", opts)).to eq({})
|
38
|
+
expect(MultiJson.load(%Q<{"foo": "bar"\n}\n // this is a comment>, opts)).to eq({foo:"bar"})
|
39
|
+
end
|
40
|
+
|
41
|
+
it "throws a SyntaxError on invalid JSON" do
|
42
|
+
expect { MultiJson.load("{ /* foo */ } /* bar ", opts) }.to raise_error(SyntaxError)
|
43
|
+
expect { MultiJson.load(%Q<{ "foo": new Date(1023) }>, opts) }.to raise_error(SyntaxError)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "copes with the example from https://github.com/getify/JsonMinify.load" do
|
47
|
+
expect(MultiJson.load( %Q'{ /* comment */ "foo": 42 \n }' , opts)).to eq({foo:42})
|
48
|
+
end
|
49
|
+
end
|
22
50
|
end
|
23
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_minify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Geoff Youngs, Alan Cohen
|
@@ -12,64 +13,50 @@ date: 2014-03-05 00:00:00.000000000 Z
|
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70357755509400 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '1'
|
20
22
|
type: :development
|
21
23
|
prerelease: false
|
22
|
-
version_requirements:
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1'
|
24
|
+
version_requirements: *70357755509400
|
27
25
|
- !ruby/object:Gem::Dependency
|
28
26
|
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &70357755508520 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
30
29
|
requirements:
|
31
|
-
- -
|
30
|
+
- - ~>
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: '10.1'
|
34
33
|
type: :development
|
35
34
|
prerelease: false
|
36
|
-
version_requirements:
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '10.1'
|
35
|
+
version_requirements: *70357755508520
|
41
36
|
- !ruby/object:Gem::Dependency
|
42
37
|
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &70357755507620 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
44
40
|
requirements:
|
45
|
-
- -
|
41
|
+
- - ~>
|
46
42
|
- !ruby/object:Gem::Version
|
47
43
|
version: '2.14'
|
48
44
|
type: :development
|
49
45
|
prerelease: false
|
50
|
-
version_requirements:
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '2.14'
|
46
|
+
version_requirements: *70357755507620
|
55
47
|
- !ruby/object:Gem::Dependency
|
56
48
|
name: multi_json
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirement: &70357755506860 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1
|
54
|
+
version: '1'
|
62
55
|
type: :runtime
|
63
56
|
prerelease: false
|
64
|
-
version_requirements:
|
65
|
-
|
66
|
-
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '1.0'
|
69
|
-
description: |-
|
70
|
-
Pre-parser for JSON that removes C/C++ style comments
|
71
|
-
and whitespace from formatted JSON, similar to
|
72
|
-
https://github.com/getify/JSON.minify.
|
57
|
+
version_requirements: *70357755506860
|
58
|
+
description: ! "Pre-parser for JSON that removes C/C++ style comments\n and
|
59
|
+
whitespace from formatted JSON, similar to\n https://github.com/getify/JSON.minify."
|
73
60
|
email:
|
74
61
|
- git@intersect-uk.co.uk
|
75
62
|
- acohen@climate.com
|
@@ -78,33 +65,35 @@ executables:
|
|
78
65
|
extensions: []
|
79
66
|
extra_rdoc_files: []
|
80
67
|
files:
|
81
|
-
- bin/json_minify
|
82
|
-
- lib/json_minify.rb
|
83
68
|
- lib/json_minify/version.rb
|
69
|
+
- lib/json_minify.rb
|
84
70
|
- spec/minify_spec.rb
|
71
|
+
- !binary |-
|
72
|
+
YmluL2pzb25fbWluaWZ5
|
85
73
|
homepage: http://github.com/lumberj/json-minify-rb
|
86
74
|
licenses:
|
87
75
|
- MIT
|
88
|
-
metadata: {}
|
89
76
|
post_install_message:
|
90
77
|
rdoc_options: []
|
91
78
|
require_paths:
|
92
79
|
- lib
|
93
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
94
82
|
requirements:
|
95
|
-
- -
|
83
|
+
- - ! '>='
|
96
84
|
- !ruby/object:Gem::Version
|
97
85
|
version: '0'
|
98
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
99
88
|
requirements:
|
100
|
-
- -
|
89
|
+
- - ! '>='
|
101
90
|
- !ruby/object:Gem::Version
|
102
91
|
version: '0'
|
103
92
|
requirements: []
|
104
93
|
rubyforge_project:
|
105
|
-
rubygems_version:
|
94
|
+
rubygems_version: 1.8.11
|
106
95
|
signing_key:
|
107
|
-
specification_version:
|
96
|
+
specification_version: 3
|
108
97
|
summary: JSON.minify implementation
|
109
98
|
test_files:
|
110
99
|
- spec/minify_spec.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 4b1a521047dc7e5c7f8ca2db29a83790e894c16c
|
4
|
-
data.tar.gz: 6faea50280d8e213df26861dab2dbbb7c393a7a0
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 48eb3797b93ae45ce392356c35b3b0580e4f29d19d19ee751d47635aa5cce236ac99bcc9565bea32e7332f5d2c824360eb94050e1953c625583f5f87768a1a5d
|
7
|
-
data.tar.gz: c34a2c0c33b72a25864082f5b618298666ba1d5560817ebe3cf799c4c20933d8df577090409f227d6565bcc0961dd667412ec17a6e0824743c1f338cb9a7f9f7
|