ende 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1377 @@
1
+ /*!
2
+ * https://github.com/es-shims/es5-shim
3
+ * @license es5-shim Copyright 2009-2014 by contributors, MIT License
4
+ * see https://github.com/es-shims/es5-shim/blob/master/LICENSE
5
+ */
6
+
7
+ // vim: ts=4 sts=4 sw=4 expandtab
8
+
9
+ //Add semicolon to prevent IIFE from being passed as argument to concated code.
10
+ ;
11
+
12
+ // UMD (Universal Module Definition)
13
+ // see https://github.com/umdjs/umd/blob/master/returnExports.js
14
+ (function (root, factory) {
15
+ if (typeof define === 'function' && define.amd) {
16
+ // AMD. Register as an anonymous module.
17
+ define(factory);
18
+ } else if (typeof exports === 'object') {
19
+ // Node. Does not work with strict CommonJS, but
20
+ // only CommonJS-like enviroments that support module.exports,
21
+ // like Node.
22
+ module.exports = factory();
23
+ } else {
24
+ // Browser globals (root is window)
25
+ root.returnExports = factory();
26
+ }
27
+ }(this, function () {
28
+
29
+ /**
30
+ * Brings an environment as close to ECMAScript 5 compliance
31
+ * as is possible with the facilities of erstwhile engines.
32
+ *
33
+ * Annotated ES5: http://es5.github.com/ (specific links below)
34
+ * ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
35
+ * Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
36
+ */
37
+
38
+ //
39
+ // Function
40
+ // ========
41
+ //
42
+
43
+ // ES-5 15.3.4.5
44
+ // http://es5.github.com/#x15.3.4.5
45
+
46
+ function Empty() {}
47
+
48
+ if (!Function.prototype.bind) {
49
+ Function.prototype.bind = function bind(that) { // .length is 1
50
+ // 1. Let Target be the this value.
51
+ var target = this;
52
+ // 2. If IsCallable(Target) is false, throw a TypeError exception.
53
+ if (typeof target != "function") {
54
+ throw new TypeError("Function.prototype.bind called on incompatible " + target);
55
+ }
56
+ // 3. Let A be a new (possibly empty) internal list of all of the
57
+ // argument values provided after thisArg (arg1, arg2 etc), in order.
58
+ // XXX slicedArgs will stand in for "A" if used
59
+ var args = _Array_slice_.call(arguments, 1); // for normal call
60
+ // 4. Let F be a new native ECMAScript object.
61
+ // 11. Set the [[Prototype]] internal property of F to the standard
62
+ // built-in Function prototype object as specified in 15.3.3.1.
63
+ // 12. Set the [[Call]] internal property of F as described in
64
+ // 15.3.4.5.1.
65
+ // 13. Set the [[Construct]] internal property of F as described in
66
+ // 15.3.4.5.2.
67
+ // 14. Set the [[HasInstance]] internal property of F as described in
68
+ // 15.3.4.5.3.
69
+ var binder = function () {
70
+
71
+ if (this instanceof bound) {
72
+ // 15.3.4.5.2 [[Construct]]
73
+ // When the [[Construct]] internal method of a function object,
74
+ // F that was created using the bind function is called with a
75
+ // list of arguments ExtraArgs, the following steps are taken:
76
+ // 1. Let target be the value of F's [[TargetFunction]]
77
+ // internal property.
78
+ // 2. If target has no [[Construct]] internal method, a
79
+ // TypeError exception is thrown.
80
+ // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
81
+ // property.
82
+ // 4. Let args be a new list containing the same values as the
83
+ // list boundArgs in the same order followed by the same
84
+ // values as the list ExtraArgs in the same order.
85
+ // 5. Return the result of calling the [[Construct]] internal
86
+ // method of target providing args as the arguments.
87
+
88
+ var result = target.apply(
89
+ this,
90
+ args.concat(_Array_slice_.call(arguments))
91
+ );
92
+ if (Object(result) === result) {
93
+ return result;
94
+ }
95
+ return this;
96
+
97
+ } else {
98
+ // 15.3.4.5.1 [[Call]]
99
+ // When the [[Call]] internal method of a function object, F,
100
+ // which was created using the bind function is called with a
101
+ // this value and a list of arguments ExtraArgs, the following
102
+ // steps are taken:
103
+ // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
104
+ // property.
105
+ // 2. Let boundThis be the value of F's [[BoundThis]] internal
106
+ // property.
107
+ // 3. Let target be the value of F's [[TargetFunction]] internal
108
+ // property.
109
+ // 4. Let args be a new list containing the same values as the
110
+ // list boundArgs in the same order followed by the same
111
+ // values as the list ExtraArgs in the same order.
112
+ // 5. Return the result of calling the [[Call]] internal method
113
+ // of target providing boundThis as the this value and
114
+ // providing args as the arguments.
115
+
116
+ // equiv: target.call(this, ...boundArgs, ...args)
117
+ return target.apply(
118
+ that,
119
+ args.concat(_Array_slice_.call(arguments))
120
+ );
121
+
122
+ }
123
+
124
+ };
125
+
126
+ // 15. If the [[Class]] internal property of Target is "Function", then
127
+ // a. Let L be the length property of Target minus the length of A.
128
+ // b. Set the length own property of F to either 0 or L, whichever is
129
+ // larger.
130
+ // 16. Else set the length own property of F to 0.
131
+
132
+ var boundLength = Math.max(0, target.length - args.length);
133
+
134
+ // 17. Set the attributes of the length own property of F to the values
135
+ // specified in 15.3.5.1.
136
+ var boundArgs = [];
137
+ for (var i = 0; i < boundLength; i++) {
138
+ boundArgs.push("$" + i);
139
+ }
140
+
141
+ // XXX Build a dynamic function with desired amount of arguments is the only
142
+ // way to set the length property of a function.
143
+ // In environments where Content Security Policies enabled (Chrome extensions,
144
+ // for ex.) all use of eval or Function costructor throws an exception.
145
+ // However in all of these environments Function.prototype.bind exists
146
+ // and so this code will never be executed.
147
+ var bound = Function("binder", "return function(" + boundArgs.join(",") + "){return binder.apply(this,arguments)}")(binder);
148
+
149
+ if (target.prototype) {
150
+ Empty.prototype = target.prototype;
151
+ bound.prototype = new Empty();
152
+ // Clean up dangling references.
153
+ Empty.prototype = null;
154
+ }
155
+
156
+ // TODO
157
+ // 18. Set the [[Extensible]] internal property of F to true.
158
+
159
+ // TODO
160
+ // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
161
+ // 20. Call the [[DefineOwnProperty]] internal method of F with
162
+ // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
163
+ // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
164
+ // false.
165
+ // 21. Call the [[DefineOwnProperty]] internal method of F with
166
+ // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
167
+ // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
168
+ // and false.
169
+
170
+ // TODO
171
+ // NOTE Function objects created using Function.prototype.bind do not
172
+ // have a prototype property or the [[Code]], [[FormalParameters]], and
173
+ // [[Scope]] internal properties.
174
+ // XXX can't delete prototype in pure-js.
175
+
176
+ // 22. Return F.
177
+ return bound;
178
+ };
179
+ }
180
+
181
+ // Shortcut to an often accessed properties, in order to avoid multiple
182
+ // dereference that costs universally.
183
+ // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
184
+ // us it in defining shortcuts.
185
+ var call = Function.prototype.call;
186
+ var prototypeOfArray = Array.prototype;
187
+ var prototypeOfObject = Object.prototype;
188
+ var _Array_slice_ = prototypeOfArray.slice;
189
+ // Having a toString local variable name breaks in Opera so use _toString.
190
+ var _toString = call.bind(prototypeOfObject.toString);
191
+ var owns = call.bind(prototypeOfObject.hasOwnProperty);
192
+
193
+ // If JS engine supports accessors creating shortcuts.
194
+ var defineGetter;
195
+ var defineSetter;
196
+ var lookupGetter;
197
+ var lookupSetter;
198
+ var supportsAccessors;
199
+ if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
200
+ defineGetter = call.bind(prototypeOfObject.__defineGetter__);
201
+ defineSetter = call.bind(prototypeOfObject.__defineSetter__);
202
+ lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
203
+ lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
204
+ }
205
+
206
+ //
207
+ // Array
208
+ // =====
209
+ //
210
+
211
+ // ES5 15.4.4.12
212
+ // http://es5.github.com/#x15.4.4.12
213
+ // Default value for second param
214
+ // [bugfix, ielt9, old browsers]
215
+ // IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12"
216
+ if ([1,2].splice(0).length != 2) {
217
+ var array_splice = Array.prototype.splice;
218
+ var array_push = Array.prototype.push;
219
+ var array_unshift = Array.prototype.unshift;
220
+
221
+ if (function() { // test IE < 9 to splice bug - see issue #138
222
+ function makeArray(l) {
223
+ var a = [];
224
+ while (l--) {
225
+ a.unshift(l)
226
+ }
227
+ return a
228
+ }
229
+
230
+ var array = []
231
+ , lengthBefore
232
+ ;
233
+
234
+ array.splice.bind(array, 0, 0).apply(null, makeArray(20));
235
+ array.splice.bind(array, 0, 0).apply(null, makeArray(26));
236
+
237
+ lengthBefore = array.length; //20
238
+ array.splice(5, 0, "XXX"); // add one element
239
+
240
+ if (lengthBefore + 1 == array.length) {
241
+ return true;// has right splice implementation without bugs
242
+ }
243
+ // else {
244
+ // IE8 bug
245
+ // }
246
+ }()) {//IE 6/7
247
+ Array.prototype.splice = function(start, deleteCount) {
248
+ if (!arguments.length) {
249
+ return [];
250
+ } else {
251
+ return array_splice.apply(this, [
252
+ start === void 0 ? 0 : start,
253
+ deleteCount === void 0 ? (this.length - start) : deleteCount
254
+ ].concat(_Array_slice_.call(arguments, 2)))
255
+ }
256
+ };
257
+ }
258
+ else {//IE8
259
+ Array.prototype.splice = function(start, deleteCount) {
260
+ var result
261
+ , args = _Array_slice_.call(arguments, 2)
262
+ , addElementsCount = args.length
263
+ ;
264
+
265
+ if (!arguments.length) {
266
+ return [];
267
+ }
268
+
269
+ if (start === void 0) { // default
270
+ start = 0;
271
+ }
272
+ if (deleteCount === void 0) { // default
273
+ deleteCount = this.length - start;
274
+ }
275
+
276
+ if (addElementsCount > 0) {
277
+ if (deleteCount <= 0) {
278
+ if (start == this.length) { // tiny optimisation #1
279
+ array_push.apply(this, args);
280
+ return [];
281
+ }
282
+
283
+ if (start == 0) { // tiny optimisation #2
284
+ array_unshift.apply(this, args);
285
+ return [];
286
+ }
287
+ }
288
+
289
+ // Array.prototype.splice implementation
290
+ result = _Array_slice_.call(this, start, start + deleteCount);// delete part
291
+ args.push.apply(args, _Array_slice_.call(this, start + deleteCount, this.length));// right part
292
+ args.unshift.apply(args, _Array_slice_.call(this, 0, start));// left part
293
+
294
+ // delete all items from this array and replace it to 'left part' + _Array_slice_.call(arguments, 2) + 'right part'
295
+ args.unshift(0, this.length);
296
+
297
+ array_splice.apply(this, args);
298
+
299
+ return result;
300
+ }
301
+
302
+ return array_splice.call(this, start, deleteCount);
303
+ }
304
+
305
+ }
306
+ }
307
+
308
+ // ES5 15.4.4.12
309
+ // http://es5.github.com/#x15.4.4.13
310
+ // Return len+argCount.
311
+ // [bugfix, ielt8]
312
+ // IE < 8 bug: [].unshift(0) == undefined but should be "1"
313
+ if ([].unshift(0) != 1) {
314
+ var array_unshift = Array.prototype.unshift;
315
+ Array.prototype.unshift = function() {
316
+ array_unshift.apply(this, arguments);
317
+ return this.length;
318
+ };
319
+ }
320
+
321
+ // ES5 15.4.3.2
322
+ // http://es5.github.com/#x15.4.3.2
323
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
324
+ if (!Array.isArray) {
325
+ Array.isArray = function isArray(obj) {
326
+ return _toString(obj) == "[object Array]";
327
+ };
328
+ }
329
+
330
+ // The IsCallable() check in the Array functions
331
+ // has been replaced with a strict check on the
332
+ // internal class of the object to trap cases where
333
+ // the provided function was actually a regular
334
+ // expression literal, which in V8 and
335
+ // JavaScriptCore is a typeof "function". Only in
336
+ // V8 are regular expression literals permitted as
337
+ // reduce parameters, so it is desirable in the
338
+ // general case for the shim to match the more
339
+ // strict and common behavior of rejecting regular
340
+ // expressions.
341
+
342
+ // ES5 15.4.4.18
343
+ // http://es5.github.com/#x15.4.4.18
344
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
345
+
346
+
347
+ // Check failure of by-index access of string characters (IE < 9)
348
+ // and failure of `0 in boxedString` (Rhino)
349
+ var boxedString = Object("a");
350
+ var splitString = boxedString[0] != "a" || !(0 in boxedString);
351
+
352
+ var properlyBoxesContext = function properlyBoxed(method) {
353
+ // Check node 0.6.21 bug where third parameter is not boxed
354
+ var properlyBoxes = true;
355
+ if (method) {
356
+ method.call('foo', function (item, index, context) {
357
+ if (typeof context !== 'object') { properlyBoxes = false; }
358
+ });
359
+ }
360
+ return !!method && properlyBoxes;
361
+ };
362
+
363
+ if (!Array.prototype.forEach || !properlyBoxesContext(Array.prototype.forEach)) {
364
+ Array.prototype.forEach = function forEach(fun /*, thisp*/) {
365
+ var object = toObject(this),
366
+ self = splitString && _toString(this) == "[object String]" ?
367
+ this.split("") :
368
+ object,
369
+ thisp = arguments[1],
370
+ i = -1,
371
+ length = self.length >>> 0;
372
+
373
+ // If no callback function or if callback is not a callable function
374
+ if (_toString(fun) != "[object Function]") {
375
+ throw new TypeError(); // TODO message
376
+ }
377
+
378
+ while (++i < length) {
379
+ if (i in self) {
380
+ // Invoke the callback function with call, passing arguments:
381
+ // context, property value, property key, thisArg object
382
+ // context
383
+ fun.call(thisp, self[i], i, object);
384
+ }
385
+ }
386
+ };
387
+ }
388
+
389
+ // ES5 15.4.4.19
390
+ // http://es5.github.com/#x15.4.4.19
391
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
392
+ if (!Array.prototype.map || !properlyBoxesContext(Array.prototype.map)) {
393
+ Array.prototype.map = function map(fun /*, thisp*/) {
394
+ var object = toObject(this),
395
+ self = splitString && _toString(this) == "[object String]" ?
396
+ this.split("") :
397
+ object,
398
+ length = self.length >>> 0,
399
+ result = Array(length),
400
+ thisp = arguments[1];
401
+
402
+ // If no callback function or if callback is not a callable function
403
+ if (_toString(fun) != "[object Function]") {
404
+ throw new TypeError(fun + " is not a function");
405
+ }
406
+
407
+ for (var i = 0; i < length; i++) {
408
+ if (i in self)
409
+ result[i] = fun.call(thisp, self[i], i, object);
410
+ }
411
+ return result;
412
+ };
413
+ }
414
+
415
+ // ES5 15.4.4.20
416
+ // http://es5.github.com/#x15.4.4.20
417
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
418
+ if (!Array.prototype.filter || !properlyBoxesContext(Array.prototype.filter)) {
419
+ Array.prototype.filter = function filter(fun /*, thisp */) {
420
+ var object = toObject(this),
421
+ self = splitString && _toString(this) == "[object String]" ?
422
+ this.split("") :
423
+ object,
424
+ length = self.length >>> 0,
425
+ result = [],
426
+ value,
427
+ thisp = arguments[1];
428
+
429
+ // If no callback function or if callback is not a callable function
430
+ if (_toString(fun) != "[object Function]") {
431
+ throw new TypeError(fun + " is not a function");
432
+ }
433
+
434
+ for (var i = 0; i < length; i++) {
435
+ if (i in self) {
436
+ value = self[i];
437
+ if (fun.call(thisp, value, i, object)) {
438
+ result.push(value);
439
+ }
440
+ }
441
+ }
442
+ return result;
443
+ };
444
+ }
445
+
446
+ // ES5 15.4.4.16
447
+ // http://es5.github.com/#x15.4.4.16
448
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
449
+ if (!Array.prototype.every || !properlyBoxesContext(Array.prototype.every)) {
450
+ Array.prototype.every = function every(fun /*, thisp */) {
451
+ var object = toObject(this),
452
+ self = splitString && _toString(this) == "[object String]" ?
453
+ this.split("") :
454
+ object,
455
+ length = self.length >>> 0,
456
+ thisp = arguments[1];
457
+
458
+ // If no callback function or if callback is not a callable function
459
+ if (_toString(fun) != "[object Function]") {
460
+ throw new TypeError(fun + " is not a function");
461
+ }
462
+
463
+ for (var i = 0; i < length; i++) {
464
+ if (i in self && !fun.call(thisp, self[i], i, object)) {
465
+ return false;
466
+ }
467
+ }
468
+ return true;
469
+ };
470
+ }
471
+
472
+ // ES5 15.4.4.17
473
+ // http://es5.github.com/#x15.4.4.17
474
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
475
+ if (!Array.prototype.some || !properlyBoxesContext(Array.prototype.some)) {
476
+ Array.prototype.some = function some(fun /*, thisp */) {
477
+ var object = toObject(this),
478
+ self = splitString && _toString(this) == "[object String]" ?
479
+ this.split("") :
480
+ object,
481
+ length = self.length >>> 0,
482
+ thisp = arguments[1];
483
+
484
+ // If no callback function or if callback is not a callable function
485
+ if (_toString(fun) != "[object Function]") {
486
+ throw new TypeError(fun + " is not a function");
487
+ }
488
+
489
+ for (var i = 0; i < length; i++) {
490
+ if (i in self && fun.call(thisp, self[i], i, object)) {
491
+ return true;
492
+ }
493
+ }
494
+ return false;
495
+ };
496
+ }
497
+
498
+ // ES5 15.4.4.21
499
+ // http://es5.github.com/#x15.4.4.21
500
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
501
+ if (!Array.prototype.reduce) {
502
+ Array.prototype.reduce = function reduce(fun /*, initial*/) {
503
+ var object = toObject(this),
504
+ self = splitString && _toString(this) == "[object String]" ?
505
+ this.split("") :
506
+ object,
507
+ length = self.length >>> 0;
508
+
509
+ // If no callback function or if callback is not a callable function
510
+ if (_toString(fun) != "[object Function]") {
511
+ throw new TypeError(fun + " is not a function");
512
+ }
513
+
514
+ // no value to return if no initial value and an empty array
515
+ if (!length && arguments.length == 1) {
516
+ throw new TypeError("reduce of empty array with no initial value");
517
+ }
518
+
519
+ var i = 0;
520
+ var result;
521
+ if (arguments.length >= 2) {
522
+ result = arguments[1];
523
+ } else {
524
+ do {
525
+ if (i in self) {
526
+ result = self[i++];
527
+ break;
528
+ }
529
+
530
+ // if array contains no values, no initial value to return
531
+ if (++i >= length) {
532
+ throw new TypeError("reduce of empty array with no initial value");
533
+ }
534
+ } while (true);
535
+ }
536
+
537
+ for (; i < length; i++) {
538
+ if (i in self) {
539
+ result = fun.call(void 0, result, self[i], i, object);
540
+ }
541
+ }
542
+
543
+ return result;
544
+ };
545
+ }
546
+
547
+ // ES5 15.4.4.22
548
+ // http://es5.github.com/#x15.4.4.22
549
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
550
+ if (!Array.prototype.reduceRight) {
551
+ Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
552
+ var object = toObject(this),
553
+ self = splitString && _toString(this) == "[object String]" ?
554
+ this.split("") :
555
+ object,
556
+ length = self.length >>> 0;
557
+
558
+ // If no callback function or if callback is not a callable function
559
+ if (_toString(fun) != "[object Function]") {
560
+ throw new TypeError(fun + " is not a function");
561
+ }
562
+
563
+ // no value to return if no initial value, empty array
564
+ if (!length && arguments.length == 1) {
565
+ throw new TypeError("reduceRight of empty array with no initial value");
566
+ }
567
+
568
+ var result, i = length - 1;
569
+ if (arguments.length >= 2) {
570
+ result = arguments[1];
571
+ } else {
572
+ do {
573
+ if (i in self) {
574
+ result = self[i--];
575
+ break;
576
+ }
577
+
578
+ // if array contains no values, no initial value to return
579
+ if (--i < 0) {
580
+ throw new TypeError("reduceRight of empty array with no initial value");
581
+ }
582
+ } while (true);
583
+ }
584
+
585
+ if (i < 0) {
586
+ return result;
587
+ }
588
+
589
+ do {
590
+ if (i in this) {
591
+ result = fun.call(void 0, result, self[i], i, object);
592
+ }
593
+ } while (i--);
594
+
595
+ return result;
596
+ };
597
+ }
598
+
599
+ // ES5 15.4.4.14
600
+ // http://es5.github.com/#x15.4.4.14
601
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
602
+ if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
603
+ Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
604
+ var self = splitString && _toString(this) == "[object String]" ?
605
+ this.split("") :
606
+ toObject(this),
607
+ length = self.length >>> 0;
608
+
609
+ if (!length) {
610
+ return -1;
611
+ }
612
+
613
+ var i = 0;
614
+ if (arguments.length > 1) {
615
+ i = toInteger(arguments[1]);
616
+ }
617
+
618
+ // handle negative indices
619
+ i = i >= 0 ? i : Math.max(0, length + i);
620
+ for (; i < length; i++) {
621
+ if (i in self && self[i] === sought) {
622
+ return i;
623
+ }
624
+ }
625
+ return -1;
626
+ };
627
+ }
628
+
629
+ // ES5 15.4.4.15
630
+ // http://es5.github.com/#x15.4.4.15
631
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
632
+ if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
633
+ Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
634
+ var self = splitString && _toString(this) == "[object String]" ?
635
+ this.split("") :
636
+ toObject(this),
637
+ length = self.length >>> 0;
638
+
639
+ if (!length) {
640
+ return -1;
641
+ }
642
+ var i = length - 1;
643
+ if (arguments.length > 1) {
644
+ i = Math.min(i, toInteger(arguments[1]));
645
+ }
646
+ // handle negative indices
647
+ i = i >= 0 ? i : length - Math.abs(i);
648
+ for (; i >= 0; i--) {
649
+ if (i in self && sought === self[i]) {
650
+ return i;
651
+ }
652
+ }
653
+ return -1;
654
+ };
655
+ }
656
+
657
+ //
658
+ // Object
659
+ // ======
660
+ //
661
+
662
+ // ES5 15.2.3.14
663
+ // http://es5.github.com/#x15.2.3.14
664
+ if (!Object.keys) {
665
+ // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
666
+ var hasDontEnumBug = true,
667
+ hasProtoEnumBug = (function () {}).propertyIsEnumerable('prototype'),
668
+ dontEnums = [
669
+ "toString",
670
+ "toLocaleString",
671
+ "valueOf",
672
+ "hasOwnProperty",
673
+ "isPrototypeOf",
674
+ "propertyIsEnumerable",
675
+ "constructor"
676
+ ],
677
+ dontEnumsLength = dontEnums.length;
678
+
679
+ for (var key in {"toString": null}) {
680
+ hasDontEnumBug = false;
681
+ }
682
+
683
+ Object.keys = function keys(object) {
684
+ var isFunction = _toString(object) === '[object Function]',
685
+ isObject = object !== null && typeof object === 'object';
686
+
687
+ if (!isObject && !isFunction) {
688
+ throw new TypeError("Object.keys called on a non-object");
689
+ }
690
+
691
+ var keys = [],
692
+ skipProto = hasProtoEnumBug && isFunction;
693
+ for (var name in object) {
694
+ if (!(skipProto && name === 'prototype') && owns(object, name)) {
695
+ keys.push(name);
696
+ }
697
+ }
698
+
699
+ if (hasDontEnumBug) {
700
+ var ctor = object.constructor,
701
+ skipConstructor = ctor && ctor.prototype === object;
702
+ for (var i = 0; i < dontEnumsLength; i++) {
703
+ var dontEnum = dontEnums[i];
704
+ if (!(skipConstructor && dontEnum === 'constructor') && owns(object, dontEnum)) {
705
+ keys.push(dontEnum);
706
+ }
707
+ }
708
+ }
709
+ return keys;
710
+ };
711
+
712
+ }
713
+
714
+ //
715
+ // Date
716
+ // ====
717
+ //
718
+
719
+ // ES5 15.9.5.43
720
+ // http://es5.github.com/#x15.9.5.43
721
+ // This function returns a String value represent the instance in time
722
+ // represented by this Date object. The format of the String is the Date Time
723
+ // string format defined in 15.9.1.15. All fields are present in the String.
724
+ // The time zone is always UTC, denoted by the suffix Z. If the time value of
725
+ // this object is not a finite Number a RangeError exception is thrown.
726
+ var negativeDate = -62198755200000,
727
+ negativeYearString = "-000001";
728
+ if (
729
+ !Date.prototype.toISOString ||
730
+ (new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1)
731
+ ) {
732
+ Date.prototype.toISOString = function toISOString() {
733
+ var result, length, value, year, month;
734
+ if (!isFinite(this)) {
735
+ throw new RangeError("Date.prototype.toISOString called on non-finite value.");
736
+ }
737
+
738
+ year = this.getUTCFullYear();
739
+
740
+ month = this.getUTCMonth();
741
+ // see https://github.com/es-shims/es5-shim/issues/111
742
+ year += Math.floor(month / 12);
743
+ month = (month % 12 + 12) % 12;
744
+
745
+ // the date time string format is specified in 15.9.1.15.
746
+ result = [month + 1, this.getUTCDate(),
747
+ this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
748
+ year = (
749
+ (year < 0 ? "-" : (year > 9999 ? "+" : "")) +
750
+ ("00000" + Math.abs(year))
751
+ .slice(0 <= year && year <= 9999 ? -4 : -6)
752
+ );
753
+
754
+ length = result.length;
755
+ while (length--) {
756
+ value = result[length];
757
+ // pad months, days, hours, minutes, and seconds to have two
758
+ // digits.
759
+ if (value < 10) {
760
+ result[length] = "0" + value;
761
+ }
762
+ }
763
+ // pad milliseconds to have three digits.
764
+ return (
765
+ year + "-" + result.slice(0, 2).join("-") +
766
+ "T" + result.slice(2).join(":") + "." +
767
+ ("000" + this.getUTCMilliseconds()).slice(-3) + "Z"
768
+ );
769
+ };
770
+ }
771
+
772
+
773
+ // ES5 15.9.5.44
774
+ // http://es5.github.com/#x15.9.5.44
775
+ // This function provides a String representation of a Date object for use by
776
+ // JSON.stringify (15.12.3).
777
+ var dateToJSONIsSupported = false;
778
+ try {
779
+ dateToJSONIsSupported = (
780
+ Date.prototype.toJSON &&
781
+ new Date(NaN).toJSON() === null &&
782
+ new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1 &&
783
+ Date.prototype.toJSON.call({ // generic
784
+ toISOString: function () {
785
+ return true;
786
+ }
787
+ })
788
+ );
789
+ } catch (e) {
790
+ }
791
+ if (!dateToJSONIsSupported) {
792
+ Date.prototype.toJSON = function toJSON(key) {
793
+ // When the toJSON method is called with argument key, the following
794
+ // steps are taken:
795
+
796
+ // 1. Let O be the result of calling ToObject, giving it the this
797
+ // value as its argument.
798
+ // 2. Let tv be toPrimitive(O, hint Number).
799
+ var o = Object(this),
800
+ tv = toPrimitive(o),
801
+ toISO;
802
+ // 3. If tv is a Number and is not finite, return null.
803
+ if (typeof tv === "number" && !isFinite(tv)) {
804
+ return null;
805
+ }
806
+ // 4. Let toISO be the result of calling the [[Get]] internal method of
807
+ // O with argument "toISOString".
808
+ toISO = o.toISOString;
809
+ // 5. If IsCallable(toISO) is false, throw a TypeError exception.
810
+ if (typeof toISO != "function") {
811
+ throw new TypeError("toISOString property is not callable");
812
+ }
813
+ // 6. Return the result of calling the [[Call]] internal method of
814
+ // toISO with O as the this value and an empty argument list.
815
+ return toISO.call(o);
816
+
817
+ // NOTE 1 The argument is ignored.
818
+
819
+ // NOTE 2 The toJSON function is intentionally generic; it does not
820
+ // require that its this value be a Date object. Therefore, it can be
821
+ // transferred to other kinds of objects for use as a method. However,
822
+ // it does require that any such object have a toISOString method. An
823
+ // object is free to use the argument key to filter its
824
+ // stringification.
825
+ };
826
+ }
827
+
828
+ // ES5 15.9.4.2
829
+ // http://es5.github.com/#x15.9.4.2
830
+ // based on work shared by Daniel Friesen (dantman)
831
+ // http://gist.github.com/303249
832
+ if (!Date.parse || "Date.parse is buggy") {
833
+ // XXX global assignment won't work in embeddings that use
834
+ // an alternate object for the context.
835
+ Date = (function(NativeDate) {
836
+
837
+ // Date.length === 7
838
+ function Date(Y, M, D, h, m, s, ms) {
839
+ var length = arguments.length;
840
+ if (this instanceof NativeDate) {
841
+ var date = length == 1 && String(Y) === Y ? // isString(Y)
842
+ // We explicitly pass it through parse:
843
+ new NativeDate(Date.parse(Y)) :
844
+ // We have to manually make calls depending on argument
845
+ // length here
846
+ length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
847
+ length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
848
+ length >= 5 ? new NativeDate(Y, M, D, h, m) :
849
+ length >= 4 ? new NativeDate(Y, M, D, h) :
850
+ length >= 3 ? new NativeDate(Y, M, D) :
851
+ length >= 2 ? new NativeDate(Y, M) :
852
+ length >= 1 ? new NativeDate(Y) :
853
+ new NativeDate();
854
+ // Prevent mixups with unfixed Date object
855
+ date.constructor = Date;
856
+ return date;
857
+ }
858
+ return NativeDate.apply(this, arguments);
859
+ };
860
+
861
+ // 15.9.1.15 Date Time String Format.
862
+ var isoDateExpression = new RegExp("^" +
863
+ "(\\d{4}|[\+\-]\\d{6})" + // four-digit year capture or sign +
864
+ // 6-digit extended year
865
+ "(?:-(\\d{2})" + // optional month capture
866
+ "(?:-(\\d{2})" + // optional day capture
867
+ "(?:" + // capture hours:minutes:seconds.milliseconds
868
+ "T(\\d{2})" + // hours capture
869
+ ":(\\d{2})" + // minutes capture
870
+ "(?:" + // optional :seconds.milliseconds
871
+ ":(\\d{2})" + // seconds capture
872
+ "(?:(\\.\\d{1,}))?" + // milliseconds capture
873
+ ")?" +
874
+ "(" + // capture UTC offset component
875
+ "Z|" + // UTC capture
876
+ "(?:" + // offset specifier +/-hours:minutes
877
+ "([-+])" + // sign capture
878
+ "(\\d{2})" + // hours offset capture
879
+ ":(\\d{2})" + // minutes offset capture
880
+ ")" +
881
+ ")?)?)?)?" +
882
+ "$");
883
+
884
+ var months = [
885
+ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
886
+ ];
887
+
888
+ function dayFromMonth(year, month) {
889
+ var t = month > 1 ? 1 : 0;
890
+ return (
891
+ months[month] +
892
+ Math.floor((year - 1969 + t) / 4) -
893
+ Math.floor((year - 1901 + t) / 100) +
894
+ Math.floor((year - 1601 + t) / 400) +
895
+ 365 * (year - 1970)
896
+ );
897
+ }
898
+
899
+ function toUTC(t) {
900
+ return Number(new NativeDate(1970, 0, 1, 0, 0, 0, t));
901
+ }
902
+
903
+ // Copy any custom methods a 3rd party library may have added
904
+ for (var key in NativeDate) {
905
+ Date[key] = NativeDate[key];
906
+ }
907
+
908
+ // Copy "native" methods explicitly; they may be non-enumerable
909
+ Date.now = NativeDate.now;
910
+ Date.UTC = NativeDate.UTC;
911
+ Date.prototype = NativeDate.prototype;
912
+ Date.prototype.constructor = Date;
913
+
914
+ // Upgrade Date.parse to handle simplified ISO 8601 strings
915
+ Date.parse = function parse(string) {
916
+ var match = isoDateExpression.exec(string);
917
+ if (match) {
918
+ // parse months, days, hours, minutes, seconds, and milliseconds
919
+ // provide default values if necessary
920
+ // parse the UTC offset component
921
+ var year = Number(match[1]),
922
+ month = Number(match[2] || 1) - 1,
923
+ day = Number(match[3] || 1) - 1,
924
+ hour = Number(match[4] || 0),
925
+ minute = Number(match[5] || 0),
926
+ second = Number(match[6] || 0),
927
+ millisecond = Math.floor(Number(match[7] || 0) * 1000),
928
+ // When time zone is missed, local offset should be used
929
+ // (ES 5.1 bug)
930
+ // see https://bugs.ecmascript.org/show_bug.cgi?id=112
931
+ isLocalTime = Boolean(match[4] && !match[8]),
932
+ signOffset = match[9] === "-" ? 1 : -1,
933
+ hourOffset = Number(match[10] || 0),
934
+ minuteOffset = Number(match[11] || 0),
935
+ result;
936
+ if (
937
+ hour < (
938
+ minute > 0 || second > 0 || millisecond > 0 ?
939
+ 24 : 25
940
+ ) &&
941
+ minute < 60 && second < 60 && millisecond < 1000 &&
942
+ month > -1 && month < 12 && hourOffset < 24 &&
943
+ minuteOffset < 60 && // detect invalid offsets
944
+ day > -1 &&
945
+ day < (
946
+ dayFromMonth(year, month + 1) -
947
+ dayFromMonth(year, month)
948
+ )
949
+ ) {
950
+ result = (
951
+ (dayFromMonth(year, month) + day) * 24 +
952
+ hour +
953
+ hourOffset * signOffset
954
+ ) * 60;
955
+ result = (
956
+ (result + minute + minuteOffset * signOffset) * 60 +
957
+ second
958
+ ) * 1000 + millisecond;
959
+ if (isLocalTime) {
960
+ result = toUTC(result);
961
+ }
962
+ if (-8.64e15 <= result && result <= 8.64e15) {
963
+ return result;
964
+ }
965
+ }
966
+ return NaN;
967
+ }
968
+ return NativeDate.parse.apply(this, arguments);
969
+ };
970
+
971
+ return Date;
972
+ })(Date);
973
+ }
974
+
975
+ // ES5 15.9.4.4
976
+ // http://es5.github.com/#x15.9.4.4
977
+ if (!Date.now) {
978
+ Date.now = function now() {
979
+ return new Date().getTime();
980
+ };
981
+ }
982
+
983
+
984
+ //
985
+ // Number
986
+ // ======
987
+ //
988
+
989
+ // ES5.1 15.7.4.5
990
+ // http://es5.github.com/#x15.7.4.5
991
+ if (!Number.prototype.toFixed || (0.00008).toFixed(3) !== '0.000' || (0.9).toFixed(0) === '0' || (1.255).toFixed(2) !== '1.25' || (1000000000000000128).toFixed(0) !== "1000000000000000128") {
992
+ // Hide these variables and functions
993
+ (function () {
994
+ var base, size, data, i;
995
+
996
+ base = 1e7;
997
+ size = 6;
998
+ data = [0, 0, 0, 0, 0, 0];
999
+
1000
+ function multiply(n, c) {
1001
+ var i = -1;
1002
+ while (++i < size) {
1003
+ c += n * data[i];
1004
+ data[i] = c % base;
1005
+ c = Math.floor(c / base);
1006
+ }
1007
+ }
1008
+
1009
+ function divide(n) {
1010
+ var i = size, c = 0;
1011
+ while (--i >= 0) {
1012
+ c += data[i];
1013
+ data[i] = Math.floor(c / n);
1014
+ c = (c % n) * base;
1015
+ }
1016
+ }
1017
+
1018
+ function toString() {
1019
+ var i = size;
1020
+ var s = '';
1021
+ while (--i >= 0) {
1022
+ if (s !== '' || i === 0 || data[i] !== 0) {
1023
+ var t = String(data[i]);
1024
+ if (s === '') {
1025
+ s = t;
1026
+ } else {
1027
+ s += '0000000'.slice(0, 7 - t.length) + t;
1028
+ }
1029
+ }
1030
+ }
1031
+ return s;
1032
+ }
1033
+
1034
+ function pow(x, n, acc) {
1035
+ return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc)));
1036
+ }
1037
+
1038
+ function log(x) {
1039
+ var n = 0;
1040
+ while (x >= 4096) {
1041
+ n += 12;
1042
+ x /= 4096;
1043
+ }
1044
+ while (x >= 2) {
1045
+ n += 1;
1046
+ x /= 2;
1047
+ }
1048
+ return n;
1049
+ }
1050
+
1051
+ Number.prototype.toFixed = function (fractionDigits) {
1052
+ var f, x, s, m, e, z, j, k;
1053
+
1054
+ // Test for NaN and round fractionDigits down
1055
+ f = Number(fractionDigits);
1056
+ f = f !== f ? 0 : Math.floor(f);
1057
+
1058
+ if (f < 0 || f > 20) {
1059
+ throw new RangeError("Number.toFixed called with invalid number of decimals");
1060
+ }
1061
+
1062
+ x = Number(this);
1063
+
1064
+ // Test for NaN
1065
+ if (x !== x) {
1066
+ return "NaN";
1067
+ }
1068
+
1069
+ // If it is too big or small, return the string value of the number
1070
+ if (x <= -1e21 || x >= 1e21) {
1071
+ return String(x);
1072
+ }
1073
+
1074
+ s = "";
1075
+
1076
+ if (x < 0) {
1077
+ s = "-";
1078
+ x = -x;
1079
+ }
1080
+
1081
+ m = "0";
1082
+
1083
+ if (x > 1e-21) {
1084
+ // 1e-21 < x < 1e21
1085
+ // -70 < log2(x) < 70
1086
+ e = log(x * pow(2, 69, 1)) - 69;
1087
+ z = (e < 0 ? x * pow(2, -e, 1) : x / pow(2, e, 1));
1088
+ z *= 0x10000000000000; // Math.pow(2, 52);
1089
+ e = 52 - e;
1090
+
1091
+ // -18 < e < 122
1092
+ // x = z / 2 ^ e
1093
+ if (e > 0) {
1094
+ multiply(0, z);
1095
+ j = f;
1096
+
1097
+ while (j >= 7) {
1098
+ multiply(1e7, 0);
1099
+ j -= 7;
1100
+ }
1101
+
1102
+ multiply(pow(10, j, 1), 0);
1103
+ j = e - 1;
1104
+
1105
+ while (j >= 23) {
1106
+ divide(1 << 23);
1107
+ j -= 23;
1108
+ }
1109
+
1110
+ divide(1 << j);
1111
+ multiply(1, 1);
1112
+ divide(2);
1113
+ m = toString();
1114
+ } else {
1115
+ multiply(0, z);
1116
+ multiply(1 << (-e), 0);
1117
+ m = toString() + '0.00000000000000000000'.slice(2, 2 + f);
1118
+ }
1119
+ }
1120
+
1121
+ if (f > 0) {
1122
+ k = m.length;
1123
+
1124
+ if (k <= f) {
1125
+ m = s + '0.0000000000000000000'.slice(0, f - k + 2) + m;
1126
+ } else {
1127
+ m = s + m.slice(0, k - f) + '.' + m.slice(k - f);
1128
+ }
1129
+ } else {
1130
+ m = s + m;
1131
+ }
1132
+
1133
+ return m;
1134
+ }
1135
+ }());
1136
+ }
1137
+
1138
+
1139
+ //
1140
+ // String
1141
+ // ======
1142
+ //
1143
+
1144
+
1145
+ // ES5 15.5.4.14
1146
+ // http://es5.github.com/#x15.5.4.14
1147
+
1148
+ // [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]
1149
+ // Many browsers do not split properly with regular expressions or they
1150
+ // do not perform the split correctly under obscure conditions.
1151
+ // See http://blog.stevenlevithan.com/archives/cross-browser-split
1152
+ // I've tested in many browsers and this seems to cover the deviant ones:
1153
+ // 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
1154
+ // '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
1155
+ // 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
1156
+ // [undefined, "t", undefined, "e", ...]
1157
+ // ''.split(/.?/) should be [], not [""]
1158
+ // '.'.split(/()()/) should be ["."], not ["", "", "."]
1159
+
1160
+ var string_split = String.prototype.split;
1161
+ if (
1162
+ 'ab'.split(/(?:ab)*/).length !== 2 ||
1163
+ '.'.split(/(.?)(.?)/).length !== 4 ||
1164
+ 'tesst'.split(/(s)*/)[1] === "t" ||
1165
+ ''.split(/.?/).length ||
1166
+ '.'.split(/()()/).length > 1
1167
+ ) {
1168
+ (function () {
1169
+ var compliantExecNpcg = /()??/.exec("")[1] === void 0; // NPCG: nonparticipating capturing group
1170
+
1171
+ String.prototype.split = function (separator, limit) {
1172
+ var string = this;
1173
+ if (separator === void 0 && limit === 0)
1174
+ return [];
1175
+
1176
+ // If `separator` is not a regex, use native split
1177
+ if (Object.prototype.toString.call(separator) !== "[object RegExp]") {
1178
+ return string_split.apply(this, arguments);
1179
+ }
1180
+
1181
+ var output = [],
1182
+ flags = (separator.ignoreCase ? "i" : "") +
1183
+ (separator.multiline ? "m" : "") +
1184
+ (separator.extended ? "x" : "") + // Proposed for ES6
1185
+ (separator.sticky ? "y" : ""), // Firefox 3+
1186
+ lastLastIndex = 0,
1187
+ // Make `global` and avoid `lastIndex` issues by working with a copy
1188
+ separator = new RegExp(separator.source, flags + "g"),
1189
+ separator2, match, lastIndex, lastLength;
1190
+ string += ""; // Type-convert
1191
+ if (!compliantExecNpcg) {
1192
+ // Doesn't need flags gy, but they don't hurt
1193
+ separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags);
1194
+ }
1195
+ /* Values for `limit`, per the spec:
1196
+ * If undefined: 4294967295 // Math.pow(2, 32) - 1
1197
+ * If 0, Infinity, or NaN: 0
1198
+ * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
1199
+ * If negative number: 4294967296 - Math.floor(Math.abs(limit))
1200
+ * If other: Type-convert, then use the above rules
1201
+ */
1202
+ limit = limit === void 0 ?
1203
+ -1 >>> 0 : // Math.pow(2, 32) - 1
1204
+ limit >>> 0; // ToUint32(limit)
1205
+ while (match = separator.exec(string)) {
1206
+ // `separator.lastIndex` is not reliable cross-browser
1207
+ lastIndex = match.index + match[0].length;
1208
+ if (lastIndex > lastLastIndex) {
1209
+ output.push(string.slice(lastLastIndex, match.index));
1210
+ // Fix browsers whose `exec` methods don't consistently return `undefined` for
1211
+ // nonparticipating capturing groups
1212
+ if (!compliantExecNpcg && match.length > 1) {
1213
+ match[0].replace(separator2, function () {
1214
+ for (var i = 1; i < arguments.length - 2; i++) {
1215
+ if (arguments[i] === void 0) {
1216
+ match[i] = void 0;
1217
+ }
1218
+ }
1219
+ });
1220
+ }
1221
+ if (match.length > 1 && match.index < string.length) {
1222
+ Array.prototype.push.apply(output, match.slice(1));
1223
+ }
1224
+ lastLength = match[0].length;
1225
+ lastLastIndex = lastIndex;
1226
+ if (output.length >= limit) {
1227
+ break;
1228
+ }
1229
+ }
1230
+ if (separator.lastIndex === match.index) {
1231
+ separator.lastIndex++; // Avoid an infinite loop
1232
+ }
1233
+ }
1234
+ if (lastLastIndex === string.length) {
1235
+ if (lastLength || !separator.test("")) {
1236
+ output.push("");
1237
+ }
1238
+ } else {
1239
+ output.push(string.slice(lastLastIndex));
1240
+ }
1241
+ return output.length > limit ? output.slice(0, limit) : output;
1242
+ };
1243
+ }());
1244
+
1245
+ // [bugfix, chrome]
1246
+ // If separator is undefined, then the result array contains just one String,
1247
+ // which is the this value (converted to a String). If limit is not undefined,
1248
+ // then the output array is truncated so that it contains no more than limit
1249
+ // elements.
1250
+ // "0".split(undefined, 0) -> []
1251
+ } else if ("0".split(void 0, 0).length) {
1252
+ String.prototype.split = function(separator, limit) {
1253
+ if (separator === void 0 && limit === 0) return [];
1254
+ return string_split.apply(this, arguments);
1255
+ }
1256
+ }
1257
+
1258
+
1259
+ // ECMA-262, 3rd B.2.3
1260
+ // Note an ECMAScript standart, although ECMAScript 3rd Edition has a
1261
+ // non-normative section suggesting uniform semantics and it should be
1262
+ // normalized across all browsers
1263
+ // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
1264
+ if ("".substr && "0b".substr(-1) !== "b") {
1265
+ var string_substr = String.prototype.substr;
1266
+ /**
1267
+ * Get the substring of a string
1268
+ * @param {integer} start where to start the substring
1269
+ * @param {integer} length how many characters to return
1270
+ * @return {string}
1271
+ */
1272
+ String.prototype.substr = function(start, length) {
1273
+ return string_substr.call(
1274
+ this,
1275
+ start < 0 ? ((start = this.length + start) < 0 ? 0 : start) : start,
1276
+ length
1277
+ );
1278
+ }
1279
+ }
1280
+
1281
+ // ES5 15.5.4.20
1282
+ // whitespace from: http://es5.github.io/#x15.5.4.20
1283
+ var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
1284
+ "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
1285
+ "\u2029\uFEFF";
1286
+ if (!String.prototype.trim || ws.trim()) {
1287
+ // http://blog.stevenlevithan.com/archives/faster-trim-javascript
1288
+ // http://perfectionkills.com/whitespace-deviations/
1289
+ ws = "[" + ws + "]";
1290
+ var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
1291
+ trimEndRegexp = new RegExp(ws + ws + "*$");
1292
+ String.prototype.trim = function trim() {
1293
+ if (this === void 0 || this === null) {
1294
+ throw new TypeError("can't convert "+this+" to object");
1295
+ }
1296
+ return String(this)
1297
+ .replace(trimBeginRegexp, "")
1298
+ .replace(trimEndRegexp, "");
1299
+ };
1300
+ }
1301
+
1302
+ // ES-5 15.1.2.2
1303
+ if (parseInt(ws + '08') !== 8 || parseInt(ws + '0x16') !== 22) {
1304
+ parseInt = (function (origParseInt) {
1305
+ var hexRegex = /^0[xX]/;
1306
+ return function parseIntES5(str, radix) {
1307
+ str = String(str).trim();
1308
+ if (!+radix) {
1309
+ radix = hexRegex.test(str) ? 16 : 10;
1310
+ }
1311
+ return origParseInt(str, radix);
1312
+ };
1313
+ }(parseInt));
1314
+ }
1315
+
1316
+ //
1317
+ // Util
1318
+ // ======
1319
+ //
1320
+
1321
+ // ES5 9.4
1322
+ // http://es5.github.com/#x9.4
1323
+ // http://jsperf.com/to-integer
1324
+
1325
+ function toInteger(n) {
1326
+ n = +n;
1327
+ if (n !== n) { // isNaN
1328
+ n = 0;
1329
+ } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
1330
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
1331
+ }
1332
+ return n;
1333
+ }
1334
+
1335
+ function isPrimitive(input) {
1336
+ var type = typeof input;
1337
+ return (
1338
+ input === null ||
1339
+ type === "undefined" ||
1340
+ type === "boolean" ||
1341
+ type === "number" ||
1342
+ type === "string"
1343
+ );
1344
+ }
1345
+
1346
+ function toPrimitive(input) {
1347
+ var val, valueOf, toString;
1348
+ if (isPrimitive(input)) {
1349
+ return input;
1350
+ }
1351
+ valueOf = input.valueOf;
1352
+ if (typeof valueOf === "function") {
1353
+ val = valueOf.call(input);
1354
+ if (isPrimitive(val)) {
1355
+ return val;
1356
+ }
1357
+ }
1358
+ toString = input.toString;
1359
+ if (typeof toString === "function") {
1360
+ val = toString.call(input);
1361
+ if (isPrimitive(val)) {
1362
+ return val;
1363
+ }
1364
+ }
1365
+ throw new TypeError();
1366
+ }
1367
+
1368
+ // ES5 9.9
1369
+ // http://es5.github.com/#x9.9
1370
+ var toObject = function (o) {
1371
+ if (o == null) { // this matches both null and undefined
1372
+ throw new TypeError("can't convert "+o+" to object");
1373
+ }
1374
+ return Object(o);
1375
+ };
1376
+
1377
+ }));