PluginProbe
HTML Forms – Simple WordPress Forms Plugin / 1.1.2
HTML Forms – Simple WordPress Forms Plugin v1.1.2
1.7.0 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.3.0 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 All 67 releases
html-forms / assets / js / public.js

public.js in HTML Forms – Simple WordPress Forms Plugin 1.1.2, at assets/js/public.js

3,109 lines 119.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () { var require = undefined; var module = undefined; var exports = undefined; var define = undefined;(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2 'use strict';
3
4 Object.defineProperty(exports, "__esModule", {
5 value: true
6 });
7 function toggleElement(el, expectedValue, show) {
8 return function (input) {
9 var value = input.value.trim();
10 var checked = input.getAttribute('type') !== 'radio' && input.getAttribute('type') !== 'checked' || input.checked;
11 var conditionMet = checked && (value === expectedValue && expectedValue !== "" || expectedValue === "" && value.length > 0);
12 if (show) {
13 el.style.display = conditionMet ? '' : 'none';
14 } else {
15 el.style.display = conditionMet ? 'none' : '';
16 }
17
18 // find all input children and toggle [required] attr
19 var inputs = el.querySelectorAll('input, select, textarea');
20 [].forEach.call(inputs, function (el) {
21 if ((conditionMet || show) && el.getAttribute('data-was-required')) {
22 el.required = true;
23 el.removeAttribute('data-was-required');
24 }
25
26 if ((!conditionMet || !show) && el.required) {
27 el.setAttribute('data-was-required', "true");
28 el.required = false;
29 }
30 });
31 };
32 }
33
34 function toggleDependents(input) {
35 var elements = input.form.querySelectorAll('[data-show-if], [data-hide-if]');
36 var inputName = (input.getAttribute('name') || '').toLowerCase();
37
38 [].forEach.call(elements, function (el) {
39 var show = !!el.getAttribute('data-show-if');
40 var conditions = show ? el.getAttribute('data-show-if').split(':') : el.getAttribute('data-hide-if').split(':');
41 var nameCondition = conditions[0];
42 var valueCondition = conditions[1] || "";
43
44 if (inputName !== nameCondition.toLowerCase()) {
45 return;
46 }
47
48 var callback = toggleElement(el, valueCondition, show);
49 callback(input);
50 });
51 }
52
53 function findInputsAndToggleDepepents() {
54 var inputElements = document.querySelectorAll('.hf-form input, .hf-form textarea, .hf-form select');
55 [].forEach.call(inputElements, toggleDependents);
56 }
57
58 function handleInputEvent(evt) {
59 if (evt.target && evt.target.form && evt.target.form.className.indexOf('hf-form') > -1) {
60 toggleDependents(evt.target);
61 }
62 }
63
64 exports.default = {
65 'init': function init() {
66 findInputsAndToggleDepepents();
67 document.addEventListener('click', handleInputEvent, true);
68 document.addEventListener('keyup', handleInputEvent, true);
69 document.addEventListener('change', handleInputEvent, true);
70 document.addEventListener('hf-refresh', findInputsAndToggleDepepents, true);
71 window.addEventListener('load', findInputsAndToggleDepepents);
72 }
73 };
74
75 },{}],2:[function(require,module,exports){
76 'use strict';
77
78 function getButtonText(button) {
79 return button.innerHTML ? button.innerHTML : button.value;
80 }
81
82 function setButtonText(button, text) {
83 button.innerHTML ? button.innerHTML = text : button.value = text;
84 }
85
86 function Loader(formElement) {
87 this.form = formElement;
88 this.button = formElement.querySelector('input[type="submit"], button[type="submit"]');
89 this.loadingInterval = 0;
90 this.character = '\xB7';
91
92 if (this.button) {
93 this.originalButton = this.button.cloneNode(true);
94 }
95 }
96
97 Loader.prototype.setCharacter = function (c) {
98 this.character = c;
99 };
100
101 Loader.prototype.start = function () {
102 if (this.button) {
103 // loading text
104 var loadingText = this.button.getAttribute('data-loading-text');
105 if (loadingText) {
106 setButtonText(this.button, loadingText);
107 return;
108 }
109
110 // Show AJAX loader
111 var styles = window.getComputedStyle(this.button);
112 this.button.style.width = styles.width;
113 setButtonText(this.button, this.character);
114 this.loadingInterval = window.setInterval(this.tick.bind(this), 500);
115 } else {
116 this.form.style.opacity = '0.5';
117 }
118 };
119
120 Loader.prototype.tick = function () {
121 // count chars, start over at 5
122 var text = getButtonText(this.button);
123 var loadingChar = this.character;
124 setButtonText(this.button, text.length >= 5 ? loadingChar : text + " " + loadingChar);
125 };
126
127 Loader.prototype.stop = function () {
128 if (this.button) {
129 this.button.style.width = this.originalButton.style.width;
130 var text = getButtonText(this.originalButton);
131 setButtonText(this.button, text);
132 window.clearInterval(this.loadingInterval);
133 } else {
134 this.form.style.opacity = '';
135 }
136 };
137
138 module.exports = Loader;
139
140 },{}],3:[function(require,module,exports){
141 "use strict";
142
143 var _conditionalElements = require('./conditional-elements.js');
144
145 var _conditionalElements2 = _interopRequireDefault(_conditionalElements);
146
147 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
148
149 var shim = require('es5-shim');
150 var serialize = require('form-serialize');
151 var Loader = require('./form-loading-indicator.js');
152 var vars = window.hf_js_vars || { ajax_url: window.location.href };
153 var EventEmitter = require('wolfy87-eventemitter');
154 var events = new EventEmitter();
155
156
157 function cleanFormMessages(formEl) {
158 var messageElements = formEl.querySelectorAll('.hf-message');
159 [].forEach.call(messageElements, function (el) {
160 el.parentNode.removeChild(el);
161 });
162 }
163
164 function addFormMessage(formEl, message) {
165 var txtElement = document.createElement('p');
166 txtElement.className = 'hf-message hf-message-' + message.type;
167 txtElement.innerHTML = message.text;
168 formEl.insertBefore(txtElement, formEl.lastElementChild.nextElementSibling);
169 }
170
171 function handleSubmitEvents(e) {
172 var formEl = e.target;
173
174 // only act on html-forms
175 if (formEl.className.indexOf('hf-form') < 0) {
176 return;
177 }
178
179 e.preventDefault();
180 submitForm(formEl);
181 }
182
183 function submitForm(formEl) {
184 events.emit('submit', [formEl]);
185
186 var data = serialize(formEl, { "hash": false, "empty": true });
187 var request = new XMLHttpRequest();
188
189 cleanFormMessages(formEl);
190 request.onreadystatechange = createRequestHandler(formEl);
191 request.open('POST', vars.ajax_url, true);
192 request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
193 request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
194 request.send(data);
195 request = null;
196 }
197
198 function createRequestHandler(formEl) {
199 var loader = new Loader(formEl);
200 loader.start();
201
202 return function () {
203 // are we done?
204 if (this.readyState === 4) {
205 var response = void 0;
206 loader.stop();
207
208 if (this.status >= 200 && this.status < 400) {
209 try {
210 response = JSON.parse(this.responseText);
211 } catch (error) {
212 console.log('HTML Forms: failed to parse AJAX response.\n\nError: "' + error + '"');
213 return;
214 }
215
216 events.emit('submitted', [formEl]);
217
218 if (response.error) {
219 events.emit('error', [formEl]);
220 } else {
221 events.emit('success', [formEl]);
222 }
223
224 // Show form message
225 if (response.message) {
226 addFormMessage(formEl, response.message);
227 }
228
229 // Should we hide form?
230 if (response.hide_form) {
231 formEl.querySelector('.hf-fields-wrap').style.display = 'none';
232 }
233
234 // Should we redirect?
235 if (response.redirect_url) {
236 window.location = response.redirect_url;
237 }
238
239 // clear form
240 if (!response.error) {
241 formEl.reset();
242 }
243 } else {
244 // Server error :(
245 console.log(this.responseText);
246 }
247 }
248 };
249 }
250
251 document.addEventListener('submit', handleSubmitEvents, true);
252 _conditionalElements2.default.init();
253
254 window.html_forms = {
255 'on': events.on.bind(events)
256 };
257
258 },{"./conditional-elements.js":1,"./form-loading-indicator.js":2,"es5-shim":4,"form-serialize":5,"wolfy87-eventemitter":6}],4:[function(require,module,exports){
259 /*!
260 * https://github.com/es-shims/es5-shim
261 * @license es5-shim Copyright 2009-2015 by contributors, MIT License
262 * see https://github.com/es-shims/es5-shim/blob/master/LICENSE
263 */
264
265 // vim: ts=4 sts=4 sw=4 expandtab
266
267 // Add semicolon to prevent IIFE from being passed as argument to concatenated code.
268 ;
269
270 // UMD (Universal Module Definition)
271 // see https://github.com/umdjs/umd/blob/master/templates/returnExports.js
272 (function (root, factory) {
273 'use strict';
274
275 /* global define, exports, module */
276 if (typeof define === 'function' && define.amd) {
277 // AMD. Register as an anonymous module.
278 define(factory);
279 } else if (typeof exports === 'object') {
280 // Node. Does not work with strict CommonJS, but
281 // only CommonJS-like enviroments that support module.exports,
282 // like Node.
283 module.exports = factory();
284 } else {
285 // Browser globals (root is window)
286 root.returnExports = factory();
287 }
288 }(this, function () {
289 /**
290 * Brings an environment as close to ECMAScript 5 compliance
291 * as is possible with the facilities of erstwhile engines.
292 *
293 * Annotated ES5: http://es5.github.com/ (specific links below)
294 * ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
295 * Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
296 */
297
298 // Shortcut to an often accessed properties, in order to avoid multiple
299 // dereference that costs universally. This also holds a reference to known-good
300 // functions.
301 var $Array = Array;
302 var ArrayPrototype = $Array.prototype;
303 var $Object = Object;
304 var ObjectPrototype = $Object.prototype;
305 var $Function = Function;
306 var FunctionPrototype = $Function.prototype;
307 var $String = String;
308 var StringPrototype = $String.prototype;
309 var $Number = Number;
310 var NumberPrototype = $Number.prototype;
311 var array_slice = ArrayPrototype.slice;
312 var array_splice = ArrayPrototype.splice;
313 var array_push = ArrayPrototype.push;
314 var array_unshift = ArrayPrototype.unshift;
315 var array_concat = ArrayPrototype.concat;
316 var array_join = ArrayPrototype.join;
317 var call = FunctionPrototype.call;
318 var apply = FunctionPrototype.apply;
319 var max = Math.max;
320 var min = Math.min;
321
322 // Having a toString local variable name breaks in Opera so use to_string.
323 var to_string = ObjectPrototype.toString;
324
325 /* global Symbol */
326 /* eslint-disable one-var-declaration-per-line, no-redeclare, max-statements-per-line */
327 var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
328 var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, constructorRegex = /^\s*class /, isES6ClassFn = function isES6ClassFn(value) { try { var fnStr = fnToStr.call(value); var singleStripped = fnStr.replace(/\/\/.*\n/g, ''); var multiStripped = singleStripped.replace(/\/\*[.\s\S]*\*\//g, ''); var spaceStripped = multiStripped.replace(/\n/mg, ' ').replace(/ {2}/g, ' '); return constructorRegex.test(spaceStripped); } catch (e) { return false; /* not a function */ } }, tryFunctionObject = function tryFunctionObject(value) { try { if (isES6ClassFn(value)) { return false; } fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]', isCallable = function isCallable(value) { if (!value) { return false; } if (typeof value !== 'function' && typeof value !== 'object') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } if (isES6ClassFn(value)) { return false; } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; };
329
330 var isRegex; /* inlined from https://npmjs.com/is-regex */ var regexExec = RegExp.prototype.exec, tryRegexExec = function tryRegexExec(value) { try { regexExec.call(value); return true; } catch (e) { return false; } }, regexClass = '[object RegExp]'; isRegex = function isRegex(value) { if (typeof value !== 'object') { return false; } return hasToStringTag ? tryRegexExec(value) : to_string.call(value) === regexClass; };
331 var isString; /* inlined from https://npmjs.com/is-string */ var strValue = String.prototype.valueOf, tryStringObject = function tryStringObject(value) { try { strValue.call(value); return true; } catch (e) { return false; } }, stringClass = '[object String]'; isString = function isString(value) { if (typeof value === 'string') { return true; } if (typeof value !== 'object') { return false; } return hasToStringTag ? tryStringObject(value) : to_string.call(value) === stringClass; };
332 /* eslint-enable one-var-declaration-per-line, no-redeclare, max-statements-per-line */
333
334 /* inlined from http://npmjs.com/define-properties */
335 var supportsDescriptors = $Object.defineProperty && (function () {
336 try {
337 var obj = {};
338 $Object.defineProperty(obj, 'x', { enumerable: false, value: obj });
339 for (var _ in obj) { // jscs:ignore disallowUnusedVariables
340 return false;
341 }
342 return obj.x === obj;
343 } catch (e) { /* this is ES3 */
344 return false;
345 }
346 }());
347 var defineProperties = (function (has) {
348 // Define configurable, writable, and non-enumerable props
349 // if they don't exist.
350 var defineProperty;
351 if (supportsDescriptors) {
352 defineProperty = function (object, name, method, forceAssign) {
353 if (!forceAssign && (name in object)) {
354 return;
355 }
356 $Object.defineProperty(object, name, {
357 configurable: true,
358 enumerable: false,
359 writable: true,
360 value: method
361 });
362 };
363 } else {
364 defineProperty = function (object, name, method, forceAssign) {
365 if (!forceAssign && (name in object)) {
366 return;
367 }
368 object[name] = method;
369 };
370 }
371 return function defineProperties(object, map, forceAssign) {
372 for (var name in map) {
373 if (has.call(map, name)) {
374 defineProperty(object, name, map[name], forceAssign);
375 }
376 }
377 };
378 }(ObjectPrototype.hasOwnProperty));
379
380 //
381 // Util
382 // ======
383 //
384
385 /* replaceable with https://npmjs.com/package/es-abstract /helpers/isPrimitive */
386 var isPrimitive = function isPrimitive(input) {
387 var type = typeof input;
388 return input === null || (type !== 'object' && type !== 'function');
389 };
390
391 var isActualNaN = $Number.isNaN || function isActualNaN(x) {
392 return x !== x;
393 };
394
395 var ES = {
396 // ES5 9.4
397 // http://es5.github.com/#x9.4
398 // http://jsperf.com/to-integer
399 /* replaceable with https://npmjs.com/package/es-abstract ES5.ToInteger */
400 ToInteger: function ToInteger(num) {
401 var n = +num;
402 if (isActualNaN(n)) {
403 n = 0;
404 } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
405 n = (n > 0 || -1) * Math.floor(Math.abs(n));
406 }
407 return n;
408 },
409
410 /* replaceable with https://npmjs.com/package/es-abstract ES5.ToPrimitive */
411 ToPrimitive: function ToPrimitive(input) {
412 var val, valueOf, toStr;
413 if (isPrimitive(input)) {
414 return input;
415 }
416 valueOf = input.valueOf;
417 if (isCallable(valueOf)) {
418 val = valueOf.call(input);
419 if (isPrimitive(val)) {
420 return val;
421 }
422 }
423 toStr = input.toString;
424 if (isCallable(toStr)) {
425 val = toStr.call(input);
426 if (isPrimitive(val)) {
427 return val;
428 }
429 }
430 throw new TypeError();
431 },
432
433 // ES5 9.9
434 // http://es5.github.com/#x9.9
435 /* replaceable with https://npmjs.com/package/es-abstract ES5.ToObject */
436 ToObject: function (o) {
437 if (o == null) { // this matches both null and undefined
438 throw new TypeError("can't convert " + o + ' to object');
439 }
440 return $Object(o);
441 },
442
443 /* replaceable with https://npmjs.com/package/es-abstract ES5.ToUint32 */
444 ToUint32: function ToUint32(x) {
445 return x >>> 0;
446 }
447 };
448
449 //
450 // Function
451 // ========
452 //
453
454 // ES-5 15.3.4.5
455 // http://es5.github.com/#x15.3.4.5
456
457 var Empty = function Empty() {};
458
459 defineProperties(FunctionPrototype, {
460 bind: function bind(that) { // .length is 1
461 // 1. Let Target be the this value.
462 var target = this;
463 // 2. If IsCallable(Target) is false, throw a TypeError exception.
464 if (!isCallable(target)) {
465 throw new TypeError('Function.prototype.bind called on incompatible ' + target);
466 }
467 // 3. Let A be a new (possibly empty) internal list of all of the
468 // argument values provided after thisArg (arg1, arg2 etc), in order.
469 // XXX slicedArgs will stand in for "A" if used
470 var args = array_slice.call(arguments, 1); // for normal call
471 // 4. Let F be a new native ECMAScript object.
472 // 11. Set the [[Prototype]] internal property of F to the standard
473 // built-in Function prototype object as specified in 15.3.3.1.
474 // 12. Set the [[Call]] internal property of F as described in
475 // 15.3.4.5.1.
476 // 13. Set the [[Construct]] internal property of F as described in
477 // 15.3.4.5.2.
478 // 14. Set the [[HasInstance]] internal property of F as described in
479 // 15.3.4.5.3.
480 var bound;
481 var binder = function () {
482
483 if (this instanceof bound) {
484 // 15.3.4.5.2 [[Construct]]
485 // When the [[Construct]] internal method of a function object,
486 // F that was created using the bind function is called with a
487 // list of arguments ExtraArgs, the following steps are taken:
488 // 1. Let target be the value of F's [[TargetFunction]]
489 // internal property.
490 // 2. If target has no [[Construct]] internal method, a
491 // TypeError exception is thrown.
492 // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
493 // property.
494 // 4. Let args be a new list containing the same values as the
495 // list boundArgs in the same order followed by the same
496 // values as the list ExtraArgs in the same order.
497 // 5. Return the result of calling the [[Construct]] internal
498 // method of target providing args as the arguments.
499
500 var result = apply.call(
501 target,
502 this,
503 array_concat.call(args, array_slice.call(arguments))
504 );
505 if ($Object(result) === result) {
506 return result;
507 }
508 return this;
509
510 } else {
511 // 15.3.4.5.1 [[Call]]
512 // When the [[Call]] internal method of a function object, F,
513 // which was created using the bind function is called with a
514 // this value and a list of arguments ExtraArgs, the following
515 // steps are taken:
516 // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
517 // property.
518 // 2. Let boundThis be the value of F's [[BoundThis]] internal
519 // property.
520 // 3. Let target be the value of F's [[TargetFunction]] internal
521 // property.
522 // 4. Let args be a new list containing the same values as the
523 // list boundArgs in the same order followed by the same
524 // values as the list ExtraArgs in the same order.
525 // 5. Return the result of calling the [[Call]] internal method
526 // of target providing boundThis as the this value and
527 // providing args as the arguments.
528
529 // equiv: target.call(this, ...boundArgs, ...args)
530 return apply.call(
531 target,
532 that,
533 array_concat.call(args, array_slice.call(arguments))
534 );
535
536 }
537
538 };
539
540 // 15. If the [[Class]] internal property of Target is "Function", then
541 // a. Let L be the length property of Target minus the length of A.
542 // b. Set the length own property of F to either 0 or L, whichever is
543 // larger.
544 // 16. Else set the length own property of F to 0.
545
546 var boundLength = max(0, target.length - args.length);
547
548 // 17. Set the attributes of the length own property of F to the values
549 // specified in 15.3.5.1.
550 var boundArgs = [];
551 for (var i = 0; i < boundLength; i++) {
552 array_push.call(boundArgs, '$' + i);
553 }
554
555 // XXX Build a dynamic function with desired amount of arguments is the only
556 // way to set the length property of a function.
557 // In environments where Content Security Policies enabled (Chrome extensions,
558 // for ex.) all use of eval or Function costructor throws an exception.
559 // However in all of these environments Function.prototype.bind exists
560 // and so this code will never be executed.
561 bound = $Function('binder', 'return function (' + array_join.call(boundArgs, ',') + '){ return binder.apply(this, arguments); }')(binder);
562
563 if (target.prototype) {
564 Empty.prototype = target.prototype;
565 bound.prototype = new Empty();
566 // Clean up dangling references.
567 Empty.prototype = null;
568 }
569
570 // TODO
571 // 18. Set the [[Extensible]] internal property of F to true.
572
573 // TODO
574 // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
575 // 20. Call the [[DefineOwnProperty]] internal method of F with
576 // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
577 // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
578 // false.
579 // 21. Call the [[DefineOwnProperty]] internal method of F with
580 // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
581 // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
582 // and false.
583
584 // TODO
585 // NOTE Function objects created using Function.prototype.bind do not
586 // have a prototype property or the [[Code]], [[FormalParameters]], and
587 // [[Scope]] internal properties.
588 // XXX can't delete prototype in pure-js.
589
590 // 22. Return F.
591 return bound;
592 }
593 });
594
595 // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
596 // use it in defining shortcuts.
597 var owns = call.bind(ObjectPrototype.hasOwnProperty);
598 var toStr = call.bind(ObjectPrototype.toString);
599 var arraySlice = call.bind(array_slice);
600 var arraySliceApply = apply.bind(array_slice);
601 /* globals document */
602 if (typeof document === 'object' && document && document.documentElement) {
603 try {
604 arraySlice(document.documentElement.childNodes);
605 } catch (e) {
606 var origArraySlice = arraySlice;
607 var origArraySliceApply = arraySliceApply;
608 arraySlice = function arraySliceIE(arr) {
609 var r = [];
610 var i = arr.length;
611 while (i-- > 0) {
612 r[i] = arr[i];
613 }
614 return origArraySliceApply(r, origArraySlice(arguments, 1));
615 };
616 arraySliceApply = function arraySliceApplyIE(arr, args) {
617 return origArraySliceApply(arraySlice(arr), args);
618 };
619 }
620 }
621 var strSlice = call.bind(StringPrototype.slice);
622 var strSplit = call.bind(StringPrototype.split);
623 var strIndexOf = call.bind(StringPrototype.indexOf);
624 var pushCall = call.bind(array_push);
625 var isEnum = call.bind(ObjectPrototype.propertyIsEnumerable);
626 var arraySort = call.bind(ArrayPrototype.sort);
627
628 //
629 // Array
630 // =====
631 //
632
633 var isArray = $Array.isArray || function isArray(obj) {
634 return toStr(obj) === '[object Array]';
635 };
636
637 // ES5 15.4.4.12
638 // http://es5.github.com/#x15.4.4.13
639 // Return len+argCount.
640 // [bugfix, ielt8]
641 // IE < 8 bug: [].unshift(0) === undefined but should be "1"
642 var hasUnshiftReturnValueBug = [].unshift(0) !== 1;
643 defineProperties(ArrayPrototype, {
644 unshift: function () {
645 array_unshift.apply(this, arguments);
646 return this.length;
647 }
648 }, hasUnshiftReturnValueBug);
649
650 // ES5 15.4.3.2
651 // http://es5.github.com/#x15.4.3.2
652 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
653 defineProperties($Array, { isArray: isArray });
654
655 // The IsCallable() check in the Array functions
656 // has been replaced with a strict check on the
657 // internal class of the object to trap cases where
658 // the provided function was actually a regular
659 // expression literal, which in V8 and
660 // JavaScriptCore is a typeof "function". Only in
661 // V8 are regular expression literals permitted as
662 // reduce parameters, so it is desirable in the
663 // general case for the shim to match the more
664 // strict and common behavior of rejecting regular
665 // expressions.
666
667 // ES5 15.4.4.18
668 // http://es5.github.com/#x15.4.4.18
669 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
670
671 // Check failure of by-index access of string characters (IE < 9)
672 // and failure of `0 in boxedString` (Rhino)
673 var boxedString = $Object('a');
674 var splitString = boxedString[0] !== 'a' || !(0 in boxedString);
675
676 var properlyBoxesContext = function properlyBoxed(method) {
677 // Check node 0.6.21 bug where third parameter is not boxed
678 var properlyBoxesNonStrict = true;
679 var properlyBoxesStrict = true;
680 var threwException = false;
681 if (method) {
682 try {
683 method.call('foo', function (_, __, context) {
684 if (typeof context !== 'object') {
685 properlyBoxesNonStrict = false;
686 }
687 });
688
689 method.call([1], function () {
690 'use strict';
691
692 properlyBoxesStrict = typeof this === 'string';
693 }, 'x');
694 } catch (e) {
695 threwException = true;
696 }
697 }
698 return !!method && !threwException && properlyBoxesNonStrict && properlyBoxesStrict;
699 };
700
701 defineProperties(ArrayPrototype, {
702 forEach: function forEach(callbackfn/*, thisArg*/) {
703 var object = ES.ToObject(this);
704 var self = splitString && isString(this) ? strSplit(this, '') : object;
705 var i = -1;
706 var length = ES.ToUint32(self.length);
707 var T;
708 if (arguments.length > 1) {
709 T = arguments[1];
710 }
711
712 // If no callback function or if callback is not a callable function
713 if (!isCallable(callbackfn)) {
714 throw new TypeError('Array.prototype.forEach callback must be a function');
715 }
716
717 while (++i < length) {
718 if (i in self) {
719 // Invoke the callback function with call, passing arguments:
720 // context, property value, property key, thisArg object
721 if (typeof T === 'undefined') {
722 callbackfn(self[i], i, object);
723 } else {
724 callbackfn.call(T, self[i], i, object);
725 }
726 }
727 }
728 }
729 }, !properlyBoxesContext(ArrayPrototype.forEach));
730
731 // ES5 15.4.4.19
732 // http://es5.github.com/#x15.4.4.19
733 // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
734 defineProperties(ArrayPrototype, {
735 map: function map(callbackfn/*, thisArg*/) {
736 var object = ES.ToObject(this);
737 var self = splitString && isString(this) ? strSplit(this, '') : object;
738 var length = ES.ToUint32(self.length);
739 var result = $Array(length);
740 var T;
741 if (arguments.length > 1) {
742 T = arguments[1];
743 }
744
745 // If no callback function or if callback is not a callable function
746 if (!isCallable(callbackfn)) {
747 throw new TypeError('Array.prototype.map callback must be a function');
748 }
749
750 for (var i = 0; i < length; i++) {
751 if (i in self) {
752 if (typeof T === 'undefined') {
753 result[i] = callbackfn(self[i], i, object);
754 } else {
755 result[i] = callbackfn.call(T, self[i], i, object);
756 }
757 }
758 }
759 return result;
760 }
761 }, !properlyBoxesContext(ArrayPrototype.map));
762
763 // ES5 15.4.4.20
764 // http://es5.github.com/#x15.4.4.20
765 // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
766 defineProperties(ArrayPrototype, {
767 filter: function filter(callbackfn/*, thisArg*/) {
768 var object = ES.ToObject(this);
769 var self = splitString && isString(this) ? strSplit(this, '') : object;
770 var length = ES.ToUint32(self.length);
771 var result = [];
772 var value;
773 var T;
774 if (arguments.length > 1) {
775 T = arguments[1];
776 }
777
778 // If no callback function or if callback is not a callable function
779 if (!isCallable(callbackfn)) {
780 throw new TypeError('Array.prototype.filter callback must be a function');
781 }
782
783 for (var i = 0; i < length; i++) {
784 if (i in self) {
785 value = self[i];
786 if (typeof T === 'undefined' ? callbackfn(value, i, object) : callbackfn.call(T, value, i, object)) {
787 pushCall(result, value);
788 }
789 }
790 }
791 return result;
792 }
793 }, !properlyBoxesContext(ArrayPrototype.filter));
794
795 // ES5 15.4.4.16
796 // http://es5.github.com/#x15.4.4.16
797 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
798 defineProperties(ArrayPrototype, {
799 every: function every(callbackfn/*, thisArg*/) {
800 var object = ES.ToObject(this);
801 var self = splitString && isString(this) ? strSplit(this, '') : object;
802 var length = ES.ToUint32(self.length);
803 var T;
804 if (arguments.length > 1) {
805 T = arguments[1];
806 }
807
808 // If no callback function or if callback is not a callable function
809 if (!isCallable(callbackfn)) {
810 throw new TypeError('Array.prototype.every callback must be a function');
811 }
812
813 for (var i = 0; i < length; i++) {
814 if (i in self && !(typeof T === 'undefined' ? callbackfn(self[i], i, object) : callbackfn.call(T, self[i], i, object))) {
815 return false;
816 }
817 }
818 return true;
819 }
820 }, !properlyBoxesContext(ArrayPrototype.every));
821
822 // ES5 15.4.4.17
823 // http://es5.github.com/#x15.4.4.17
824 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
825 defineProperties(ArrayPrototype, {
826 some: function some(callbackfn/*, thisArg */) {
827 var object = ES.ToObject(this);
828 var self = splitString && isString(this) ? strSplit(this, '') : object;
829 var length = ES.ToUint32(self.length);
830 var T;
831 if (arguments.length > 1) {
832 T = arguments[1];
833 }
834
835 // If no callback function or if callback is not a callable function
836 if (!isCallable(callbackfn)) {
837 throw new TypeError('Array.prototype.some callback must be a function');
838 }
839
840 for (var i = 0; i < length; i++) {
841 if (i in self && (typeof T === 'undefined' ? callbackfn(self[i], i, object) : callbackfn.call(T, self[i], i, object))) {
842 return true;
843 }
844 }
845 return false;
846 }
847 }, !properlyBoxesContext(ArrayPrototype.some));
848
849 // ES5 15.4.4.21
850 // http://es5.github.com/#x15.4.4.21
851 // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
852 var reduceCoercesToObject = false;
853 if (ArrayPrototype.reduce) {
854 reduceCoercesToObject = typeof ArrayPrototype.reduce.call('es5', function (_, __, ___, list) {
855 return list;
856 }) === 'object';
857 }
858 defineProperties(ArrayPrototype, {
859 reduce: function reduce(callbackfn/*, initialValue*/) {
860 var object = ES.ToObject(this);
861 var self = splitString && isString(this) ? strSplit(this, '') : object;
862 var length = ES.ToUint32(self.length);
863
864 // If no callback function or if callback is not a callable function
865 if (!isCallable(callbackfn)) {
866 throw new TypeError('Array.prototype.reduce callback must be a function');
867 }
868
869 // no value to return if no initial value and an empty array
870 if (length === 0 && arguments.length === 1) {
871 throw new TypeError('reduce of empty array with no initial value');
872 }
873
874 var i = 0;
875 var result;
876 if (arguments.length >= 2) {
877 result = arguments[1];
878 } else {
879 do {
880 if (i in self) {
881 result = self[i++];
882 break;
883 }
884
885 // if array contains no values, no initial value to return
886 if (++i >= length) {
887 throw new TypeError('reduce of empty array with no initial value');
888 }
889 } while (true);
890 }
891
892 for (; i < length; i++) {
893 if (i in self) {
894 result = callbackfn(result, self[i], i, object);
895 }
896 }
897
898 return result;
899 }
900 }, !reduceCoercesToObject);
901
902 // ES5 15.4.4.22
903 // http://es5.github.com/#x15.4.4.22
904 // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
905 var reduceRightCoercesToObject = false;
906 if (ArrayPrototype.reduceRight) {
907 reduceRightCoercesToObject = typeof ArrayPrototype.reduceRight.call('es5', function (_, __, ___, list) {
908 return list;
909 }) === 'object';
910 }
911 defineProperties(ArrayPrototype, {
912 reduceRight: function reduceRight(callbackfn/*, initial*/) {
913 var object = ES.ToObject(this);
914 var self = splitString && isString(this) ? strSplit(this, '') : object;
915 var length = ES.ToUint32(self.length);
916
917 // If no callback function or if callback is not a callable function
918 if (!isCallable(callbackfn)) {
919 throw new TypeError('Array.prototype.reduceRight callback must be a function');
920 }
921
922 // no value to return if no initial value, empty array
923 if (length === 0 && arguments.length === 1) {
924 throw new TypeError('reduceRight of empty array with no initial value');
925 }
926
927 var result;
928 var i = length - 1;
929 if (arguments.length >= 2) {
930 result = arguments[1];
931 } else {
932 do {
933 if (i in self) {
934 result = self[i--];
935 break;
936 }
937
938 // if array contains no values, no initial value to return
939 if (--i < 0) {
940 throw new TypeError('reduceRight of empty array with no initial value');
941 }
942 } while (true);
943 }
944
945 if (i < 0) {
946 return result;
947 }
948
949 do {
950 if (i in self) {
951 result = callbackfn(result, self[i], i, object);
952 }
953 } while (i--);
954
955 return result;
956 }
957 }, !reduceRightCoercesToObject);
958
959 // ES5 15.4.4.14
960 // http://es5.github.com/#x15.4.4.14
961 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
962 var hasFirefox2IndexOfBug = ArrayPrototype.indexOf && [0, 1].indexOf(1, 2) !== -1;
963 defineProperties(ArrayPrototype, {
964 indexOf: function indexOf(searchElement/*, fromIndex */) {
965 var self = splitString && isString(this) ? strSplit(this, '') : ES.ToObject(this);
966 var length = ES.ToUint32(self.length);
967
968 if (length === 0) {
969 return -1;
970 }
971
972 var i = 0;
973 if (arguments.length > 1) {
974 i = ES.ToInteger(arguments[1]);
975 }
976
977 // handle negative indices
978 i = i >= 0 ? i : max(0, length + i);
979 for (; i < length; i++) {
980 if (i in self && self[i] === searchElement) {
981 return i;
982 }
983 }
984 return -1;
985 }
986 }, hasFirefox2IndexOfBug);
987
988 // ES5 15.4.4.15
989 // http://es5.github.com/#x15.4.4.15
990 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
991 var hasFirefox2LastIndexOfBug = ArrayPrototype.lastIndexOf && [0, 1].lastIndexOf(0, -3) !== -1;
992 defineProperties(ArrayPrototype, {
993 lastIndexOf: function lastIndexOf(searchElement/*, fromIndex */) {
994 var self = splitString && isString(this) ? strSplit(this, '') : ES.ToObject(this);
995 var length = ES.ToUint32(self.length);
996
997 if (length === 0) {
998 return -1;
999 }
1000 var i = length - 1;
1001 if (arguments.length > 1) {
1002 i = min(i, ES.ToInteger(arguments[1]));
1003 }
1004 // handle negative indices
1005 i = i >= 0 ? i : length - Math.abs(i);
1006 for (; i >= 0; i--) {
1007 if (i in self && searchElement === self[i]) {
1008 return i;
1009 }
1010 }
1011 return -1;
1012 }
1013 }, hasFirefox2LastIndexOfBug);
1014
1015 // ES5 15.4.4.12
1016 // http://es5.github.com/#x15.4.4.12
1017 var spliceNoopReturnsEmptyArray = (function () {
1018 var a = [1, 2];
1019 var result = a.splice();
1020 return a.length === 2 && isArray(result) && result.length === 0;
1021 }());
1022 defineProperties(ArrayPrototype, {
1023 // Safari 5.0 bug where .splice() returns undefined
1024 splice: function splice(start, deleteCount) {
1025 if (arguments.length === 0) {
1026 return [];
1027 } else {
1028 return array_splice.apply(this, arguments);
1029 }
1030 }
1031 }, !spliceNoopReturnsEmptyArray);
1032
1033 var spliceWorksWithEmptyObject = (function () {
1034 var obj = {};
1035 ArrayPrototype.splice.call(obj, 0, 0, 1);
1036 return obj.length === 1;
1037 }());
1038 defineProperties(ArrayPrototype, {
1039 splice: function splice(start, deleteCount) {
1040 if (arguments.length === 0) {
1041 return [];
1042 }
1043 var args = arguments;
1044 this.length = max(ES.ToInteger(this.length), 0);
1045 if (arguments.length > 0 && typeof deleteCount !== 'number') {
1046 args = arraySlice(arguments);
1047 if (args.length < 2) {
1048 pushCall(args, this.length - start);
1049 } else {
1050 args[1] = ES.ToInteger(deleteCount);
1051 }
1052 }
1053 return array_splice.apply(this, args);
1054 }
1055 }, !spliceWorksWithEmptyObject);
1056 var spliceWorksWithLargeSparseArrays = (function () {
1057 // Per https://github.com/es-shims/es5-shim/issues/295
1058 // Safari 7/8 breaks with sparse arrays of size 1e5 or greater
1059 var arr = new $Array(1e5);
1060 // note: the index MUST be 8 or larger or the test will false pass
1061 arr[8] = 'x';
1062 arr.splice(1, 1);
1063 // note: this test must be defined *after* the indexOf shim
1064 // per https://github.com/es-shims/es5-shim/issues/313
1065 return arr.indexOf('x') === 7;
1066 }());
1067 var spliceWorksWithSmallSparseArrays = (function () {
1068 // Per https://github.com/es-shims/es5-shim/issues/295
1069 // Opera 12.15 breaks on this, no idea why.
1070 var n = 256;
1071 var arr = [];
1072 arr[n] = 'a';
1073 arr.splice(n + 1, 0, 'b');
1074 return arr[n] === 'a';
1075 }());
1076 defineProperties(ArrayPrototype, {
1077 splice: function splice(start, deleteCount) {
1078 var O = ES.ToObject(this);
1079 var A = [];
1080 var len = ES.ToUint32(O.length);
1081 var relativeStart = ES.ToInteger(start);
1082 var actualStart = relativeStart < 0 ? max((len + relativeStart), 0) : min(relativeStart, len);
1083 var actualDeleteCount = min(max(ES.ToInteger(deleteCount), 0), len - actualStart);
1084
1085 var k = 0;
1086 var from;
1087 while (k < actualDeleteCount) {
1088 from = $String(actualStart + k);
1089 if (owns(O, from)) {
1090 A[k] = O[from];
1091 }
1092 k += 1;
1093 }
1094
1095 var items = arraySlice(arguments, 2);
1096 var itemCount = items.length;
1097 var to;
1098 if (itemCount < actualDeleteCount) {
1099 k = actualStart;
1100 var maxK = len - actualDeleteCount;
1101 while (k < maxK) {
1102 from = $String(k + actualDeleteCount);
1103 to = $String(k + itemCount);
1104 if (owns(O, from)) {
1105 O[to] = O[from];
1106 } else {
1107 delete O[to];
1108 }
1109 k += 1;
1110 }
1111 k = len;
1112 var minK = len - actualDeleteCount + itemCount;
1113 while (k > minK) {
1114 delete O[k - 1];
1115 k -= 1;
1116 }
1117 } else if (itemCount > actualDeleteCount) {
1118 k = len - actualDeleteCount;
1119 while (k > actualStart) {
1120 from = $String(k + actualDeleteCount - 1);
1121 to = $String(k + itemCount - 1);
1122 if (owns(O, from)) {
1123 O[to] = O[from];
1124 } else {
1125 delete O[to];
1126 }
1127 k -= 1;
1128 }
1129 }
1130 k = actualStart;
1131 for (var i = 0; i < items.length; ++i) {
1132 O[k] = items[i];
1133 k += 1;
1134 }
1135 O.length = len - actualDeleteCount + itemCount;
1136
1137 return A;
1138 }
1139 }, !spliceWorksWithLargeSparseArrays || !spliceWorksWithSmallSparseArrays);
1140
1141 var originalJoin = ArrayPrototype.join;
1142 var hasStringJoinBug;
1143 try {
1144 hasStringJoinBug = Array.prototype.join.call('123', ',') !== '1,2,3';
1145 } catch (e) {
1146 hasStringJoinBug = true;
1147 }
1148 if (hasStringJoinBug) {
1149 defineProperties(ArrayPrototype, {
1150 join: function join(separator) {
1151 var sep = typeof separator === 'undefined' ? ',' : separator;
1152 return originalJoin.call(isString(this) ? strSplit(this, '') : this, sep);
1153 }
1154 }, hasStringJoinBug);
1155 }
1156
1157 var hasJoinUndefinedBug = [1, 2].join(undefined) !== '1,2';
1158 if (hasJoinUndefinedBug) {
1159 defineProperties(ArrayPrototype, {
1160 join: function join(separator) {
1161 var sep = typeof separator === 'undefined' ? ',' : separator;
1162 return originalJoin.call(this, sep);
1163 }
1164 }, hasJoinUndefinedBug);
1165 }
1166
1167 var pushShim = function push(item) {
1168 var O = ES.ToObject(this);
1169 var n = ES.ToUint32(O.length);
1170 var i = 0;
1171 while (i < arguments.length) {
1172 O[n + i] = arguments[i];
1173 i += 1;
1174 }
1175 O.length = n + i;
1176 return n + i;
1177 };
1178
1179 var pushIsNotGeneric = (function () {
1180 var obj = {};
1181 var result = Array.prototype.push.call(obj, undefined);
1182 return result !== 1 || obj.length !== 1 || typeof obj[0] !== 'undefined' || !owns(obj, 0);
1183 }());
1184 defineProperties(ArrayPrototype, {
1185 push: function push(item) {
1186 if (isArray(this)) {
1187 return array_push.apply(this, arguments);
1188 }
1189 return pushShim.apply(this, arguments);
1190 }
1191 }, pushIsNotGeneric);
1192
1193 // This fixes a very weird bug in Opera 10.6 when pushing `undefined
1194 var pushUndefinedIsWeird = (function () {
1195 var arr = [];
1196 var result = arr.push(undefined);
1197 return result !== 1 || arr.length !== 1 || typeof arr[0] !== 'undefined' || !owns(arr, 0);
1198 }());
1199 defineProperties(ArrayPrototype, { push: pushShim }, pushUndefinedIsWeird);
1200
1201 // ES5 15.2.3.14
1202 // http://es5.github.io/#x15.4.4.10
1203 // Fix boxed string bug
1204 defineProperties(ArrayPrototype, {
1205 slice: function (start, end) {
1206 var arr = isString(this) ? strSplit(this, '') : this;
1207 return arraySliceApply(arr, arguments);
1208 }
1209 }, splitString);
1210
1211 var sortIgnoresNonFunctions = (function () {
1212 try {
1213 [1, 2].sort(null);
1214 } catch (e) {
1215 try {
1216 [1, 2].sort({});
1217 } catch (e2) {
1218 return false;
1219 }
1220 }
1221 return true;
1222 }());
1223 var sortThrowsOnRegex = (function () {
1224 // this is a problem in Firefox 4, in which `typeof /a/ === 'function'`
1225 try {
1226 [1, 2].sort(/a/);
1227 return false;
1228 } catch (e) {}
1229 return true;
1230 }());
1231 var sortIgnoresUndefined = (function () {
1232 // applies in IE 8, for one.
1233 try {
1234 [1, 2].sort(undefined);
1235 return true;
1236 } catch (e) {}
1237 return false;
1238 }());
1239 defineProperties(ArrayPrototype, {
1240 sort: function sort(compareFn) {
1241 if (typeof compareFn === 'undefined') {
1242 return arraySort(this);
1243 }
1244 if (!isCallable(compareFn)) {
1245 throw new TypeError('Array.prototype.sort callback must be a function');
1246 }
1247 return arraySort(this, compareFn);
1248 }
1249 }, sortIgnoresNonFunctions || !sortIgnoresUndefined || !sortThrowsOnRegex);
1250
1251 //
1252 // Object
1253 // ======
1254 //
1255
1256 // ES5 15.2.3.14
1257 // http://es5.github.com/#x15.2.3.14
1258
1259 // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
1260 var hasDontEnumBug = !isEnum({ 'toString': null }, 'toString'); // jscs:ignore disallowQuotedKeysInObjects
1261 var hasProtoEnumBug = isEnum(function () {}, 'prototype');
1262 var hasStringEnumBug = !owns('x', '0');
1263 var equalsConstructorPrototype = function (o) {
1264 var ctor = o.constructor;
1265 return ctor && ctor.prototype === o;
1266 };
1267 var excludedKeys = {
1268 $window: true,
1269 $console: true,
1270 $parent: true,
1271 $self: true,
1272 $frame: true,
1273 $frames: true,
1274 $frameElement: true,
1275 $webkitIndexedDB: true,
1276 $webkitStorageInfo: true,
1277 $external: true,
1278 $width: true,
1279 $height: true,
1280 $top: true,
1281 $localStorage: true
1282 };
1283 var hasAutomationEqualityBug = (function () {
1284 /* globals window */
1285 if (typeof window === 'undefined') {
1286 return false;
1287 }
1288 for (var k in window) {
1289 try {
1290 if (!excludedKeys['$' + k] && owns(window, k) && window[k] !== null && typeof window[k] === 'object') {
1291 equalsConstructorPrototype(window[k]);
1292 }
1293 } catch (e) {
1294 return true;
1295 }
1296 }
1297 return false;
1298 }());
1299 var equalsConstructorPrototypeIfNotBuggy = function (object) {
1300 if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
1301 return equalsConstructorPrototype(object);
1302 }
1303 try {
1304 return equalsConstructorPrototype(object);
1305 } catch (e) {
1306 return false;
1307 }
1308 };
1309 var dontEnums = [
1310 'toString',
1311 'toLocaleString',
1312 'valueOf',
1313 'hasOwnProperty',
1314 'isPrototypeOf',
1315 'propertyIsEnumerable',
1316 'constructor'
1317 ];
1318 var dontEnumsLength = dontEnums.length;
1319
1320 // taken directly from https://github.com/ljharb/is-arguments/blob/master/index.js
1321 // can be replaced with require('is-arguments') if we ever use a build process instead
1322 var isStandardArguments = function isArguments(value) {
1323 return toStr(value) === '[object Arguments]';
1324 };
1325 var isLegacyArguments = function isArguments(value) {
1326 return value !== null
1327 && typeof value === 'object'
1328 && typeof value.length === 'number'
1329 && value.length >= 0
1330 && !isArray(value)
1331 && isCallable(value.callee);
1332 };
1333 var isArguments = isStandardArguments(arguments) ? isStandardArguments : isLegacyArguments;
1334
1335 defineProperties($Object, {
1336 keys: function keys(object) {
1337 var isFn = isCallable(object);
1338 var isArgs = isArguments(object);
1339 var isObject = object !== null && typeof object === 'object';
1340 var isStr = isObject && isString(object);
1341
1342 if (!isObject && !isFn && !isArgs) {
1343 throw new TypeError('Object.keys called on a non-object');
1344 }
1345
1346 var theKeys = [];
1347 var skipProto = hasProtoEnumBug && isFn;
1348 if ((isStr && hasStringEnumBug) || isArgs) {
1349 for (var i = 0; i < object.length; ++i) {
1350 pushCall(theKeys, $String(i));
1351 }
1352 }
1353
1354 if (!isArgs) {
1355 for (var name in object) {
1356 if (!(skipProto && name === 'prototype') && owns(object, name)) {
1357 pushCall(theKeys, $String(name));
1358 }
1359 }
1360 }
1361
1362 if (hasDontEnumBug) {
1363 var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
1364 for (var j = 0; j < dontEnumsLength; j++) {
1365 var dontEnum = dontEnums[j];
1366 if (!(skipConstructor && dontEnum === 'constructor') && owns(object, dontEnum)) {
1367 pushCall(theKeys, dontEnum);
1368 }
1369 }
1370 }
1371 return theKeys;
1372 }
1373 });
1374
1375 var keysWorksWithArguments = $Object.keys && (function () {
1376 // Safari 5.0 bug
1377 return $Object.keys(arguments).length === 2;
1378 }(1, 2));
1379 var keysHasArgumentsLengthBug = $Object.keys && (function () {
1380 var argKeys = $Object.keys(arguments);
1381 return arguments.length !== 1 || argKeys.length !== 1 || argKeys[0] !== 1;
1382 }(1));
1383 var originalKeys = $Object.keys;
1384 defineProperties($Object, {
1385 keys: function keys(object) {
1386 if (isArguments(object)) {
1387 return originalKeys(arraySlice(object));
1388 } else {
1389 return originalKeys(object);
1390 }
1391 }
1392 }, !keysWorksWithArguments || keysHasArgumentsLengthBug);
1393
1394 //
1395 // Date
1396 // ====
1397 //
1398
1399 var hasNegativeMonthYearBug = new Date(-3509827329600292).getUTCMonth() !== 0;
1400 var aNegativeTestDate = new Date(-1509842289600292);
1401 var aPositiveTestDate = new Date(1449662400000);
1402 var hasToUTCStringFormatBug = aNegativeTestDate.toUTCString() !== 'Mon, 01 Jan -45875 11:59:59 GMT';
1403 var hasToDateStringFormatBug;
1404 var hasToStringFormatBug;
1405 var timeZoneOffset = aNegativeTestDate.getTimezoneOffset();
1406 if (timeZoneOffset < -720) {
1407 hasToDateStringFormatBug = aNegativeTestDate.toDateString() !== 'Tue Jan 02 -45875';
1408 hasToStringFormatBug = !(/^Thu Dec 10 2015 \d\d:\d\d:\d\d GMT[-+]\d\d\d\d(?: |$)/).test(String(aPositiveTestDate));
1409 } else {
1410 hasToDateStringFormatBug = aNegativeTestDate.toDateString() !== 'Mon Jan 01 -45875';
1411 hasToStringFormatBug = !(/^Wed Dec 09 2015 \d\d:\d\d:\d\d GMT[-+]\d\d\d\d(?: |$)/).test(String(aPositiveTestDate));
1412 }
1413
1414 var originalGetFullYear = call.bind(Date.prototype.getFullYear);
1415 var originalGetMonth = call.bind(Date.prototype.getMonth);
1416 var originalGetDate = call.bind(Date.prototype.getDate);
1417 var originalGetUTCFullYear = call.bind(Date.prototype.getUTCFullYear);
1418 var originalGetUTCMonth = call.bind(Date.prototype.getUTCMonth);
1419 var originalGetUTCDate = call.bind(Date.prototype.getUTCDate);
1420 var originalGetUTCDay = call.bind(Date.prototype.getUTCDay);
1421 var originalGetUTCHours = call.bind(Date.prototype.getUTCHours);
1422 var originalGetUTCMinutes = call.bind(Date.prototype.getUTCMinutes);
1423 var originalGetUTCSeconds = call.bind(Date.prototype.getUTCSeconds);
1424 var originalGetUTCMilliseconds = call.bind(Date.prototype.getUTCMilliseconds);
1425 var dayName = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
1426 var monthName = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
1427 var daysInMonth = function daysInMonth(month, year) {
1428 return originalGetDate(new Date(year, month, 0));
1429 };
1430
1431 defineProperties(Date.prototype, {
1432 getFullYear: function getFullYear() {
1433 if (!this || !(this instanceof Date)) {
1434 throw new TypeError('this is not a Date object.');
1435 }
1436 var year = originalGetFullYear(this);
1437 if (year < 0 && originalGetMonth(this) > 11) {
1438 return year + 1;
1439 }
1440 return year;
1441 },
1442 getMonth: function getMonth() {
1443 if (!this || !(this instanceof Date)) {
1444 throw new TypeError('this is not a Date object.');
1445 }
1446 var year = originalGetFullYear(this);
1447 var month = originalGetMonth(this);
1448 if (year < 0 && month > 11) {
1449 return 0;
1450 }
1451 return month;
1452 },
1453 getDate: function getDate() {
1454 if (!this || !(this instanceof Date)) {
1455 throw new TypeError('this is not a Date object.');
1456 }
1457 var year = originalGetFullYear(this);
1458 var month = originalGetMonth(this);
1459 var date = originalGetDate(this);
1460 if (year < 0 && month > 11) {
1461 if (month === 12) {
1462 return date;
1463 }
1464 var days = daysInMonth(0, year + 1);
1465 return (days - date) + 1;
1466 }
1467 return date;
1468 },
1469 getUTCFullYear: function getUTCFullYear() {
1470 if (!this || !(this instanceof Date)) {
1471 throw new TypeError('this is not a Date object.');
1472 }
1473 var year = originalGetUTCFullYear(this);
1474 if (year < 0 && originalGetUTCMonth(this) > 11) {
1475 return year + 1;
1476 }
1477 return year;
1478 },
1479 getUTCMonth: function getUTCMonth() {
1480 if (!this || !(this instanceof Date)) {
1481 throw new TypeError('this is not a Date object.');
1482 }
1483 var year = originalGetUTCFullYear(this);
1484 var month = originalGetUTCMonth(this);
1485 if (year < 0 && month > 11) {
1486 return 0;
1487 }
1488 return month;
1489 },
1490 getUTCDate: function getUTCDate() {
1491 if (!this || !(this instanceof Date)) {
1492 throw new TypeError('this is not a Date object.');
1493 }
1494 var year = originalGetUTCFullYear(this);
1495 var month = originalGetUTCMonth(this);
1496 var date = originalGetUTCDate(this);
1497 if (year < 0 && month > 11) {
1498 if (month === 12) {
1499 return date;
1500 }
1501 var days = daysInMonth(0, year + 1);
1502 return (days - date) + 1;
1503 }
1504 return date;
1505 }
1506 }, hasNegativeMonthYearBug);
1507
1508 defineProperties(Date.prototype, {
1509 toUTCString: function toUTCString() {
1510 if (!this || !(this instanceof Date)) {
1511 throw new TypeError('this is not a Date object.');
1512 }
1513 var day = originalGetUTCDay(this);
1514 var date = originalGetUTCDate(this);
1515 var month = originalGetUTCMonth(this);
1516 var year = originalGetUTCFullYear(this);
1517 var hour = originalGetUTCHours(this);
1518 var minute = originalGetUTCMinutes(this);
1519 var second = originalGetUTCSeconds(this);
1520 return dayName[day] + ', '
1521 + (date < 10 ? '0' + date : date) + ' '
1522 + monthName[month] + ' '
1523 + year + ' '
1524 + (hour < 10 ? '0' + hour : hour) + ':'
1525 + (minute < 10 ? '0' + minute : minute) + ':'
1526 + (second < 10 ? '0' + second : second) + ' GMT';
1527 }
1528 }, hasNegativeMonthYearBug || hasToUTCStringFormatBug);
1529
1530 // Opera 12 has `,`
1531 defineProperties(Date.prototype, {
1532 toDateString: function toDateString() {
1533 if (!this || !(this instanceof Date)) {
1534 throw new TypeError('this is not a Date object.');
1535 }
1536 var day = this.getDay();
1537 var date = this.getDate();
1538 var month = this.getMonth();
1539 var year = this.getFullYear();
1540 return dayName[day] + ' '
1541 + monthName[month] + ' '
1542 + (date < 10 ? '0' + date : date) + ' '
1543 + year;
1544 }
1545 }, hasNegativeMonthYearBug || hasToDateStringFormatBug);
1546
1547 // can't use defineProperties here because of toString enumeration issue in IE <= 8
1548 if (hasNegativeMonthYearBug || hasToStringFormatBug) {
1549 Date.prototype.toString = function toString() {
1550 if (!this || !(this instanceof Date)) {
1551 throw new TypeError('this is not a Date object.');
1552 }
1553 var day = this.getDay();
1554 var date = this.getDate();
1555 var month = this.getMonth();
1556 var year = this.getFullYear();
1557 var hour = this.getHours();
1558 var minute = this.getMinutes();
1559 var second = this.getSeconds();
1560 var timezoneOffset = this.getTimezoneOffset();
1561 var hoursOffset = Math.floor(Math.abs(timezoneOffset) / 60);
1562 var minutesOffset = Math.floor(Math.abs(timezoneOffset) % 60);
1563 return dayName[day] + ' '
1564 + monthName[month] + ' '
1565 + (date < 10 ? '0' + date : date) + ' '
1566 + year + ' '
1567 + (hour < 10 ? '0' + hour : hour) + ':'
1568 + (minute < 10 ? '0' + minute : minute) + ':'
1569 + (second < 10 ? '0' + second : second) + ' GMT'
1570 + (timezoneOffset > 0 ? '-' : '+')
1571 + (hoursOffset < 10 ? '0' + hoursOffset : hoursOffset)
1572 + (minutesOffset < 10 ? '0' + minutesOffset : minutesOffset);
1573 };
1574 if (supportsDescriptors) {
1575 $Object.defineProperty(Date.prototype, 'toString', {
1576 configurable: true,
1577 enumerable: false,
1578 writable: true
1579 });
1580 }
1581 }
1582
1583 // ES5 15.9.5.43
1584 // http://es5.github.com/#x15.9.5.43
1585 // This function returns a String value represent the instance in time
1586 // represented by this Date object. The format of the String is the Date Time
1587 // string format defined in 15.9.1.15. All fields are present in the String.
1588 // The time zone is always UTC, denoted by the suffix Z. If the time value of
1589 // this object is not a finite Number a RangeError exception is thrown.
1590 var negativeDate = -62198755200000;
1591 var negativeYearString = '-000001';
1592 var hasNegativeDateBug = Date.prototype.toISOString && new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1; // eslint-disable-line max-len
1593 var hasSafari51DateBug = Date.prototype.toISOString && new Date(-1).toISOString() !== '1969-12-31T23:59:59.999Z';
1594
1595 var getTime = call.bind(Date.prototype.getTime);
1596
1597 defineProperties(Date.prototype, {
1598 toISOString: function toISOString() {
1599 if (!isFinite(this) || !isFinite(getTime(this))) {
1600 // Adope Photoshop requires the second check.
1601 throw new RangeError('Date.prototype.toISOString called on non-finite value.');
1602 }
1603
1604 var year = originalGetUTCFullYear(this);
1605
1606 var month = originalGetUTCMonth(this);
1607 // see https://github.com/es-shims/es5-shim/issues/111
1608 year += Math.floor(month / 12);
1609 month = ((month % 12) + 12) % 12;
1610
1611 // the date time string format is specified in 15.9.1.15.
1612 var result = [
1613 month + 1,
1614 originalGetUTCDate(this),
1615 originalGetUTCHours(this),
1616 originalGetUTCMinutes(this),
1617 originalGetUTCSeconds(this)
1618 ];
1619 year = (
1620 (year < 0 ? '-' : (year > 9999 ? '+' : ''))
1621 + strSlice('00000' + Math.abs(year), (0 <= year && year <= 9999) ? -4 : -6)
1622 );
1623
1624 for (var i = 0; i < result.length; ++i) {
1625 // pad months, days, hours, minutes, and seconds to have two digits.
1626 result[i] = strSlice('00' + result[i], -2);
1627 }
1628 // pad milliseconds to have three digits.
1629 return (
1630 year + '-' + arraySlice(result, 0, 2).join('-')
1631 + 'T' + arraySlice(result, 2).join(':') + '.'
1632 + strSlice('000' + originalGetUTCMilliseconds(this), -3) + 'Z'
1633 );
1634 }
1635 }, hasNegativeDateBug || hasSafari51DateBug);
1636
1637 // ES5 15.9.5.44
1638 // http://es5.github.com/#x15.9.5.44
1639 // This function provides a String representation of a Date object for use by
1640 // JSON.stringify (15.12.3).
1641 var dateToJSONIsSupported = (function () {
1642 try {
1643 return Date.prototype.toJSON
1644 && new Date(NaN).toJSON() === null
1645 && new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1
1646 && Date.prototype.toJSON.call({ // generic
1647 toISOString: function () { return true; }
1648 });
1649 } catch (e) {
1650 return false;
1651 }
1652 }());
1653 if (!dateToJSONIsSupported) {
1654 Date.prototype.toJSON = function toJSON(key) {
1655 // When the toJSON method is called with argument key, the following
1656 // steps are taken:
1657
1658 // 1. Let O be the result of calling ToObject, giving it the this
1659 // value as its argument.
1660 // 2. Let tv be ES.ToPrimitive(O, hint Number).
1661 var O = $Object(this);
1662 var tv = ES.ToPrimitive(O);
1663 // 3. If tv is a Number and is not finite, return null.
1664 if (typeof tv === 'number' && !isFinite(tv)) {
1665 return null;
1666 }
1667 // 4. Let toISO be the result of calling the [[Get]] internal method of
1668 // O with argument "toISOString".
1669 var toISO = O.toISOString;
1670 // 5. If IsCallable(toISO) is false, throw a TypeError exception.
1671 if (!isCallable(toISO)) {
1672 throw new TypeError('toISOString property is not callable');
1673 }
1674 // 6. Return the result of calling the [[Call]] internal method of
1675 // toISO with O as the this value and an empty argument list.
1676 return toISO.call(O);
1677
1678 // NOTE 1 The argument is ignored.
1679
1680 // NOTE 2 The toJSON function is intentionally generic; it does not
1681 // require that its this value be a Date object. Therefore, it can be
1682 // transferred to other kinds of objects for use as a method. However,
1683 // it does require that any such object have a toISOString method. An
1684 // object is free to use the argument key to filter its
1685 // stringification.
1686 };
1687 }
1688
1689 // ES5 15.9.4.2
1690 // http://es5.github.com/#x15.9.4.2
1691 // based on work shared by Daniel Friesen (dantman)
1692 // http://gist.github.com/303249
1693 var supportsExtendedYears = Date.parse('+033658-09-27T01:46:40.000Z') === 1e15;
1694 var acceptsInvalidDates = !isNaN(Date.parse('2012-04-04T24:00:00.500Z')) || !isNaN(Date.parse('2012-11-31T23:59:59.000Z')) || !isNaN(Date.parse('2012-12-31T23:59:60.000Z'));
1695 var doesNotParseY2KNewYear = isNaN(Date.parse('2000-01-01T00:00:00.000Z'));
1696 if (doesNotParseY2KNewYear || acceptsInvalidDates || !supportsExtendedYears) {
1697 // XXX global assignment won't work in embeddings that use
1698 // an alternate object for the context.
1699 /* global Date: true */
1700 var maxSafeUnsigned32Bit = Math.pow(2, 31) - 1;
1701 var hasSafariSignedIntBug = isActualNaN(new Date(1970, 0, 1, 0, 0, 0, maxSafeUnsigned32Bit + 1).getTime());
1702 // eslint-disable-next-line no-implicit-globals, no-global-assign
1703 Date = (function (NativeDate) {
1704 // Date.length === 7
1705 var DateShim = function Date(Y, M, D, h, m, s, ms) {
1706 var length = arguments.length;
1707 var date;
1708 if (this instanceof NativeDate) {
1709 var seconds = s;
1710 var millis = ms;
1711 if (hasSafariSignedIntBug && length >= 7 && ms > maxSafeUnsigned32Bit) {
1712 // work around a Safari 8/9 bug where it treats the seconds as signed
1713 var msToShift = Math.floor(ms / maxSafeUnsigned32Bit) * maxSafeUnsigned32Bit;
1714 var sToShift = Math.floor(msToShift / 1e3);
1715 seconds += sToShift;
1716 millis -= sToShift * 1e3;
1717 }
1718 date = length === 1 && $String(Y) === Y // isString(Y)
1719 // We explicitly pass it through parse:
1720 ? new NativeDate(DateShim.parse(Y))
1721 // We have to manually make calls depending on argument
1722 // length here
1723 : length >= 7 ? new NativeDate(Y, M, D, h, m, seconds, millis)
1724 : length >= 6 ? new NativeDate(Y, M, D, h, m, seconds)
1725 : length >= 5 ? new NativeDate(Y, M, D, h, m)
1726 : length >= 4 ? new NativeDate(Y, M, D, h)
1727 : length >= 3 ? new NativeDate(Y, M, D)
1728 : length >= 2 ? new NativeDate(Y, M)
1729 : length >= 1 ? new NativeDate(Y instanceof NativeDate ? +Y : Y)
1730 : new NativeDate();
1731 } else {
1732 date = NativeDate.apply(this, arguments);
1733 }
1734 if (!isPrimitive(date)) {
1735 // Prevent mixups with unfixed Date object
1736 defineProperties(date, { constructor: DateShim }, true);
1737 }
1738 return date;
1739 };
1740
1741 // 15.9.1.15 Date Time String Format.
1742 var isoDateExpression = new RegExp('^'
1743 + '(\\d{4}|[+-]\\d{6})' // four-digit year capture or sign + 6-digit extended year
1744 + '(?:-(\\d{2})' // optional month capture
1745 + '(?:-(\\d{2})' // optional day capture
1746 + '(?:' // capture hours:minutes:seconds.milliseconds
1747 + 'T(\\d{2})' // hours capture
1748 + ':(\\d{2})' // minutes capture
1749 + '(?:' // optional :seconds.milliseconds
1750 + ':(\\d{2})' // seconds capture
1751 + '(?:(\\.\\d{1,}))?' // milliseconds capture
1752 + ')?'
1753 + '(' // capture UTC offset component
1754 + 'Z|' // UTC capture
1755 + '(?:' // offset specifier +/-hours:minutes
1756 + '([-+])' // sign capture
1757 + '(\\d{2})' // hours offset capture
1758 + ':(\\d{2})' // minutes offset capture
1759 + ')'
1760 + ')?)?)?)?'
1761 + '$');
1762
1763 var months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
1764
1765 var dayFromMonth = function dayFromMonth(year, month) {
1766 var t = month > 1 ? 1 : 0;
1767 return (
1768 months[month]
1769 + Math.floor((year - 1969 + t) / 4)
1770 - Math.floor((year - 1901 + t) / 100)
1771 + Math.floor((year - 1601 + t) / 400)
1772 + (365 * (year - 1970))
1773 );
1774 };
1775
1776 var toUTC = function toUTC(t) {
1777 var s = 0;
1778 var ms = t;
1779 if (hasSafariSignedIntBug && ms > maxSafeUnsigned32Bit) {
1780 // work around a Safari 8/9 bug where it treats the seconds as signed
1781 var msToShift = Math.floor(ms / maxSafeUnsigned32Bit) * maxSafeUnsigned32Bit;
1782 var sToShift = Math.floor(msToShift / 1e3);
1783 s += sToShift;
1784 ms -= sToShift * 1e3;
1785 }
1786 return $Number(new NativeDate(1970, 0, 1, 0, 0, s, ms));
1787 };
1788
1789 // Copy any custom methods a 3rd party library may have added
1790 for (var key in NativeDate) {
1791 if (owns(NativeDate, key)) {
1792 DateShim[key] = NativeDate[key];
1793 }
1794 }
1795
1796 // Copy "native" methods explicitly; they may be non-enumerable
1797 defineProperties(DateShim, {
1798 now: NativeDate.now,
1799 UTC: NativeDate.UTC
1800 }, true);
1801 DateShim.prototype = NativeDate.prototype;
1802 defineProperties(DateShim.prototype, { constructor: DateShim }, true);
1803
1804 // Upgrade Date.parse to handle simplified ISO 8601 strings
1805 var parseShim = function parse(string) {
1806 var match = isoDateExpression.exec(string);
1807 if (match) {
1808 // parse months, days, hours, minutes, seconds, and milliseconds
1809 // provide default values if necessary
1810 // parse the UTC offset component
1811 var year = $Number(match[1]),
1812 month = $Number(match[2] || 1) - 1,
1813 day = $Number(match[3] || 1) - 1,
1814 hour = $Number(match[4] || 0),
1815 minute = $Number(match[5] || 0),
1816 second = $Number(match[6] || 0),
1817 millisecond = Math.floor($Number(match[7] || 0) * 1000),
1818 // When time zone is missed, local offset should be used
1819 // (ES 5.1 bug)
1820 // see https://bugs.ecmascript.org/show_bug.cgi?id=112
1821 isLocalTime = Boolean(match[4] && !match[8]),
1822 signOffset = match[9] === '-' ? 1 : -1,
1823 hourOffset = $Number(match[10] || 0),
1824 minuteOffset = $Number(match[11] || 0),
1825 result;
1826 var hasMinutesOrSecondsOrMilliseconds = minute > 0 || second > 0 || millisecond > 0;
1827 if (
1828 hour < (hasMinutesOrSecondsOrMilliseconds ? 24 : 25)
1829 && minute < 60 && second < 60 && millisecond < 1000
1830 && month > -1 && month < 12 && hourOffset < 24
1831 && minuteOffset < 60 // detect invalid offsets
1832 && day > -1
1833 && day < (dayFromMonth(year, month + 1) - dayFromMonth(year, month))
1834 ) {
1835 result = (
1836 ((dayFromMonth(year, month) + day) * 24)
1837 + hour
1838 + (hourOffset * signOffset)
1839 ) * 60;
1840 result = ((
1841 ((result + minute + (minuteOffset * signOffset)) * 60)
1842 + second
1843 ) * 1000) + millisecond;
1844 if (isLocalTime) {
1845 result = toUTC(result);
1846 }
1847 if (-8.64e15 <= result && result <= 8.64e15) {
1848 return result;
1849 }
1850 }
1851 return NaN;
1852 }
1853 return NativeDate.parse.apply(this, arguments);
1854 };
1855 defineProperties(DateShim, { parse: parseShim });
1856
1857 return DateShim;
1858 }(Date));
1859 /* global Date: false */
1860 }
1861
1862 // ES5 15.9.4.4
1863 // http://es5.github.com/#x15.9.4.4
1864 if (!Date.now) {
1865 Date.now = function now() {
1866 return new Date().getTime();
1867 };
1868 }
1869
1870 //
1871 // Number
1872 // ======
1873 //
1874
1875 // ES5.1 15.7.4.5
1876 // http://es5.github.com/#x15.7.4.5
1877 var hasToFixedBugs = NumberPrototype.toFixed && (
1878 (0.00008).toFixed(3) !== '0.000'
1879 || (0.9).toFixed(0) !== '1'
1880 || (1.255).toFixed(2) !== '1.25'
1881 || (1000000000000000128).toFixed(0) !== '1000000000000000128'
1882 );
1883
1884 var toFixedHelpers = {
1885 base: 1e7,
1886 size: 6,
1887 data: [0, 0, 0, 0, 0, 0],
1888 multiply: function multiply(n, c) {
1889 var i = -1;
1890 var c2 = c;
1891 while (++i < toFixedHelpers.size) {
1892 c2 += n * toFixedHelpers.data[i];
1893 toFixedHelpers.data[i] = c2 % toFixedHelpers.base;
1894 c2 = Math.floor(c2 / toFixedHelpers.base);
1895 }
1896 },
1897 divide: function divide(n) {
1898 var i = toFixedHelpers.size;
1899 var c = 0;
1900 while (--i >= 0) {
1901 c += toFixedHelpers.data[i];
1902 toFixedHelpers.data[i] = Math.floor(c / n);
1903 c = (c % n) * toFixedHelpers.base;
1904 }
1905 },
1906 numToString: function numToString() {
1907 var i = toFixedHelpers.size;
1908 var s = '';
1909 while (--i >= 0) {
1910 if (s !== '' || i === 0 || toFixedHelpers.data[i] !== 0) {
1911 var t = $String(toFixedHelpers.data[i]);
1912 if (s === '') {
1913 s = t;
1914 } else {
1915 s += strSlice('0000000', 0, 7 - t.length) + t;
1916 }
1917 }
1918 }
1919 return s;
1920 },
1921 pow: function pow(x, n, acc) {
1922 return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc)));
1923 },
1924 log: function log(x) {
1925 var n = 0;
1926 var x2 = x;
1927 while (x2 >= 4096) {
1928 n += 12;
1929 x2 /= 4096;
1930 }
1931 while (x2 >= 2) {
1932 n += 1;
1933 x2 /= 2;
1934 }
1935 return n;
1936 }
1937 };
1938
1939 var toFixedShim = function toFixed(fractionDigits) {
1940 var f, x, s, m, e, z, j, k;
1941
1942 // Test for NaN and round fractionDigits down
1943 f = $Number(fractionDigits);
1944 f = isActualNaN(f) ? 0 : Math.floor(f);
1945
1946 if (f < 0 || f > 20) {
1947 throw new RangeError('Number.toFixed called with invalid number of decimals');
1948 }
1949
1950 x = $Number(this);
1951
1952 if (isActualNaN(x)) {
1953 return 'NaN';
1954 }
1955
1956 // If it is too big or small, return the string value of the number
1957 if (x <= -1e21 || x >= 1e21) {
1958 return $String(x);
1959 }
1960
1961 s = '';
1962
1963 if (x < 0) {
1964 s = '-';
1965 x = -x;
1966 }
1967
1968 m = '0';
1969
1970 if (x > 1e-21) {
1971 // 1e-21 < x < 1e21
1972 // -70 < log2(x) < 70
1973 e = toFixedHelpers.log(x * toFixedHelpers.pow(2, 69, 1)) - 69;
1974 z = (e < 0 ? x * toFixedHelpers.pow(2, -e, 1) : x / toFixedHelpers.pow(2, e, 1));
1975 z *= 0x10000000000000; // Math.pow(2, 52);
1976 e = 52 - e;
1977
1978 // -18 < e < 122
1979 // x = z / 2 ^ e
1980 if (e > 0) {
1981 toFixedHelpers.multiply(0, z);
1982 j = f;
1983
1984 while (j >= 7) {
1985 toFixedHelpers.multiply(1e7, 0);
1986 j -= 7;
1987 }
1988
1989 toFixedHelpers.multiply(toFixedHelpers.pow(10, j, 1), 0);
1990 j = e - 1;
1991
1992 while (j >= 23) {
1993 toFixedHelpers.divide(1 << 23);
1994 j -= 23;
1995 }
1996
1997 toFixedHelpers.divide(1 << j);
1998 toFixedHelpers.multiply(1, 1);
1999 toFixedHelpers.divide(2);
2000 m = toFixedHelpers.numToString();
2001 } else {
2002 toFixedHelpers.multiply(0, z);
2003 toFixedHelpers.multiply(1 << (-e), 0);
2004 m = toFixedHelpers.numToString() + strSlice('0.00000000000000000000', 2, 2 + f);
2005 }
2006 }
2007
2008 if (f > 0) {
2009 k = m.length;
2010
2011 if (k <= f) {
2012 m = s + strSlice('0.0000000000000000000', 0, f - k + 2) + m;
2013 } else {
2014 m = s + strSlice(m, 0, k - f) + '.' + strSlice(m, k - f);
2015 }
2016 } else {
2017 m = s + m;
2018 }
2019
2020 return m;
2021 };
2022 defineProperties(NumberPrototype, { toFixed: toFixedShim }, hasToFixedBugs);
2023
2024 var hasToPrecisionUndefinedBug = (function () {
2025 try {
2026 return 1.0.toPrecision(undefined) === '1';
2027 } catch (e) {
2028 return true;
2029 }
2030 }());
2031 var originalToPrecision = NumberPrototype.toPrecision;
2032 defineProperties(NumberPrototype, {
2033 toPrecision: function toPrecision(precision) {
2034 return typeof precision === 'undefined' ? originalToPrecision.call(this) : originalToPrecision.call(this, precision);
2035 }
2036 }, hasToPrecisionUndefinedBug);
2037
2038 //
2039 // String
2040 // ======
2041 //
2042
2043 // ES5 15.5.4.14
2044 // http://es5.github.com/#x15.5.4.14
2045
2046 // [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]
2047 // Many browsers do not split properly with regular expressions or they
2048 // do not perform the split correctly under obscure conditions.
2049 // See http://blog.stevenlevithan.com/archives/cross-browser-split
2050 // I've tested in many browsers and this seems to cover the deviant ones:
2051 // 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
2052 // '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
2053 // 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
2054 // [undefined, "t", undefined, "e", ...]
2055 // ''.split(/.?/) should be [], not [""]
2056 // '.'.split(/()()/) should be ["."], not ["", "", "."]
2057
2058 if (
2059 'ab'.split(/(?:ab)*/).length !== 2
2060 || '.'.split(/(.?)(.?)/).length !== 4
2061 || 'tesst'.split(/(s)*/)[1] === 't'
2062 || 'test'.split(/(?:)/, -1).length !== 4
2063 || ''.split(/.?/).length
2064 || '.'.split(/()()/).length > 1
2065 ) {
2066 (function () {
2067 var compliantExecNpcg = typeof (/()??/).exec('')[1] === 'undefined'; // NPCG: nonparticipating capturing group
2068 var maxSafe32BitInt = Math.pow(2, 32) - 1;
2069
2070 StringPrototype.split = function (separator, limit) {
2071 var string = String(this);
2072 if (typeof separator === 'undefined' && limit === 0) {
2073 return [];
2074 }
2075
2076 // If `separator` is not a regex, use native split
2077 if (!isRegex(separator)) {
2078 return strSplit(this, separator, limit);
2079 }
2080
2081 var output = [];
2082 var flags = (separator.ignoreCase ? 'i' : '')
2083 + (separator.multiline ? 'm' : '')
2084 + (separator.unicode ? 'u' : '') // in ES6
2085 + (separator.sticky ? 'y' : ''), // Firefox 3+ and ES6
2086 lastLastIndex = 0,
2087 // Make `global` and avoid `lastIndex` issues by working with a copy
2088 separator2, match, lastIndex, lastLength;
2089 var separatorCopy = new RegExp(separator.source, flags + 'g');
2090 if (!compliantExecNpcg) {
2091 // Doesn't need flags gy, but they don't hurt
2092 separator2 = new RegExp('^' + separatorCopy.source + '$(?!\\s)', flags);
2093 }
2094 /* Values for `limit`, per the spec:
2095 * If undefined: 4294967295 // maxSafe32BitInt
2096 * If 0, Infinity, or NaN: 0
2097 * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
2098 * If negative number: 4294967296 - Math.floor(Math.abs(limit))
2099 * If other: Type-convert, then use the above rules
2100 */
2101 var splitLimit = typeof limit === 'undefined' ? maxSafe32BitInt : ES.ToUint32(limit);
2102 match = separatorCopy.exec(string);
2103 while (match) {
2104 // `separatorCopy.lastIndex` is not reliable cross-browser
2105 lastIndex = match.index + match[0].length;
2106 if (lastIndex > lastLastIndex) {
2107 pushCall(output, strSlice(string, lastLastIndex, match.index));
2108 // Fix browsers whose `exec` methods don't consistently return `undefined` for
2109 // nonparticipating capturing groups
2110 if (!compliantExecNpcg && match.length > 1) {
2111 /* eslint-disable no-loop-func */
2112 match[0].replace(separator2, function () {
2113 for (var i = 1; i < arguments.length - 2; i++) {
2114 if (typeof arguments[i] === 'undefined') {
2115 match[i] = void 0;
2116 }
2117 }
2118 });
2119 /* eslint-enable no-loop-func */
2120 }
2121 if (match.length > 1 && match.index < string.length) {
2122 array_push.apply(output, arraySlice(match, 1));
2123 }
2124 lastLength = match[0].length;
2125 lastLastIndex = lastIndex;
2126 if (output.length >= splitLimit) {
2127 break;
2128 }
2129 }
2130 if (separatorCopy.lastIndex === match.index) {
2131 separatorCopy.lastIndex++; // Avoid an infinite loop
2132 }
2133 match = separatorCopy.exec(string);
2134 }
2135 if (lastLastIndex === string.length) {
2136 if (lastLength || !separatorCopy.test('')) {
2137 pushCall(output, '');
2138 }
2139 } else {
2140 pushCall(output, strSlice(string, lastLastIndex));
2141 }
2142 return output.length > splitLimit ? arraySlice(output, 0, splitLimit) : output;
2143 };
2144 }());
2145
2146 // [bugfix, chrome]
2147 // If separator is undefined, then the result array contains just one String,
2148 // which is the this value (converted to a String). If limit is not undefined,
2149 // then the output array is truncated so that it contains no more than limit
2150 // elements.
2151 // "0".split(undefined, 0) -> []
2152 } else if ('0'.split(void 0, 0).length) {
2153 StringPrototype.split = function split(separator, limit) {
2154 if (typeof separator === 'undefined' && limit === 0) {
2155 return [];
2156 }
2157 return strSplit(this, separator, limit);
2158 };
2159 }
2160
2161 var str_replace = StringPrototype.replace;
2162 var replaceReportsGroupsCorrectly = (function () {
2163 var groups = [];
2164 'x'.replace(/x(.)?/g, function (match, group) {
2165 pushCall(groups, group);
2166 });
2167 return groups.length === 1 && typeof groups[0] === 'undefined';
2168 }());
2169
2170 if (!replaceReportsGroupsCorrectly) {
2171 StringPrototype.replace = function replace(searchValue, replaceValue) {
2172 var isFn = isCallable(replaceValue);
2173 var hasCapturingGroups = isRegex(searchValue) && (/\)[*?]/).test(searchValue.source);
2174 if (!isFn || !hasCapturingGroups) {
2175 return str_replace.call(this, searchValue, replaceValue);
2176 } else {
2177 var wrappedReplaceValue = function (match) {
2178 var length = arguments.length;
2179 var originalLastIndex = searchValue.lastIndex;
2180 searchValue.lastIndex = 0;
2181 var args = searchValue.exec(match) || [];
2182 searchValue.lastIndex = originalLastIndex;
2183 pushCall(args, arguments[length - 2], arguments[length - 1]);
2184 return replaceValue.apply(this, args);
2185 };
2186 return str_replace.call(this, searchValue, wrappedReplaceValue);
2187 }
2188 };
2189 }
2190
2191 // ECMA-262, 3rd B.2.3
2192 // Not an ECMAScript standard, although ECMAScript 3rd Edition has a
2193 // non-normative section suggesting uniform semantics and it should be
2194 // normalized across all browsers
2195 // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
2196 var string_substr = StringPrototype.substr;
2197 var hasNegativeSubstrBug = ''.substr && '0b'.substr(-1) !== 'b';
2198 defineProperties(StringPrototype, {
2199 substr: function substr(start, length) {
2200 var normalizedStart = start;
2201 if (start < 0) {
2202 normalizedStart = max(this.length + start, 0);
2203 }
2204 return string_substr.call(this, normalizedStart, length);
2205 }
2206 }, hasNegativeSubstrBug);
2207
2208 // ES5 15.5.4.20
2209 // whitespace from: http://es5.github.io/#x15.5.4.20
2210 var ws = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003'
2211 + '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028'
2212 + '\u2029\uFEFF';
2213 var zeroWidth = '\u200b';
2214 var wsRegexChars = '[' + ws + ']';
2215 var trimBeginRegexp = new RegExp('^' + wsRegexChars + wsRegexChars + '*');
2216 var trimEndRegexp = new RegExp(wsRegexChars + wsRegexChars + '*$');
2217 var hasTrimWhitespaceBug = StringPrototype.trim && (ws.trim() || !zeroWidth.trim());
2218 defineProperties(StringPrototype, {
2219 // http://blog.stevenlevithan.com/archives/faster-trim-javascript
2220 // http://perfectionkills.com/whitespace-deviations/
2221 trim: function trim() {
2222 if (typeof this === 'undefined' || this === null) {
2223 throw new TypeError("can't convert " + this + ' to object');
2224 }
2225 return $String(this).replace(trimBeginRegexp, '').replace(trimEndRegexp, '');
2226 }
2227 }, hasTrimWhitespaceBug);
2228 var trim = call.bind(String.prototype.trim);
2229
2230 var hasLastIndexBug = StringPrototype.lastIndexOf && 'abcあい'.lastIndexOf('あい', 2) !== -1;
2231 defineProperties(StringPrototype, {
2232 lastIndexOf: function lastIndexOf(searchString) {
2233 if (typeof this === 'undefined' || this === null) {
2234 throw new TypeError("can't convert " + this + ' to object');
2235 }
2236 var S = $String(this);
2237 var searchStr = $String(searchString);
2238 var numPos = arguments.length > 1 ? $Number(arguments[1]) : NaN;
2239 var pos = isActualNaN(numPos) ? Infinity : ES.ToInteger(numPos);
2240 var start = min(max(pos, 0), S.length);
2241 var searchLen = searchStr.length;
2242 var k = start + searchLen;
2243 while (k > 0) {
2244 k = max(0, k - searchLen);
2245 var index = strIndexOf(strSlice(S, k, start + searchLen), searchStr);
2246 if (index !== -1) {
2247 return k + index;
2248 }
2249 }
2250 return -1;
2251 }
2252 }, hasLastIndexBug);
2253
2254 var originalLastIndexOf = StringPrototype.lastIndexOf;
2255 defineProperties(StringPrototype, {
2256 lastIndexOf: function lastIndexOf(searchString) {
2257 return originalLastIndexOf.apply(this, arguments);
2258 }
2259 }, StringPrototype.lastIndexOf.length !== 1);
2260
2261 // ES-5 15.1.2.2
2262 // eslint-disable-next-line radix
2263 if (parseInt(ws + '08') !== 8 || parseInt(ws + '0x16') !== 22) {
2264 /* global parseInt: true */
2265 parseInt = (function (origParseInt) {
2266 var hexRegex = /^[-+]?0[xX]/;
2267 return function parseInt(str, radix) {
2268 if (typeof str === 'symbol') {
2269 // handle Symbols in node 8.3/8.4
2270 // eslint-disable-next-line no-implicit-coercion, no-unused-expressions
2271 '' + str; // jscs:ignore disallowImplicitTypeConversion
2272 }
2273
2274 var string = trim(String(str));
2275 var defaultedRadix = $Number(radix) || (hexRegex.test(string) ? 16 : 10);
2276 return origParseInt(string, defaultedRadix);
2277 };
2278 }(parseInt));
2279 }
2280
2281 // https://es5.github.io/#x15.1.2.3
2282 if (1 / parseFloat('-0') !== -Infinity) {
2283 /* global parseFloat: true */
2284 parseFloat = (function (origParseFloat) {
2285 return function parseFloat(string) {
2286 var inputString = trim(String(string));
2287 var result = origParseFloat(inputString);
2288 return result === 0 && strSlice(inputString, 0, 1) === '-' ? -0 : result;
2289 };
2290 }(parseFloat));
2291 }
2292
2293 if (String(new RangeError('test')) !== 'RangeError: test') {
2294 var errorToStringShim = function toString() {
2295 if (typeof this === 'undefined' || this === null) {
2296 throw new TypeError("can't convert " + this + ' to object');
2297 }
2298 var name = this.name;
2299 if (typeof name === 'undefined') {
2300 name = 'Error';
2301 } else if (typeof name !== 'string') {
2302 name = $String(name);
2303 }
2304 var msg = this.message;
2305 if (typeof msg === 'undefined') {
2306 msg = '';
2307 } else if (typeof msg !== 'string') {
2308 msg = $String(msg);
2309 }
2310 if (!name) {
2311 return msg;
2312 }
2313 if (!msg) {
2314 return name;
2315 }
2316 return name + ': ' + msg;
2317 };
2318 // can't use defineProperties here because of toString enumeration issue in IE <= 8
2319 Error.prototype.toString = errorToStringShim;
2320 }
2321
2322 if (supportsDescriptors) {
2323 var ensureNonEnumerable = function (obj, prop) {
2324 if (isEnum(obj, prop)) {
2325 var desc = Object.getOwnPropertyDescriptor(obj, prop);
2326 if (desc.configurable) {
2327 desc.enumerable = false;
2328 Object.defineProperty(obj, prop, desc);
2329 }
2330 }
2331 };
2332 ensureNonEnumerable(Error.prototype, 'message');
2333 if (Error.prototype.message !== '') {
2334 Error.prototype.message = '';
2335 }
2336 ensureNonEnumerable(Error.prototype, 'name');
2337 }
2338
2339 if (String(/a/mig) !== '/a/gim') {
2340 var regexToString = function toString() {
2341 var str = '/' + this.source + '/';
2342 if (this.global) {
2343 str += 'g';
2344 }
2345 if (this.ignoreCase) {
2346 str += 'i';
2347 }
2348 if (this.multiline) {
2349 str += 'm';
2350 }
2351 return str;
2352 };
2353 // can't use defineProperties here because of toString enumeration issue in IE <= 8
2354 RegExp.prototype.toString = regexToString;
2355 }
2356 }));
2357
2358 },{}],5:[function(require,module,exports){
2359 // get successful control from form and assemble into object
2360 // http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2
2361
2362 // types which indicate a submit action and are not successful controls
2363 // these will be ignored
2364 var k_r_submitter = /^(?:submit|button|image|reset|file)$/i;
2365
2366 // node names which could be successful controls
2367 var k_r_success_contrls = /^(?:input|select|textarea|keygen)/i;
2368
2369 // Matches bracket notation.
2370 var brackets = /(\[[^\[\]]*\])/g;
2371
2372 // serializes form fields
2373 // @param form MUST be an HTMLForm element
2374 // @param options is an optional argument to configure the serialization. Default output
2375 // with no options specified is a url encoded string
2376 // - hash: [true | false] Configure the output type. If true, the output will
2377 // be a js object.
2378 // - serializer: [function] Optional serializer function to override the default one.
2379 // The function takes 3 arguments (result, key, value) and should return new result
2380 // hash and url encoded str serializers are provided with this module
2381 // - disabled: [true | false]. If true serialize disabled fields.
2382 // - empty: [true | false]. If true serialize empty fields
2383 function serialize(form, options) {
2384 if (typeof options != 'object') {
2385 options = { hash: !!options };
2386 }
2387 else if (options.hash === undefined) {
2388 options.hash = true;
2389 }
2390
2391 var result = (options.hash) ? {} : '';
2392 var serializer = options.serializer || ((options.hash) ? hash_serializer : str_serialize);
2393
2394 var elements = form && form.elements ? form.elements : [];
2395
2396 //Object store each radio and set if it's empty or not
2397 var radio_store = Object.create(null);
2398
2399 for (var i=0 ; i<elements.length ; ++i) {
2400 var element = elements[i];
2401
2402 // ingore disabled fields
2403 if ((!options.disabled && element.disabled) || !element.name) {
2404 continue;
2405 }
2406 // ignore anyhting that is not considered a success field
2407 if (!k_r_success_contrls.test(element.nodeName) ||
2408 k_r_submitter.test(element.type)) {
2409 continue;
2410 }
2411
2412 var key = element.name;
2413 var val = element.value;
2414
2415 // we can't just use element.value for checkboxes cause some browsers lie to us
2416 // they say "on" for value when the box isn't checked
2417 if ((element.type === 'checkbox' || element.type === 'radio') && !element.checked) {
2418 val = undefined;
2419 }
2420
2421 // If we want empty elements
2422 if (options.empty) {
2423 // for checkbox
2424 if (element.type === 'checkbox' && !element.checked) {
2425 val = '';
2426 }
2427
2428 // for radio
2429 if (element.type === 'radio') {
2430 if (!radio_store[element.name] && !element.checked) {
2431 radio_store[element.name] = false;
2432 }
2433 else if (element.checked) {
2434 radio_store[element.name] = true;
2435 }
2436 }
2437
2438 // if options empty is true, continue only if its radio
2439 if (val == undefined && element.type == 'radio') {
2440 continue;
2441 }
2442 }
2443 else {
2444 // value-less fields are ignored unless options.empty is true
2445 if (!val) {
2446 continue;
2447 }
2448 }
2449
2450 // multi select boxes
2451 if (element.type === 'select-multiple') {
2452 val = [];
2453
2454 var selectOptions = element.options;
2455 var isSelectedOptions = false;
2456 for (var j=0 ; j<selectOptions.length ; ++j) {
2457 var option = selectOptions[j];
2458 var allowedEmpty = options.empty && !option.value;
2459 var hasValue = (option.value || allowedEmpty);
2460 if (option.selected && hasValue) {
2461 isSelectedOptions = true;
2462
2463 // If using a hash serializer be sure to add the
2464 // correct notation for an array in the multi-select
2465 // context. Here the name attribute on the select element
2466 // might be missing the trailing bracket pair. Both names
2467 // "foo" and "foo[]" should be arrays.
2468 if (options.hash && key.slice(key.length - 2) !== '[]') {
2469 result = serializer(result, key + '[]', option.value);
2470 }
2471 else {
2472 result = serializer(result, key, option.value);
2473 }
2474 }
2475 }
2476
2477 // Serialize if no selected options and options.empty is true
2478 if (!isSelectedOptions && options.empty) {
2479 result = serializer(result, key, '');
2480 }
2481
2482 continue;
2483 }
2484
2485 result = serializer(result, key, val);
2486 }
2487
2488 // Check for all empty radio buttons and serialize them with key=""
2489 if (options.empty) {
2490 for (var key in radio_store) {
2491 if (!radio_store[key]) {
2492 result = serializer(result, key, '');
2493 }
2494 }
2495 }
2496
2497 return result;
2498 }
2499
2500 function parse_keys(string) {
2501 var keys = [];
2502 var prefix = /^([^\[\]]*)/;
2503 var children = new RegExp(brackets);
2504 var match = prefix.exec(string);
2505
2506 if (match[1]) {
2507 keys.push(match[1]);
2508 }
2509
2510 while ((match = children.exec(string)) !== null) {
2511 keys.push(match[1]);
2512 }
2513
2514 return keys;
2515 }
2516
2517 function hash_assign(result, keys, value) {
2518 if (keys.length === 0) {
2519 result = value;
2520 return result;
2521 }
2522
2523 var key = keys.shift();
2524 var between = key.match(/^\[(.+?)\]$/);
2525
2526 if (key === '[]') {
2527 result = result || [];
2528
2529 if (Array.isArray(result)) {
2530 result.push(hash_assign(null, keys, value));
2531 }
2532 else {
2533 // This might be the result of bad name attributes like "[][foo]",
2534 // in this case the original `result` object will already be
2535 // assigned to an object literal. Rather than coerce the object to
2536 // an array, or cause an exception the attribute "_values" is
2537 // assigned as an array.
2538 result._values = result._values || [];
2539 result._values.push(hash_assign(null, keys, value));
2540 }
2541
2542 return result;
2543 }
2544
2545 // Key is an attribute name and can be assigned directly.
2546 if (!between) {
2547 result[key] = hash_assign(result[key], keys, value);
2548 }
2549 else {
2550 var string = between[1];
2551 // +var converts the variable into a number
2552 // better than parseInt because it doesn't truncate away trailing
2553 // letters and actually fails if whole thing is not a number
2554 var index = +string;
2555
2556 // If the characters between the brackets is not a number it is an
2557 // attribute name and can be assigned directly.
2558 if (isNaN(index)) {
2559 result = result || {};
2560 result[string] = hash_assign(result[string], keys, value);
2561 }
2562 else {
2563 result = result || [];
2564 result[index] = hash_assign(result[index], keys, value);
2565 }
2566 }
2567
2568 return result;
2569 }
2570
2571 // Object/hash encoding serializer.
2572 function hash_serializer(result, key, value) {
2573 var matches = key.match(brackets);
2574
2575 // Has brackets? Use the recursive assignment function to walk the keys,
2576 // construct any missing objects in the result tree and make the assignment
2577 // at the end of the chain.
2578 if (matches) {
2579 var keys = parse_keys(key);
2580 hash_assign(result, keys, value);
2581 }
2582 else {
2583 // Non bracket notation can make assignments directly.
2584 var existing = result[key];
2585
2586 // If the value has been assigned already (for instance when a radio and
2587 // a checkbox have the same name attribute) convert the previous value
2588 // into an array before pushing into it.
2589 //
2590 // NOTE: If this requirement were removed all hash creation and
2591 // assignment could go through `hash_assign`.
2592 if (existing) {
2593 if (!Array.isArray(existing)) {
2594 result[key] = [ existing ];
2595 }
2596
2597 result[key].push(value);
2598 }
2599 else {
2600 result[key] = value;
2601 }
2602 }
2603
2604 return result;
2605 }
2606
2607 // urlform encoding serializer
2608 function str_serialize(result, key, value) {
2609 // encode newlines as \r\n cause the html spec says so
2610 value = value.replace(/(\r)?\n/g, '\r\n');
2611 value = encodeURIComponent(value);
2612
2613 // spaces should be '+' rather than '%20'.
2614 value = value.replace(/%20/g, '+');
2615 return result + (result ? '&' : '') + encodeURIComponent(key) + '=' + value;
2616 }
2617
2618 module.exports = serialize;
2619
2620 },{}],6:[function(require,module,exports){
2621 /*!
2622 * EventEmitter v5.2.4 - git.io/ee
2623 * Unlicense - http://unlicense.org/
2624 * Oliver Caldwell - http://oli.me.uk/
2625 * @preserve
2626 */
2627
2628 ;(function (exports) {
2629 'use strict';
2630
2631 /**
2632 * Class for managing events.
2633 * Can be extended to provide event functionality in other classes.
2634 *
2635 * @class EventEmitter Manages event registering and emitting.
2636 */
2637 function EventEmitter() {}
2638
2639 // Shortcuts to improve speed and size
2640 var proto = EventEmitter.prototype;
2641 var originalGlobalValue = exports.EventEmitter;
2642
2643 /**
2644 * Finds the index of the listener for the event in its storage array.
2645 *
2646 * @param {Function[]} listeners Array of listeners to search through.
2647 * @param {Function} listener Method to look for.
2648 * @return {Number} Index of the specified listener, -1 if not found
2649 * @api private
2650 */
2651 function indexOfListener(listeners, listener) {
2652 var i = listeners.length;
2653 while (i--) {
2654 if (listeners[i].listener === listener) {
2655 return i;
2656 }
2657 }
2658
2659 return -1;
2660 }
2661
2662 /**
2663 * Alias a method while keeping the context correct, to allow for overwriting of target method.
2664 *
2665 * @param {String} name The name of the target method.
2666 * @return {Function} The aliased method
2667 * @api private
2668 */
2669 function alias(name) {
2670 return function aliasClosure() {
2671 return this[name].apply(this, arguments);
2672 };
2673 }
2674
2675 /**
2676 * Returns the listener array for the specified event.
2677 * Will initialise the event object and listener arrays if required.
2678 * Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.
2679 * Each property in the object response is an array of listener functions.
2680 *
2681 * @param {String|RegExp} evt Name of the event to return the listeners from.
2682 * @return {Function[]|Object} All listener functions for the event.
2683 */
2684 proto.getListeners = function getListeners(evt) {
2685 var events = this._getEvents();
2686 var response;
2687 var key;
2688
2689 // Return a concatenated array of all matching events if
2690 // the selector is a regular expression.
2691 if (evt instanceof RegExp) {
2692 response = {};
2693 for (key in events) {
2694 if (events.hasOwnProperty(key) && evt.test(key)) {
2695 response[key] = events[key];
2696 }
2697 }
2698 }
2699 else {
2700 response = events[evt] || (events[evt] = []);
2701 }
2702
2703 return response;
2704 };
2705
2706 /**
2707 * Takes a list of listener objects and flattens it into a list of listener functions.
2708 *
2709 * @param {Object[]} listeners Raw listener objects.
2710 * @return {Function[]} Just the listener functions.
2711 */
2712 proto.flattenListeners = function flattenListeners(listeners) {
2713 var flatListeners = [];
2714 var i;
2715
2716 for (i = 0; i < listeners.length; i += 1) {
2717 flatListeners.push(listeners[i].listener);
2718 }
2719
2720 return flatListeners;
2721 };
2722
2723 /**
2724 * Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.
2725 *
2726 * @param {String|RegExp} evt Name of the event to return the listeners from.
2727 * @return {Object} All listener functions for an event in an object.
2728 */
2729 proto.getListenersAsObject = function getListenersAsObject(evt) {
2730 var listeners = this.getListeners(evt);
2731 var response;
2732
2733 if (listeners instanceof Array) {
2734 response = {};
2735 response[evt] = listeners;
2736 }
2737
2738 return response || listeners;
2739 };
2740
2741 function isValidListener (listener) {
2742 if (typeof listener === 'function' || listener instanceof RegExp) {
2743 return true
2744 } else if (listener && typeof listener === 'object') {
2745 return isValidListener(listener.listener)
2746 } else {
2747 return false
2748 }
2749 }
2750
2751 /**
2752 * Adds a listener function to the specified event.
2753 * The listener will not be added if it is a duplicate.
2754 * If the listener returns true then it will be removed after it is called.
2755 * If you pass a regular expression as the event name then the listener will be added to all events that match it.
2756 *
2757 * @param {String|RegExp} evt Name of the event to attach the listener to.
2758 * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
2759 * @return {Object} Current instance of EventEmitter for chaining.
2760 */
2761 proto.addListener = function addListener(evt, listener) {
2762 if (!isValidListener(listener)) {
2763 throw new TypeError('listener must be a function');
2764 }
2765
2766 var listeners = this.getListenersAsObject(evt);
2767 var listenerIsWrapped = typeof listener === 'object';
2768 var key;
2769
2770 for (key in listeners) {
2771 if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {
2772 listeners[key].push(listenerIsWrapped ? listener : {
2773 listener: listener,
2774 once: false
2775 });
2776 }
2777 }
2778
2779 return this;
2780 };
2781
2782 /**
2783 * Alias of addListener
2784 */
2785 proto.on = alias('addListener');
2786
2787 /**
2788 * Semi-alias of addListener. It will add a listener that will be
2789 * automatically removed after its first execution.
2790 *
2791 * @param {String|RegExp} evt Name of the event to attach the listener to.
2792 * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
2793 * @return {Object} Current instance of EventEmitter for chaining.
2794 */
2795 proto.addOnceListener = function addOnceListener(evt, listener) {
2796 return this.addListener(evt, {
2797 listener: listener,
2798 once: true
2799 });
2800 };
2801
2802 /**
2803 * Alias of addOnceListener.
2804 */
2805 proto.once = alias('addOnceListener');
2806
2807 /**
2808 * Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.
2809 * You need to tell it what event names should be matched by a regex.
2810 *
2811 * @param {String} evt Name of the event to create.
2812 * @return {Object} Current instance of EventEmitter for chaining.
2813 */
2814 proto.defineEvent = function defineEvent(evt) {
2815 this.getListeners(evt);
2816 return this;
2817 };
2818
2819 /**
2820 * Uses defineEvent to define multiple events.
2821 *
2822 * @param {String[]} evts An array of event names to define.
2823 * @return {Object} Current instance of EventEmitter for chaining.
2824 */
2825 proto.defineEvents = function defineEvents(evts) {
2826 for (var i = 0; i < evts.length; i += 1) {
2827 this.defineEvent(evts[i]);
2828 }
2829 return this;
2830 };
2831
2832 /**
2833 * Removes a listener function from the specified event.
2834 * When passed a regular expression as the event name, it will remove the listener from all events that match it.
2835 *
2836 * @param {String|RegExp} evt Name of the event to remove the listener from.
2837 * @param {Function} listener Method to remove from the event.
2838 * @return {Object} Current instance of EventEmitter for chaining.
2839 */
2840 proto.removeListener = function removeListener(evt, listener) {
2841 var listeners = this.getListenersAsObject(evt);
2842 var index;
2843 var key;
2844
2845 for (key in listeners) {
2846 if (listeners.hasOwnProperty(key)) {
2847 index = indexOfListener(listeners[key], listener);
2848
2849 if (index !== -1) {
2850 listeners[key].splice(index, 1);
2851 }
2852 }
2853 }
2854
2855 return this;
2856 };
2857
2858 /**
2859 * Alias of removeListener
2860 */
2861 proto.off = alias('removeListener');
2862
2863 /**
2864 * Adds listeners in bulk using the manipulateListeners method.
2865 * If you pass an object as the first argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.
2866 * You can also pass it a regular expression to add the array of listeners to all events that match it.
2867 * Yeah, this function does quite a bit. That's probably a bad thing.
2868 *
2869 * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.
2870 * @param {Function[]} [listeners] An optional array of listener functions to add.
2871 * @return {Object} Current instance of EventEmitter for chaining.
2872 */
2873 proto.addListeners = function addListeners(evt, listeners) {
2874 // Pass through to manipulateListeners
2875 return this.manipulateListeners(false, evt, listeners);
2876 };
2877
2878 /**
2879 * Removes listeners in bulk using the manipulateListeners method.
2880 * If you pass an object as the first argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
2881 * You can also pass it an event name and an array of listeners to be removed.
2882 * You can also pass it a regular expression to remove the listeners from all events that match it.
2883 *
2884 * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.
2885 * @param {Function[]} [listeners] An optional array of listener functions to remove.
2886 * @return {Object} Current instance of EventEmitter for chaining.
2887 */
2888 proto.removeListeners = function removeListeners(evt, listeners) {
2889 // Pass through to manipulateListeners
2890 return this.manipulateListeners(true, evt, listeners);
2891 };
2892
2893 /**
2894 * Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.
2895 * The first argument will determine if the listeners are removed (true) or added (false).
2896 * If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
2897 * You can also pass it an event name and an array of listeners to be added/removed.
2898 * You can also pass it a regular expression to manipulate the listeners of all events that match it.
2899 *
2900 * @param {Boolean} remove True if you want to remove listeners, false if you want to add.
2901 * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.
2902 * @param {Function[]} [listeners] An optional array of listener functions to add/remove.
2903 * @return {Object} Current instance of EventEmitter for chaining.
2904 */
2905 proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {
2906 var i;
2907 var value;
2908 var single = remove ? this.removeListener : this.addListener;
2909 var multiple = remove ? this.removeListeners : this.addListeners;
2910
2911 // If evt is an object then pass each of its properties to this method
2912 if (typeof evt === 'object' && !(evt instanceof RegExp)) {
2913 for (i in evt) {
2914 if (evt.hasOwnProperty(i) && (value = evt[i])) {
2915 // Pass the single listener straight through to the singular method
2916 if (typeof value === 'function') {
2917 single.call(this, i, value);
2918 }
2919 else {
2920 // Otherwise pass back to the multiple function
2921 multiple.call(this, i, value);
2922 }
2923 }
2924 }
2925 }
2926 else {
2927 // So evt must be a string
2928 // And listeners must be an array of listeners
2929 // Loop over it and pass each one to the multiple method
2930 i = listeners.length;
2931 while (i--) {
2932 single.call(this, evt, listeners[i]);
2933 }
2934 }
2935
2936 return this;
2937 };
2938
2939 /**
2940 * Removes all listeners from a specified event.
2941 * If you do not specify an event then all listeners will be removed.
2942 * That means every event will be emptied.
2943 * You can also pass a regex to remove all events that match it.
2944 *
2945 * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.
2946 * @return {Object} Current instance of EventEmitter for chaining.
2947 */
2948 proto.removeEvent = function removeEvent(evt) {
2949 var type = typeof evt;
2950 var events = this._getEvents();
2951 var key;
2952
2953 // Remove different things depending on the state of evt
2954 if (type === 'string') {
2955 // Remove all listeners for the specified event
2956 delete events[evt];
2957 }
2958 else if (evt instanceof RegExp) {
2959 // Remove all events matching the regex.
2960 for (key in events) {
2961 if (events.hasOwnProperty(key) && evt.test(key)) {
2962 delete events[key];
2963 }
2964 }
2965 }
2966 else {
2967 // Remove all listeners in all events
2968 delete this._events;
2969 }
2970
2971 return this;
2972 };
2973
2974 /**
2975 * Alias of removeEvent.
2976 *
2977 * Added to mirror the node API.
2978 */
2979 proto.removeAllListeners = alias('removeEvent');
2980
2981 /**
2982 * Emits an event of your choice.
2983 * When emitted, every listener attached to that event will be executed.
2984 * If you pass the optional argument array then those arguments will be passed to every listener upon execution.
2985 * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.
2986 * So they will not arrive within the array on the other side, they will be separate.
2987 * You can also pass a regular expression to emit to all events that match it.
2988 *
2989 * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
2990 * @param {Array} [args] Optional array of arguments to be passed to each listener.
2991 * @return {Object} Current instance of EventEmitter for chaining.
2992 */
2993 proto.emitEvent = function emitEvent(evt, args) {
2994 var listenersMap = this.getListenersAsObject(evt);
2995 var listeners;
2996 var listener;
2997 var i;
2998 var key;
2999 var response;
3000
3001 for (key in listenersMap) {
3002 if (listenersMap.hasOwnProperty(key)) {
3003 listeners = listenersMap[key].slice(0);
3004
3005 for (i = 0; i < listeners.length; i++) {
3006 // If the listener returns true then it shall be removed from the event
3007 // The function is executed either with a basic call or an apply if there is an args array
3008 listener = listeners[i];
3009
3010 if (listener.once === true) {
3011 this.removeListener(evt, listener.listener);
3012 }
3013
3014 response = listener.listener.apply(this, args || []);
3015
3016 if (response === this._getOnceReturnValue()) {
3017 this.removeListener(evt, listener.listener);
3018 }
3019 }
3020 }
3021 }
3022
3023 return this;
3024 };
3025
3026 /**
3027 * Alias of emitEvent
3028 */
3029 proto.trigger = alias('emitEvent');
3030
3031 /**
3032 * Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.
3033 * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.
3034 *
3035 * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
3036 * @param {...*} Optional additional arguments to be passed to each listener.
3037 * @return {Object} Current instance of EventEmitter for chaining.
3038 */
3039 proto.emit = function emit(evt) {
3040 var args = Array.prototype.slice.call(arguments, 1);
3041 return this.emitEvent(evt, args);
3042 };
3043
3044 /**
3045 * Sets the current value to check against when executing listeners. If a
3046 * listeners return value matches the one set here then it will be removed
3047 * after execution. This value defaults to true.
3048 *
3049 * @param {*} value The new value to check for when executing listeners.
3050 * @return {Object} Current instance of EventEmitter for chaining.
3051 */
3052 proto.setOnceReturnValue = function setOnceReturnValue(value) {
3053 this._onceReturnValue = value;
3054 return this;
3055 };
3056
3057 /**
3058 * Fetches the current value to check against when executing listeners. If
3059 * the listeners return value matches this one then it should be removed
3060 * automatically. It will return true by default.
3061 *
3062 * @return {*|Boolean} The current value to check for or the default, true.
3063 * @api private
3064 */
3065 proto._getOnceReturnValue = function _getOnceReturnValue() {
3066 if (this.hasOwnProperty('_onceReturnValue')) {
3067 return this._onceReturnValue;
3068 }
3069 else {
3070 return true;
3071 }
3072 };
3073
3074 /**
3075 * Fetches the events object and creates one if required.
3076 *
3077 * @return {Object} The events storage object.
3078 * @api private
3079 */
3080 proto._getEvents = function _getEvents() {
3081 return this._events || (this._events = {});
3082 };
3083
3084 /**
3085 * Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version.
3086 *
3087 * @return {Function} Non conflicting EventEmitter class.
3088 */
3089 EventEmitter.noConflict = function noConflict() {
3090 exports.EventEmitter = originalGlobalValue;
3091 return EventEmitter;
3092 };
3093
3094 // Expose the class either via AMD, CommonJS or the global object
3095 if (typeof define === 'function' && define.amd) {
3096 define(function () {
3097 return EventEmitter;
3098 });
3099 }
3100 else if (typeof module === 'object' && module.exports){
3101 module.exports = EventEmitter;
3102 }
3103 else {
3104 exports.EventEmitter = EventEmitter;
3105 }
3106 }(this || {}));
3107
3108 },{}]},{},[3]);
3109 ; })();