json-minify 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +25 -0
- data/README.md +44 -0
- data/Rakefile +5 -0
- data/json-minify.gemspec +25 -0
- data/lib/json/minify.rb +57 -0
- data/lib/json/minify/version.rb +5 -0
- data/spec/minify_spec.rb +24 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6ca223097ab556986fe54fba09c40c6daf3654f9
|
4
|
+
data.tar.gz: 375b20f9d9cc35fb3bb55329d1eac9251e7a20f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d94e03273a9b097d6f4d8fb06c85bceb4ba9fe5099c0bdc9194cab7638c6c98bee6b6745c5d0d28962c2a74e39792c965b33428b3a167637dc0cd4242ff6a2b1
|
7
|
+
data.tar.gz: f05dc098243c5345af7076d82b76d1363d3b936333b2262a47d1bccd73109e6f46036c8eafab26c47837d5f31cb4e6aebd09cefac473449d1c01b8d1a96d2615
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2014 Geoff Youngs
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
MIT License
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
a copy of this software and associated documentation files (the
|
10
|
+
"Software"), to deal in the Software without restriction, including
|
11
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
the following conditions:
|
15
|
+
|
16
|
+
The above copyright notice and this permission notice shall be
|
17
|
+
included in all copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# JSON::Minify
|
2
|
+
|
3
|
+
JSON.minify implementation
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'json-minify'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install json-minify
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Rationale is here: https://github.com/getify/JSON.minify
|
22
|
+
|
23
|
+
Though comments are not officially part of the JSON standard, this post from
|
24
|
+
Douglas Crockford back in late 2005 helps explain the motivation behind this project.
|
25
|
+
|
26
|
+
http://tech.groups.yahoo.com/group/json/message/152
|
27
|
+
|
28
|
+
"A JSON encoder MUST NOT output comments. A JSON decoder MAY accept and ignore comments."
|
29
|
+
|
30
|
+
|
31
|
+
API is compatible with JSON.minify in the npm node-json-minify package.
|
32
|
+
|
33
|
+
JSON.minify("{ }") #=> "{}"
|
34
|
+
|
35
|
+
JSON.minify("{ /* comment */ }") #=> "{}"
|
36
|
+
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( http://github.com/geoffyoungs/json-minify-rb/fork )
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/json-minify.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'json/minify/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "json-minify"
|
8
|
+
spec.version = JSON::Minify::VERSION
|
9
|
+
spec.authors = ["Geoff Youngs\n\n\n"]
|
10
|
+
spec.email = ["git@intersect-uk.co.uk"]
|
11
|
+
spec.summary = %q{JSON.minify implementation}
|
12
|
+
spec.description = %q{Pre-parser for JSON that removes C/C++ style comments and whitespace from formatted JSON, similar to https://github.com/getify/JSON.minify.}
|
13
|
+
spec.homepage = "http://github.com/geoffyoungs/json-minify-rb"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake", '~> 10.1'
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.14"
|
24
|
+
spec.add_dependency "json", "> 0"
|
25
|
+
end
|
data/lib/json/minify.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'strscan'
|
2
|
+
require 'json'
|
3
|
+
require "json/minify/version"
|
4
|
+
|
5
|
+
module JSON
|
6
|
+
module Minify
|
7
|
+
def self.included(mod)
|
8
|
+
mod.send(:extend, self)
|
9
|
+
end
|
10
|
+
def minify(str)
|
11
|
+
ss, buf = StringScanner.new(str), ''
|
12
|
+
|
13
|
+
until ss.eos?
|
14
|
+
# Remove whitespace
|
15
|
+
if s = ss.scan(/\s+/)
|
16
|
+
|
17
|
+
# Scan punctuation
|
18
|
+
elsif s = ss.scan(/[{},:\]\[]/)
|
19
|
+
buf << s
|
20
|
+
|
21
|
+
# Scan strings
|
22
|
+
elsif s = ss.scan(/"(.*?[^\\])?"/)
|
23
|
+
buf << s
|
24
|
+
|
25
|
+
# Scan reserved words
|
26
|
+
elsif s = ss.scan(/(true|false|null)/)
|
27
|
+
buf << s
|
28
|
+
|
29
|
+
# Scan numbers
|
30
|
+
elsif s = ss.scan(/-?\d+([.]\d+)?([eE][-+]?[0-9]+)?/)
|
31
|
+
buf << s
|
32
|
+
|
33
|
+
# Remove C++ style comments
|
34
|
+
elsif s = ss.scan(%r<//>)
|
35
|
+
ss.scan_until(/(\r?\n|$)/)
|
36
|
+
|
37
|
+
# Remove C style comments
|
38
|
+
elsif s = ss.scan(%r'/[*]')
|
39
|
+
ss.scan_until(%r'[*]/') or raise SyntaxError, "Unterminated /*...*/ comment - #{ss.rest}"
|
40
|
+
|
41
|
+
# Anything else is invalid JSON
|
42
|
+
else
|
43
|
+
raise SyntaxError, "Unable to pre-scan string: #{ss.rest}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
buf
|
47
|
+
end
|
48
|
+
|
49
|
+
def minify_parse(buf)
|
50
|
+
JSON.parse(minify(buf))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
module JSON
|
56
|
+
include JSON::Minify
|
57
|
+
end
|
data/spec/minify_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
$: << File.dirname(__FILE__)+"../lib"
|
2
|
+
|
3
|
+
require 'json/minify'
|
4
|
+
|
5
|
+
describe JSON::Minify do
|
6
|
+
it "should remove whitespace from JSON" do
|
7
|
+
expect(JSON.minify("{ }")).to eql("{}")
|
8
|
+
expect(JSON.minify(%Q<{"foo": "bar"\n}\n>)).to eql(%Q<{"foo":"bar"}>)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should remove comments from JSON" do
|
12
|
+
expect(JSON.minify("{ /* foo */ } /* bar */")).to eql("{}")
|
13
|
+
expect(JSON.minify(%Q<{"foo": "bar"\n}\n // this is a comment>)).to eql(%Q<{"foo":"bar"}>)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should throw a SyntaxError on invalid JSON" do
|
17
|
+
expect { JSON.minify("{ /* foo */ } /* bar ") }.to raise_error(SyntaxError)
|
18
|
+
expect { JSON.minify(%Q<{ "foo": new Date(1023) }>) }.to raise_error(SyntaxError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should cope with the example from https://github.com/getify/JSON.minify" do
|
22
|
+
expect(JSON.minify( %Q'{ /* comment */ "foo": 42 \n }' )).to eql('{"foo":42}')
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: json-minify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- |+
|
8
|
+
Geoff Youngs
|
9
|
+
|
10
|
+
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bundler
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.5'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.5'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ~>
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '10.1'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '10.1'
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: rspec
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ~>
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '2.14'
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '2.14'
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: json
|
60
|
+
requirement: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>'
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>'
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
description: Pre-parser for JSON that removes C/C++ style comments and whitespace
|
73
|
+
from formatted JSON, similar to https://github.com/getify/JSON.minify.
|
74
|
+
email:
|
75
|
+
- git@intersect-uk.co.uk
|
76
|
+
executables: []
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- .gitignore
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- json-minify.gemspec
|
86
|
+
- lib/json/minify.rb
|
87
|
+
- lib/json/minify/version.rb
|
88
|
+
- spec/minify_spec.rb
|
89
|
+
homepage: http://github.com/geoffyoungs/json-minify-rb
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.1
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: JSON.minify implementation
|
113
|
+
test_files:
|
114
|
+
- spec/minify_spec.rb
|