is_js_rails 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0fe737ac0e54eed9ea20aa3178f41b36addfe63d
4
+ data.tar.gz: 2b29a42341364ca729b76294b6312f493aee256a
5
+ SHA512:
6
+ metadata.gz: 6785d5d0e1ebfce8ab55b575deb42302c586f3dca561378267011aef58e4583f1eb61802bf392fcb9f2879e6031a9c6b3ff62665696f577b26eab05670bb94e4
7
+ data.tar.gz: 19461f409771a1217106cf0e9c48983f8e9e457331d8f0ccfd2f6b9acc80e83e5906b08a3ef02a083b72618fa3dd0db488b81399fccdb01f3b5ee25bc5adb8f4
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ rvm:
5
+ - jruby
6
+ - 2.0.0
7
+ - 2.1.0
8
+ - 2.1.5
9
+
10
+ script: 'bundle exec rspec spec'
11
+
12
+ notifications:
13
+ email:
14
+ recipients:
15
+ - agmond@gmx.com.br
16
+ on_failure: change
17
+ on_success: never
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in is_js_rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Guinsly Mondesir
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ # is.js Rails
2
+
3
+ Adding is.js [https://arasatasaygin.github.io/is.js](https://arasatasaygin.github.io/is.js) in your rails app. Is.js is a pretty neat library to check variable types.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'is_js_rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install is_js_rails
20
+
21
+ ## Usage
22
+
23
+ add in `app/assets/javascripts/application.js`
24
+
25
+ //= require is_js_rails
26
+
27
+
28
+ ```javascript
29
+ is.url('https://rubygems.org/');
30
+ => true
31
+
32
+ is.url('rugygems');
33
+ => false
34
+
35
+ is.not.url(true);
36
+ => true
37
+
38
+ is.all.url('http://www.rubygems.com', 'rubygems');
39
+ => false
40
+
41
+ is.any.url('http://www.rubygems.com', true);
42
+ => true
43
+
44
+ // 'all' and 'any' interfaces can also take array parameter
45
+ is.all.url(['http://www.rubygems.com', 'foo', undefined]);
46
+ => false
47
+ ```
48
+
49
+
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it ( https://github.com/guinslym/is_js_rails/fork )
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'is_js_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "is_js_rails"
8
+ spec.version = IsJsRails::VERSION
9
+ spec.authors = ["Guinsly Mondesir"]
10
+ spec.email = ["gmond@gmx.com.br"]
11
+ spec.summary = %q{Adding is.js in your rails app. https://arasatasaygin.github.io/is.js A Micro check library}
12
+ spec.description = %q{Implementing is.js in your rails app. https://arasatasaygin.github.io/is.js A Micro check library}
13
+ spec.homepage = "https://github.com/guinslym/is_js_rails"
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.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,11 @@
1
+ require "is_js_rails/version"
2
+
3
+ module IsJsRails
4
+ module Rails
5
+ if defined?(::Rails) and Gem::Requirement.new('>= 3.1').satisfied_by?(Gem::Version.new ::Rails.version)
6
+ class Rails::Engine < ::Rails::Engine
7
+ # this class enables the asset pipeline
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module IsJsRails
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,801 @@
1
+ // is.js 0.2.0
2
+ // Author: Aras Atasaygin
3
+
4
+ // AMD with global, Node, or global
5
+ ;(function(root, factory) {
6
+ if(typeof define === 'function' && define.amd) {
7
+ // AMD. Register as an anonymous module.
8
+ define(['is'], function(is) {
9
+ // Also create a global in case some scripts
10
+ // that are loaded still are looking for
11
+ // a global even when an AMD loader is in use.
12
+ return (root.is = factory(is));
13
+ });
14
+ } else if(typeof exports === 'object') {
15
+ // Node. Does not work with strict CommonJS, but
16
+ // only CommonJS-like enviroments that support module.exports,
17
+ // like Node.
18
+ module.exports = factory(require('is_js'));
19
+ } else {
20
+ // Browser globals (root is window)
21
+ root.is = factory(root.is);
22
+ }
23
+ }(this, function(is) {
24
+
25
+ // Baseline
26
+ /* -------------------------------------------------------------------------- */
27
+
28
+ var root = this;
29
+ var previousIs = root.is;
30
+
31
+ // define 'is' object and current version
32
+ is = {};
33
+ is.VERSION = '0.2.0';
34
+
35
+ // define interfaces
36
+ is.not = {};
37
+ is.all = {};
38
+ is.any = {};
39
+
40
+ // cache some methods to call later on
41
+ var toString = Object.prototype.toString;
42
+ var arraySlice = Array.prototype.slice;
43
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
44
+
45
+ // helper function which reverses the sense of predicate result
46
+ function not(func) {
47
+ return function() {
48
+ return !func.apply(null, arraySlice.call(arguments));
49
+ };
50
+ }
51
+
52
+ // helper function which call predicate function per parameter and return true if all pass
53
+ function all(func) {
54
+ return function() {
55
+ var parameters = arraySlice.call(arguments);
56
+ var length = parameters.length;
57
+ if(length === 1 && is.array(parameters[0])) { // support array
58
+ parameters = parameters[0];
59
+ length = parameters.length;
60
+ }
61
+ var results = [];
62
+ for (var i = 0; i < length; i++) {
63
+ results.push(func.call(null, parameters[i]));
64
+ }
65
+ for (i = 0; i < results.length; i++) {
66
+ if(!results[i]) {
67
+ return false;
68
+ }
69
+ }
70
+ return true;
71
+ };
72
+ }
73
+
74
+ // helper function which call predicate function per parameter and return true if any pass
75
+ function any(func) {
76
+ return function() {
77
+ var parameters = arraySlice.call(arguments);
78
+ var length = parameters.length;
79
+ if(length === 1 && is.array(parameters[0])) { // support array
80
+ parameters = parameters[0];
81
+ length = parameters.length;
82
+ }
83
+ var results = [];
84
+ for (var i = 0; i < length; i++) {
85
+ results.push(func.call(null, parameters[i]));
86
+ }
87
+ for (i = 0; i < results.length; i++) {
88
+ if(results[i]) {
89
+ return true;
90
+ }
91
+ }
92
+ return false;
93
+ };
94
+ }
95
+
96
+ // Type checks
97
+ /* -------------------------------------------------------------------------- */
98
+
99
+ // is a given value Arguments?
100
+ is.arguments = function(value) { // fallback check is for IE
101
+ return is.not.null(value) && (toString.call(value) === '[object Arguments]' || (typeof value === 'object' && 'callee' in value));
102
+ };
103
+
104
+ // is a given value Array?
105
+ is.array = Array.isArray || function(value) { // check native isArray first
106
+ return toString.call(value) === '[object Array]';
107
+ };
108
+
109
+ // is a given value Boolean?
110
+ is.boolean = function(value) {
111
+ return value === true || value === false || toString.call(value) === '[object Boolean]';
112
+ };
113
+
114
+ // is a given value Date Object?
115
+ is.date = function(value) {
116
+ return toString.call(value) === '[object Date]';
117
+ };
118
+
119
+ // is a given value Error object?
120
+ is.error = function(value) {
121
+ return toString.call(value) === '[object Error]';
122
+ };
123
+
124
+ // is a given value function?
125
+ is.function = function(value) { // fallback check is for IE
126
+ return toString.call(value) === '[object Function]' || typeof value === 'function';
127
+ };
128
+
129
+ // is a given value NaN?
130
+ is.nan = function(value) { // NaN is number :) Also it is the only value which does not equal itself
131
+ return is.number(value) && value !== value;
132
+ };
133
+
134
+ // is a given value null?
135
+ is.null = function(value) {
136
+ return value === null || toString.call(value) === '[object Null]';
137
+ };
138
+
139
+ // is a given value number?
140
+ is.number = function(value) {
141
+ return toString.call(value) === '[object Number]';
142
+ };
143
+
144
+ // is a given value object?
145
+ is.object = function(value) {
146
+ var type = typeof value;
147
+ return type === 'function' || type === 'object' && !!value;
148
+ };
149
+
150
+ // is a given value RegExp?
151
+ is.regexp = function(value) {
152
+ return toString.call(value) === '[object RegExp]';
153
+ };
154
+
155
+ // are given values same type?
156
+ // prevent NaN, Number same type check
157
+ is.sameType = function(value1, value2) {
158
+ if(is.nan(value1) || is.nan(value2)) {
159
+ return is.nan(value1) === is.nan(value2);
160
+ }
161
+ return toString.call(value1) === toString.call(value2);
162
+ };
163
+ // sameType method does not support 'all' and 'any' interfaces
164
+ is.sameType.api = ['not'];
165
+
166
+ // is a given value String?
167
+ is.string = function(value) {
168
+ return toString.call(value) === '[object String]';
169
+ };
170
+
171
+ // is a given value Char?
172
+ is.char = function(value) {
173
+ return is.string(value) && value.length === 1;
174
+ };
175
+
176
+ // is a given value undefined?
177
+ is.undefined = function(value) {
178
+ return value === void 0;
179
+ };
180
+
181
+ // Presence checks
182
+ /* -------------------------------------------------------------------------- */
183
+
184
+ // is a given value empty? Objects, arrays, strings
185
+ is.empty = function(value) {
186
+ if(is.null(value)) {
187
+ return false;
188
+ } else if(is.object(value)) {
189
+ for(var prop in value) {
190
+ if(value.hasOwnProperty(prop))
191
+ return false;
192
+ }
193
+ return true;
194
+ } else if(is.array(value) || is.arguments(value)) {
195
+ return value.length === 0;
196
+ } else { // string case
197
+ return value === '';
198
+ }
199
+ };
200
+
201
+ // is a given value existy?
202
+ is.existy = function(value) {
203
+ return value !== null && value !== undefined;
204
+ };
205
+
206
+ // is a given value truthy?
207
+ is.truthy = function(value) {
208
+ return is.existy(value) && value !== false;
209
+ };
210
+
211
+ // is a given value falsy?
212
+ is.falsy = not(is.truthy);
213
+
214
+ // is a given value space?
215
+ // horizantal tab: 9, line feed: 10, vertical tab: 11, form feed: 12, carriage return: 13, space: 32
216
+ is.space = function(value) {
217
+ if(is.string(value)) {
218
+ var characterCode = value.charCodeAt(0);
219
+ return (characterCode > 8 && characterCode < 14) || characterCode === 32;
220
+ } else {
221
+ return false;
222
+ }
223
+ };
224
+
225
+ // Arithmetic checks
226
+ /* -------------------------------------------------------------------------- */
227
+
228
+ // are given values equal? supports numbers, strings, regexps, booleans
229
+ // TODO: Add object and array support
230
+ is.equal = function(value1, value2) {
231
+ // check 0 and -0 equity with Infinity and -Infinity
232
+ if(is.all.number(value1, value2)) {
233
+ return value1 === value2 && 1 / value1 === 1 / value2;
234
+ }
235
+ // check regexps as strings too
236
+ if(is.all.string(value1, value2) || is.all.regexp(value1, value2)) {
237
+ return '' + value1 === '' + value2;
238
+ }
239
+ if(is.all.boolean(value1, value2)) {
240
+ return value1 === value2;
241
+ }
242
+ return false;
243
+ };
244
+ // equal method does not support 'all' and 'any' interfaces
245
+ is.equal.api = ['not'];
246
+
247
+ // is a given number even?
248
+ is.even = function(numb) {
249
+ return is.number(numb) && numb % 2 === 0;
250
+ };
251
+
252
+ // is a given number odd?
253
+ is.odd = function(numb) {
254
+ return is.number(numb) && numb % 2 !== 0;
255
+ };
256
+
257
+ // is a given number positive?
258
+ is.positive = function(numb) {
259
+ return is.number(numb) && numb > 0;
260
+ };
261
+
262
+ // is a given number negative?
263
+ is.negative = function(numb) {
264
+ return is.number(numb) && numb < 0;
265
+ };
266
+
267
+ // is a given number above minimum parameter?
268
+ is.above = function(numb, min) {
269
+ return is.all.number(numb, min) && numb > min;
270
+ };
271
+ // above method does not support 'all' and 'any' interfaces
272
+ is.above.api = ['not'];
273
+
274
+ // is a given number above maximum parameter?
275
+ is.under = function(numb, max) {
276
+ return is.all.number(numb, max) && numb < max;
277
+ };
278
+ // least method does not support 'all' and 'any' interfaces
279
+ is.under.api = ['not'];
280
+
281
+ // is a given number within minimum and maximum parameters?
282
+ is.within = function(numb, min, max) {
283
+ return is.all.number(numb, min, max) && numb > min && numb < max;
284
+ };
285
+ // within method does not support 'all' and 'any' interfaces
286
+ is.within.api = ['not'];
287
+
288
+ // is a given number decimal?
289
+ is.decimal = function(numb) {
290
+ return is.number(numb) && numb % 1 !== 0;
291
+ };
292
+
293
+ // is a given number integer?
294
+ is.integer = function(numb) {
295
+ return is.number(numb) && numb % 1 === 0;
296
+ };
297
+
298
+ // is a given number finite?
299
+ is.finite = isFinite || function(numb) {
300
+ return numb !== Infinity && numb !== -Infinity && is.not.nan(numb);
301
+ };
302
+
303
+ // is a given number infinite?
304
+ is.infinite = not(is.finite);
305
+
306
+ // Regexp checks
307
+ /* -------------------------------------------------------------------------- */
308
+ // Steven Levithan, Jan Goyvaerts: Regular Expressions Cookbook
309
+ // Scott Gonzalez: Email address validation
310
+
311
+ // eppPhone match extensible provisioning protocol format
312
+ // nanpPhone match north american number plan format
313
+ // dateString match m/d/yy and mm/dd/yyyy, allowing any combination of one or two digits for the day and month, and two or four digits for the year
314
+ // time match hours, minutes, and seconds, 24-hour clock
315
+ var regexps = {
316
+ url: /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/,
317
+ email: /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i,
318
+ creditCard: /^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/,
319
+ alphaNumeric: /^[A-Za-z0-9]+$/,
320
+ timeString: /^(2[0-3]|[01]?[0-9]):([0-5]?[0-9]):([0-5]?[0-9])$/,
321
+ dateString: /^(1[0-2]|0?[1-9])\/(3[01]|[12][0-9]|0?[1-9])\/(?:[0-9]{2})?[0-9]{2}$/,
322
+ usZipCode: /^[0-9]{5}(?:-[0-9]{4})?$/,
323
+ caPostalCode: /^(?!.*[DFIOQU])[A-VXY][0-9][A-Z]?[0-9][A-Z][0-9]$/,
324
+ ukPostCode: /^[A-Z]{1,2}[0-9R][0-9A-Z]?[0-9][ABD-HJLNP-UW-Z]{2}$/,
325
+ nanpPhone: /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/,
326
+ eppPhone: /^\+[0-9]{1,3}\.[0-9]{4,14}(?:x.+)?$/,
327
+ socialSecurityNumber: /^(?!000|666)[0-8][0-9]{2}-(?!00)[0-9]{2}-(?!0000)[0-9]{4}$/,
328
+ affirmative: /^(?:1|t(?:rue)?|y(?:es)?|ok(?:ay)?)$/
329
+ };
330
+
331
+ // create regexp checks methods from 'regexp' object
332
+ for(var regexp in regexps) {
333
+ if(regexps.hasOwnProperty(regexp)) {
334
+ regexpCheck(regexp, regexps);
335
+ }
336
+ }
337
+
338
+ function regexpCheck(regexp, regexps) {
339
+ is[regexp] = function(value) {
340
+ return regexps[regexp].test(value);
341
+ };
342
+ }
343
+
344
+ // String checks
345
+ /* -------------------------------------------------------------------------- */
346
+
347
+ // is a given string inculde parameter substring?
348
+ is.include = String.prototype.includes || function(str, substr) {
349
+ return str.indexOf(substr) > -1;
350
+ };
351
+ // include method does not support 'all' and 'any' interfaces
352
+ is.include.api = ['not'];
353
+
354
+ // is a given string all uppercase?
355
+ is.upperCase = function(str) {
356
+ return is.string(str) && str === str.toUpperCase();
357
+ };
358
+
359
+ // is a given string all lowercase?
360
+ is.lowerCase = function(str) {
361
+ return is.string(str) && str === str.toLowerCase();
362
+ };
363
+
364
+ // is string start with a given startWith parameter?
365
+ is.startWith = function(str, startWith) {
366
+ return is.string(str) && str.indexOf(startWith) === 0;
367
+ };
368
+ // startWith method does not support 'all' and 'any' interfaces
369
+ is.startWith.api = ['not'];
370
+
371
+ // is string end with a given endWith parameter?
372
+ is.endWith = function(str, endWith) {
373
+ return is.string(str) && str.indexOf(endWith) === str.length - endWith.length;
374
+ };
375
+ // endWith method does not support 'all' and 'any' interfaces
376
+ is.endWith.api = ['not'];
377
+
378
+ // is a given string or sentence capitalized?
379
+ is.capitalized = function(str) {
380
+ if(is.not.string(str)) {
381
+ return false;
382
+ }
383
+ var words = str.split(' ');
384
+ var capitalized = [];
385
+ for(var i = 0; i < words.length; i++) {
386
+ capitalized.push(words[i][0] === words[i][0].toUpperCase());
387
+ }
388
+ return is.all.truthy.apply(null, capitalized);
389
+ };
390
+
391
+ // Time checks
392
+ /* -------------------------------------------------------------------------- */
393
+
394
+ var days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
395
+ var months = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
396
+
397
+ // is a given date indicate today?
398
+ is.today = function(obj) {
399
+ var now = new Date();
400
+ var todayString = now.toDateString();
401
+ return is.date(obj) && obj.toDateString() === todayString;
402
+ };
403
+
404
+ // is a given date indicate yesterday?
405
+ is.yesterday = function(obj) {
406
+ var now = new Date();
407
+ var yesterdayString = new Date(now.setDate(now.getDate() - 1)).toDateString();
408
+ return is.date(obj) && obj.toDateString() === yesterdayString;
409
+ };
410
+
411
+ // is a given date indicate tomorrow?
412
+ is.tomorrow = function(obj) {
413
+ var now = new Date();
414
+ var tomorrowString = new Date(now.setDate(now.getDate() + 1)).toDateString();
415
+ return is.date(obj) && obj.toDateString() === tomorrowString;
416
+ };
417
+
418
+ // is a given date past?
419
+ is.past = function(obj) {
420
+ var now = new Date();
421
+ return is.date(obj) && obj.getTime() < now.getTime();
422
+ };
423
+
424
+ // is a given date future?
425
+ is.future = not(is.past);
426
+
427
+ // is a given dates day equal given dayString parameter?
428
+ is.day = function(obj, dayString) {
429
+ return is.date(obj) && dayString.toLowerCase() === days[obj.getDay()];
430
+ };
431
+ // day method does not support 'all' and 'any' interfaces
432
+ is.day.api = ['not'];
433
+
434
+ // is a given dates month equal given monthString parameter?
435
+ is.month = function(obj, monthString) {
436
+ return is.date(obj) && monthString.toLowerCase() === months[obj.getMonth()];
437
+ };
438
+ // month method does not support 'all' and 'any' interfaces
439
+ is.month.api = ['not'];
440
+
441
+ // is a given dates year equal given year parameter?
442
+ is.year = function(obj, year) {
443
+ return is.date(obj) && is.number(year) && year === obj.getFullYear();
444
+ };
445
+ // year method does not support 'all' and 'any' interfaces
446
+ is.year.api = ['not'];
447
+
448
+ // is a given date weekend?
449
+ // 6: Saturday, 0: Sunday
450
+ is.weekend = function(obj) {
451
+ return is.date(obj) && (obj.getDay() === 6 || obj.getDay() === 0);
452
+ };
453
+
454
+ // is a given date weekday?
455
+ is.weekday = not(is.weekend);
456
+
457
+ // is date within given range?
458
+ is.inDateRange = function(obj, startObj, endObj) {
459
+ if(is.not.date(obj) || is.not.date(startObj) || is.not.date(endObj)) {
460
+ return false;
461
+ }
462
+ var givenDate = obj.getTime();
463
+ var start = startObj.getTime();
464
+ var end = endObj.getTime();
465
+ return givenDate > start && givenDate < end;
466
+ };
467
+ // inDateRange method does not support 'all' and 'any' interfaces
468
+ is.inDateRange.api = ['not'];
469
+
470
+ // is a given date in last week range?
471
+ is.inLastWeek = function(obj) {
472
+ return is.inDateRange(obj, new Date(new Date().setDate(new Date().getDate() - 7)), new Date());
473
+ };
474
+
475
+ // is a given date in last month range?
476
+ is.inLastMonth = function(obj) {
477
+ return is.inDateRange(obj, new Date(new Date().setMonth(new Date().getMonth() - 1)), new Date());
478
+ };
479
+
480
+ // is a given date in last year range?
481
+ is.inLastYear = function(obj) {
482
+ return is.inDateRange(obj, new Date(new Date().setFullYear(new Date().getFullYear() - 1)), new Date());
483
+ };
484
+
485
+ // is a given date in next week range?
486
+ is.inNextWeek = function(obj) {
487
+ return is.inDateRange(obj, new Date(), new Date(new Date().setDate(new Date().getDate() + 7)));
488
+ };
489
+
490
+ // is a given date in next month range?
491
+ is.inNextMonth = function(obj) {
492
+ return is.inDateRange(obj, new Date(), new Date(new Date().setMonth(new Date().getMonth() + 1)));
493
+ };
494
+
495
+ // is a given date in next year range?
496
+ is.inNextYear = function(obj) {
497
+ return is.inDateRange(obj, new Date(), new Date(new Date().setFullYear(new Date().getFullYear() + 1)));
498
+ };
499
+
500
+ // is a given date in the parameter quarter?
501
+ is.quarterOfYear = function(obj, quarterNumber) {
502
+ return is.date(obj) && is.number(quarterNumber) && quarterNumber === Math.floor((obj.getMonth() + 3) / 3);
503
+ };
504
+ // quarterOfYear method does not support 'all' and 'any' interfaces
505
+ is.quarterOfYear.api = ['not'];
506
+
507
+ // is a given date in daylight saving time?
508
+ is.dayLightSavingTime = function(obj) {
509
+ var january = new Date(obj.getFullYear(), 0, 1);
510
+ var july = new Date(obj.getFullYear(), 6, 1);
511
+ var stdTimezoneOffset = Math.max(january.getTimezoneOffset(), july.getTimezoneOffset());
512
+ return obj.getTimezoneOffset() < stdTimezoneOffset;
513
+ };
514
+
515
+ // Environment checks
516
+ /* -------------------------------------------------------------------------- */
517
+
518
+ // check if library is used as a Node.js module
519
+ if(typeof window !== 'undefined') {
520
+
521
+ // store navigator properties to use later
522
+ var userAgent = 'navigator' in window && navigator.userAgent.toLowerCase() || '';
523
+ var vendor = 'navigator' in window && navigator.vendor.toLowerCase() || '';
524
+ var appVersion = 'navigator' in window && navigator.appVersion.toLowerCase() || '';
525
+
526
+ // is current browser chrome?
527
+ is.chrome = function() {
528
+ return /chrome|chromium/i.test(userAgent) && /google inc/.test(vendor);
529
+ };
530
+ // chrome method does not support 'all' and 'any' interfaces
531
+ is.chrome.api = ['not'];
532
+
533
+ // is current browser firefox?
534
+ is.firefox = function() {
535
+ return /firefox/i.test(userAgent);
536
+ };
537
+ // firefox method does not support 'all' and 'any' interfaces
538
+ is.firefox.api = ['not'];
539
+
540
+ // is current browser internet explorer?
541
+ // parameter is optional
542
+ is.ie = function(version) {
543
+ if(!version) {
544
+ return /msie/i.test(userAgent);
545
+ }
546
+ return new RegExp('msie ' + version).test(userAgent);
547
+ };
548
+ // ie method does not support 'all' and 'any' interfaces
549
+ is.ie.api = ['not'];
550
+
551
+ // is current browser opera?
552
+ is.opera = function() {
553
+ return /opr/i.test(userAgent);
554
+ };
555
+ // opera method does not support 'all' and 'any' interfaces
556
+ is.opera.api = ['not'];
557
+
558
+ // is current browser safari?
559
+ is.safari = function() {
560
+ return /safari/i.test(userAgent) && /apple computer/i.test(vendor);
561
+ };
562
+ // safari method does not support 'all' and 'any' interfaces
563
+ is.safari.api = ['not'];
564
+
565
+ // is current device ios?
566
+ is.ios = function() {
567
+ return is.iphone() || is.ipad() || is.ipod();
568
+ };
569
+ // ios method does not support 'all' and 'any' interfaces
570
+ is.ios.api = ['not'];
571
+
572
+ // is current device iphone?
573
+ is.iphone = function() {
574
+ return /iphone/i.test(userAgent);
575
+ };
576
+ // iphone method does not support 'all' and 'any' interfaces
577
+ is.iphone.api = ['not'];
578
+
579
+ // is current device ipad?
580
+ is.ipad = function() {
581
+ return /ipad/i.test(userAgent);
582
+ };
583
+ // ipad method does not support 'all' and 'any' interfaces
584
+ is.ipad.api = ['not'];
585
+
586
+ // is current device ipod?
587
+ is.ipod = function() {
588
+ return /ipod/i.test(userAgent);
589
+ };
590
+ // ipod method does not support 'all' and 'any' interfaces
591
+ is.ipod.api = ['not'];
592
+
593
+ // is current device android?
594
+ is.android = function() {
595
+ return /android/i.test(userAgent);
596
+ };
597
+ // android method does not support 'all' and 'any' interfaces
598
+ is.android.api = ['not'];
599
+
600
+ // is current device android phone?
601
+ is.androidPhone = function() {
602
+ return /android/i.test(userAgent) && /mobile/i.test(userAgent);
603
+ };
604
+ // androidPhone method does not support 'all' and 'any' interfaces
605
+ is.androidPhone.api = ['not'];
606
+
607
+ // is current device android tablet?
608
+ is.androidTablet = function() {
609
+ return /android/i.test(userAgent) && !/mobile/i.test(userAgent);
610
+ };
611
+ // androidTablet method does not support 'all' and 'any' interfaces
612
+ is.androidTablet.api = ['not'];
613
+
614
+ // is current device blackberry?
615
+ is.blackberry = function() {
616
+ return /blackberry/i.test(userAgent);
617
+ };
618
+ // blackberry method does not support 'all' and 'any' interfaces
619
+ is.blackberry.api = ['not'];
620
+
621
+ // is current device desktop?
622
+ is.desktop = function() {
623
+ return is.not.mobile() && is.not.tablet();
624
+ };
625
+ // desktop method does not support 'all' and 'any' interfaces
626
+ is.desktop.api = ['not'];
627
+
628
+ // is current operating system linux?
629
+ is.linux = function() {
630
+ return /linux/i.test(appVersion);
631
+ };
632
+ // linux method does not support 'all' and 'any' interfaces
633
+ is.linux.api = ['not'];
634
+
635
+ // is current operating system mac?
636
+ is.mac = function() {
637
+ return /mac/i.test(appVersion);
638
+ };
639
+ // mac method does not support 'all' and 'any' interfaces
640
+ is.mac.api = ['not'];
641
+
642
+ // is current operating system windows?
643
+ is.windows = function() {
644
+ return /win/i.test(appVersion);
645
+ };
646
+ // windows method does not support 'all' and 'any' interfaces
647
+ is.windows.api = ['not'];
648
+
649
+ // is current device windows phone?
650
+ is.windowsPhone = function() {
651
+ return is.windows() && /phone/i.test(userAgent);
652
+ };
653
+ // windowsPhone method does not support 'all' and 'any' interfaces
654
+ is.windowsPhone.api = ['not'];
655
+
656
+ // is current device windows tablet?
657
+ is.windowsTablet = function() {
658
+ return is.windows() && is.not.windowsPhone() && /touch/i.test(userAgent);
659
+ };
660
+ // windowsTablet method does not support 'all' and 'any' interfaces
661
+ is.windowsTablet.api = ['not'];
662
+
663
+ // is current device mobile?
664
+ is.mobile = function() {
665
+ return is.iphone() || is.ipod() || is.androidPhone() || is.blackberry() || is.windowsPhone();
666
+ };
667
+ // mobile method does not support 'all' and 'any' interfaces
668
+ is.mobile.api = ['not'];
669
+
670
+ // is current device tablet?
671
+ is.tablet = function() {
672
+ return is.ipad() || is.androidTablet() || is.windowsTablet();
673
+ };
674
+ // tablet method does not support 'all' and 'any' interfaces
675
+ is.tablet.api = ['not'];
676
+
677
+ // is current state online?
678
+ is.online = function() {
679
+ return navigator.onLine;
680
+ };
681
+ // online method does not support 'all' and 'any' interfaces
682
+ is.online.api = ['not'];
683
+
684
+ // is current state offline?
685
+ is.offline = not(is.online);
686
+ // offline method does not support 'all' and 'any' interfaces
687
+ is.offline.api = ['not'];
688
+ }
689
+
690
+ // Object checks
691
+ /* -------------------------------------------------------------------------- */
692
+
693
+ // has a given object got parameterized count property?
694
+ is.propertyCount = function(obj, count) {
695
+ if(!is.object(obj) || !is.number(count)) {
696
+ return false;
697
+ }
698
+ if(Object.keys) {
699
+ return Object.keys(obj).length === count;
700
+ }
701
+ var properties = [],
702
+ property;
703
+ for(property in obj) {
704
+ if (hasOwnProperty.call(obj, property)) {
705
+ properties.push(property);
706
+ }
707
+ }
708
+ return properties.length === count;
709
+ };
710
+ // propertyCount method does not support 'all' and 'any' interfaces
711
+ is.propertyCount.api = ['not'];
712
+
713
+ // is given object has parameterized property?
714
+ is.propertyDefined = function(obj, property) {
715
+ return is.object(obj) && is.string(property) && property in obj;
716
+ };
717
+ // propertyDefined method does not support 'all' and 'any' interfaces
718
+ is.propertyDefined.api = ['not'];
719
+
720
+ // is a given object window?
721
+ // setInterval method is only available for window object
722
+ is.windowObject = function(obj) {
723
+ return typeof obj === 'object' && 'setInterval' in obj;
724
+ };
725
+
726
+ // Array checks
727
+ /* -------------------------------------------------------------------------- */
728
+
729
+ // is a given item in an array?
730
+ is.inArray = function(val, arr){
731
+ if(is.not.array(arr)) {
732
+ return false;
733
+ }
734
+ for(var i = 0; i < arr.length; i++) {
735
+ if (arr[i] === val) return true;
736
+ }
737
+ return false;
738
+ };
739
+ // inArray method does not support 'all' and 'any' interfaces
740
+ is.inArray.api = ['not'];
741
+
742
+ // is a given array sorted?
743
+ is.sorted = function(arr) {
744
+ if(is.not.array(arr)) {
745
+ return false;
746
+ }
747
+ for(var i = 0; i < arr.length; i++) {
748
+ if(arr[i] > arr[i + 1]) return false;
749
+ }
750
+ return true;
751
+ };
752
+
753
+ // API
754
+ // Set 'not', 'all' and 'any' interfaces to methods based on their api property
755
+ /* -------------------------------------------------------------------------- */
756
+
757
+ function setInterfaces() {
758
+ var options = is;
759
+ for(var option in options) {
760
+ if(hasOwnProperty.call(options, option) && is.function(options[option])) {
761
+ var interfaces = options[option].api || ['not', 'all', 'any'];
762
+ for (var i = 0; i < interfaces.length; i++) {
763
+ if(interfaces[i] === 'not') {
764
+ is.not[option] = not(is[option]);
765
+ }
766
+ if(interfaces[i] === 'all') {
767
+ is.all[option] = all(is[option]);
768
+ }
769
+ if(interfaces[i] === 'any') {
770
+ is.any[option] = any(is[option]);
771
+ }
772
+ }
773
+ }
774
+ }
775
+ }
776
+ setInterfaces();
777
+
778
+ // Configuration methods
779
+ // Intentionally added after setInterfaces function
780
+ /* -------------------------------------------------------------------------- */
781
+
782
+ // set optional regexps to methods if you think they suck
783
+ is.setRegexp = function(regexp, regexpName) {
784
+ for(var r in regexps) {
785
+ if(hasOwnProperty.call(regexps, r) && (regexpName === r)) {
786
+ regexps[r] = regexp;
787
+ }
788
+ }
789
+ };
790
+
791
+ // change namespace of library to prevent name collisions
792
+ // var preferredName = is.setNamespace();
793
+ // preferredName.odd(3);
794
+ // => true
795
+ is.setNamespace = function() {
796
+ root.is = previousIs;
797
+ return this;
798
+ };
799
+
800
+ return is;
801
+ }));
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: is_js_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Guinsly Mondesir
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Implementing is.js in your rails app. https://arasatasaygin.github.io/is.js
42
+ A Micro check library
43
+ email:
44
+ - gmond@gmx.com.br
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - is_js_rails.gemspec
56
+ - lib/is_js_rails.rb
57
+ - lib/is_js_rails/version.rb
58
+ - vendor/assets/javascripts/is_js_rails.js
59
+ homepage: https://github.com/guinslym/is_js_rails
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Adding is.js in your rails app. https://arasatasaygin.github.io/is.js A Micro
83
+ check library
84
+ test_files: []
85
+ has_rdoc: