judge 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.travis.yml +2 -1
- data/Gemfile +1 -10
- data/Rakefile +9 -44
- data/judge.gemspec +17 -164
- data/lib/generators/judge/templates/json2.js +46 -42
- data/lib/generators/judge/templates/judge.js +42 -41
- data/lib/generators/judge/templates/underscore.js +219 -97
- data/lib/judge.rb +6 -4
- data/lib/judge/form_builder.rb +75 -0
- data/lib/judge/{utils.rb → message_collection.rb} +45 -28
- data/lib/judge/validator.rb +21 -0
- data/lib/judge/validator_collection.rb +28 -0
- data/lib/judge/version.rb +3 -0
- data/spec/javascripts/JudgeSpec.js +25 -23
- data/test/expected_elements.rb +235 -0
- data/test/factories.rb +23 -0
- data/test/setup.rb +70 -0
- data/test/test_form_builder.rb +69 -0
- data/test/test_helper.rb +8 -20
- data/test/test_message_collection.rb +84 -0
- data/test/test_validator.rb +37 -0
- data/test/test_validator_collection.rb +19 -0
- metadata +46 -137
- data/.document +0 -5
- data/Gemfile.lock +0 -116
- data/VERSION +0 -1
- data/docs/docco.css +0 -196
- data/docs/judge.html +0 -280
- data/lib/judge/form.rb +0 -59
- data/test/dummy/Gemfile +0 -3
- data/test/dummy/Gemfile.lock +0 -75
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/controllers/foos_controller.rb +0 -11
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/models/city.rb +0 -5
- data/test/dummy/app/models/continent.rb +0 -4
- data/test/dummy/app/models/country.rb +0 -6
- data/test/dummy/app/models/fake.rb +0 -2
- data/test/dummy/app/models/foo.rb +0 -19
- data/test/dummy/app/views/foos/new.html.erb +0 -71
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -45
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/database.yml +0 -22
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -26
- data/test/dummy/config/environments/production.rb +0 -49
- data/test/dummy/config/environments/test.rb +0 -35
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -10
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/locales/en.yml +0 -12
- data/test/dummy/config/routes.rb +0 -3
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20110624115516_create_foos.rb +0 -26
- data/test/dummy/db/migrate/20110724201117_create_fake_collections.rb +0 -14
- data/test/dummy/db/migrate/20110724201548_rename_fake_collection_to_fake.rb +0 -9
- data/test/dummy/db/migrate/20110725082530_create_continent_country_and_city_tables.rb +0 -24
- data/test/dummy/db/schema.rb +0 -55
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/server.log +0 -0
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -26
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/javascripts/application.js +0 -2
- data/test/dummy/public/javascripts/controls.js +0 -965
- data/test/dummy/public/javascripts/dragdrop.js +0 -974
- data/test/dummy/public/javascripts/effects.js +0 -1123
- data/test/dummy/public/javascripts/prototype.js +0 -6001
- data/test/dummy/public/javascripts/rails.js +0 -175
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/judge_test.rb +0 -186
data/.gitignore
ADDED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,12 +1,3 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
|
4
|
-
gem "bundler", "~> 1.0.18"
|
5
|
-
gem "jeweler", "~> 1.5.2"
|
6
|
-
gem "jasmine", "~> 1.0.2"
|
7
|
-
gem "rails", "~> 3.0.10"
|
8
|
-
gem "shoulda", "~> 2.11.3"
|
9
|
-
gem "sqlite3-ruby", "~> 1.3.2"
|
10
|
-
gem "nokogiri", "~> 1.4.7"
|
11
|
-
gem "json", "~> 1.6.0"
|
12
|
-
end
|
3
|
+
gemspec
|
data/Rakefile
CHANGED
@@ -1,52 +1,17 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require 'jeweler'
|
5
|
-
require 'rdoc/task'
|
6
|
-
require 'jasmine'
|
7
|
-
require 'rake/testtask'
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "jasmine"
|
3
|
+
require "rake/testtask"
|
8
4
|
|
9
|
-
load
|
10
|
-
load
|
11
|
-
|
12
|
-
begin
|
13
|
-
Bundler.setup(:default, :development)
|
14
|
-
rescue Bundler::BundlerError => e
|
15
|
-
$stderr.puts e.message
|
16
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
17
|
-
exit e.status_code
|
18
|
-
end
|
19
|
-
|
20
|
-
Jeweler::Tasks.new do |gem|
|
21
|
-
gem.name = "judge"
|
22
|
-
gem.homepage = "http://github.com/joecorcoran/judge"
|
23
|
-
gem.license = "MIT"
|
24
|
-
gem.summary = %Q{Simple client-side ActiveModel::Validators}
|
25
|
-
gem.description = %Q{Validate forms in-place using your model validations}
|
26
|
-
gem.email = "joe@tribesports.com"
|
27
|
-
gem.authors = ["Joe Corcoran"]
|
28
|
-
end
|
29
|
-
Jeweler::RubygemsDotOrgTasks.new
|
30
|
-
|
31
|
-
RDoc::Task.new do |rdoc|
|
32
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
33
|
-
|
34
|
-
rdoc.rdoc_dir = 'rdoc'
|
35
|
-
rdoc.title = "judge #{version}"
|
36
|
-
rdoc.rdoc_files.include('README*')
|
37
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
38
|
-
end
|
5
|
+
load "jasmine/tasks/jasmine.rake"
|
6
|
+
load "lib/tasks/js_tests.rake"
|
39
7
|
|
40
8
|
namespace :test do
|
41
|
-
Rake::TestTask.new(:
|
42
|
-
test.libs <<
|
43
|
-
test.pattern =
|
9
|
+
Rake::TestTask.new(:ruby) do |test|
|
10
|
+
test.libs << "lib" << "test"
|
11
|
+
test.pattern = "test/**/test_*.rb"
|
44
12
|
test.verbose = true
|
45
13
|
end
|
46
|
-
|
47
|
-
desc "Run javascript tests"
|
48
|
-
task :js => ["jasmine:phantom"]
|
49
14
|
end
|
50
15
|
|
51
16
|
desc "Run all tests"
|
52
|
-
task :test => ["test:
|
17
|
+
task :test => ["test:ruby", "jasmine:phantom"]
|
data/judge.gemspec
CHANGED
@@ -1,171 +1,24 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "judge/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version =
|
9
|
-
|
10
|
-
s.
|
6
|
+
s.name = "judge"
|
7
|
+
s.version = Judge::VERSION
|
8
|
+
s.homepage = "http://github.com/joecorcoran/judge"
|
9
|
+
s.license = "MIT"
|
10
|
+
s.summary = %Q{Simple client side ActiveModel::Validators}
|
11
|
+
s.description = %Q{Validate forms on the client side, cleanly}
|
12
|
+
s.email = "joe@tribesports.com"
|
11
13
|
s.authors = ["Joe Corcoran"]
|
12
|
-
s.date = %q{2011-11-13}
|
13
|
-
s.description = %q{Validate forms in-place using your model validations}
|
14
|
-
s.email = %q{joe@tribesports.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE.txt",
|
17
|
-
"README.md"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".travis.yml",
|
22
|
-
"Gemfile",
|
23
|
-
"Gemfile.lock",
|
24
|
-
"LICENSE.txt",
|
25
|
-
"README.md",
|
26
|
-
"Rakefile",
|
27
|
-
"VERSION",
|
28
|
-
"docs/docco.css",
|
29
|
-
"docs/judge.html",
|
30
|
-
"judge.gemspec",
|
31
|
-
"lib/generators/judge/judge_generator.rb",
|
32
|
-
"lib/generators/judge/templates/json2.js",
|
33
|
-
"lib/generators/judge/templates/judge.js",
|
34
|
-
"lib/generators/judge/templates/underscore.js",
|
35
|
-
"lib/judge.rb",
|
36
|
-
"lib/judge/form.rb",
|
37
|
-
"lib/judge/utils.rb",
|
38
|
-
"lib/tasks/js_tests.rake",
|
39
|
-
"spec/javascripts/JudgeSpec.js",
|
40
|
-
"spec/javascripts/fixtures/form.html",
|
41
|
-
"spec/javascripts/helpers/customMatchers.js",
|
42
|
-
"spec/javascripts/helpers/jasmine-jquery.js",
|
43
|
-
"spec/javascripts/helpers/jquery-1.5.1.min.js",
|
44
|
-
"spec/javascripts/helpers/json2.js",
|
45
|
-
"spec/javascripts/helpers/underscore.js",
|
46
|
-
"spec/javascripts/support/jasmine.yml",
|
47
|
-
"spec/javascripts/support/jasmine_config.rb",
|
48
|
-
"spec/javascripts/support/jasmine_runner.rb",
|
49
|
-
"spec/javascripts/support/phantomRunner.js",
|
50
|
-
"test/dummy/Gemfile",
|
51
|
-
"test/dummy/Gemfile.lock",
|
52
|
-
"test/dummy/Rakefile",
|
53
|
-
"test/dummy/app/controllers/application_controller.rb",
|
54
|
-
"test/dummy/app/controllers/foos_controller.rb",
|
55
|
-
"test/dummy/app/helpers/application_helper.rb",
|
56
|
-
"test/dummy/app/models/city.rb",
|
57
|
-
"test/dummy/app/models/continent.rb",
|
58
|
-
"test/dummy/app/models/country.rb",
|
59
|
-
"test/dummy/app/models/fake.rb",
|
60
|
-
"test/dummy/app/models/foo.rb",
|
61
|
-
"test/dummy/app/views/foos/new.html.erb",
|
62
|
-
"test/dummy/app/views/layouts/application.html.erb",
|
63
|
-
"test/dummy/config.ru",
|
64
|
-
"test/dummy/config/application.rb",
|
65
|
-
"test/dummy/config/boot.rb",
|
66
|
-
"test/dummy/config/database.yml",
|
67
|
-
"test/dummy/config/environment.rb",
|
68
|
-
"test/dummy/config/environments/development.rb",
|
69
|
-
"test/dummy/config/environments/production.rb",
|
70
|
-
"test/dummy/config/environments/test.rb",
|
71
|
-
"test/dummy/config/initializers/backtrace_silencers.rb",
|
72
|
-
"test/dummy/config/initializers/inflections.rb",
|
73
|
-
"test/dummy/config/initializers/mime_types.rb",
|
74
|
-
"test/dummy/config/initializers/secret_token.rb",
|
75
|
-
"test/dummy/config/initializers/session_store.rb",
|
76
|
-
"test/dummy/config/locales/en.yml",
|
77
|
-
"test/dummy/config/routes.rb",
|
78
|
-
"test/dummy/db/development.sqlite3",
|
79
|
-
"test/dummy/db/migrate/20110624115516_create_foos.rb",
|
80
|
-
"test/dummy/db/migrate/20110724201117_create_fake_collections.rb",
|
81
|
-
"test/dummy/db/migrate/20110724201548_rename_fake_collection_to_fake.rb",
|
82
|
-
"test/dummy/db/migrate/20110725082530_create_continent_country_and_city_tables.rb",
|
83
|
-
"test/dummy/db/schema.rb",
|
84
|
-
"test/dummy/db/test.sqlite3",
|
85
|
-
"test/dummy/log/server.log",
|
86
|
-
"test/dummy/public/404.html",
|
87
|
-
"test/dummy/public/422.html",
|
88
|
-
"test/dummy/public/500.html",
|
89
|
-
"test/dummy/public/favicon.ico",
|
90
|
-
"test/dummy/public/javascripts/application.js",
|
91
|
-
"test/dummy/public/javascripts/controls.js",
|
92
|
-
"test/dummy/public/javascripts/dragdrop.js",
|
93
|
-
"test/dummy/public/javascripts/effects.js",
|
94
|
-
"test/dummy/public/javascripts/prototype.js",
|
95
|
-
"test/dummy/public/javascripts/rails.js",
|
96
|
-
"test/dummy/public/stylesheets/.gitkeep",
|
97
|
-
"test/dummy/script/rails",
|
98
|
-
"test/judge_test.rb",
|
99
|
-
"test/test_helper.rb"
|
100
|
-
]
|
101
|
-
s.homepage = %q{http://github.com/joecorcoran/judge}
|
102
|
-
s.licenses = ["MIT"]
|
103
|
-
s.require_paths = ["lib"]
|
104
|
-
s.rubygems_version = %q{1.6.2}
|
105
|
-
s.summary = %q{Simple client-side ActiveModel::Validators}
|
106
|
-
s.test_files = [
|
107
|
-
"spec/javascripts/support/jasmine_config.rb",
|
108
|
-
"spec/javascripts/support/jasmine_runner.rb",
|
109
|
-
"test/dummy/app/controllers/application_controller.rb",
|
110
|
-
"test/dummy/app/controllers/foos_controller.rb",
|
111
|
-
"test/dummy/app/helpers/application_helper.rb",
|
112
|
-
"test/dummy/app/models/city.rb",
|
113
|
-
"test/dummy/app/models/continent.rb",
|
114
|
-
"test/dummy/app/models/country.rb",
|
115
|
-
"test/dummy/app/models/fake.rb",
|
116
|
-
"test/dummy/app/models/foo.rb",
|
117
|
-
"test/dummy/config/application.rb",
|
118
|
-
"test/dummy/config/boot.rb",
|
119
|
-
"test/dummy/config/environment.rb",
|
120
|
-
"test/dummy/config/environments/development.rb",
|
121
|
-
"test/dummy/config/environments/production.rb",
|
122
|
-
"test/dummy/config/environments/test.rb",
|
123
|
-
"test/dummy/config/initializers/backtrace_silencers.rb",
|
124
|
-
"test/dummy/config/initializers/inflections.rb",
|
125
|
-
"test/dummy/config/initializers/mime_types.rb",
|
126
|
-
"test/dummy/config/initializers/secret_token.rb",
|
127
|
-
"test/dummy/config/initializers/session_store.rb",
|
128
|
-
"test/dummy/config/routes.rb",
|
129
|
-
"test/dummy/db/migrate/20110624115516_create_foos.rb",
|
130
|
-
"test/dummy/db/migrate/20110724201117_create_fake_collections.rb",
|
131
|
-
"test/dummy/db/migrate/20110724201548_rename_fake_collection_to_fake.rb",
|
132
|
-
"test/dummy/db/migrate/20110725082530_create_continent_country_and_city_tables.rb",
|
133
|
-
"test/dummy/db/schema.rb",
|
134
|
-
"test/judge_test.rb",
|
135
|
-
"test/test_helper.rb"
|
136
|
-
]
|
137
14
|
|
138
|
-
|
139
|
-
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.require_paths = ["lib"]
|
140
18
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
s.add_development_dependency(%q<shoulda>, ["~> 2.11.3"])
|
147
|
-
s.add_development_dependency(%q<sqlite3-ruby>, ["~> 1.3.2"])
|
148
|
-
s.add_development_dependency(%q<nokogiri>, ["~> 1.4.7"])
|
149
|
-
s.add_development_dependency(%q<json>, ["~> 1.6.0"])
|
150
|
-
else
|
151
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.18"])
|
152
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
153
|
-
s.add_dependency(%q<jasmine>, ["~> 1.0.2"])
|
154
|
-
s.add_dependency(%q<rails>, ["~> 3.0.10"])
|
155
|
-
s.add_dependency(%q<shoulda>, ["~> 2.11.3"])
|
156
|
-
s.add_dependency(%q<sqlite3-ruby>, ["~> 1.3.2"])
|
157
|
-
s.add_dependency(%q<nokogiri>, ["~> 1.4.7"])
|
158
|
-
s.add_dependency(%q<json>, ["~> 1.6.0"])
|
159
|
-
end
|
160
|
-
else
|
161
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.18"])
|
162
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
163
|
-
s.add_dependency(%q<jasmine>, ["~> 1.0.2"])
|
164
|
-
s.add_dependency(%q<rails>, ["~> 3.0.10"])
|
165
|
-
s.add_dependency(%q<shoulda>, ["~> 2.11.3"])
|
166
|
-
s.add_dependency(%q<sqlite3-ruby>, ["~> 1.3.2"])
|
167
|
-
s.add_dependency(%q<nokogiri>, ["~> 1.4.7"])
|
168
|
-
s.add_dependency(%q<json>, ["~> 1.6.0"])
|
169
|
-
end
|
19
|
+
s.add_development_dependency "jasmine", "~> 1.0.2"
|
20
|
+
s.add_development_dependency "rails", "~> 3.0.10"
|
21
|
+
s.add_development_dependency "shoulda", "~> 2.11.3"
|
22
|
+
s.add_development_dependency "sqlite3-ruby", "~> 1.3.2"
|
23
|
+
s.add_development_dependency "factory_girl", "~> 2.2.0"
|
170
24
|
end
|
171
|
-
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
http://www.JSON.org/json2.js
|
3
|
-
|
3
|
+
2011-10-19
|
4
4
|
|
5
5
|
Public Domain.
|
6
6
|
|
@@ -146,7 +146,7 @@
|
|
146
146
|
redistribute.
|
147
147
|
*/
|
148
148
|
|
149
|
-
/*jslint evil: true,
|
149
|
+
/*jslint evil: true, regexp: true */
|
150
150
|
|
151
151
|
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
152
152
|
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
@@ -159,11 +159,13 @@
|
|
159
159
|
// Create a JSON object only if one does not already exist. We create the
|
160
160
|
// methods in a closure to avoid creating global variables.
|
161
161
|
|
162
|
-
|
163
|
-
|
162
|
+
var JSON;
|
163
|
+
if (!JSON) {
|
164
|
+
JSON = {};
|
164
165
|
}
|
165
166
|
|
166
167
|
(function () {
|
168
|
+
'use strict';
|
167
169
|
|
168
170
|
function f(n) {
|
169
171
|
// Format integers to have at least two digits.
|
@@ -174,20 +176,21 @@ if (!this.JSON) {
|
|
174
176
|
|
175
177
|
Date.prototype.toJSON = function (key) {
|
176
178
|
|
177
|
-
return isFinite(this.valueOf())
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
179
|
+
return isFinite(this.valueOf())
|
180
|
+
? this.getUTCFullYear() + '-' +
|
181
|
+
f(this.getUTCMonth() + 1) + '-' +
|
182
|
+
f(this.getUTCDate()) + 'T' +
|
183
|
+
f(this.getUTCHours()) + ':' +
|
184
|
+
f(this.getUTCMinutes()) + ':' +
|
185
|
+
f(this.getUTCSeconds()) + 'Z'
|
186
|
+
: null;
|
184
187
|
};
|
185
188
|
|
186
|
-
String.prototype.toJSON
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
189
|
+
String.prototype.toJSON =
|
190
|
+
Number.prototype.toJSON =
|
191
|
+
Boolean.prototype.toJSON = function (key) {
|
192
|
+
return this.valueOf();
|
193
|
+
};
|
191
194
|
}
|
192
195
|
|
193
196
|
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
@@ -214,13 +217,12 @@ if (!this.JSON) {
|
|
214
217
|
// sequences.
|
215
218
|
|
216
219
|
escapable.lastIndex = 0;
|
217
|
-
return escapable.test(string) ?
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
'"' + string + '"';
|
220
|
+
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
|
221
|
+
var c = meta[a];
|
222
|
+
return typeof c === 'string'
|
223
|
+
? c
|
224
|
+
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
225
|
+
}) + '"' : '"' + string + '"';
|
224
226
|
}
|
225
227
|
|
226
228
|
|
@@ -303,11 +305,11 @@ if (!this.JSON) {
|
|
303
305
|
// Join all of the elements together, separated with commas, and wrap them in
|
304
306
|
// brackets.
|
305
307
|
|
306
|
-
v = partial.length === 0
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
308
|
+
v = partial.length === 0
|
309
|
+
? '[]'
|
310
|
+
: gap
|
311
|
+
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
|
312
|
+
: '[' + partial.join(',') + ']';
|
311
313
|
gap = mind;
|
312
314
|
return v;
|
313
315
|
}
|
@@ -317,8 +319,8 @@ if (!this.JSON) {
|
|
317
319
|
if (rep && typeof rep === 'object') {
|
318
320
|
length = rep.length;
|
319
321
|
for (i = 0; i < length; i += 1) {
|
320
|
-
|
321
|
-
|
322
|
+
if (typeof rep[i] === 'string') {
|
323
|
+
k = rep[i];
|
322
324
|
v = str(k, value);
|
323
325
|
if (v) {
|
324
326
|
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
@@ -330,7 +332,7 @@ if (!this.JSON) {
|
|
330
332
|
// Otherwise, iterate through all of the keys in the object.
|
331
333
|
|
332
334
|
for (k in value) {
|
333
|
-
if (Object.hasOwnProperty.call(value, k)) {
|
335
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
334
336
|
v = str(k, value);
|
335
337
|
if (v) {
|
336
338
|
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
@@ -342,9 +344,11 @@ if (!this.JSON) {
|
|
342
344
|
// Join all of the member texts together, separated with commas,
|
343
345
|
// and wrap them in braces.
|
344
346
|
|
345
|
-
v = partial.length === 0
|
346
|
-
|
347
|
-
|
347
|
+
v = partial.length === 0
|
348
|
+
? '{}'
|
349
|
+
: gap
|
350
|
+
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
|
351
|
+
: '{' + partial.join(',') + '}';
|
348
352
|
gap = mind;
|
349
353
|
return v;
|
350
354
|
}
|
@@ -385,7 +389,7 @@ if (!this.JSON) {
|
|
385
389
|
rep = replacer;
|
386
390
|
if (replacer && typeof replacer !== 'function' &&
|
387
391
|
(typeof replacer !== 'object' ||
|
388
|
-
|
392
|
+
typeof replacer.length !== 'number')) {
|
389
393
|
throw new Error('JSON.stringify');
|
390
394
|
}
|
391
395
|
|
@@ -415,7 +419,7 @@ if (!this.JSON) {
|
|
415
419
|
var k, v, value = holder[key];
|
416
420
|
if (value && typeof value === 'object') {
|
417
421
|
for (k in value) {
|
418
|
-
if (Object.hasOwnProperty.call(value, k)) {
|
422
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
419
423
|
v = walk(value, k);
|
420
424
|
if (v !== undefined) {
|
421
425
|
value[k] = v;
|
@@ -456,9 +460,9 @@ if (!this.JSON) {
|
|
456
460
|
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
457
461
|
|
458
462
|
if (/^[\],:{}\s]*$/
|
459
|
-
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
460
|
-
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
461
|
-
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
463
|
+
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
464
|
+
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
465
|
+
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
462
466
|
|
463
467
|
// In the third stage we use the eval function to compile the text into a
|
464
468
|
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
@@ -470,8 +474,9 @@ if (!this.JSON) {
|
|
470
474
|
// In the optional fourth stage, we recursively walk the new structure, passing
|
471
475
|
// each name/value pair to a reviver function for possible transformation.
|
472
476
|
|
473
|
-
return typeof reviver === 'function'
|
474
|
-
walk({'': j}, '')
|
477
|
+
return typeof reviver === 'function'
|
478
|
+
? walk({'': j}, '')
|
479
|
+
: j;
|
475
480
|
}
|
476
481
|
|
477
482
|
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
@@ -480,4 +485,3 @@ if (!this.JSON) {
|
|
480
485
|
};
|
481
486
|
}
|
482
487
|
}());
|
483
|
-
|