UNPKG

337 kBJavaScriptView Raw
1(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.armature = f()}})(function(){var define,module,exports;return (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";
3var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
4 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5 if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
6 r = Reflect.decorate(decorators, target, key, desc);
7 else
8 for (var i = decorators.length - 1; i >= 0; i--)
9 if (d = decorators[i])
10 r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
11 return c > 3 && r && Object.defineProperty(target, key, r), r;
12};
13var UUID_1 = require("./UUID");
14var Decorators_1 = require("./Decorators");
15var ComponentStore_1 = require("./ComponentStore");
16var assign = require("object-assign");
17/**
18 * The base for all Armature components.
19 */
20var Component = (function () {
21 /**
22 * Creates a new component with the given data.
23 *
24 * @param data The data to initialize the component with
25 */
26 function Component(data) {
27 /**
28 * The components this component contains.
29 */
30 this.$children = [];
31 this.$data = data;
32 this.$id = UUID_1.default.get();
33 }
34 /**
35 * Creates or retrieves a component that is attached to another component.
36 * Using the same parent and 'label' parameters will retrieve the same object.
37 * Pass null to the data attribute to throw if a new component is created.
38 *
39 * @param parent The component to attach to
40 * @param label The label to use when creating or retrieving the component
41 * @param data The data to initialize the component with if it hasn't been created
42 */
43 Component.$for = function (parent, label, data) {
44 var identifier = this.$getIdentifier(label);
45 var existing = parent.$children.find(function (v) { return v.$getIdentifier() === identifier; });
46 if (existing) {
47 return existing;
48 }
49 if (data === null) {
50 throw new Error("Subcomponent was created with no data!");
51 }
52 var inst = new this(data);
53 inst.$label = label;
54 inst.$parent = parent;
55 parent.$children.push(inst);
56 return inst;
57 };
58 /**
59 * Serializes the component's data for potential recreation.
60 */
61 Component.prototype.$serializeData = function () {
62 return assign({}, this.$data);
63 };
64 /**
65 * Returns a way to uniquely identify this component type.
66 */
67 Component.$getTypeName = function () {
68 var classString = this.$classNames.map(function (v) { return "." + v; }).join("");
69 return this.$tagName + classString;
70 };
71 /**
72 * Creates an object that can be used to recreate this component.
73 */
74 Component.prototype.$deflate = function () {
75 var thisClass = this.constructor;
76 return {
77 type: thisClass.$getTypeName(),
78 data: this.$serializeData(),
79 id: this.$id,
80 label: this.$label,
81 children: this.$children.map(function (v) { return v.$deflate(); })
82 };
83 };
84 /**
85 * Creates an instance of a component from data generated by $deflate.
86 *
87 * @param deflated The deflated component data to use
88 * @param inst An optional existing object to inflate
89 */
90 Component.$inflate = function (deflated, inst) {
91 if (!inst) {
92 inst = new this(deflated.data);
93 }
94 inst.$id = deflated.id;
95 inst.$label = deflated.label;
96 if (deflated.children) {
97 for (var _i = 0, _a = deflated.children; _i < _a.length; _i++) {
98 var child = _a[_i];
99 var thatClass = ComponentStore_1.default.get(child.type);
100 var childInst = thatClass.$for(inst, child.label, child.data);
101 thatClass.$inflate(child, childInst);
102 }
103 }
104 return inst;
105 };
106 /**
107 * Returns an identifier that should be unique among a component's siblings.
108 *
109 * @param label The label of the component to create the label for
110 */
111 Component.$getIdentifier = function (label) {
112 return this.$getTypeName() + "__" + label;
113 };
114 /**
115 * Returns an identifier that should be unique among a component's siblings.
116 */
117 Component.prototype.$getIdentifier = function () {
118 var thisClass = this.constructor;
119 return thisClass.$getIdentifier(this.$label);
120 };
121 Component.prototype.toString = function () {
122 return this.$getHTML();
123 };
124 /**
125 * Builds the HTML associated with this component.
126 */
127 Component.prototype.$getHTML = function () {
128 var thisClass = this.constructor;
129 return "<" + thisClass.$tagName + "\n\t\t\tclass=\"" + thisClass.$classNames.join(" ") + "\"\n\t\t\tdata-armid=\"" + this.$id + "\"\n\t\t\t" + (this.$label ? "data-label=\"" + this.$label + "\"" : "") + "\n\t\t\t>" + this.$template(this) + "</" + thisClass.$tagName + ">";
130 };
131 /**
132 * Creates an HTML element for this component if one does not exist.
133 */
134 Component.prototype.$ensureElement = function () {
135 if (!this.$element) {
136 var thisClass = this.constructor;
137 var el = document.createElement(thisClass.$tagName);
138 (_a = el.classList).add.apply(_a, thisClass.$classNames);
139 this.$attachTo(el);
140 }
141 var _a;
142 };
143 /**
144 * Attaches this component to an existing HTML element.
145 *
146 * @param element The element to attach to
147 */
148 Component.prototype.$attachTo = function (element) {
149 this.$element = element;
150 element.setAttribute("data-armid", this.$id.toString());
151 if (this.$label) {
152 element.setAttribute("data-label", this.$label);
153 }
154 };
155 /**
156 * Attempts to locate this component's element from a parent element.
157 *
158 * @param parent The element to search in
159 */
160 Component.prototype.$locate = function (parent) {
161 if (parent === void 0) {
162 parent = document.body;
163 }
164 var thisClass = this.constructor;
165 var el = parent.querySelector(thisClass.$tagName + "[data-armid=\"" + this.$id + "\"]");
166 if (el) {
167 this.$element = el;
168 this.$children.forEach(function (child) {
169 child.$locate(el);
170 });
171 return el;
172 }
173 };
174 /**
175 * Evaluates the component's template and puts the result into the component's element
176 */
177 Component.prototype.$render = function () {
178 this.$element.innerHTML = this.$template(this);
179 };
180 /**
181 * Attaches event handlers for the component and its children.
182 * Often used after $render, or as part of $reify.
183 */
184 Component.prototype.$hydrate = function () {
185 for (var _i = 0, _a = this.$children; _i < _a.length; _i++) {
186 var child = _a[_i];
187 if (child.$locate(this.$element)) {
188 child.$hydrate();
189 }
190 }
191 };
192 /**
193 * Ensures this component's element exists, then renders and hydrates it.
194 */
195 Component.prototype.$reify = function () {
196 this.$ensureElement();
197 this.$render();
198 this.$hydrate();
199 };
200 /**
201 * A list of class names to apply to the component's root element.
202 */
203 Component.$classNames = [];
204 Component = __decorate([
205 Decorators_1.TagName("arm-component"),
206 Decorators_1.Template(function () { return ""; })
207 ], Component);
208 return Component;
209}());
210exports.Component = Component;
211
212
213},{"./ComponentStore":2,"./Decorators":3,"./UUID":5,"object-assign":42}],2:[function(require,module,exports){
214"use strict";
215var ComponentStore = {
216 store: new Map(),
217 register: function (componentType) {
218 this.store.set(componentType.$getTypeName(), componentType);
219 },
220 get: function (typeName) {
221 return this.store.get(typeName);
222 }
223};
224Object.defineProperty(exports, "__esModule", { value: true });
225exports.default = ComponentStore;
226
227
228},{}],3:[function(require,module,exports){
229"use strict";
230/**
231 * Attaches a template to a Component
232 * @param template The template to attach
233 */
234function Template(template) {
235 return function (target) {
236 target.prototype.$template = template;
237 };
238}
239exports.Template = Template;
240/**
241 * Sets the HTML tag name of a Component
242 * @param name The tag name to attach
243 */
244function TagName(name) {
245 return function (target) {
246 target.$tagName = name;
247 };
248}
249exports.TagName = TagName;
250/**
251 * Attaches HTML class names to a Component's element
252 * @param names The names to attach
253 */
254function ClassNames() {
255 var names = [];
256 for (var _i = 0; _i < arguments.length; _i++) {
257 names[_i - 0] = arguments[_i];
258 }
259 return function (target) {
260 (_a = target.$classNames).push.apply(_a, names);
261 var _a;
262 };
263}
264exports.ClassNames = ClassNames;
265
266
267},{}],4:[function(require,module,exports){
268"use strict";
269var ComponentStore_1 = require("./ComponentStore");
270function Properties(data) {
271 return function (target) {
272 target.prototype.$template = data.template;
273 target.$tagName = data.tag;
274 if (data.classes) {
275 target.$classNames = target.$classNames.concat(data.classes);
276 }
277 ComponentStore_1.default.register(target);
278 };
279}
280exports.Properties = Properties;
281
282
283},{"./ComponentStore":2}],5:[function(require,module,exports){
284"use strict";
285var randomBuffer = new Uint16Array(1);
286/**
287 * Returns a random number on [0, 1)
288 * Uses window.crypto if available
289 */
290function rand() {
291 if (typeof crypto !== "undefined") {
292 crypto.getRandomValues(randomBuffer);
293 return randomBuffer[0] / Math.pow(2, 16);
294 }
295 else {
296 return Math.random();
297 }
298}
299var UUID = {
300 /**
301 * Generates a v4 UUID.
302 */
303 get: function () {
304 var template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
305 var value = template.replace(/[xy]/g, function (c) {
306 var v = Math.floor(rand() * 16);
307 if (c !== "x") {
308 v = v & 0x3 | 0x8;
309 }
310 return v.toString(16);
311 });
312 return value;
313 }
314};
315Object.defineProperty(exports, "__esModule", { value: true });
316exports.default = UUID;
317
318
319},{}],6:[function(require,module,exports){
320"use strict";
321function __export(m) {
322 for (var p in m)
323 if (!exports.hasOwnProperty(p))
324 exports[p] = m[p];
325}
326__export(require("./Component"));
327var ComponentStore_1 = require("./ComponentStore");
328exports.ComponentStore = ComponentStore_1.default;
329var UUID_1 = require("./UUID");
330exports.UUID = UUID_1.default;
331__export(require("./Decorators"));
332__export(require("./Properties"));
333
334
335},{"./Component":1,"./ComponentStore":2,"./Decorators":3,"./Properties":4,"./UUID":5}],7:[function(require,module,exports){
336(function (process,__filename){
337/** vim: et:ts=4:sw=4:sts=4
338 * @license amdefine 1.0.0 Copyright (c) 2011-2015, The Dojo Foundation All Rights Reserved.
339 * Available via the MIT or new BSD license.
340 * see: http://github.com/jrburke/amdefine for details
341 */
342
343/*jslint node: true */
344/*global module, process */
345'use strict';
346
347/**
348 * Creates a define for node.
349 * @param {Object} module the "module" object that is defined by Node for the
350 * current module.
351 * @param {Function} [requireFn]. Node's require function for the current module.
352 * It only needs to be passed in Node versions before 0.5, when module.require
353 * did not exist.
354 * @returns {Function} a define function that is usable for the current node
355 * module.
356 */
357function amdefine(module, requireFn) {
358 'use strict';
359 var defineCache = {},
360 loaderCache = {},
361 alreadyCalled = false,
362 path = require('path'),
363 makeRequire, stringRequire;
364
365 /**
366 * Trims the . and .. from an array of path segments.
367 * It will keep a leading path segment if a .. will become
368 * the first path segment, to help with module name lookups,
369 * which act like paths, but can be remapped. But the end result,
370 * all paths that use this function should look normalized.
371 * NOTE: this method MODIFIES the input array.
372 * @param {Array} ary the array of path segments.
373 */
374 function trimDots(ary) {
375 var i, part;
376 for (i = 0; ary[i]; i+= 1) {
377 part = ary[i];
378 if (part === '.') {
379 ary.splice(i, 1);
380 i -= 1;
381 } else if (part === '..') {
382 if (i === 1 && (ary[2] === '..' || ary[0] === '..')) {
383 //End of the line. Keep at least one non-dot
384 //path segment at the front so it can be mapped
385 //correctly to disk. Otherwise, there is likely
386 //no path mapping for a path starting with '..'.
387 //This can still fail, but catches the most reasonable
388 //uses of ..
389 break;
390 } else if (i > 0) {
391 ary.splice(i - 1, 2);
392 i -= 2;
393 }
394 }
395 }
396 }
397
398 function normalize(name, baseName) {
399 var baseParts;
400
401 //Adjust any relative paths.
402 if (name && name.charAt(0) === '.') {
403 //If have a base name, try to normalize against it,
404 //otherwise, assume it is a top-level require that will
405 //be relative to baseUrl in the end.
406 if (baseName) {
407 baseParts = baseName.split('/');
408 baseParts = baseParts.slice(0, baseParts.length - 1);
409 baseParts = baseParts.concat(name.split('/'));
410 trimDots(baseParts);
411 name = baseParts.join('/');
412 }
413 }
414
415 return name;
416 }
417
418 /**
419 * Create the normalize() function passed to a loader plugin's
420 * normalize method.
421 */
422 function makeNormalize(relName) {
423 return function (name) {
424 return normalize(name, relName);
425 };
426 }
427
428 function makeLoad(id) {
429 function load(value) {
430 loaderCache[id] = value;
431 }
432
433 load.fromText = function (id, text) {
434 //This one is difficult because the text can/probably uses
435 //define, and any relative paths and requires should be relative
436 //to that id was it would be found on disk. But this would require
437 //bootstrapping a module/require fairly deeply from node core.
438 //Not sure how best to go about that yet.
439 throw new Error('amdefine does not implement load.fromText');
440 };
441
442 return load;
443 }
444
445 makeRequire = function (systemRequire, exports, module, relId) {
446 function amdRequire(deps, callback) {
447 if (typeof deps === 'string') {
448 //Synchronous, single module require('')
449 return stringRequire(systemRequire, exports, module, deps, relId);
450 } else {
451 //Array of dependencies with a callback.
452
453 //Convert the dependencies to modules.
454 deps = deps.map(function (depName) {
455 return stringRequire(systemRequire, exports, module, depName, relId);
456 });
457
458 //Wait for next tick to call back the require call.
459 if (callback) {
460 process.nextTick(function () {
461 callback.apply(null, deps);
462 });
463 }
464 }
465 }
466
467 amdRequire.toUrl = function (filePath) {
468 if (filePath.indexOf('.') === 0) {
469 return normalize(filePath, path.dirname(module.filename));
470 } else {
471 return filePath;
472 }
473 };
474
475 return amdRequire;
476 };
477
478 //Favor explicit value, passed in if the module wants to support Node 0.4.
479 requireFn = requireFn || function req() {
480 return module.require.apply(module, arguments);
481 };
482
483 function runFactory(id, deps, factory) {
484 var r, e, m, result;
485
486 if (id) {
487 e = loaderCache[id] = {};
488 m = {
489 id: id,
490 uri: __filename,
491 exports: e
492 };
493 r = makeRequire(requireFn, e, m, id);
494 } else {
495 //Only support one define call per file
496 if (alreadyCalled) {
497 throw new Error('amdefine with no module ID cannot be called more than once per file.');
498 }
499 alreadyCalled = true;
500
501 //Use the real variables from node
502 //Use module.exports for exports, since
503 //the exports in here is amdefine exports.
504 e = module.exports;
505 m = module;
506 r = makeRequire(requireFn, e, m, module.id);
507 }
508
509 //If there are dependencies, they are strings, so need
510 //to convert them to dependency values.
511 if (deps) {
512 deps = deps.map(function (depName) {
513 return r(depName);
514 });
515 }
516
517 //Call the factory with the right dependencies.
518 if (typeof factory === 'function') {
519 result = factory.apply(m.exports, deps);
520 } else {
521 result = factory;
522 }
523
524 if (result !== undefined) {
525 m.exports = result;
526 if (id) {
527 loaderCache[id] = m.exports;
528 }
529 }
530 }
531
532 stringRequire = function (systemRequire, exports, module, id, relId) {
533 //Split the ID by a ! so that
534 var index = id.indexOf('!'),
535 originalId = id,
536 prefix, plugin;
537
538 if (index === -1) {
539 id = normalize(id, relId);
540
541 //Straight module lookup. If it is one of the special dependencies,
542 //deal with it, otherwise, delegate to node.
543 if (id === 'require') {
544 return makeRequire(systemRequire, exports, module, relId);
545 } else if (id === 'exports') {
546 return exports;
547 } else if (id === 'module') {
548 return module;
549 } else if (loaderCache.hasOwnProperty(id)) {
550 return loaderCache[id];
551 } else if (defineCache[id]) {
552 runFactory.apply(null, defineCache[id]);
553 return loaderCache[id];
554 } else {
555 if(systemRequire) {
556 return systemRequire(originalId);
557 } else {
558 throw new Error('No module with ID: ' + id);
559 }
560 }
561 } else {
562 //There is a plugin in play.
563 prefix = id.substring(0, index);
564 id = id.substring(index + 1, id.length);
565
566 plugin = stringRequire(systemRequire, exports, module, prefix, relId);
567
568 if (plugin.normalize) {
569 id = plugin.normalize(id, makeNormalize(relId));
570 } else {
571 //Normalize the ID normally.
572 id = normalize(id, relId);
573 }
574
575 if (loaderCache[id]) {
576 return loaderCache[id];
577 } else {
578 plugin.load(id, makeRequire(systemRequire, exports, module, relId), makeLoad(id), {});
579
580 return loaderCache[id];
581 }
582 }
583 };
584
585 //Create a define function specific to the module asking for amdefine.
586 function define(id, deps, factory) {
587 if (Array.isArray(id)) {
588 factory = deps;
589 deps = id;
590 id = undefined;
591 } else if (typeof id !== 'string') {
592 factory = id;
593 id = deps = undefined;
594 }
595
596 if (deps && !Array.isArray(deps)) {
597 factory = deps;
598 deps = undefined;
599 }
600
601 if (!deps) {
602 deps = ['require', 'exports', 'module'];
603 }
604
605 //Set up properties for this module. If an ID, then use
606 //internal cache. If no ID, then use the external variables
607 //for this node module.
608 if (id) {
609 //Put the module in deep freeze until there is a
610 //require call for it.
611 defineCache[id] = [id, deps, factory];
612 } else {
613 runFactory(id, deps, factory);
614 }
615 }
616
617 //define.require, which has access to all the values in the
618 //cache. Useful for AMD modules that all have IDs in the file,
619 //but need to finally export a value to node based on one of those
620 //IDs.
621 define.require = function (id) {
622 if (loaderCache[id]) {
623 return loaderCache[id];
624 }
625
626 if (defineCache[id]) {
627 runFactory.apply(null, defineCache[id]);
628 return loaderCache[id];
629 }
630 };
631
632 define.amd = {};
633
634 return define;
635}
636
637module.exports = amdefine;
638
639}).call(this,require('_process'),"/node_modules/amdefine/amdefine.js")
640
641},{"_process":67,"path":66}],8:[function(require,module,exports){
642/*!
643 * assertion-error
644 * Copyright(c) 2013 Jake Luer <jake@qualiancy.com>
645 * MIT Licensed
646 */
647/*!
648 * Return a function that will copy properties from
649 * one object to another excluding any originally
650 * listed. Returned function will create a new `{}`.
651 *
652 * @param {String} excluded properties ...
653 * @return {Function}
654 */
655function exclude() {
656 var excludes = [].slice.call(arguments);
657 function excludeProps(res, obj) {
658 Object.keys(obj).forEach(function (key) {
659 if (!~excludes.indexOf(key))
660 res[key] = obj[key];
661 });
662 }
663 return function extendExclude() {
664 var args = [].slice.call(arguments), i = 0, res = {};
665 for (; i < args.length; i++) {
666 excludeProps(res, args[i]);
667 }
668 return res;
669 };
670}
671;
672/*!
673 * Primary Exports
674 */
675module.exports = AssertionError;
676/**
677 * ### AssertionError
678 *
679 * An extension of the JavaScript `Error` constructor for
680 * assertion and validation scenarios.
681 *
682 * @param {String} message
683 * @param {Object} properties to include (optional)
684 * @param {callee} start stack function (optional)
685 */
686function AssertionError(message, _props, ssf) {
687 var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON'), props = extend(_props || {});
688 // default values
689 this.message = message || 'Unspecified AssertionError';
690 this.showDiff = false;
691 // copy from properties
692 for (var key in props) {
693 this[key] = props[key];
694 }
695 // capture stack trace
696 ssf = ssf || arguments.callee;
697 if (ssf && Error.captureStackTrace) {
698 Error.captureStackTrace(this, ssf);
699 }
700 else {
701 this.stack = new Error().stack;
702 }
703}
704/*!
705 * Inherit from Error.prototype
706 */
707AssertionError.prototype = Object.create(Error.prototype);
708/*!
709 * Statically set name
710 */
711AssertionError.prototype.name = 'AssertionError';
712/*!
713 * Ensure correct constructor
714 */
715AssertionError.prototype.constructor = AssertionError;
716/**
717 * Allow errors to be converted to JSON for static transfer.
718 *
719 * @param {Boolean} include stack (default: `true`)
720 * @return {Object} object that can be `JSON.stringify`
721 */
722AssertionError.prototype.toJSON = function (stack) {
723 var extend = exclude('constructor', 'toJSON', 'stack'), props = extend({ name: this.name }, this);
724 // include stack if exists and not turned off
725 if (false !== stack && this.stack) {
726 props.stack = this.stack;
727 }
728 return props;
729};
730
731},{}],9:[function(require,module,exports){
732module.exports = require('./lib/chai');
733
734},{"./lib/chai":10}],10:[function(require,module,exports){
735/*!
736 * chai
737 * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
738 * MIT Licensed
739 */
740var used = [], exports = module.exports = {};
741/*!
742 * Chai version
743 */
744exports.version = '3.5.0';
745/*!
746 * Assertion Error
747 */
748exports.AssertionError = require('assertion-error');
749/*!
750 * Utils for plugins (not exported)
751 */
752var util = require('./chai/utils');
753/**
754 * # .use(function)
755 *
756 * Provides a way to extend the internals of Chai
757 *
758 * @param {Function}
759 * @returns {this} for chaining
760 * @api public
761 */
762exports.use = function (fn) {
763 if (!~used.indexOf(fn)) {
764 fn(this, util);
765 used.push(fn);
766 }
767 return this;
768};
769/*!
770 * Utility Functions
771 */
772exports.util = util;
773/*!
774 * Configuration
775 */
776var config = require('./chai/config');
777exports.config = config;
778/*!
779 * Primary `Assertion` prototype
780 */
781var assertion = require('./chai/assertion');
782exports.use(assertion);
783/*!
784 * Core Assertions
785 */
786var core = require('./chai/core/assertions');
787exports.use(core);
788/*!
789 * Expect interface
790 */
791var expect = require('./chai/interface/expect');
792exports.use(expect);
793/*!
794 * Should interface
795 */
796var should = require('./chai/interface/should');
797exports.use(should);
798/*!
799 * Assert interface
800 */
801var assert = require('./chai/interface/assert');
802exports.use(assert);
803
804},{"./chai/assertion":11,"./chai/config":12,"./chai/core/assertions":13,"./chai/interface/assert":14,"./chai/interface/expect":15,"./chai/interface/should":16,"./chai/utils":30,"assertion-error":8}],11:[function(require,module,exports){
805/*!
806 * chai
807 * http://chaijs.com
808 * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
809 * MIT Licensed
810 */
811var config = require('./config');
812module.exports = function (_chai, util) {
813 /*!
814 * Module dependencies.
815 */
816 var AssertionError = _chai.AssertionError, flag = util.flag;
817 /*!
818 * Module export.
819 */
820 _chai.Assertion = Assertion;
821 /*!
822 * Assertion Constructor
823 *
824 * Creates object for chaining.
825 *
826 * @api private
827 */
828 function Assertion(obj, msg, stack) {
829 flag(this, 'ssfi', stack || arguments.callee);
830 flag(this, 'object', obj);
831 flag(this, 'message', msg);
832 }
833 Object.defineProperty(Assertion, 'includeStack', {
834 get: function () {
835 console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
836 return config.includeStack;
837 },
838 set: function (value) {
839 console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
840 config.includeStack = value;
841 }
842 });
843 Object.defineProperty(Assertion, 'showDiff', {
844 get: function () {
845 console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
846 return config.showDiff;
847 },
848 set: function (value) {
849 console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
850 config.showDiff = value;
851 }
852 });
853 Assertion.addProperty = function (name, fn) {
854 util.addProperty(this.prototype, name, fn);
855 };
856 Assertion.addMethod = function (name, fn) {
857 util.addMethod(this.prototype, name, fn);
858 };
859 Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
860 util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
861 };
862 Assertion.overwriteProperty = function (name, fn) {
863 util.overwriteProperty(this.prototype, name, fn);
864 };
865 Assertion.overwriteMethod = function (name, fn) {
866 util.overwriteMethod(this.prototype, name, fn);
867 };
868 Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
869 util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
870 };
871 /**
872 * ### .assert(expression, message, negateMessage, expected, actual, showDiff)
873 *
874 * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
875 *
876 * @name assert
877 * @param {Philosophical} expression to be tested
878 * @param {String|Function} message or function that returns message to display if expression fails
879 * @param {String|Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
880 * @param {Mixed} expected value (remember to check for negation)
881 * @param {Mixed} actual (optional) will default to `this.obj`
882 * @param {Boolean} showDiff (optional) when set to `true`, assert will display a diff in addition to the message if expression fails
883 * @api private
884 */
885 Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
886 var ok = util.test(this, arguments);
887 if (true !== showDiff)
888 showDiff = false;
889 if (true !== config.showDiff)
890 showDiff = false;
891 if (!ok) {
892 var msg = util.getMessage(this, arguments), actual = util.getActual(this, arguments);
893 throw new AssertionError(msg, {
894 actual: actual,
895 expected: expected,
896 showDiff: showDiff
897 }, (config.includeStack) ? this.assert : flag(this, 'ssfi'));
898 }
899 };
900 /*!
901 * ### ._obj
902 *
903 * Quick reference to stored `actual` value for plugin developers.
904 *
905 * @api private
906 */
907 Object.defineProperty(Assertion.prototype, '_obj', { get: function () {
908 return flag(this, 'object');
909 },
910 set: function (val) {
911 flag(this, 'object', val);
912 }
913 });
914};
915
916},{"./config":12}],12:[function(require,module,exports){
917module.exports = {
918 /**
919 * ### config.includeStack
920 *
921 * User configurable property, influences whether stack trace
922 * is included in Assertion error message. Default of false
923 * suppresses stack trace in the error message.
924 *
925 * chai.config.includeStack = true; // enable stack on error
926 *
927 * @param {Boolean}
928 * @api public
929 */
930 includeStack: false,
931 /**
932 * ### config.showDiff
933 *
934 * User configurable property, influences whether or not
935 * the `showDiff` flag should be included in the thrown
936 * AssertionErrors. `false` will always be `false`; `true`
937 * will be true when the assertion has requested a diff
938 * be shown.
939 *
940 * @param {Boolean}
941 * @api public
942 */
943 showDiff: true,
944 /**
945 * ### config.truncateThreshold
946 *
947 * User configurable property, sets length threshold for actual and
948 * expected values in assertion errors. If this threshold is exceeded, for
949 * example for large data structures, the value is replaced with something
950 * like `[ Array(3) ]` or `{ Object (prop1, prop2) }`.
951 *
952 * Set it to zero if you want to disable truncating altogether.
953 *
954 * This is especially userful when doing assertions on arrays: having this
955 * set to a reasonable large value makes the failure messages readily
956 * inspectable.
957 *
958 * chai.config.truncateThreshold = 0; // disable truncating
959 *
960 * @param {Number}
961 * @api public
962 */
963 truncateThreshold: 40
964};
965
966},{}],13:[function(require,module,exports){
967/*!
968 * chai
969 * http://chaijs.com
970 * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
971 * MIT Licensed
972 */
973module.exports = function (chai, _) {
974 var Assertion = chai.Assertion, toString = Object.prototype.toString, flag = _.flag;
975 /**
976 * ### Language Chains
977 *
978 * The following are provided as chainable getters to
979 * improve the readability of your assertions. They
980 * do not provide testing capabilities unless they
981 * have been overwritten by a plugin.
982 *
983 * **Chains**
984 *
985 * - to
986 * - be
987 * - been
988 * - is
989 * - that
990 * - which
991 * - and
992 * - has
993 * - have
994 * - with
995 * - at
996 * - of
997 * - same
998 *
999 * @name language chains
1000 * @namespace BDD
1001 * @api public
1002 */
1003 ['to', 'be', 'been',
1004 'is', 'and', 'has', 'have',
1005 'with', 'that', 'which', 'at',
1006 'of', 'same'].forEach(function (chain) {
1007 Assertion.addProperty(chain, function () {
1008 return this;
1009 });
1010 });
1011 /**
1012 * ### .not
1013 *
1014 * Negates any of assertions following in the chain.
1015 *
1016 * expect(foo).to.not.equal('bar');
1017 * expect(goodFn).to.not.throw(Error);
1018 * expect({ foo: 'baz' }).to.have.property('foo')
1019 * .and.not.equal('bar');
1020 *
1021 * @name not
1022 * @namespace BDD
1023 * @api public
1024 */
1025 Assertion.addProperty('not', function () {
1026 flag(this, 'negate', true);
1027 });
1028 /**
1029 * ### .deep
1030 *
1031 * Sets the `deep` flag, later used by the `equal` and
1032 * `property` assertions.
1033 *
1034 * expect(foo).to.deep.equal({ bar: 'baz' });
1035 * expect({ foo: { bar: { baz: 'quux' } } })
1036 * .to.have.deep.property('foo.bar.baz', 'quux');
1037 *
1038 * `.deep.property` special characters can be escaped
1039 * by adding two slashes before the `.` or `[]`.
1040 *
1041 * var deepCss = { '.link': { '[target]': 42 }};
1042 * expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42);
1043 *
1044 * @name deep
1045 * @namespace BDD
1046 * @api public
1047 */
1048 Assertion.addProperty('deep', function () {
1049 flag(this, 'deep', true);
1050 });
1051 /**
1052 * ### .any
1053 *
1054 * Sets the `any` flag, (opposite of the `all` flag)
1055 * later used in the `keys` assertion.
1056 *
1057 * expect(foo).to.have.any.keys('bar', 'baz');
1058 *
1059 * @name any
1060 * @namespace BDD
1061 * @api public
1062 */
1063 Assertion.addProperty('any', function () {
1064 flag(this, 'any', true);
1065 flag(this, 'all', false);
1066 });
1067 /**
1068 * ### .all
1069 *
1070 * Sets the `all` flag (opposite of the `any` flag)
1071 * later used by the `keys` assertion.
1072 *
1073 * expect(foo).to.have.all.keys('bar', 'baz');
1074 *
1075 * @name all
1076 * @namespace BDD
1077 * @api public
1078 */
1079 Assertion.addProperty('all', function () {
1080 flag(this, 'all', true);
1081 flag(this, 'any', false);
1082 });
1083 /**
1084 * ### .a(type)
1085 *
1086 * The `a` and `an` assertions are aliases that can be
1087 * used either as language chains or to assert a value's
1088 * type.
1089 *
1090 * // typeof
1091 * expect('test').to.be.a('string');
1092 * expect({ foo: 'bar' }).to.be.an('object');
1093 * expect(null).to.be.a('null');
1094 * expect(undefined).to.be.an('undefined');
1095 * expect(new Error).to.be.an('error');
1096 * expect(new Promise).to.be.a('promise');
1097 * expect(new Float32Array()).to.be.a('float32array');
1098 * expect(Symbol()).to.be.a('symbol');
1099 *
1100 * // es6 overrides
1101 * expect({[Symbol.toStringTag]:()=>'foo'}).to.be.a('foo');
1102 *
1103 * // language chain
1104 * expect(foo).to.be.an.instanceof(Foo);
1105 *
1106 * @name a
1107 * @alias an
1108 * @param {String} type
1109 * @param {String} message _optional_
1110 * @namespace BDD
1111 * @api public
1112 */
1113 function an(type, msg) {
1114 if (msg)
1115 flag(this, 'message', msg);
1116 type = type.toLowerCase();
1117 var obj = flag(this, 'object'), article = ~['a', 'e', 'i', 'o', 'u'].indexOf(type.charAt(0)) ? 'an ' : 'a ';
1118 this.assert(type === _.type(obj), 'expected #{this} to be ' + article + type, 'expected #{this} not to be ' + article + type);
1119 }
1120 Assertion.addChainableMethod('an', an);
1121 Assertion.addChainableMethod('a', an);
1122 /**
1123 * ### .include(value)
1124 *
1125 * The `include` and `contain` assertions can be used as either property
1126 * based language chains or as methods to assert the inclusion of an object
1127 * in an array or a substring in a string. When used as language chains,
1128 * they toggle the `contains` flag for the `keys` assertion.
1129 *
1130 * expect([1,2,3]).to.include(2);
1131 * expect('foobar').to.contain('foo');
1132 * expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');
1133 *
1134 * @name include
1135 * @alias contain
1136 * @alias includes
1137 * @alias contains
1138 * @param {Object|String|Number} obj
1139 * @param {String} message _optional_
1140 * @namespace BDD
1141 * @api public
1142 */
1143 function includeChainingBehavior() {
1144 flag(this, 'contains', true);
1145 }
1146 function include(val, msg) {
1147 _.expectTypes(this, ['array', 'object', 'string']);
1148 if (msg)
1149 flag(this, 'message', msg);
1150 var obj = flag(this, 'object');
1151 var expected = false;
1152 if (_.type(obj) === 'array' && _.type(val) === 'object') {
1153 for (var i in obj) {
1154 if (_.eql(obj[i], val)) {
1155 expected = true;
1156 break;
1157 }
1158 }
1159 }
1160 else if (_.type(val) === 'object') {
1161 if (!flag(this, 'negate')) {
1162 for (var k in val)
1163 new Assertion(obj).property(k, val[k]);
1164 return;
1165 }
1166 var subset = {};
1167 for (var k in val)
1168 subset[k] = obj[k];
1169 expected = _.eql(subset, val);
1170 }
1171 else {
1172 expected = (obj != undefined) && ~obj.indexOf(val);
1173 }
1174 this.assert(expected, 'expected #{this} to include ' + _.inspect(val), 'expected #{this} to not include ' + _.inspect(val));
1175 }
1176 Assertion.addChainableMethod('include', include, includeChainingBehavior);
1177 Assertion.addChainableMethod('contain', include, includeChainingBehavior);
1178 Assertion.addChainableMethod('contains', include, includeChainingBehavior);
1179 Assertion.addChainableMethod('includes', include, includeChainingBehavior);
1180 /**
1181 * ### .ok
1182 *
1183 * Asserts that the target is truthy.
1184 *
1185 * expect('everything').to.be.ok;
1186 * expect(1).to.be.ok;
1187 * expect(false).to.not.be.ok;
1188 * expect(undefined).to.not.be.ok;
1189 * expect(null).to.not.be.ok;
1190 *
1191 * @name ok
1192 * @namespace BDD
1193 * @api public
1194 */
1195 Assertion.addProperty('ok', function () {
1196 this.assert(flag(this, 'object'), 'expected #{this} to be truthy', 'expected #{this} to be falsy');
1197 });
1198 /**
1199 * ### .true
1200 *
1201 * Asserts that the target is `true`.
1202 *
1203 * expect(true).to.be.true;
1204 * expect(1).to.not.be.true;
1205 *
1206 * @name true
1207 * @namespace BDD
1208 * @api public
1209 */
1210 Assertion.addProperty('true', function () {
1211 this.assert(true === flag(this, 'object'), 'expected #{this} to be true', 'expected #{this} to be false', this.negate ? false : true);
1212 });
1213 /**
1214 * ### .false
1215 *
1216 * Asserts that the target is `false`.
1217 *
1218 * expect(false).to.be.false;
1219 * expect(0).to.not.be.false;
1220 *
1221 * @name false
1222 * @namespace BDD
1223 * @api public
1224 */
1225 Assertion.addProperty('false', function () {
1226 this.assert(false === flag(this, 'object'), 'expected #{this} to be false', 'expected #{this} to be true', this.negate ? true : false);
1227 });
1228 /**
1229 * ### .null
1230 *
1231 * Asserts that the target is `null`.
1232 *
1233 * expect(null).to.be.null;
1234 * expect(undefined).to.not.be.null;
1235 *
1236 * @name null
1237 * @namespace BDD
1238 * @api public
1239 */
1240 Assertion.addProperty('null', function () {
1241 this.assert(null === flag(this, 'object'), 'expected #{this} to be null', 'expected #{this} not to be null');
1242 });
1243 /**
1244 * ### .undefined
1245 *
1246 * Asserts that the target is `undefined`.
1247 *
1248 * expect(undefined).to.be.undefined;
1249 * expect(null).to.not.be.undefined;
1250 *
1251 * @name undefined
1252 * @namespace BDD
1253 * @api public
1254 */
1255 Assertion.addProperty('undefined', function () {
1256 this.assert(undefined === flag(this, 'object'), 'expected #{this} to be undefined', 'expected #{this} not to be undefined');
1257 });
1258 /**
1259 * ### .NaN
1260 * Asserts that the target is `NaN`.
1261 *
1262 * expect('foo').to.be.NaN;
1263 * expect(4).not.to.be.NaN;
1264 *
1265 * @name NaN
1266 * @namespace BDD
1267 * @api public
1268 */
1269 Assertion.addProperty('NaN', function () {
1270 this.assert(isNaN(flag(this, 'object')), 'expected #{this} to be NaN', 'expected #{this} not to be NaN');
1271 });
1272 /**
1273 * ### .exist
1274 *
1275 * Asserts that the target is neither `null` nor `undefined`.
1276 *
1277 * var foo = 'hi'
1278 * , bar = null
1279 * , baz;
1280 *
1281 * expect(foo).to.exist;
1282 * expect(bar).to.not.exist;
1283 * expect(baz).to.not.exist;
1284 *
1285 * @name exist
1286 * @namespace BDD
1287 * @api public
1288 */
1289 Assertion.addProperty('exist', function () {
1290 this.assert(null != flag(this, 'object'), 'expected #{this} to exist', 'expected #{this} to not exist');
1291 });
1292 /**
1293 * ### .empty
1294 *
1295 * Asserts that the target's length is `0`. For arrays and strings, it checks
1296 * the `length` property. For objects, it gets the count of
1297 * enumerable keys.
1298 *
1299 * expect([]).to.be.empty;
1300 * expect('').to.be.empty;
1301 * expect({}).to.be.empty;
1302 *
1303 * @name empty
1304 * @namespace BDD
1305 * @api public
1306 */
1307 Assertion.addProperty('empty', function () {
1308 var obj = flag(this, 'object'), expected = obj;
1309 if (Array.isArray(obj) || 'string' === typeof object) {
1310 expected = obj.length;
1311 }
1312 else if (typeof obj === 'object') {
1313 expected = Object.keys(obj).length;
1314 }
1315 this.assert(!expected, 'expected #{this} to be empty', 'expected #{this} not to be empty');
1316 });
1317 /**
1318 * ### .arguments
1319 *
1320 * Asserts that the target is an arguments object.
1321 *
1322 * function test () {
1323 * expect(arguments).to.be.arguments;
1324 * }
1325 *
1326 * @name arguments
1327 * @alias Arguments
1328 * @namespace BDD
1329 * @api public
1330 */
1331 function checkArguments() {
1332 var obj = flag(this, 'object'), type = Object.prototype.toString.call(obj);
1333 this.assert('[object Arguments]' === type, 'expected #{this} to be arguments but got ' + type, 'expected #{this} to not be arguments');
1334 }
1335 Assertion.addProperty('arguments', checkArguments);
1336 Assertion.addProperty('Arguments', checkArguments);
1337 /**
1338 * ### .equal(value)
1339 *
1340 * Asserts that the target is strictly equal (`===`) to `value`.
1341 * Alternately, if the `deep` flag is set, asserts that
1342 * the target is deeply equal to `value`.
1343 *
1344 * expect('hello').to.equal('hello');
1345 * expect(42).to.equal(42);
1346 * expect(1).to.not.equal(true);
1347 * expect({ foo: 'bar' }).to.not.equal({ foo: 'bar' });
1348 * expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
1349 *
1350 * @name equal
1351 * @alias equals
1352 * @alias eq
1353 * @alias deep.equal
1354 * @param {Mixed} value
1355 * @param {String} message _optional_
1356 * @namespace BDD
1357 * @api public
1358 */
1359 function assertEqual(val, msg) {
1360 if (msg)
1361 flag(this, 'message', msg);
1362 var obj = flag(this, 'object');
1363 if (flag(this, 'deep')) {
1364 return this.eql(val);
1365 }
1366 else {
1367 this.assert(val === obj, 'expected #{this} to equal #{exp}', 'expected #{this} to not equal #{exp}', val, this._obj, true);
1368 }
1369 }
1370 Assertion.addMethod('equal', assertEqual);
1371 Assertion.addMethod('equals', assertEqual);
1372 Assertion.addMethod('eq', assertEqual);
1373 /**
1374 * ### .eql(value)
1375 *
1376 * Asserts that the target is deeply equal to `value`.
1377 *
1378 * expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
1379 * expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);
1380 *
1381 * @name eql
1382 * @alias eqls
1383 * @param {Mixed} value
1384 * @param {String} message _optional_
1385 * @namespace BDD
1386 * @api public
1387 */
1388 function assertEql(obj, msg) {
1389 if (msg)
1390 flag(this, 'message', msg);
1391 this.assert(_.eql(obj, flag(this, 'object')), 'expected #{this} to deeply equal #{exp}', 'expected #{this} to not deeply equal #{exp}', obj, this._obj, true);
1392 }
1393 Assertion.addMethod('eql', assertEql);
1394 Assertion.addMethod('eqls', assertEql);
1395 /**
1396 * ### .above(value)
1397 *
1398 * Asserts that the target is greater than `value`.
1399 *
1400 * expect(10).to.be.above(5);
1401 *
1402 * Can also be used in conjunction with `length` to
1403 * assert a minimum length. The benefit being a
1404 * more informative error message than if the length
1405 * was supplied directly.
1406 *
1407 * expect('foo').to.have.length.above(2);
1408 * expect([ 1, 2, 3 ]).to.have.length.above(2);
1409 *
1410 * @name above
1411 * @alias gt
1412 * @alias greaterThan
1413 * @param {Number} value
1414 * @param {String} message _optional_
1415 * @namespace BDD
1416 * @api public
1417 */
1418 function assertAbove(n, msg) {
1419 if (msg)
1420 flag(this, 'message', msg);
1421 var obj = flag(this, 'object');
1422 if (flag(this, 'doLength')) {
1423 new Assertion(obj, msg).to.have.property('length');
1424 var len = obj.length;
1425 this.assert(len > n, 'expected #{this} to have a length above #{exp} but got #{act}', 'expected #{this} to not have a length above #{exp}', n, len);
1426 }
1427 else {
1428 this.assert(obj > n, 'expected #{this} to be above ' + n, 'expected #{this} to be at most ' + n);
1429 }
1430 }
1431 Assertion.addMethod('above', assertAbove);
1432 Assertion.addMethod('gt', assertAbove);
1433 Assertion.addMethod('greaterThan', assertAbove);
1434 /**
1435 * ### .least(value)
1436 *
1437 * Asserts that the target is greater than or equal to `value`.
1438 *
1439 * expect(10).to.be.at.least(10);
1440 *
1441 * Can also be used in conjunction with `length` to
1442 * assert a minimum length. The benefit being a
1443 * more informative error message than if the length
1444 * was supplied directly.
1445 *
1446 * expect('foo').to.have.length.of.at.least(2);
1447 * expect([ 1, 2, 3 ]).to.have.length.of.at.least(3);
1448 *
1449 * @name least
1450 * @alias gte
1451 * @param {Number} value
1452 * @param {String} message _optional_
1453 * @namespace BDD
1454 * @api public
1455 */
1456 function assertLeast(n, msg) {
1457 if (msg)
1458 flag(this, 'message', msg);
1459 var obj = flag(this, 'object');
1460 if (flag(this, 'doLength')) {
1461 new Assertion(obj, msg).to.have.property('length');
1462 var len = obj.length;
1463 this.assert(len >= n, 'expected #{this} to have a length at least #{exp} but got #{act}', 'expected #{this} to have a length below #{exp}', n, len);
1464 }
1465 else {
1466 this.assert(obj >= n, 'expected #{this} to be at least ' + n, 'expected #{this} to be below ' + n);
1467 }
1468 }
1469 Assertion.addMethod('least', assertLeast);
1470 Assertion.addMethod('gte', assertLeast);
1471 /**
1472 * ### .below(value)
1473 *
1474 * Asserts that the target is less than `value`.
1475 *
1476 * expect(5).to.be.below(10);
1477 *
1478 * Can also be used in conjunction with `length` to
1479 * assert a maximum length. The benefit being a
1480 * more informative error message than if the length
1481 * was supplied directly.
1482 *
1483 * expect('foo').to.have.length.below(4);
1484 * expect([ 1, 2, 3 ]).to.have.length.below(4);
1485 *
1486 * @name below
1487 * @alias lt
1488 * @alias lessThan
1489 * @param {Number} value
1490 * @param {String} message _optional_
1491 * @namespace BDD
1492 * @api public
1493 */
1494 function assertBelow(n, msg) {
1495 if (msg)
1496 flag(this, 'message', msg);
1497 var obj = flag(this, 'object');
1498 if (flag(this, 'doLength')) {
1499 new Assertion(obj, msg).to.have.property('length');
1500 var len = obj.length;
1501 this.assert(len < n, 'expected #{this} to have a length below #{exp} but got #{act}', 'expected #{this} to not have a length below #{exp}', n, len);
1502 }
1503 else {
1504 this.assert(obj < n, 'expected #{this} to be below ' + n, 'expected #{this} to be at least ' + n);
1505 }
1506 }
1507 Assertion.addMethod('below', assertBelow);
1508 Assertion.addMethod('lt', assertBelow);
1509 Assertion.addMethod('lessThan', assertBelow);
1510 /**
1511 * ### .most(value)
1512 *
1513 * Asserts that the target is less than or equal to `value`.
1514 *
1515 * expect(5).to.be.at.most(5);
1516 *
1517 * Can also be used in conjunction with `length` to
1518 * assert a maximum length. The benefit being a
1519 * more informative error message than if the length
1520 * was supplied directly.
1521 *
1522 * expect('foo').to.have.length.of.at.most(4);
1523 * expect([ 1, 2, 3 ]).to.have.length.of.at.most(3);
1524 *
1525 * @name most
1526 * @alias lte
1527 * @param {Number} value
1528 * @param {String} message _optional_
1529 * @namespace BDD
1530 * @api public
1531 */
1532 function assertMost(n, msg) {
1533 if (msg)
1534 flag(this, 'message', msg);
1535 var obj = flag(this, 'object');
1536 if (flag(this, 'doLength')) {
1537 new Assertion(obj, msg).to.have.property('length');
1538 var len = obj.length;
1539 this.assert(len <= n, 'expected #{this} to have a length at most #{exp} but got #{act}', 'expected #{this} to have a length above #{exp}', n, len);
1540 }
1541 else {
1542 this.assert(obj <= n, 'expected #{this} to be at most ' + n, 'expected #{this} to be above ' + n);
1543 }
1544 }
1545 Assertion.addMethod('most', assertMost);
1546 Assertion.addMethod('lte', assertMost);
1547 /**
1548 * ### .within(start, finish)
1549 *
1550 * Asserts that the target is within a range.
1551 *
1552 * expect(7).to.be.within(5,10);
1553 *
1554 * Can also be used in conjunction with `length` to
1555 * assert a length range. The benefit being a
1556 * more informative error message than if the length
1557 * was supplied directly.
1558 *
1559 * expect('foo').to.have.length.within(2,4);
1560 * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
1561 *
1562 * @name within
1563 * @param {Number} start lowerbound inclusive
1564 * @param {Number} finish upperbound inclusive
1565 * @param {String} message _optional_
1566 * @namespace BDD
1567 * @api public
1568 */
1569 Assertion.addMethod('within', function (start, finish, msg) {
1570 if (msg)
1571 flag(this, 'message', msg);
1572 var obj = flag(this, 'object'), range = start + '..' + finish;
1573 if (flag(this, 'doLength')) {
1574 new Assertion(obj, msg).to.have.property('length');
1575 var len = obj.length;
1576 this.assert(len >= start && len <= finish, 'expected #{this} to have a length within ' + range, 'expected #{this} to not have a length within ' + range);
1577 }
1578 else {
1579 this.assert(obj >= start && obj <= finish, 'expected #{this} to be within ' + range, 'expected #{this} to not be within ' + range);
1580 }
1581 });
1582 /**
1583 * ### .instanceof(constructor)
1584 *
1585 * Asserts that the target is an instance of `constructor`.
1586 *
1587 * var Tea = function (name) { this.name = name; }
1588 * , Chai = new Tea('chai');
1589 *
1590 * expect(Chai).to.be.an.instanceof(Tea);
1591 * expect([ 1, 2, 3 ]).to.be.instanceof(Array);
1592 *
1593 * @name instanceof
1594 * @param {Constructor} constructor
1595 * @param {String} message _optional_
1596 * @alias instanceOf
1597 * @namespace BDD
1598 * @api public
1599 */
1600 function assertInstanceOf(constructor, msg) {
1601 if (msg)
1602 flag(this, 'message', msg);
1603 var name = _.getName(constructor);
1604 this.assert(flag(this, 'object') instanceof constructor, 'expected #{this} to be an instance of ' + name, 'expected #{this} to not be an instance of ' + name);
1605 }
1606 ;
1607 Assertion.addMethod('instanceof', assertInstanceOf);
1608 Assertion.addMethod('instanceOf', assertInstanceOf);
1609 /**
1610 * ### .property(name, [value])
1611 *
1612 * Asserts that the target has a property `name`, optionally asserting that
1613 * the value of that property is strictly equal to `value`.
1614 * If the `deep` flag is set, you can use dot- and bracket-notation for deep
1615 * references into objects and arrays.
1616 *
1617 * // simple referencing
1618 * var obj = { foo: 'bar' };
1619 * expect(obj).to.have.property('foo');
1620 * expect(obj).to.have.property('foo', 'bar');
1621 *
1622 * // deep referencing
1623 * var deepObj = {
1624 * green: { tea: 'matcha' }
1625 * , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
1626 * };
1627 *
1628 * expect(deepObj).to.have.deep.property('green.tea', 'matcha');
1629 * expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
1630 * expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');
1631 *
1632 * You can also use an array as the starting point of a `deep.property`
1633 * assertion, or traverse nested arrays.
1634 *
1635 * var arr = [
1636 * [ 'chai', 'matcha', 'konacha' ]
1637 * , [ { tea: 'chai' }
1638 * , { tea: 'matcha' }
1639 * , { tea: 'konacha' } ]
1640 * ];
1641 *
1642 * expect(arr).to.have.deep.property('[0][1]', 'matcha');
1643 * expect(arr).to.have.deep.property('[1][2].tea', 'konacha');
1644 *
1645 * Furthermore, `property` changes the subject of the assertion
1646 * to be the value of that property from the original object. This
1647 * permits for further chainable assertions on that property.
1648 *
1649 * expect(obj).to.have.property('foo')
1650 * .that.is.a('string');
1651 * expect(deepObj).to.have.property('green')
1652 * .that.is.an('object')
1653 * .that.deep.equals({ tea: 'matcha' });
1654 * expect(deepObj).to.have.property('teas')
1655 * .that.is.an('array')
1656 * .with.deep.property('[2]')
1657 * .that.deep.equals({ tea: 'konacha' });
1658 *
1659 * Note that dots and bracket in `name` must be backslash-escaped when
1660 * the `deep` flag is set, while they must NOT be escaped when the `deep`
1661 * flag is not set.
1662 *
1663 * // simple referencing
1664 * var css = { '.link[target]': 42 };
1665 * expect(css).to.have.property('.link[target]', 42);
1666 *
1667 * // deep referencing
1668 * var deepCss = { '.link': { '[target]': 42 }};
1669 * expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42);
1670 *
1671 * @name property
1672 * @alias deep.property
1673 * @param {String} name
1674 * @param {Mixed} value (optional)
1675 * @param {String} message _optional_
1676 * @returns value of property for chaining
1677 * @namespace BDD
1678 * @api public
1679 */
1680 Assertion.addMethod('property', function (name, val, msg) {
1681 if (msg)
1682 flag(this, 'message', msg);
1683 var isDeep = !!flag(this, 'deep'), descriptor = isDeep ? 'deep property ' : 'property ', negate = flag(this, 'negate'), obj = flag(this, 'object'), pathInfo = isDeep ? _.getPathInfo(name, obj) : null, hasProperty = isDeep
1684 ? pathInfo.exists
1685 : _.hasProperty(name, obj), value = isDeep
1686 ? pathInfo.value
1687 : obj[name];
1688 if (negate && arguments.length > 1) {
1689 if (undefined === value) {
1690 msg = (msg != null) ? msg + ': ' : '';
1691 throw new Error(msg + _.inspect(obj) + ' has no ' + descriptor + _.inspect(name));
1692 }
1693 }
1694 else {
1695 this.assert(hasProperty, 'expected #{this} to have a ' + descriptor + _.inspect(name), 'expected #{this} to not have ' + descriptor + _.inspect(name));
1696 }
1697 if (arguments.length > 1) {
1698 this.assert(val === value, 'expected #{this} to have a ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}', 'expected #{this} to not have a ' + descriptor + _.inspect(name) + ' of #{act}', val, value);
1699 }
1700 flag(this, 'object', value);
1701 });
1702 /**
1703 * ### .ownProperty(name)
1704 *
1705 * Asserts that the target has an own property `name`.
1706 *
1707 * expect('test').to.have.ownProperty('length');
1708 *
1709 * @name ownProperty
1710 * @alias haveOwnProperty
1711 * @param {String} name
1712 * @param {String} message _optional_
1713 * @namespace BDD
1714 * @api public
1715 */
1716 function assertOwnProperty(name, msg) {
1717 if (msg)
1718 flag(this, 'message', msg);
1719 var obj = flag(this, 'object');
1720 this.assert(obj.hasOwnProperty(name), 'expected #{this} to have own property ' + _.inspect(name), 'expected #{this} to not have own property ' + _.inspect(name));
1721 }
1722 Assertion.addMethod('ownProperty', assertOwnProperty);
1723 Assertion.addMethod('haveOwnProperty', assertOwnProperty);
1724 /**
1725 * ### .ownPropertyDescriptor(name[, descriptor[, message]])
1726 *
1727 * Asserts that the target has an own property descriptor `name`, that optionally matches `descriptor`.
1728 *
1729 * expect('test').to.have.ownPropertyDescriptor('length');
1730 * expect('test').to.have.ownPropertyDescriptor('length', { enumerable: false, configurable: false, writable: false, value: 4 });
1731 * expect('test').not.to.have.ownPropertyDescriptor('length', { enumerable: false, configurable: false, writable: false, value: 3 });
1732 * expect('test').ownPropertyDescriptor('length').to.have.property('enumerable', false);
1733 * expect('test').ownPropertyDescriptor('length').to.have.keys('value');
1734 *
1735 * @name ownPropertyDescriptor
1736 * @alias haveOwnPropertyDescriptor
1737 * @param {String} name
1738 * @param {Object} descriptor _optional_
1739 * @param {String} message _optional_
1740 * @namespace BDD
1741 * @api public
1742 */
1743 function assertOwnPropertyDescriptor(name, descriptor, msg) {
1744 if (typeof descriptor === 'string') {
1745 msg = descriptor;
1746 descriptor = null;
1747 }
1748 if (msg)
1749 flag(this, 'message', msg);
1750 var obj = flag(this, 'object');
1751 var actualDescriptor = Object.getOwnPropertyDescriptor(Object(obj), name);
1752 if (actualDescriptor && descriptor) {
1753 this.assert(_.eql(descriptor, actualDescriptor), 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to match ' + _.inspect(descriptor) + ', got ' + _.inspect(actualDescriptor), 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to not match ' + _.inspect(descriptor), descriptor, actualDescriptor, true);
1754 }
1755 else {
1756 this.assert(actualDescriptor, 'expected #{this} to have an own property descriptor for ' + _.inspect(name), 'expected #{this} to not have an own property descriptor for ' + _.inspect(name));
1757 }
1758 flag(this, 'object', actualDescriptor);
1759 }
1760 Assertion.addMethod('ownPropertyDescriptor', assertOwnPropertyDescriptor);
1761 Assertion.addMethod('haveOwnPropertyDescriptor', assertOwnPropertyDescriptor);
1762 /**
1763 * ### .length
1764 *
1765 * Sets the `doLength` flag later used as a chain precursor to a value
1766 * comparison for the `length` property.
1767 *
1768 * expect('foo').to.have.length.above(2);
1769 * expect([ 1, 2, 3 ]).to.have.length.above(2);
1770 * expect('foo').to.have.length.below(4);
1771 * expect([ 1, 2, 3 ]).to.have.length.below(4);
1772 * expect('foo').to.have.length.within(2,4);
1773 * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
1774 *
1775 * *Deprecation notice:* Using `length` as an assertion will be deprecated
1776 * in version 2.4.0 and removed in 3.0.0. Code using the old style of
1777 * asserting for `length` property value using `length(value)` should be
1778 * switched to use `lengthOf(value)` instead.
1779 *
1780 * @name length
1781 * @namespace BDD
1782 * @api public
1783 */
1784 /**
1785 * ### .lengthOf(value[, message])
1786 *
1787 * Asserts that the target's `length` property has
1788 * the expected value.
1789 *
1790 * expect([ 1, 2, 3]).to.have.lengthOf(3);
1791 * expect('foobar').to.have.lengthOf(6);
1792 *
1793 * @name lengthOf
1794 * @param {Number} length
1795 * @param {String} message _optional_
1796 * @namespace BDD
1797 * @api public
1798 */
1799 function assertLengthChain() {
1800 flag(this, 'doLength', true);
1801 }
1802 function assertLength(n, msg) {
1803 if (msg)
1804 flag(this, 'message', msg);
1805 var obj = flag(this, 'object');
1806 new Assertion(obj, msg).to.have.property('length');
1807 var len = obj.length;
1808 this.assert(len == n, 'expected #{this} to have a length of #{exp} but got #{act}', 'expected #{this} to not have a length of #{act}', n, len);
1809 }
1810 Assertion.addChainableMethod('length', assertLength, assertLengthChain);
1811 Assertion.addMethod('lengthOf', assertLength);
1812 /**
1813 * ### .match(regexp)
1814 *
1815 * Asserts that the target matches a regular expression.
1816 *
1817 * expect('foobar').to.match(/^foo/);
1818 *
1819 * @name match
1820 * @alias matches
1821 * @param {RegExp} RegularExpression
1822 * @param {String} message _optional_
1823 * @namespace BDD
1824 * @api public
1825 */
1826 function assertMatch(re, msg) {
1827 if (msg)
1828 flag(this, 'message', msg);
1829 var obj = flag(this, 'object');
1830 this.assert(re.exec(obj), 'expected #{this} to match ' + re, 'expected #{this} not to match ' + re);
1831 }
1832 Assertion.addMethod('match', assertMatch);
1833 Assertion.addMethod('matches', assertMatch);
1834 /**
1835 * ### .string(string)
1836 *
1837 * Asserts that the string target contains another string.
1838 *
1839 * expect('foobar').to.have.string('bar');
1840 *
1841 * @name string
1842 * @param {String} string
1843 * @param {String} message _optional_
1844 * @namespace BDD
1845 * @api public
1846 */
1847 Assertion.addMethod('string', function (str, msg) {
1848 if (msg)
1849 flag(this, 'message', msg);
1850 var obj = flag(this, 'object');
1851 new Assertion(obj, msg).is.a('string');
1852 this.assert(~obj.indexOf(str), 'expected #{this} to contain ' + _.inspect(str), 'expected #{this} to not contain ' + _.inspect(str));
1853 });
1854 /**
1855 * ### .keys(key1, [key2], [...])
1856 *
1857 * Asserts that the target contains any or all of the passed-in keys.
1858 * Use in combination with `any`, `all`, `contains`, or `have` will affect
1859 * what will pass.
1860 *
1861 * When used in conjunction with `any`, at least one key that is passed
1862 * in must exist in the target object. This is regardless whether or not
1863 * the `have` or `contain` qualifiers are used. Note, either `any` or `all`
1864 * should be used in the assertion. If neither are used, the assertion is
1865 * defaulted to `all`.
1866 *
1867 * When both `all` and `contain` are used, the target object must have at
1868 * least all of the passed-in keys but may have more keys not listed.
1869 *
1870 * When both `all` and `have` are used, the target object must both contain
1871 * all of the passed-in keys AND the number of keys in the target object must
1872 * match the number of keys passed in (in other words, a target object must
1873 * have all and only all of the passed-in keys).
1874 *
1875 * expect({ foo: 1, bar: 2 }).to.have.any.keys('foo', 'baz');
1876 * expect({ foo: 1, bar: 2 }).to.have.any.keys('foo');
1877 * expect({ foo: 1, bar: 2 }).to.contain.any.keys('bar', 'baz');
1878 * expect({ foo: 1, bar: 2 }).to.contain.any.keys(['foo']);
1879 * expect({ foo: 1, bar: 2 }).to.contain.any.keys({'foo': 6});
1880 * expect({ foo: 1, bar: 2 }).to.have.all.keys(['bar', 'foo']);
1881 * expect({ foo: 1, bar: 2 }).to.have.all.keys({'bar': 6, 'foo': 7});
1882 * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys(['bar', 'foo']);
1883 * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys({'bar': 6});
1884 *
1885 *
1886 * @name keys
1887 * @alias key
1888 * @param {...String|Array|Object} keys
1889 * @namespace BDD
1890 * @api public
1891 */
1892 function assertKeys(keys) {
1893 var obj = flag(this, 'object'), str, ok = true, mixedArgsMsg = 'keys must be given single argument of Array|Object|String, or multiple String arguments';
1894 switch (_.type(keys)) {
1895 case "array":
1896 if (arguments.length > 1)
1897 throw (new Error(mixedArgsMsg));
1898 break;
1899 case "object":
1900 if (arguments.length > 1)
1901 throw (new Error(mixedArgsMsg));
1902 keys = Object.keys(keys);
1903 break;
1904 default:
1905 keys = Array.prototype.slice.call(arguments);
1906 }
1907 if (!keys.length)
1908 throw new Error('keys required');
1909 var actual = Object.keys(obj), expected = keys, len = keys.length, any = flag(this, 'any'), all = flag(this, 'all');
1910 if (!any && !all) {
1911 all = true;
1912 }
1913 // Has any
1914 if (any) {
1915 var intersection = expected.filter(function (key) {
1916 return ~actual.indexOf(key);
1917 });
1918 ok = intersection.length > 0;
1919 }
1920 // Has all
1921 if (all) {
1922 ok = keys.every(function (key) {
1923 return ~actual.indexOf(key);
1924 });
1925 if (!flag(this, 'negate') && !flag(this, 'contains')) {
1926 ok = ok && keys.length == actual.length;
1927 }
1928 }
1929 // Key string
1930 if (len > 1) {
1931 keys = keys.map(function (key) {
1932 return _.inspect(key);
1933 });
1934 var last = keys.pop();
1935 if (all) {
1936 str = keys.join(', ') + ', and ' + last;
1937 }
1938 if (any) {
1939 str = keys.join(', ') + ', or ' + last;
1940 }
1941 }
1942 else {
1943 str = _.inspect(keys[0]);
1944 }
1945 // Form
1946 str = (len > 1 ? 'keys ' : 'key ') + str;
1947 // Have / include
1948 str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
1949 // Assertion
1950 this.assert(ok, 'expected #{this} to ' + str, 'expected #{this} to not ' + str, expected.slice(0).sort(), actual.sort(), true);
1951 }
1952 Assertion.addMethod('keys', assertKeys);
1953 Assertion.addMethod('key', assertKeys);
1954 /**
1955 * ### .throw(constructor)
1956 *
1957 * Asserts that the function target will throw a specific error, or specific type of error
1958 * (as determined using `instanceof`), optionally with a RegExp or string inclusion test
1959 * for the error's message.
1960 *
1961 * var err = new ReferenceError('This is a bad function.');
1962 * var fn = function () { throw err; }
1963 * expect(fn).to.throw(ReferenceError);
1964 * expect(fn).to.throw(Error);
1965 * expect(fn).to.throw(/bad function/);
1966 * expect(fn).to.not.throw('good function');
1967 * expect(fn).to.throw(ReferenceError, /bad function/);
1968 * expect(fn).to.throw(err);
1969 *
1970 * Please note that when a throw expectation is negated, it will check each
1971 * parameter independently, starting with error constructor type. The appropriate way
1972 * to check for the existence of a type of error but for a message that does not match
1973 * is to use `and`.
1974 *
1975 * expect(fn).to.throw(ReferenceError)
1976 * .and.not.throw(/good function/);
1977 *
1978 * @name throw
1979 * @alias throws
1980 * @alias Throw
1981 * @param {ErrorConstructor} constructor
1982 * @param {String|RegExp} expected error message
1983 * @param {String} message _optional_
1984 * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
1985 * @returns error for chaining (null if no error)
1986 * @namespace BDD
1987 * @api public
1988 */
1989 function assertThrows(constructor, errMsg, msg) {
1990 if (msg)
1991 flag(this, 'message', msg);
1992 var obj = flag(this, 'object');
1993 new Assertion(obj, msg).is.a('function');
1994 var thrown = false, desiredError = null, name = null, thrownError = null;
1995 if (arguments.length === 0) {
1996 errMsg = null;
1997 constructor = null;
1998 }
1999 else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
2000 errMsg = constructor;
2001 constructor = null;
2002 }
2003 else if (constructor && constructor instanceof Error) {
2004 desiredError = constructor;
2005 constructor = null;
2006 errMsg = null;
2007 }
2008 else if (typeof constructor === 'function') {
2009 name = constructor.prototype.name;
2010 if (!name || (name === 'Error' && constructor !== Error)) {
2011 name = constructor.name || (new constructor()).name;
2012 }
2013 }
2014 else {
2015 constructor = null;
2016 }
2017 try {
2018 obj();
2019 }
2020 catch (err) {
2021 // first, check desired error
2022 if (desiredError) {
2023 this.assert(err === desiredError, 'expected #{this} to throw #{exp} but #{act} was thrown', 'expected #{this} to not throw #{exp}', (desiredError instanceof Error ? desiredError.toString() : desiredError), (err instanceof Error ? err.toString() : err));
2024 flag(this, 'object', err);
2025 return this;
2026 }
2027 // next, check constructor
2028 if (constructor) {
2029 this.assert(err instanceof constructor, 'expected #{this} to throw #{exp} but #{act} was thrown', 'expected #{this} to not throw #{exp} but #{act} was thrown', name, (err instanceof Error ? err.toString() : err));
2030 if (!errMsg) {
2031 flag(this, 'object', err);
2032 return this;
2033 }
2034 }
2035 // next, check message
2036 var message = 'error' === _.type(err) && "message" in err
2037 ? err.message
2038 : '' + err;
2039 if ((message != null) && errMsg && errMsg instanceof RegExp) {
2040 this.assert(errMsg.exec(message), 'expected #{this} to throw error matching #{exp} but got #{act}', 'expected #{this} to throw error not matching #{exp}', errMsg, message);
2041 flag(this, 'object', err);
2042 return this;
2043 }
2044 else if ((message != null) && errMsg && 'string' === typeof errMsg) {
2045 this.assert(~message.indexOf(errMsg), 'expected #{this} to throw error including #{exp} but got #{act}', 'expected #{this} to throw error not including #{act}', errMsg, message);
2046 flag(this, 'object', err);
2047 return this;
2048 }
2049 else {
2050 thrown = true;
2051 thrownError = err;
2052 }
2053 }
2054 var actuallyGot = '', expectedThrown = name !== null
2055 ? name
2056 : desiredError
2057 ? '#{exp}' //_.inspect(desiredError)
2058 : 'an error';
2059 if (thrown) {
2060 actuallyGot = ' but #{act} was thrown';
2061 }
2062 this.assert(thrown === true, 'expected #{this} to throw ' + expectedThrown + actuallyGot, 'expected #{this} to not throw ' + expectedThrown + actuallyGot, (desiredError instanceof Error ? desiredError.toString() : desiredError), (thrownError instanceof Error ? thrownError.toString() : thrownError));
2063 flag(this, 'object', thrownError);
2064 }
2065 ;
2066 Assertion.addMethod('throw', assertThrows);
2067 Assertion.addMethod('throws', assertThrows);
2068 Assertion.addMethod('Throw', assertThrows);
2069 /**
2070 * ### .respondTo(method)
2071 *
2072 * Asserts that the object or class target will respond to a method.
2073 *
2074 * Klass.prototype.bar = function(){};
2075 * expect(Klass).to.respondTo('bar');
2076 * expect(obj).to.respondTo('bar');
2077 *
2078 * To check if a constructor will respond to a static function,
2079 * set the `itself` flag.
2080 *
2081 * Klass.baz = function(){};
2082 * expect(Klass).itself.to.respondTo('baz');
2083 *
2084 * @name respondTo
2085 * @alias respondsTo
2086 * @param {String} method
2087 * @param {String} message _optional_
2088 * @namespace BDD
2089 * @api public
2090 */
2091 function respondTo(method, msg) {
2092 if (msg)
2093 flag(this, 'message', msg);
2094 var obj = flag(this, 'object'), itself = flag(this, 'itself'), context = ('function' === _.type(obj) && !itself)
2095 ? obj.prototype[method]
2096 : obj[method];
2097 this.assert('function' === typeof context, 'expected #{this} to respond to ' + _.inspect(method), 'expected #{this} to not respond to ' + _.inspect(method));
2098 }
2099 Assertion.addMethod('respondTo', respondTo);
2100 Assertion.addMethod('respondsTo', respondTo);
2101 /**
2102 * ### .itself
2103 *
2104 * Sets the `itself` flag, later used by the `respondTo` assertion.
2105 *
2106 * function Foo() {}
2107 * Foo.bar = function() {}
2108 * Foo.prototype.baz = function() {}
2109 *
2110 * expect(Foo).itself.to.respondTo('bar');
2111 * expect(Foo).itself.not.to.respondTo('baz');
2112 *
2113 * @name itself
2114 * @namespace BDD
2115 * @api public
2116 */
2117 Assertion.addProperty('itself', function () {
2118 flag(this, 'itself', true);
2119 });
2120 /**
2121 * ### .satisfy(method)
2122 *
2123 * Asserts that the target passes a given truth test.
2124 *
2125 * expect(1).to.satisfy(function(num) { return num > 0; });
2126 *
2127 * @name satisfy
2128 * @alias satisfies
2129 * @param {Function} matcher
2130 * @param {String} message _optional_
2131 * @namespace BDD
2132 * @api public
2133 */
2134 function satisfy(matcher, msg) {
2135 if (msg)
2136 flag(this, 'message', msg);
2137 var obj = flag(this, 'object');
2138 var result = matcher(obj);
2139 this.assert(result, 'expected #{this} to satisfy ' + _.objDisplay(matcher), 'expected #{this} to not satisfy' + _.objDisplay(matcher), this.negate ? false : true, result);
2140 }
2141 Assertion.addMethod('satisfy', satisfy);
2142 Assertion.addMethod('satisfies', satisfy);
2143 /**
2144 * ### .closeTo(expected, delta)
2145 *
2146 * Asserts that the target is equal `expected`, to within a +/- `delta` range.
2147 *
2148 * expect(1.5).to.be.closeTo(1, 0.5);
2149 *
2150 * @name closeTo
2151 * @alias approximately
2152 * @param {Number} expected
2153 * @param {Number} delta
2154 * @param {String} message _optional_
2155 * @namespace BDD
2156 * @api public
2157 */
2158 function closeTo(expected, delta, msg) {
2159 if (msg)
2160 flag(this, 'message', msg);
2161 var obj = flag(this, 'object');
2162 new Assertion(obj, msg).is.a('number');
2163 if (_.type(expected) !== 'number' || _.type(delta) !== 'number') {
2164 throw new Error('the arguments to closeTo or approximately must be numbers');
2165 }
2166 this.assert(Math.abs(obj - expected) <= delta, 'expected #{this} to be close to ' + expected + ' +/- ' + delta, 'expected #{this} not to be close to ' + expected + ' +/- ' + delta);
2167 }
2168 Assertion.addMethod('closeTo', closeTo);
2169 Assertion.addMethod('approximately', closeTo);
2170 function isSubsetOf(subset, superset, cmp) {
2171 return subset.every(function (elem) {
2172 if (!cmp)
2173 return superset.indexOf(elem) !== -1;
2174 return superset.some(function (elem2) {
2175 return cmp(elem, elem2);
2176 });
2177 });
2178 }
2179 /**
2180 * ### .members(set)
2181 *
2182 * Asserts that the target is a superset of `set`,
2183 * or that the target and `set` have the same strictly-equal (===) members.
2184 * Alternately, if the `deep` flag is set, set members are compared for deep
2185 * equality.
2186 *
2187 * expect([1, 2, 3]).to.include.members([3, 2]);
2188 * expect([1, 2, 3]).to.not.include.members([3, 2, 8]);
2189 *
2190 * expect([4, 2]).to.have.members([2, 4]);
2191 * expect([5, 2]).to.not.have.members([5, 2, 1]);
2192 *
2193 * expect([{ id: 1 }]).to.deep.include.members([{ id: 1 }]);
2194 *
2195 * @name members
2196 * @param {Array} set
2197 * @param {String} message _optional_
2198 * @namespace BDD
2199 * @api public
2200 */
2201 Assertion.addMethod('members', function (subset, msg) {
2202 if (msg)
2203 flag(this, 'message', msg);
2204 var obj = flag(this, 'object');
2205 new Assertion(obj).to.be.an('array');
2206 new Assertion(subset).to.be.an('array');
2207 var cmp = flag(this, 'deep') ? _.eql : undefined;
2208 if (flag(this, 'contains')) {
2209 return this.assert(isSubsetOf(subset, obj, cmp), 'expected #{this} to be a superset of #{act}', 'expected #{this} to not be a superset of #{act}', obj, subset);
2210 }
2211 this.assert(isSubsetOf(obj, subset, cmp) && isSubsetOf(subset, obj, cmp), 'expected #{this} to have the same members as #{act}', 'expected #{this} to not have the same members as #{act}', obj, subset);
2212 });
2213 /**
2214 * ### .oneOf(list)
2215 *
2216 * Assert that a value appears somewhere in the top level of array `list`.
2217 *
2218 * expect('a').to.be.oneOf(['a', 'b', 'c']);
2219 * expect(9).to.not.be.oneOf(['z']);
2220 * expect([3]).to.not.be.oneOf([1, 2, [3]]);
2221 *
2222 * var three = [3];
2223 * // for object-types, contents are not compared
2224 * expect(three).to.not.be.oneOf([1, 2, [3]]);
2225 * // comparing references works
2226 * expect(three).to.be.oneOf([1, 2, three]);
2227 *
2228 * @name oneOf
2229 * @param {Array<*>} list
2230 * @param {String} message _optional_
2231 * @namespace BDD
2232 * @api public
2233 */
2234 function oneOf(list, msg) {
2235 if (msg)
2236 flag(this, 'message', msg);
2237 var expected = flag(this, 'object');
2238 new Assertion(list).to.be.an('array');
2239 this.assert(list.indexOf(expected) > -1, 'expected #{this} to be one of #{exp}', 'expected #{this} to not be one of #{exp}', list, expected);
2240 }
2241 Assertion.addMethod('oneOf', oneOf);
2242 /**
2243 * ### .change(function)
2244 *
2245 * Asserts that a function changes an object property
2246 *
2247 * var obj = { val: 10 };
2248 * var fn = function() { obj.val += 3 };
2249 * var noChangeFn = function() { return 'foo' + 'bar'; }
2250 * expect(fn).to.change(obj, 'val');
2251 * expect(noChangeFn).to.not.change(obj, 'val')
2252 *
2253 * @name change
2254 * @alias changes
2255 * @alias Change
2256 * @param {String} object
2257 * @param {String} property name
2258 * @param {String} message _optional_
2259 * @namespace BDD
2260 * @api public
2261 */
2262 function assertChanges(object, prop, msg) {
2263 if (msg)
2264 flag(this, 'message', msg);
2265 var fn = flag(this, 'object');
2266 new Assertion(object, msg).to.have.property(prop);
2267 new Assertion(fn).is.a('function');
2268 var initial = object[prop];
2269 fn();
2270 this.assert(initial !== object[prop], 'expected .' + prop + ' to change', 'expected .' + prop + ' to not change');
2271 }
2272 Assertion.addChainableMethod('change', assertChanges);
2273 Assertion.addChainableMethod('changes', assertChanges);
2274 /**
2275 * ### .increase(function)
2276 *
2277 * Asserts that a function increases an object property
2278 *
2279 * var obj = { val: 10 };
2280 * var fn = function() { obj.val = 15 };
2281 * expect(fn).to.increase(obj, 'val');
2282 *
2283 * @name increase
2284 * @alias increases
2285 * @alias Increase
2286 * @param {String} object
2287 * @param {String} property name
2288 * @param {String} message _optional_
2289 * @namespace BDD
2290 * @api public
2291 */
2292 function assertIncreases(object, prop, msg) {
2293 if (msg)
2294 flag(this, 'message', msg);
2295 var fn = flag(this, 'object');
2296 new Assertion(object, msg).to.have.property(prop);
2297 new Assertion(fn).is.a('function');
2298 var initial = object[prop];
2299 fn();
2300 this.assert(object[prop] - initial > 0, 'expected .' + prop + ' to increase', 'expected .' + prop + ' to not increase');
2301 }
2302 Assertion.addChainableMethod('increase', assertIncreases);
2303 Assertion.addChainableMethod('increases', assertIncreases);
2304 /**
2305 * ### .decrease(function)
2306 *
2307 * Asserts that a function decreases an object property
2308 *
2309 * var obj = { val: 10 };
2310 * var fn = function() { obj.val = 5 };
2311 * expect(fn).to.decrease(obj, 'val');
2312 *
2313 * @name decrease
2314 * @alias decreases
2315 * @alias Decrease
2316 * @param {String} object
2317 * @param {String} property name
2318 * @param {String} message _optional_
2319 * @namespace BDD
2320 * @api public
2321 */
2322 function assertDecreases(object, prop, msg) {
2323 if (msg)
2324 flag(this, 'message', msg);
2325 var fn = flag(this, 'object');
2326 new Assertion(object, msg).to.have.property(prop);
2327 new Assertion(fn).is.a('function');
2328 var initial = object[prop];
2329 fn();
2330 this.assert(object[prop] - initial < 0, 'expected .' + prop + ' to decrease', 'expected .' + prop + ' to not decrease');
2331 }
2332 Assertion.addChainableMethod('decrease', assertDecreases);
2333 Assertion.addChainableMethod('decreases', assertDecreases);
2334 /**
2335 * ### .extensible
2336 *
2337 * Asserts that the target is extensible (can have new properties added to
2338 * it).
2339 *
2340 * var nonExtensibleObject = Object.preventExtensions({});
2341 * var sealedObject = Object.seal({});
2342 * var frozenObject = Object.freeze({});
2343 *
2344 * expect({}).to.be.extensible;
2345 * expect(nonExtensibleObject).to.not.be.extensible;
2346 * expect(sealedObject).to.not.be.extensible;
2347 * expect(frozenObject).to.not.be.extensible;
2348 *
2349 * @name extensible
2350 * @namespace BDD
2351 * @api public
2352 */
2353 Assertion.addProperty('extensible', function () {
2354 var obj = flag(this, 'object');
2355 // In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
2356 // In ES6, a non-object argument will be treated as if it was a non-extensible ordinary object, simply return false.
2357 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible
2358 // The following provides ES6 behavior when a TypeError is thrown under ES5.
2359 var isExtensible;
2360 try {
2361 isExtensible = Object.isExtensible(obj);
2362 }
2363 catch (err) {
2364 if (err instanceof TypeError)
2365 isExtensible = false;
2366 else
2367 throw err;
2368 }
2369 this.assert(isExtensible, 'expected #{this} to be extensible', 'expected #{this} to not be extensible');
2370 });
2371 /**
2372 * ### .sealed
2373 *
2374 * Asserts that the target is sealed (cannot have new properties added to it
2375 * and its existing properties cannot be removed).
2376 *
2377 * var sealedObject = Object.seal({});
2378 * var frozenObject = Object.freeze({});
2379 *
2380 * expect(sealedObject).to.be.sealed;
2381 * expect(frozenObject).to.be.sealed;
2382 * expect({}).to.not.be.sealed;
2383 *
2384 * @name sealed
2385 * @namespace BDD
2386 * @api public
2387 */
2388 Assertion.addProperty('sealed', function () {
2389 var obj = flag(this, 'object');
2390 // In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
2391 // In ES6, a non-object argument will be treated as if it was a sealed ordinary object, simply return true.
2392 // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed
2393 // The following provides ES6 behavior when a TypeError is thrown under ES5.
2394 var isSealed;
2395 try {
2396 isSealed = Object.isSealed(obj);
2397 }
2398 catch (err) {
2399 if (err instanceof TypeError)
2400 isSealed = true;
2401 else
2402 throw err;
2403 }
2404 this.assert(isSealed, 'expected #{this} to be sealed', 'expected #{this} to not be sealed');
2405 });
2406 /**
2407 * ### .frozen
2408 *
2409 * Asserts that the target is frozen (cannot have new properties added to it
2410 * and its existing properties cannot be modified).
2411 *
2412 * var frozenObject = Object.freeze({});
2413 *
2414 * expect(frozenObject).to.be.frozen;
2415 * expect({}).to.not.be.frozen;
2416 *
2417 * @name frozen
2418 * @namespace BDD
2419 * @api public
2420 */
2421 Assertion.addProperty('frozen', function () {
2422 var obj = flag(this, 'object');
2423 // In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
2424 // In ES6, a non-object argument will be treated as if it was a frozen ordinary object, simply return true.
2425 // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen
2426 // The following provides ES6 behavior when a TypeError is thrown under ES5.
2427 var isFrozen;
2428 try {
2429 isFrozen = Object.isFrozen(obj);
2430 }
2431 catch (err) {
2432 if (err instanceof TypeError)
2433 isFrozen = true;
2434 else
2435 throw err;
2436 }
2437 this.assert(isFrozen, 'expected #{this} to be frozen', 'expected #{this} to not be frozen');
2438 });
2439};
2440
2441},{}],14:[function(require,module,exports){
2442/*!
2443 * chai
2444 * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
2445 * MIT Licensed
2446 */
2447module.exports = function (chai, util) {
2448 /*!
2449 * Chai dependencies.
2450 */
2451 var Assertion = chai.Assertion, flag = util.flag;
2452 /*!
2453 * Module export.
2454 */
2455 /**
2456 * ### assert(expression, message)
2457 *
2458 * Write your own test expressions.
2459 *
2460 * assert('foo' !== 'bar', 'foo is not bar');
2461 * assert(Array.isArray([]), 'empty arrays are arrays');
2462 *
2463 * @param {Mixed} expression to test for truthiness
2464 * @param {String} message to display on error
2465 * @name assert
2466 * @namespace Assert
2467 * @api public
2468 */
2469 var assert = chai.assert = function (express, errmsg) {
2470 var test = new Assertion(null, null, chai.assert);
2471 test.assert(express, errmsg, '[ negation message unavailable ]');
2472 };
2473 /**
2474 * ### .fail(actual, expected, [message], [operator])
2475 *
2476 * Throw a failure. Node.js `assert` module-compatible.
2477 *
2478 * @name fail
2479 * @param {Mixed} actual
2480 * @param {Mixed} expected
2481 * @param {String} message
2482 * @param {String} operator
2483 * @namespace Assert
2484 * @api public
2485 */
2486 assert.fail = function (actual, expected, message, operator) {
2487 message = message || 'assert.fail()';
2488 throw new chai.AssertionError(message, {
2489 actual: actual,
2490 expected: expected,
2491 operator: operator
2492 }, assert.fail);
2493 };
2494 /**
2495 * ### .isOk(object, [message])
2496 *
2497 * Asserts that `object` is truthy.
2498 *
2499 * assert.isOk('everything', 'everything is ok');
2500 * assert.isOk(false, 'this will fail');
2501 *
2502 * @name isOk
2503 * @alias ok
2504 * @param {Mixed} object to test
2505 * @param {String} message
2506 * @namespace Assert
2507 * @api public
2508 */
2509 assert.isOk = function (val, msg) {
2510 new Assertion(val, msg).is.ok;
2511 };
2512 /**
2513 * ### .isNotOk(object, [message])
2514 *
2515 * Asserts that `object` is falsy.
2516 *
2517 * assert.isNotOk('everything', 'this will fail');
2518 * assert.isNotOk(false, 'this will pass');
2519 *
2520 * @name isNotOk
2521 * @alias notOk
2522 * @param {Mixed} object to test
2523 * @param {String} message
2524 * @namespace Assert
2525 * @api public
2526 */
2527 assert.isNotOk = function (val, msg) {
2528 new Assertion(val, msg).is.not.ok;
2529 };
2530 /**
2531 * ### .equal(actual, expected, [message])
2532 *
2533 * Asserts non-strict equality (`==`) of `actual` and `expected`.
2534 *
2535 * assert.equal(3, '3', '== coerces values to strings');
2536 *
2537 * @name equal
2538 * @param {Mixed} actual
2539 * @param {Mixed} expected
2540 * @param {String} message
2541 * @namespace Assert
2542 * @api public
2543 */
2544 assert.equal = function (act, exp, msg) {
2545 var test = new Assertion(act, msg, assert.equal);
2546 test.assert(exp == flag(test, 'object'), 'expected #{this} to equal #{exp}', 'expected #{this} to not equal #{act}', exp, act);
2547 };
2548 /**
2549 * ### .notEqual(actual, expected, [message])
2550 *
2551 * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
2552 *
2553 * assert.notEqual(3, 4, 'these numbers are not equal');
2554 *
2555 * @name notEqual
2556 * @param {Mixed} actual
2557 * @param {Mixed} expected
2558 * @param {String} message
2559 * @namespace Assert
2560 * @api public
2561 */
2562 assert.notEqual = function (act, exp, msg) {
2563 var test = new Assertion(act, msg, assert.notEqual);
2564 test.assert(exp != flag(test, 'object'), 'expected #{this} to not equal #{exp}', 'expected #{this} to equal #{act}', exp, act);
2565 };
2566 /**
2567 * ### .strictEqual(actual, expected, [message])
2568 *
2569 * Asserts strict equality (`===`) of `actual` and `expected`.
2570 *
2571 * assert.strictEqual(true, true, 'these booleans are strictly equal');
2572 *
2573 * @name strictEqual
2574 * @param {Mixed} actual
2575 * @param {Mixed} expected
2576 * @param {String} message
2577 * @namespace Assert
2578 * @api public
2579 */
2580 assert.strictEqual = function (act, exp, msg) {
2581 new Assertion(act, msg).to.equal(exp);
2582 };
2583 /**
2584 * ### .notStrictEqual(actual, expected, [message])
2585 *
2586 * Asserts strict inequality (`!==`) of `actual` and `expected`.
2587 *
2588 * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
2589 *
2590 * @name notStrictEqual
2591 * @param {Mixed} actual
2592 * @param {Mixed} expected
2593 * @param {String} message
2594 * @namespace Assert
2595 * @api public
2596 */
2597 assert.notStrictEqual = function (act, exp, msg) {
2598 new Assertion(act, msg).to.not.equal(exp);
2599 };
2600 /**
2601 * ### .deepEqual(actual, expected, [message])
2602 *
2603 * Asserts that `actual` is deeply equal to `expected`.
2604 *
2605 * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
2606 *
2607 * @name deepEqual
2608 * @param {Mixed} actual
2609 * @param {Mixed} expected
2610 * @param {String} message
2611 * @namespace Assert
2612 * @api public
2613 */
2614 assert.deepEqual = function (act, exp, msg) {
2615 new Assertion(act, msg).to.eql(exp);
2616 };
2617 /**
2618 * ### .notDeepEqual(actual, expected, [message])
2619 *
2620 * Assert that `actual` is not deeply equal to `expected`.
2621 *
2622 * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
2623 *
2624 * @name notDeepEqual
2625 * @param {Mixed} actual
2626 * @param {Mixed} expected
2627 * @param {String} message
2628 * @namespace Assert
2629 * @api public
2630 */
2631 assert.notDeepEqual = function (act, exp, msg) {
2632 new Assertion(act, msg).to.not.eql(exp);
2633 };
2634 /**
2635 * ### .isAbove(valueToCheck, valueToBeAbove, [message])
2636 *
2637 * Asserts `valueToCheck` is strictly greater than (>) `valueToBeAbove`
2638 *
2639 * assert.isAbove(5, 2, '5 is strictly greater than 2');
2640 *
2641 * @name isAbove
2642 * @param {Mixed} valueToCheck
2643 * @param {Mixed} valueToBeAbove
2644 * @param {String} message
2645 * @namespace Assert
2646 * @api public
2647 */
2648 assert.isAbove = function (val, abv, msg) {
2649 new Assertion(val, msg).to.be.above(abv);
2650 };
2651 /**
2652 * ### .isAtLeast(valueToCheck, valueToBeAtLeast, [message])
2653 *
2654 * Asserts `valueToCheck` is greater than or equal to (>=) `valueToBeAtLeast`
2655 *
2656 * assert.isAtLeast(5, 2, '5 is greater or equal to 2');
2657 * assert.isAtLeast(3, 3, '3 is greater or equal to 3');
2658 *
2659 * @name isAtLeast
2660 * @param {Mixed} valueToCheck
2661 * @param {Mixed} valueToBeAtLeast
2662 * @param {String} message
2663 * @namespace Assert
2664 * @api public
2665 */
2666 assert.isAtLeast = function (val, atlst, msg) {
2667 new Assertion(val, msg).to.be.least(atlst);
2668 };
2669 /**
2670 * ### .isBelow(valueToCheck, valueToBeBelow, [message])
2671 *
2672 * Asserts `valueToCheck` is strictly less than (<) `valueToBeBelow`
2673 *
2674 * assert.isBelow(3, 6, '3 is strictly less than 6');
2675 *
2676 * @name isBelow
2677 * @param {Mixed} valueToCheck
2678 * @param {Mixed} valueToBeBelow
2679 * @param {String} message
2680 * @namespace Assert
2681 * @api public
2682 */
2683 assert.isBelow = function (val, blw, msg) {
2684 new Assertion(val, msg).to.be.below(blw);
2685 };
2686 /**
2687 * ### .isAtMost(valueToCheck, valueToBeAtMost, [message])
2688 *
2689 * Asserts `valueToCheck` is less than or equal to (<=) `valueToBeAtMost`
2690 *
2691 * assert.isAtMost(3, 6, '3 is less than or equal to 6');
2692 * assert.isAtMost(4, 4, '4 is less than or equal to 4');
2693 *
2694 * @name isAtMost
2695 * @param {Mixed} valueToCheck
2696 * @param {Mixed} valueToBeAtMost
2697 * @param {String} message
2698 * @namespace Assert
2699 * @api public
2700 */
2701 assert.isAtMost = function (val, atmst, msg) {
2702 new Assertion(val, msg).to.be.most(atmst);
2703 };
2704 /**
2705 * ### .isTrue(value, [message])
2706 *
2707 * Asserts that `value` is true.
2708 *
2709 * var teaServed = true;
2710 * assert.isTrue(teaServed, 'the tea has been served');
2711 *
2712 * @name isTrue
2713 * @param {Mixed} value
2714 * @param {String} message
2715 * @namespace Assert
2716 * @api public
2717 */
2718 assert.isTrue = function (val, msg) {
2719 new Assertion(val, msg).is['true'];
2720 };
2721 /**
2722 * ### .isNotTrue(value, [message])
2723 *
2724 * Asserts that `value` is not true.
2725 *
2726 * var tea = 'tasty chai';
2727 * assert.isNotTrue(tea, 'great, time for tea!');
2728 *
2729 * @name isNotTrue
2730 * @param {Mixed} value
2731 * @param {String} message
2732 * @namespace Assert
2733 * @api public
2734 */
2735 assert.isNotTrue = function (val, msg) {
2736 new Assertion(val, msg).to.not.equal(true);
2737 };
2738 /**
2739 * ### .isFalse(value, [message])
2740 *
2741 * Asserts that `value` is false.
2742 *
2743 * var teaServed = false;
2744 * assert.isFalse(teaServed, 'no tea yet? hmm...');
2745 *
2746 * @name isFalse
2747 * @param {Mixed} value
2748 * @param {String} message
2749 * @namespace Assert
2750 * @api public
2751 */
2752 assert.isFalse = function (val, msg) {
2753 new Assertion(val, msg).is['false'];
2754 };
2755 /**
2756 * ### .isNotFalse(value, [message])
2757 *
2758 * Asserts that `value` is not false.
2759 *
2760 * var tea = 'tasty chai';
2761 * assert.isNotFalse(tea, 'great, time for tea!');
2762 *
2763 * @name isNotFalse
2764 * @param {Mixed} value
2765 * @param {String} message
2766 * @namespace Assert
2767 * @api public
2768 */
2769 assert.isNotFalse = function (val, msg) {
2770 new Assertion(val, msg).to.not.equal(false);
2771 };
2772 /**
2773 * ### .isNull(value, [message])
2774 *
2775 * Asserts that `value` is null.
2776 *
2777 * assert.isNull(err, 'there was no error');
2778 *
2779 * @name isNull
2780 * @param {Mixed} value
2781 * @param {String} message
2782 * @namespace Assert
2783 * @api public
2784 */
2785 assert.isNull = function (val, msg) {
2786 new Assertion(val, msg).to.equal(null);
2787 };
2788 /**
2789 * ### .isNotNull(value, [message])
2790 *
2791 * Asserts that `value` is not null.
2792 *
2793 * var tea = 'tasty chai';
2794 * assert.isNotNull(tea, 'great, time for tea!');
2795 *
2796 * @name isNotNull
2797 * @param {Mixed} value
2798 * @param {String} message
2799 * @namespace Assert
2800 * @api public
2801 */
2802 assert.isNotNull = function (val, msg) {
2803 new Assertion(val, msg).to.not.equal(null);
2804 };
2805 /**
2806 * ### .isNaN
2807 * Asserts that value is NaN
2808 *
2809 * assert.isNaN('foo', 'foo is NaN');
2810 *
2811 * @name isNaN
2812 * @param {Mixed} value
2813 * @param {String} message
2814 * @namespace Assert
2815 * @api public
2816 */
2817 assert.isNaN = function (val, msg) {
2818 new Assertion(val, msg).to.be.NaN;
2819 };
2820 /**
2821 * ### .isNotNaN
2822 * Asserts that value is not NaN
2823 *
2824 * assert.isNotNaN(4, '4 is not NaN');
2825 *
2826 * @name isNotNaN
2827 * @param {Mixed} value
2828 * @param {String} message
2829 * @namespace Assert
2830 * @api public
2831 */
2832 assert.isNotNaN = function (val, msg) {
2833 new Assertion(val, msg).not.to.be.NaN;
2834 };
2835 /**
2836 * ### .isUndefined(value, [message])
2837 *
2838 * Asserts that `value` is `undefined`.
2839 *
2840 * var tea;
2841 * assert.isUndefined(tea, 'no tea defined');
2842 *
2843 * @name isUndefined
2844 * @param {Mixed} value
2845 * @param {String} message
2846 * @namespace Assert
2847 * @api public
2848 */
2849 assert.isUndefined = function (val, msg) {
2850 new Assertion(val, msg).to.equal(undefined);
2851 };
2852 /**
2853 * ### .isDefined(value, [message])
2854 *
2855 * Asserts that `value` is not `undefined`.
2856 *
2857 * var tea = 'cup of chai';
2858 * assert.isDefined(tea, 'tea has been defined');
2859 *
2860 * @name isDefined
2861 * @param {Mixed} value
2862 * @param {String} message
2863 * @namespace Assert
2864 * @api public
2865 */
2866 assert.isDefined = function (val, msg) {
2867 new Assertion(val, msg).to.not.equal(undefined);
2868 };
2869 /**
2870 * ### .isFunction(value, [message])
2871 *
2872 * Asserts that `value` is a function.
2873 *
2874 * function serveTea() { return 'cup of tea'; };
2875 * assert.isFunction(serveTea, 'great, we can have tea now');
2876 *
2877 * @name isFunction
2878 * @param {Mixed} value
2879 * @param {String} message
2880 * @namespace Assert
2881 * @api public
2882 */
2883 assert.isFunction = function (val, msg) {
2884 new Assertion(val, msg).to.be.a('function');
2885 };
2886 /**
2887 * ### .isNotFunction(value, [message])
2888 *
2889 * Asserts that `value` is _not_ a function.
2890 *
2891 * var serveTea = [ 'heat', 'pour', 'sip' ];
2892 * assert.isNotFunction(serveTea, 'great, we have listed the steps');
2893 *
2894 * @name isNotFunction
2895 * @param {Mixed} value
2896 * @param {String} message
2897 * @namespace Assert
2898 * @api public
2899 */
2900 assert.isNotFunction = function (val, msg) {
2901 new Assertion(val, msg).to.not.be.a('function');
2902 };
2903 /**
2904 * ### .isObject(value, [message])
2905 *
2906 * Asserts that `value` is an object of type 'Object' (as revealed by `Object.prototype.toString`).
2907 * _The assertion does not match subclassed objects._
2908 *
2909 * var selection = { name: 'Chai', serve: 'with spices' };
2910 * assert.isObject(selection, 'tea selection is an object');
2911 *
2912 * @name isObject
2913 * @param {Mixed} value
2914 * @param {String} message
2915 * @namespace Assert
2916 * @api public
2917 */
2918 assert.isObject = function (val, msg) {
2919 new Assertion(val, msg).to.be.a('object');
2920 };
2921 /**
2922 * ### .isNotObject(value, [message])
2923 *
2924 * Asserts that `value` is _not_ an object of type 'Object' (as revealed by `Object.prototype.toString`).
2925 *
2926 * var selection = 'chai'
2927 * assert.isNotObject(selection, 'tea selection is not an object');
2928 * assert.isNotObject(null, 'null is not an object');
2929 *
2930 * @name isNotObject
2931 * @param {Mixed} value
2932 * @param {String} message
2933 * @namespace Assert
2934 * @api public
2935 */
2936 assert.isNotObject = function (val, msg) {
2937 new Assertion(val, msg).to.not.be.a('object');
2938 };
2939 /**
2940 * ### .isArray(value, [message])
2941 *
2942 * Asserts that `value` is an array.
2943 *
2944 * var menu = [ 'green', 'chai', 'oolong' ];
2945 * assert.isArray(menu, 'what kind of tea do we want?');
2946 *
2947 * @name isArray
2948 * @param {Mixed} value
2949 * @param {String} message
2950 * @namespace Assert
2951 * @api public
2952 */
2953 assert.isArray = function (val, msg) {
2954 new Assertion(val, msg).to.be.an('array');
2955 };
2956 /**
2957 * ### .isNotArray(value, [message])
2958 *
2959 * Asserts that `value` is _not_ an array.
2960 *
2961 * var menu = 'green|chai|oolong';
2962 * assert.isNotArray(menu, 'what kind of tea do we want?');
2963 *
2964 * @name isNotArray
2965 * @param {Mixed} value
2966 * @param {String} message
2967 * @namespace Assert
2968 * @api public
2969 */
2970 assert.isNotArray = function (val, msg) {
2971 new Assertion(val, msg).to.not.be.an('array');
2972 };
2973 /**
2974 * ### .isString(value, [message])
2975 *
2976 * Asserts that `value` is a string.
2977 *
2978 * var teaOrder = 'chai';
2979 * assert.isString(teaOrder, 'order placed');
2980 *
2981 * @name isString
2982 * @param {Mixed} value
2983 * @param {String} message
2984 * @namespace Assert
2985 * @api public
2986 */
2987 assert.isString = function (val, msg) {
2988 new Assertion(val, msg).to.be.a('string');
2989 };
2990 /**
2991 * ### .isNotString(value, [message])
2992 *
2993 * Asserts that `value` is _not_ a string.
2994 *
2995 * var teaOrder = 4;
2996 * assert.isNotString(teaOrder, 'order placed');
2997 *
2998 * @name isNotString
2999 * @param {Mixed} value
3000 * @param {String} message
3001 * @namespace Assert
3002 * @api public
3003 */
3004 assert.isNotString = function (val, msg) {
3005 new Assertion(val, msg).to.not.be.a('string');
3006 };
3007 /**
3008 * ### .isNumber(value, [message])
3009 *
3010 * Asserts that `value` is a number.
3011 *
3012 * var cups = 2;
3013 * assert.isNumber(cups, 'how many cups');
3014 *
3015 * @name isNumber
3016 * @param {Number} value
3017 * @param {String} message
3018 * @namespace Assert
3019 * @api public
3020 */
3021 assert.isNumber = function (val, msg) {
3022 new Assertion(val, msg).to.be.a('number');
3023 };
3024 /**
3025 * ### .isNotNumber(value, [message])
3026 *
3027 * Asserts that `value` is _not_ a number.
3028 *
3029 * var cups = '2 cups please';
3030 * assert.isNotNumber(cups, 'how many cups');
3031 *
3032 * @name isNotNumber
3033 * @param {Mixed} value
3034 * @param {String} message
3035 * @namespace Assert
3036 * @api public
3037 */
3038 assert.isNotNumber = function (val, msg) {
3039 new Assertion(val, msg).to.not.be.a('number');
3040 };
3041 /**
3042 * ### .isBoolean(value, [message])
3043 *
3044 * Asserts that `value` is a boolean.
3045 *
3046 * var teaReady = true
3047 * , teaServed = false;
3048 *
3049 * assert.isBoolean(teaReady, 'is the tea ready');
3050 * assert.isBoolean(teaServed, 'has tea been served');
3051 *
3052 * @name isBoolean
3053 * @param {Mixed} value
3054 * @param {String} message
3055 * @namespace Assert
3056 * @api public
3057 */
3058 assert.isBoolean = function (val, msg) {
3059 new Assertion(val, msg).to.be.a('boolean');
3060 };
3061 /**
3062 * ### .isNotBoolean(value, [message])
3063 *
3064 * Asserts that `value` is _not_ a boolean.
3065 *
3066 * var teaReady = 'yep'
3067 * , teaServed = 'nope';
3068 *
3069 * assert.isNotBoolean(teaReady, 'is the tea ready');
3070 * assert.isNotBoolean(teaServed, 'has tea been served');
3071 *
3072 * @name isNotBoolean
3073 * @param {Mixed} value
3074 * @param {String} message
3075 * @namespace Assert
3076 * @api public
3077 */
3078 assert.isNotBoolean = function (val, msg) {
3079 new Assertion(val, msg).to.not.be.a('boolean');
3080 };
3081 /**
3082 * ### .typeOf(value, name, [message])
3083 *
3084 * Asserts that `value`'s type is `name`, as determined by
3085 * `Object.prototype.toString`.
3086 *
3087 * assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
3088 * assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
3089 * assert.typeOf('tea', 'string', 'we have a string');
3090 * assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
3091 * assert.typeOf(null, 'null', 'we have a null');
3092 * assert.typeOf(undefined, 'undefined', 'we have an undefined');
3093 *
3094 * @name typeOf
3095 * @param {Mixed} value
3096 * @param {String} name
3097 * @param {String} message
3098 * @namespace Assert
3099 * @api public
3100 */
3101 assert.typeOf = function (val, type, msg) {
3102 new Assertion(val, msg).to.be.a(type);
3103 };
3104 /**
3105 * ### .notTypeOf(value, name, [message])
3106 *
3107 * Asserts that `value`'s type is _not_ `name`, as determined by
3108 * `Object.prototype.toString`.
3109 *
3110 * assert.notTypeOf('tea', 'number', 'strings are not numbers');
3111 *
3112 * @name notTypeOf
3113 * @param {Mixed} value
3114 * @param {String} typeof name
3115 * @param {String} message
3116 * @namespace Assert
3117 * @api public
3118 */
3119 assert.notTypeOf = function (val, type, msg) {
3120 new Assertion(val, msg).to.not.be.a(type);
3121 };
3122 /**
3123 * ### .instanceOf(object, constructor, [message])
3124 *
3125 * Asserts that `value` is an instance of `constructor`.
3126 *
3127 * var Tea = function (name) { this.name = name; }
3128 * , chai = new Tea('chai');
3129 *
3130 * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
3131 *
3132 * @name instanceOf
3133 * @param {Object} object
3134 * @param {Constructor} constructor
3135 * @param {String} message
3136 * @namespace Assert
3137 * @api public
3138 */
3139 assert.instanceOf = function (val, type, msg) {
3140 new Assertion(val, msg).to.be.instanceOf(type);
3141 };
3142 /**
3143 * ### .notInstanceOf(object, constructor, [message])
3144 *
3145 * Asserts `value` is not an instance of `constructor`.
3146 *
3147 * var Tea = function (name) { this.name = name; }
3148 * , chai = new String('chai');
3149 *
3150 * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
3151 *
3152 * @name notInstanceOf
3153 * @param {Object} object
3154 * @param {Constructor} constructor
3155 * @param {String} message
3156 * @namespace Assert
3157 * @api public
3158 */
3159 assert.notInstanceOf = function (val, type, msg) {
3160 new Assertion(val, msg).to.not.be.instanceOf(type);
3161 };
3162 /**
3163 * ### .include(haystack, needle, [message])
3164 *
3165 * Asserts that `haystack` includes `needle`. Works
3166 * for strings and arrays.
3167 *
3168 * assert.include('foobar', 'bar', 'foobar contains string "bar"');
3169 * assert.include([ 1, 2, 3 ], 3, 'array contains value');
3170 *
3171 * @name include
3172 * @param {Array|String} haystack
3173 * @param {Mixed} needle
3174 * @param {String} message
3175 * @namespace Assert
3176 * @api public
3177 */
3178 assert.include = function (exp, inc, msg) {
3179 new Assertion(exp, msg, assert.include).include(inc);
3180 };
3181 /**
3182 * ### .notInclude(haystack, needle, [message])
3183 *
3184 * Asserts that `haystack` does not include `needle`. Works
3185 * for strings and arrays.
3186 *
3187 * assert.notInclude('foobar', 'baz', 'string not include substring');
3188 * assert.notInclude([ 1, 2, 3 ], 4, 'array not include contain value');
3189 *
3190 * @name notInclude
3191 * @param {Array|String} haystack
3192 * @param {Mixed} needle
3193 * @param {String} message
3194 * @namespace Assert
3195 * @api public
3196 */
3197 assert.notInclude = function (exp, inc, msg) {
3198 new Assertion(exp, msg, assert.notInclude).not.include(inc);
3199 };
3200 /**
3201 * ### .match(value, regexp, [message])
3202 *
3203 * Asserts that `value` matches the regular expression `regexp`.
3204 *
3205 * assert.match('foobar', /^foo/, 'regexp matches');
3206 *
3207 * @name match
3208 * @param {Mixed} value
3209 * @param {RegExp} regexp
3210 * @param {String} message
3211 * @namespace Assert
3212 * @api public
3213 */
3214 assert.match = function (exp, re, msg) {
3215 new Assertion(exp, msg).to.match(re);
3216 };
3217 /**
3218 * ### .notMatch(value, regexp, [message])
3219 *
3220 * Asserts that `value` does not match the regular expression `regexp`.
3221 *
3222 * assert.notMatch('foobar', /^foo/, 'regexp does not match');
3223 *
3224 * @name notMatch
3225 * @param {Mixed} value
3226 * @param {RegExp} regexp
3227 * @param {String} message
3228 * @namespace Assert
3229 * @api public
3230 */
3231 assert.notMatch = function (exp, re, msg) {
3232 new Assertion(exp, msg).to.not.match(re);
3233 };
3234 /**
3235 * ### .property(object, property, [message])
3236 *
3237 * Asserts that `object` has a property named by `property`.
3238 *
3239 * assert.property({ tea: { green: 'matcha' }}, 'tea');
3240 *
3241 * @name property
3242 * @param {Object} object
3243 * @param {String} property
3244 * @param {String} message
3245 * @namespace Assert
3246 * @api public
3247 */
3248 assert.property = function (obj, prop, msg) {
3249 new Assertion(obj, msg).to.have.property(prop);
3250 };
3251 /**
3252 * ### .notProperty(object, property, [message])
3253 *
3254 * Asserts that `object` does _not_ have a property named by `property`.
3255 *
3256 * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
3257 *
3258 * @name notProperty
3259 * @param {Object} object
3260 * @param {String} property
3261 * @param {String} message
3262 * @namespace Assert
3263 * @api public
3264 */
3265 assert.notProperty = function (obj, prop, msg) {
3266 new Assertion(obj, msg).to.not.have.property(prop);
3267 };
3268 /**
3269 * ### .deepProperty(object, property, [message])
3270 *
3271 * Asserts that `object` has a property named by `property`, which can be a
3272 * string using dot- and bracket-notation for deep reference.
3273 *
3274 * assert.deepProperty({ tea: { green: 'matcha' }}, 'tea.green');
3275 *
3276 * @name deepProperty
3277 * @param {Object} object
3278 * @param {String} property
3279 * @param {String} message
3280 * @namespace Assert
3281 * @api public
3282 */
3283 assert.deepProperty = function (obj, prop, msg) {
3284 new Assertion(obj, msg).to.have.deep.property(prop);
3285 };
3286 /**
3287 * ### .notDeepProperty(object, property, [message])
3288 *
3289 * Asserts that `object` does _not_ have a property named by `property`, which
3290 * can be a string using dot- and bracket-notation for deep reference.
3291 *
3292 * assert.notDeepProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
3293 *
3294 * @name notDeepProperty
3295 * @param {Object} object
3296 * @param {String} property
3297 * @param {String} message
3298 * @namespace Assert
3299 * @api public
3300 */
3301 assert.notDeepProperty = function (obj, prop, msg) {
3302 new Assertion(obj, msg).to.not.have.deep.property(prop);
3303 };
3304 /**
3305 * ### .propertyVal(object, property, value, [message])
3306 *
3307 * Asserts that `object` has a property named by `property` with value given
3308 * by `value`.
3309 *
3310 * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
3311 *
3312 * @name propertyVal
3313 * @param {Object} object
3314 * @param {String} property
3315 * @param {Mixed} value
3316 * @param {String} message
3317 * @namespace Assert
3318 * @api public
3319 */
3320 assert.propertyVal = function (obj, prop, val, msg) {
3321 new Assertion(obj, msg).to.have.property(prop, val);
3322 };
3323 /**
3324 * ### .propertyNotVal(object, property, value, [message])
3325 *
3326 * Asserts that `object` has a property named by `property`, but with a value
3327 * different from that given by `value`.
3328 *
3329 * assert.propertyNotVal({ tea: 'is good' }, 'tea', 'is bad');
3330 *
3331 * @name propertyNotVal
3332 * @param {Object} object
3333 * @param {String} property
3334 * @param {Mixed} value
3335 * @param {String} message
3336 * @namespace Assert
3337 * @api public
3338 */
3339 assert.propertyNotVal = function (obj, prop, val, msg) {
3340 new Assertion(obj, msg).to.not.have.property(prop, val);
3341 };
3342 /**
3343 * ### .deepPropertyVal(object, property, value, [message])
3344 *
3345 * Asserts that `object` has a property named by `property` with value given
3346 * by `value`. `property` can use dot- and bracket-notation for deep
3347 * reference.
3348 *
3349 * assert.deepPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
3350 *
3351 * @name deepPropertyVal
3352 * @param {Object} object
3353 * @param {String} property
3354 * @param {Mixed} value
3355 * @param {String} message
3356 * @namespace Assert
3357 * @api public
3358 */
3359 assert.deepPropertyVal = function (obj, prop, val, msg) {
3360 new Assertion(obj, msg).to.have.deep.property(prop, val);
3361 };
3362 /**
3363 * ### .deepPropertyNotVal(object, property, value, [message])
3364 *
3365 * Asserts that `object` has a property named by `property`, but with a value
3366 * different from that given by `value`. `property` can use dot- and
3367 * bracket-notation for deep reference.
3368 *
3369 * assert.deepPropertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
3370 *
3371 * @name deepPropertyNotVal
3372 * @param {Object} object
3373 * @param {String} property
3374 * @param {Mixed} value
3375 * @param {String} message
3376 * @namespace Assert
3377 * @api public
3378 */
3379 assert.deepPropertyNotVal = function (obj, prop, val, msg) {
3380 new Assertion(obj, msg).to.not.have.deep.property(prop, val);
3381 };
3382 /**
3383 * ### .lengthOf(object, length, [message])
3384 *
3385 * Asserts that `object` has a `length` property with the expected value.
3386 *
3387 * assert.lengthOf([1,2,3], 3, 'array has length of 3');
3388 * assert.lengthOf('foobar', 6, 'string has length of 6');
3389 *
3390 * @name lengthOf
3391 * @param {Mixed} object
3392 * @param {Number} length
3393 * @param {String} message
3394 * @namespace Assert
3395 * @api public
3396 */
3397 assert.lengthOf = function (exp, len, msg) {
3398 new Assertion(exp, msg).to.have.length(len);
3399 };
3400 /**
3401 * ### .throws(function, [constructor/string/regexp], [string/regexp], [message])
3402 *
3403 * Asserts that `function` will throw an error that is an instance of
3404 * `constructor`, or alternately that it will throw an error with message
3405 * matching `regexp`.
3406 *
3407 * assert.throws(fn, 'function throws a reference error');
3408 * assert.throws(fn, /function throws a reference error/);
3409 * assert.throws(fn, ReferenceError);
3410 * assert.throws(fn, ReferenceError, 'function throws a reference error');
3411 * assert.throws(fn, ReferenceError, /function throws a reference error/);
3412 *
3413 * @name throws
3414 * @alias throw
3415 * @alias Throw
3416 * @param {Function} function
3417 * @param {ErrorConstructor} constructor
3418 * @param {RegExp} regexp
3419 * @param {String} message
3420 * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
3421 * @namespace Assert
3422 * @api public
3423 */
3424 assert.throws = function (fn, errt, errs, msg) {
3425 if ('string' === typeof errt || errt instanceof RegExp) {
3426 errs = errt;
3427 errt = null;
3428 }
3429 var assertErr = new Assertion(fn, msg).to.throw(errt, errs);
3430 return flag(assertErr, 'object');
3431 };
3432 /**
3433 * ### .doesNotThrow(function, [constructor/regexp], [message])
3434 *
3435 * Asserts that `function` will _not_ throw an error that is an instance of
3436 * `constructor`, or alternately that it will not throw an error with message
3437 * matching `regexp`.
3438 *
3439 * assert.doesNotThrow(fn, Error, 'function does not throw');
3440 *
3441 * @name doesNotThrow
3442 * @param {Function} function
3443 * @param {ErrorConstructor} constructor
3444 * @param {RegExp} regexp
3445 * @param {String} message
3446 * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
3447 * @namespace Assert
3448 * @api public
3449 */
3450 assert.doesNotThrow = function (fn, type, msg) {
3451 if ('string' === typeof type) {
3452 msg = type;
3453 type = null;
3454 }
3455 new Assertion(fn, msg).to.not.Throw(type);
3456 };
3457 /**
3458 * ### .operator(val1, operator, val2, [message])
3459 *
3460 * Compares two values using `operator`.
3461 *
3462 * assert.operator(1, '<', 2, 'everything is ok');
3463 * assert.operator(1, '>', 2, 'this will fail');
3464 *
3465 * @name operator
3466 * @param {Mixed} val1
3467 * @param {String} operator
3468 * @param {Mixed} val2
3469 * @param {String} message
3470 * @namespace Assert
3471 * @api public
3472 */
3473 assert.operator = function (val, operator, val2, msg) {
3474 var ok;
3475 switch (operator) {
3476 case '==':
3477 ok = val == val2;
3478 break;
3479 case '===':
3480 ok = val === val2;
3481 break;
3482 case '>':
3483 ok = val > val2;
3484 break;
3485 case '>=':
3486 ok = val >= val2;
3487 break;
3488 case '<':
3489 ok = val < val2;
3490 break;
3491 case '<=':
3492 ok = val <= val2;
3493 break;
3494 case '!=':
3495 ok = val != val2;
3496 break;
3497 case '!==':
3498 ok = val !== val2;
3499 break;
3500 default:
3501 throw new Error('Invalid operator "' + operator + '"');
3502 }
3503 var test = new Assertion(ok, msg);
3504 test.assert(true === flag(test, 'object'), 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2), 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2));
3505 };
3506 /**
3507 * ### .closeTo(actual, expected, delta, [message])
3508 *
3509 * Asserts that the target is equal `expected`, to within a +/- `delta` range.
3510 *
3511 * assert.closeTo(1.5, 1, 0.5, 'numbers are close');
3512 *
3513 * @name closeTo
3514 * @param {Number} actual
3515 * @param {Number} expected
3516 * @param {Number} delta
3517 * @param {String} message
3518 * @namespace Assert
3519 * @api public
3520 */
3521 assert.closeTo = function (act, exp, delta, msg) {
3522 new Assertion(act, msg).to.be.closeTo(exp, delta);
3523 };
3524 /**
3525 * ### .approximately(actual, expected, delta, [message])
3526 *
3527 * Asserts that the target is equal `expected`, to within a +/- `delta` range.
3528 *
3529 * assert.approximately(1.5, 1, 0.5, 'numbers are close');
3530 *
3531 * @name approximately
3532 * @param {Number} actual
3533 * @param {Number} expected
3534 * @param {Number} delta
3535 * @param {String} message
3536 * @namespace Assert
3537 * @api public
3538 */
3539 assert.approximately = function (act, exp, delta, msg) {
3540 new Assertion(act, msg).to.be.approximately(exp, delta);
3541 };
3542 /**
3543 * ### .sameMembers(set1, set2, [message])
3544 *
3545 * Asserts that `set1` and `set2` have the same members.
3546 * Order is not taken into account.
3547 *
3548 * assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
3549 *
3550 * @name sameMembers
3551 * @param {Array} set1
3552 * @param {Array} set2
3553 * @param {String} message
3554 * @namespace Assert
3555 * @api public
3556 */
3557 assert.sameMembers = function (set1, set2, msg) {
3558 new Assertion(set1, msg).to.have.same.members(set2);
3559 };
3560 /**
3561 * ### .sameDeepMembers(set1, set2, [message])
3562 *
3563 * Asserts that `set1` and `set2` have the same members - using a deep equality checking.
3564 * Order is not taken into account.
3565 *
3566 * assert.sameDeepMembers([ {b: 3}, {a: 2}, {c: 5} ], [ {c: 5}, {b: 3}, {a: 2} ], 'same deep members');
3567 *
3568 * @name sameDeepMembers
3569 * @param {Array} set1
3570 * @param {Array} set2
3571 * @param {String} message
3572 * @namespace Assert
3573 * @api public
3574 */
3575 assert.sameDeepMembers = function (set1, set2, msg) {
3576 new Assertion(set1, msg).to.have.same.deep.members(set2);
3577 };
3578 /**
3579 * ### .includeMembers(superset, subset, [message])
3580 *
3581 * Asserts that `subset` is included in `superset`.
3582 * Order is not taken into account.
3583 *
3584 * assert.includeMembers([ 1, 2, 3 ], [ 2, 1 ], 'include members');
3585 *
3586 * @name includeMembers
3587 * @param {Array} superset
3588 * @param {Array} subset
3589 * @param {String} message
3590 * @namespace Assert
3591 * @api public
3592 */
3593 assert.includeMembers = function (superset, subset, msg) {
3594 new Assertion(superset, msg).to.include.members(subset);
3595 };
3596 /**
3597 * ### .includeDeepMembers(superset, subset, [message])
3598 *
3599 * Asserts that `subset` is included in `superset` - using deep equality checking.
3600 * Order is not taken into account.
3601 * Duplicates are ignored.
3602 *
3603 * assert.includeDeepMembers([ {a: 1}, {b: 2}, {c: 3} ], [ {b: 2}, {a: 1}, {b: 2} ], 'include deep members');
3604 *
3605 * @name includeDeepMembers
3606 * @param {Array} superset
3607 * @param {Array} subset
3608 * @param {String} message
3609 * @namespace Assert
3610 * @api public
3611 */
3612 assert.includeDeepMembers = function (superset, subset, msg) {
3613 new Assertion(superset, msg).to.include.deep.members(subset);
3614 };
3615 /**
3616 * ### .oneOf(inList, list, [message])
3617 *
3618 * Asserts that non-object, non-array value `inList` appears in the flat array `list`.
3619 *
3620 * assert.oneOf(1, [ 2, 1 ], 'Not found in list');
3621 *
3622 * @name oneOf
3623 * @param {*} inList
3624 * @param {Array<*>} list
3625 * @param {String} message
3626 * @namespace Assert
3627 * @api public
3628 */
3629 assert.oneOf = function (inList, list, msg) {
3630 new Assertion(inList, msg).to.be.oneOf(list);
3631 };
3632 /**
3633 * ### .changes(function, object, property)
3634 *
3635 * Asserts that a function changes the value of a property
3636 *
3637 * var obj = { val: 10 };
3638 * var fn = function() { obj.val = 22 };
3639 * assert.changes(fn, obj, 'val');
3640 *
3641 * @name changes
3642 * @param {Function} modifier function
3643 * @param {Object} object
3644 * @param {String} property name
3645 * @param {String} message _optional_
3646 * @namespace Assert
3647 * @api public
3648 */
3649 assert.changes = function (fn, obj, prop) {
3650 new Assertion(fn).to.change(obj, prop);
3651 };
3652 /**
3653 * ### .doesNotChange(function, object, property)
3654 *
3655 * Asserts that a function does not changes the value of a property
3656 *
3657 * var obj = { val: 10 };
3658 * var fn = function() { console.log('foo'); };
3659 * assert.doesNotChange(fn, obj, 'val');
3660 *
3661 * @name doesNotChange
3662 * @param {Function} modifier function
3663 * @param {Object} object
3664 * @param {String} property name
3665 * @param {String} message _optional_
3666 * @namespace Assert
3667 * @api public
3668 */
3669 assert.doesNotChange = function (fn, obj, prop) {
3670 new Assertion(fn).to.not.change(obj, prop);
3671 };
3672 /**
3673 * ### .increases(function, object, property)
3674 *
3675 * Asserts that a function increases an object property
3676 *
3677 * var obj = { val: 10 };
3678 * var fn = function() { obj.val = 13 };
3679 * assert.increases(fn, obj, 'val');
3680 *
3681 * @name increases
3682 * @param {Function} modifier function
3683 * @param {Object} object
3684 * @param {String} property name
3685 * @param {String} message _optional_
3686 * @namespace Assert
3687 * @api public
3688 */
3689 assert.increases = function (fn, obj, prop) {
3690 new Assertion(fn).to.increase(obj, prop);
3691 };
3692 /**
3693 * ### .doesNotIncrease(function, object, property)
3694 *
3695 * Asserts that a function does not increase object property
3696 *
3697 * var obj = { val: 10 };
3698 * var fn = function() { obj.val = 8 };
3699 * assert.doesNotIncrease(fn, obj, 'val');
3700 *
3701 * @name doesNotIncrease
3702 * @param {Function} modifier function
3703 * @param {Object} object
3704 * @param {String} property name
3705 * @param {String} message _optional_
3706 * @namespace Assert
3707 * @api public
3708 */
3709 assert.doesNotIncrease = function (fn, obj, prop) {
3710 new Assertion(fn).to.not.increase(obj, prop);
3711 };
3712 /**
3713 * ### .decreases(function, object, property)
3714 *
3715 * Asserts that a function decreases an object property
3716 *
3717 * var obj = { val: 10 };
3718 * var fn = function() { obj.val = 5 };
3719 * assert.decreases(fn, obj, 'val');
3720 *
3721 * @name decreases
3722 * @param {Function} modifier function
3723 * @param {Object} object
3724 * @param {String} property name
3725 * @param {String} message _optional_
3726 * @namespace Assert
3727 * @api public
3728 */
3729 assert.decreases = function (fn, obj, prop) {
3730 new Assertion(fn).to.decrease(obj, prop);
3731 };
3732 /**
3733 * ### .doesNotDecrease(function, object, property)
3734 *
3735 * Asserts that a function does not decreases an object property
3736 *
3737 * var obj = { val: 10 };
3738 * var fn = function() { obj.val = 15 };
3739 * assert.doesNotDecrease(fn, obj, 'val');
3740 *
3741 * @name doesNotDecrease
3742 * @param {Function} modifier function
3743 * @param {Object} object
3744 * @param {String} property name
3745 * @param {String} message _optional_
3746 * @namespace Assert
3747 * @api public
3748 */
3749 assert.doesNotDecrease = function (fn, obj, prop) {
3750 new Assertion(fn).to.not.decrease(obj, prop);
3751 };
3752 /*!
3753 * ### .ifError(object)
3754 *
3755 * Asserts if value is not a false value, and throws if it is a true value.
3756 * This is added to allow for chai to be a drop-in replacement for Node's
3757 * assert class.
3758 *
3759 * var err = new Error('I am a custom error');
3760 * assert.ifError(err); // Rethrows err!
3761 *
3762 * @name ifError
3763 * @param {Object} object
3764 * @namespace Assert
3765 * @api public
3766 */
3767 assert.ifError = function (val) {
3768 if (val) {
3769 throw (val);
3770 }
3771 };
3772 /**
3773 * ### .isExtensible(object)
3774 *
3775 * Asserts that `object` is extensible (can have new properties added to it).
3776 *
3777 * assert.isExtensible({});
3778 *
3779 * @name isExtensible
3780 * @alias extensible
3781 * @param {Object} object
3782 * @param {String} message _optional_
3783 * @namespace Assert
3784 * @api public
3785 */
3786 assert.isExtensible = function (obj, msg) {
3787 new Assertion(obj, msg).to.be.extensible;
3788 };
3789 /**
3790 * ### .isNotExtensible(object)
3791 *
3792 * Asserts that `object` is _not_ extensible.
3793 *
3794 * var nonExtensibleObject = Object.preventExtensions({});
3795 * var sealedObject = Object.seal({});
3796 * var frozenObject = Object.freese({});
3797 *
3798 * assert.isNotExtensible(nonExtensibleObject);
3799 * assert.isNotExtensible(sealedObject);
3800 * assert.isNotExtensible(frozenObject);
3801 *
3802 * @name isNotExtensible
3803 * @alias notExtensible
3804 * @param {Object} object
3805 * @param {String} message _optional_
3806 * @namespace Assert
3807 * @api public
3808 */
3809 assert.isNotExtensible = function (obj, msg) {
3810 new Assertion(obj, msg).to.not.be.extensible;
3811 };
3812 /**
3813 * ### .isSealed(object)
3814 *
3815 * Asserts that `object` is sealed (cannot have new properties added to it
3816 * and its existing properties cannot be removed).
3817 *
3818 * var sealedObject = Object.seal({});
3819 * var frozenObject = Object.seal({});
3820 *
3821 * assert.isSealed(sealedObject);
3822 * assert.isSealed(frozenObject);
3823 *
3824 * @name isSealed
3825 * @alias sealed
3826 * @param {Object} object
3827 * @param {String} message _optional_
3828 * @namespace Assert
3829 * @api public
3830 */
3831 assert.isSealed = function (obj, msg) {
3832 new Assertion(obj, msg).to.be.sealed;
3833 };
3834 /**
3835 * ### .isNotSealed(object)
3836 *
3837 * Asserts that `object` is _not_ sealed.
3838 *
3839 * assert.isNotSealed({});
3840 *
3841 * @name isNotSealed
3842 * @alias notSealed
3843 * @param {Object} object
3844 * @param {String} message _optional_
3845 * @namespace Assert
3846 * @api public
3847 */
3848 assert.isNotSealed = function (obj, msg) {
3849 new Assertion(obj, msg).to.not.be.sealed;
3850 };
3851 /**
3852 * ### .isFrozen(object)
3853 *
3854 * Asserts that `object` is frozen (cannot have new properties added to it
3855 * and its existing properties cannot be modified).
3856 *
3857 * var frozenObject = Object.freeze({});
3858 * assert.frozen(frozenObject);
3859 *
3860 * @name isFrozen
3861 * @alias frozen
3862 * @param {Object} object
3863 * @param {String} message _optional_
3864 * @namespace Assert
3865 * @api public
3866 */
3867 assert.isFrozen = function (obj, msg) {
3868 new Assertion(obj, msg).to.be.frozen;
3869 };
3870 /**
3871 * ### .isNotFrozen(object)
3872 *
3873 * Asserts that `object` is _not_ frozen.
3874 *
3875 * assert.isNotFrozen({});
3876 *
3877 * @name isNotFrozen
3878 * @alias notFrozen
3879 * @param {Object} object
3880 * @param {String} message _optional_
3881 * @namespace Assert
3882 * @api public
3883 */
3884 assert.isNotFrozen = function (obj, msg) {
3885 new Assertion(obj, msg).to.not.be.frozen;
3886 };
3887 /*!
3888 * Aliases.
3889 */
3890 (function alias(name, as) {
3891 assert[as] = assert[name];
3892 return alias;
3893 })('isOk', 'ok')('isNotOk', 'notOk')('throws', 'throw')('throws', 'Throw')('isExtensible', 'extensible')('isNotExtensible', 'notExtensible')('isSealed', 'sealed')('isNotSealed', 'notSealed')('isFrozen', 'frozen')('isNotFrozen', 'notFrozen');
3894};
3895
3896},{}],15:[function(require,module,exports){
3897/*!
3898 * chai
3899 * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
3900 * MIT Licensed
3901 */
3902module.exports = function (chai, util) {
3903 chai.expect = function (val, message) {
3904 return new chai.Assertion(val, message);
3905 };
3906 /**
3907 * ### .fail(actual, expected, [message], [operator])
3908 *
3909 * Throw a failure.
3910 *
3911 * @name fail
3912 * @param {Mixed} actual
3913 * @param {Mixed} expected
3914 * @param {String} message
3915 * @param {String} operator
3916 * @namespace Expect
3917 * @api public
3918 */
3919 chai.expect.fail = function (actual, expected, message, operator) {
3920 message = message || 'expect.fail()';
3921 throw new chai.AssertionError(message, {
3922 actual: actual,
3923 expected: expected,
3924 operator: operator
3925 }, chai.expect.fail);
3926 };
3927};
3928
3929},{}],16:[function(require,module,exports){
3930/*!
3931 * chai
3932 * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
3933 * MIT Licensed
3934 */
3935module.exports = function (chai, util) {
3936 var Assertion = chai.Assertion;
3937 function loadShould() {
3938 // explicitly define this method as function as to have it's name to include as `ssfi`
3939 function shouldGetter() {
3940 if (this instanceof String || this instanceof Number || this instanceof Boolean) {
3941 return new Assertion(this.valueOf(), null, shouldGetter);
3942 }
3943 return new Assertion(this, null, shouldGetter);
3944 }
3945 function shouldSetter(value) {
3946 // See https://github.com/chaijs/chai/issues/86: this makes
3947 // `whatever.should = someValue` actually set `someValue`, which is
3948 // especially useful for `global.should = require('chai').should()`.
3949 //
3950 // Note that we have to use [[DefineProperty]] instead of [[Put]]
3951 // since otherwise we would trigger this very setter!
3952 Object.defineProperty(this, 'should', {
3953 value: value,
3954 enumerable: true,
3955 configurable: true,
3956 writable: true
3957 });
3958 }
3959 // modify Object.prototype to have `should`
3960 Object.defineProperty(Object.prototype, 'should', {
3961 set: shouldSetter,
3962 get: shouldGetter,
3963 configurable: true
3964 });
3965 var should = {};
3966 /**
3967 * ### .fail(actual, expected, [message], [operator])
3968 *
3969 * Throw a failure.
3970 *
3971 * @name fail
3972 * @param {Mixed} actual
3973 * @param {Mixed} expected
3974 * @param {String} message
3975 * @param {String} operator
3976 * @namespace Should
3977 * @api public
3978 */
3979 should.fail = function (actual, expected, message, operator) {
3980 message = message || 'should.fail()';
3981 throw new chai.AssertionError(message, {
3982 actual: actual,
3983 expected: expected,
3984 operator: operator
3985 }, should.fail);
3986 };
3987 /**
3988 * ### .equal(actual, expected, [message])
3989 *
3990 * Asserts non-strict equality (`==`) of `actual` and `expected`.
3991 *
3992 * should.equal(3, '3', '== coerces values to strings');
3993 *
3994 * @name equal
3995 * @param {Mixed} actual
3996 * @param {Mixed} expected
3997 * @param {String} message
3998 * @namespace Should
3999 * @api public
4000 */
4001 should.equal = function (val1, val2, msg) {
4002 new Assertion(val1, msg).to.equal(val2);
4003 };
4004 /**
4005 * ### .throw(function, [constructor/string/regexp], [string/regexp], [message])
4006 *
4007 * Asserts that `function` will throw an error that is an instance of
4008 * `constructor`, or alternately that it will throw an error with message
4009 * matching `regexp`.
4010 *
4011 * should.throw(fn, 'function throws a reference error');
4012 * should.throw(fn, /function throws a reference error/);
4013 * should.throw(fn, ReferenceError);
4014 * should.throw(fn, ReferenceError, 'function throws a reference error');
4015 * should.throw(fn, ReferenceError, /function throws a reference error/);
4016 *
4017 * @name throw
4018 * @alias Throw
4019 * @param {Function} function
4020 * @param {ErrorConstructor} constructor
4021 * @param {RegExp} regexp
4022 * @param {String} message
4023 * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
4024 * @namespace Should
4025 * @api public
4026 */
4027 should.Throw = function (fn, errt, errs, msg) {
4028 new Assertion(fn, msg).to.Throw(errt, errs);
4029 };
4030 /**
4031 * ### .exist
4032 *
4033 * Asserts that the target is neither `null` nor `undefined`.
4034 *
4035 * var foo = 'hi';
4036 *
4037 * should.exist(foo, 'foo exists');
4038 *
4039 * @name exist
4040 * @namespace Should
4041 * @api public
4042 */
4043 should.exist = function (val, msg) {
4044 new Assertion(val, msg).to.exist;
4045 };
4046 // negation
4047 should.not = {};
4048 /**
4049 * ### .not.equal(actual, expected, [message])
4050 *
4051 * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
4052 *
4053 * should.not.equal(3, 4, 'these numbers are not equal');
4054 *
4055 * @name not.equal
4056 * @param {Mixed} actual
4057 * @param {Mixed} expected
4058 * @param {String} message
4059 * @namespace Should
4060 * @api public
4061 */
4062 should.not.equal = function (val1, val2, msg) {
4063 new Assertion(val1, msg).to.not.equal(val2);
4064 };
4065 /**
4066 * ### .throw(function, [constructor/regexp], [message])
4067 *
4068 * Asserts that `function` will _not_ throw an error that is an instance of
4069 * `constructor`, or alternately that it will not throw an error with message
4070 * matching `regexp`.
4071 *
4072 * should.not.throw(fn, Error, 'function does not throw');
4073 *
4074 * @name not.throw
4075 * @alias not.Throw
4076 * @param {Function} function
4077 * @param {ErrorConstructor} constructor
4078 * @param {RegExp} regexp
4079 * @param {String} message
4080 * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
4081 * @namespace Should
4082 * @api public
4083 */
4084 should.not.Throw = function (fn, errt, errs, msg) {
4085 new Assertion(fn, msg).to.not.Throw(errt, errs);
4086 };
4087 /**
4088 * ### .not.exist
4089 *
4090 * Asserts that the target is neither `null` nor `undefined`.
4091 *
4092 * var bar = null;
4093 *
4094 * should.not.exist(bar, 'bar does not exist');
4095 *
4096 * @name not.exist
4097 * @namespace Should
4098 * @api public
4099 */
4100 should.not.exist = function (val, msg) {
4101 new Assertion(val, msg).to.not.exist;
4102 };
4103 should['throw'] = should['Throw'];
4104 should.not['throw'] = should.not['Throw'];
4105 return should;
4106 }
4107 ;
4108 chai.should = loadShould;
4109 chai.Should = loadShould;
4110};
4111
4112},{}],17:[function(require,module,exports){
4113/*!
4114 * Chai - addChainingMethod utility
4115 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4116 * MIT Licensed
4117 */
4118/*!
4119 * Module dependencies
4120 */
4121var transferFlags = require('./transferFlags');
4122var flag = require('./flag');
4123var config = require('../config');
4124/*!
4125 * Module variables
4126 */
4127// Check whether `__proto__` is supported
4128var hasProtoSupport = '__proto__' in Object;
4129// Without `__proto__` support, this module will need to add properties to a function.
4130// However, some Function.prototype methods cannot be overwritten,
4131// and there seems no easy cross-platform way to detect them (@see chaijs/chai/issues/69).
4132var excludeNames = /^(?:length|name|arguments|caller)$/;
4133// Cache `Function` properties
4134var call = Function.prototype.call, apply = Function.prototype.apply;
4135/**
4136 * ### addChainableMethod (ctx, name, method, chainingBehavior)
4137 *
4138 * Adds a method to an object, such that the method can also be chained.
4139 *
4140 * utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
4141 * var obj = utils.flag(this, 'object');
4142 * new chai.Assertion(obj).to.be.equal(str);
4143 * });
4144 *
4145 * Can also be accessed directly from `chai.Assertion`.
4146 *
4147 * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
4148 *
4149 * The result can then be used as both a method assertion, executing both `method` and
4150 * `chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
4151 *
4152 * expect(fooStr).to.be.foo('bar');
4153 * expect(fooStr).to.be.foo.equal('foo');
4154 *
4155 * @param {Object} ctx object to which the method is added
4156 * @param {String} name of method to add
4157 * @param {Function} method function to be used for `name`, when called
4158 * @param {Function} chainingBehavior function to be called every time the property is accessed
4159 * @namespace Utils
4160 * @name addChainableMethod
4161 * @api public
4162 */
4163module.exports = function (ctx, name, method, chainingBehavior) {
4164 if (typeof chainingBehavior !== 'function') {
4165 chainingBehavior = function () { };
4166 }
4167 var chainableBehavior = {
4168 method: method,
4169 chainingBehavior: chainingBehavior
4170 };
4171 // save the methods so we can overwrite them later, if we need to.
4172 if (!ctx.__methods) {
4173 ctx.__methods = {};
4174 }
4175 ctx.__methods[name] = chainableBehavior;
4176 Object.defineProperty(ctx, name, { get: function () {
4177 chainableBehavior.chainingBehavior.call(this);
4178 var assert = function assert() {
4179 var old_ssfi = flag(this, 'ssfi');
4180 if (old_ssfi && config.includeStack === false)
4181 flag(this, 'ssfi', assert);
4182 var result = chainableBehavior.method.apply(this, arguments);
4183 return result === undefined ? this : result;
4184 };
4185 // Use `__proto__` if available
4186 if (hasProtoSupport) {
4187 // Inherit all properties from the object by replacing the `Function` prototype
4188 var prototype = assert.__proto__ = Object.create(this);
4189 // Restore the `call` and `apply` methods from `Function`
4190 prototype.call = call;
4191 prototype.apply = apply;
4192 }
4193 else {
4194 var asserterNames = Object.getOwnPropertyNames(ctx);
4195 asserterNames.forEach(function (asserterName) {
4196 if (!excludeNames.test(asserterName)) {
4197 var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
4198 Object.defineProperty(assert, asserterName, pd);
4199 }
4200 });
4201 }
4202 transferFlags(this, assert);
4203 return assert;
4204 },
4205 configurable: true
4206 });
4207};
4208
4209},{"../config":12,"./flag":21,"./transferFlags":37}],18:[function(require,module,exports){
4210/*!
4211 * Chai - addMethod utility
4212 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4213 * MIT Licensed
4214 */
4215var config = require('../config');
4216/**
4217 * ### .addMethod (ctx, name, method)
4218 *
4219 * Adds a method to the prototype of an object.
4220 *
4221 * utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
4222 * var obj = utils.flag(this, 'object');
4223 * new chai.Assertion(obj).to.be.equal(str);
4224 * });
4225 *
4226 * Can also be accessed directly from `chai.Assertion`.
4227 *
4228 * chai.Assertion.addMethod('foo', fn);
4229 *
4230 * Then can be used as any other assertion.
4231 *
4232 * expect(fooStr).to.be.foo('bar');
4233 *
4234 * @param {Object} ctx object to which the method is added
4235 * @param {String} name of method to add
4236 * @param {Function} method function to be used for name
4237 * @namespace Utils
4238 * @name addMethod
4239 * @api public
4240 */
4241var flag = require('./flag');
4242module.exports = function (ctx, name, method) {
4243 ctx[name] = function () {
4244 var old_ssfi = flag(this, 'ssfi');
4245 if (old_ssfi && config.includeStack === false)
4246 flag(this, 'ssfi', ctx[name]);
4247 var result = method.apply(this, arguments);
4248 return result === undefined ? this : result;
4249 };
4250};
4251
4252},{"../config":12,"./flag":21}],19:[function(require,module,exports){
4253/*!
4254 * Chai - addProperty utility
4255 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4256 * MIT Licensed
4257 */
4258var config = require('../config');
4259var flag = require('./flag');
4260/**
4261 * ### addProperty (ctx, name, getter)
4262 *
4263 * Adds a property to the prototype of an object.
4264 *
4265 * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
4266 * var obj = utils.flag(this, 'object');
4267 * new chai.Assertion(obj).to.be.instanceof(Foo);
4268 * });
4269 *
4270 * Can also be accessed directly from `chai.Assertion`.
4271 *
4272 * chai.Assertion.addProperty('foo', fn);
4273 *
4274 * Then can be used as any other assertion.
4275 *
4276 * expect(myFoo).to.be.foo;
4277 *
4278 * @param {Object} ctx object to which the property is added
4279 * @param {String} name of property to add
4280 * @param {Function} getter function to be used for name
4281 * @namespace Utils
4282 * @name addProperty
4283 * @api public
4284 */
4285module.exports = function (ctx, name, getter) {
4286 Object.defineProperty(ctx, name, { get: function addProperty() {
4287 var old_ssfi = flag(this, 'ssfi');
4288 if (old_ssfi && config.includeStack === false)
4289 flag(this, 'ssfi', addProperty);
4290 var result = getter.call(this);
4291 return result === undefined ? this : result;
4292 },
4293 configurable: true
4294 });
4295};
4296
4297},{"../config":12,"./flag":21}],20:[function(require,module,exports){
4298/*!
4299 * Chai - expectTypes utility
4300 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4301 * MIT Licensed
4302 */
4303/**
4304 * ### expectTypes(obj, types)
4305 *
4306 * Ensures that the object being tested against is of a valid type.
4307 *
4308 * utils.expectTypes(this, ['array', 'object', 'string']);
4309 *
4310 * @param {Mixed} obj constructed Assertion
4311 * @param {Array} type A list of allowed types for this assertion
4312 * @namespace Utils
4313 * @name expectTypes
4314 * @api public
4315 */
4316var AssertionError = require('assertion-error');
4317var flag = require('./flag');
4318var type = require('type-detect');
4319module.exports = function (obj, types) {
4320 var obj = flag(obj, 'object');
4321 types = types.map(function (t) { return t.toLowerCase(); });
4322 types.sort();
4323 // Transforms ['lorem', 'ipsum'] into 'a lirum, or an ipsum'
4324 var str = types.map(function (t, index) {
4325 var art = ~['a', 'e', 'i', 'o', 'u'].indexOf(t.charAt(0)) ? 'an' : 'a';
4326 var or = types.length > 1 && index === types.length - 1 ? 'or ' : '';
4327 return or + art + ' ' + t;
4328 }).join(', ');
4329 if (!types.some(function (expected) { return type(obj) === expected; })) {
4330 throw new AssertionError('object tested must be ' + str + ', but ' + type(obj) + ' given');
4331 }
4332};
4333
4334},{"./flag":21,"assertion-error":8,"type-detect":53}],21:[function(require,module,exports){
4335/*!
4336 * Chai - flag utility
4337 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4338 * MIT Licensed
4339 */
4340/**
4341 * ### flag(object, key, [value])
4342 *
4343 * Get or set a flag value on an object. If a
4344 * value is provided it will be set, else it will
4345 * return the currently set value or `undefined` if
4346 * the value is not set.
4347 *
4348 * utils.flag(this, 'foo', 'bar'); // setter
4349 * utils.flag(this, 'foo'); // getter, returns `bar`
4350 *
4351 * @param {Object} object constructed Assertion
4352 * @param {String} key
4353 * @param {Mixed} value (optional)
4354 * @namespace Utils
4355 * @name flag
4356 * @api private
4357 */
4358module.exports = function (obj, key, value) {
4359 var flags = obj.__flags || (obj.__flags = Object.create(null));
4360 if (arguments.length === 3) {
4361 flags[key] = value;
4362 }
4363 else {
4364 return flags[key];
4365 }
4366};
4367
4368},{}],22:[function(require,module,exports){
4369/*!
4370 * Chai - getActual utility
4371 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4372 * MIT Licensed
4373 */
4374/**
4375 * # getActual(object, [actual])
4376 *
4377 * Returns the `actual` value for an Assertion
4378 *
4379 * @param {Object} object (constructed Assertion)
4380 * @param {Arguments} chai.Assertion.prototype.assert arguments
4381 * @namespace Utils
4382 * @name getActual
4383 */
4384module.exports = function (obj, args) {
4385 return args.length > 4 ? args[4] : obj._obj;
4386};
4387
4388},{}],23:[function(require,module,exports){
4389/*!
4390 * Chai - getEnumerableProperties utility
4391 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4392 * MIT Licensed
4393 */
4394/**
4395 * ### .getEnumerableProperties(object)
4396 *
4397 * This allows the retrieval of enumerable property names of an object,
4398 * inherited or not.
4399 *
4400 * @param {Object} object
4401 * @returns {Array}
4402 * @namespace Utils
4403 * @name getEnumerableProperties
4404 * @api public
4405 */
4406module.exports = function getEnumerableProperties(object) {
4407 var result = [];
4408 for (var name in object) {
4409 result.push(name);
4410 }
4411 return result;
4412};
4413
4414},{}],24:[function(require,module,exports){
4415/*!
4416 * Chai - message composition utility
4417 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4418 * MIT Licensed
4419 */
4420/*!
4421 * Module dependancies
4422 */
4423var flag = require('./flag'), getActual = require('./getActual'), inspect = require('./inspect'), objDisplay = require('./objDisplay');
4424/**
4425 * ### .getMessage(object, message, negateMessage)
4426 *
4427 * Construct the error message based on flags
4428 * and template tags. Template tags will return
4429 * a stringified inspection of the object referenced.
4430 *
4431 * Message template tags:
4432 * - `#{this}` current asserted object
4433 * - `#{act}` actual value
4434 * - `#{exp}` expected value
4435 *
4436 * @param {Object} object (constructed Assertion)
4437 * @param {Arguments} chai.Assertion.prototype.assert arguments
4438 * @namespace Utils
4439 * @name getMessage
4440 * @api public
4441 */
4442module.exports = function (obj, args) {
4443 var negate = flag(obj, 'negate'), val = flag(obj, 'object'), expected = args[3], actual = getActual(obj, args), msg = negate ? args[2] : args[1], flagMsg = flag(obj, 'message');
4444 if (typeof msg === "function")
4445 msg = msg();
4446 msg = msg || '';
4447 msg = msg
4448 .replace(/#\{this\}/g, function () { return objDisplay(val); })
4449 .replace(/#\{act\}/g, function () { return objDisplay(actual); })
4450 .replace(/#\{exp\}/g, function () { return objDisplay(expected); });
4451 return flagMsg ? flagMsg + ': ' + msg : msg;
4452};
4453
4454},{"./flag":21,"./getActual":22,"./inspect":31,"./objDisplay":32}],25:[function(require,module,exports){
4455/*!
4456 * Chai - getName utility
4457 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4458 * MIT Licensed
4459 */
4460/**
4461 * # getName(func)
4462 *
4463 * Gets the name of a function, in a cross-browser way.
4464 *
4465 * @param {Function} a function (usually a constructor)
4466 * @namespace Utils
4467 * @name getName
4468 */
4469module.exports = function (func) {
4470 if (func.name)
4471 return func.name;
4472 var match = /^\s?function ([^(]*)\(/.exec(func);
4473 return match && match[1] ? match[1] : "";
4474};
4475
4476},{}],26:[function(require,module,exports){
4477/*!
4478 * Chai - getPathInfo utility
4479 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4480 * MIT Licensed
4481 */
4482var hasProperty = require('./hasProperty');
4483/**
4484 * ### .getPathInfo(path, object)
4485 *
4486 * This allows the retrieval of property info in an
4487 * object given a string path.
4488 *
4489 * The path info consists of an object with the
4490 * following properties:
4491 *
4492 * * parent - The parent object of the property referenced by `path`
4493 * * name - The name of the final property, a number if it was an array indexer
4494 * * value - The value of the property, if it exists, otherwise `undefined`
4495 * * exists - Whether the property exists or not
4496 *
4497 * @param {String} path
4498 * @param {Object} object
4499 * @returns {Object} info
4500 * @namespace Utils
4501 * @name getPathInfo
4502 * @api public
4503 */
4504module.exports = function getPathInfo(path, obj) {
4505 var parsed = parsePath(path), last = parsed[parsed.length - 1];
4506 var info = {
4507 parent: parsed.length > 1 ? _getPathValue(parsed, obj, parsed.length - 1) : obj,
4508 name: last.p || last.i,
4509 value: _getPathValue(parsed, obj)
4510 };
4511 info.exists = hasProperty(info.name, info.parent);
4512 return info;
4513};
4514/*!
4515 * ## parsePath(path)
4516 *
4517 * Helper function used to parse string object
4518 * paths. Use in conjunction with `_getPathValue`.
4519 *
4520 * var parsed = parsePath('myobject.property.subprop');
4521 *
4522 * ### Paths:
4523 *
4524 * * Can be as near infinitely deep and nested
4525 * * Arrays are also valid using the formal `myobject.document[3].property`.
4526 * * Literal dots and brackets (not delimiter) must be backslash-escaped.
4527 *
4528 * @param {String} path
4529 * @returns {Object} parsed
4530 * @api private
4531 */
4532function parsePath(path) {
4533 var str = path.replace(/([^\\])\[/g, '$1.['), parts = str.match(/(\\\.|[^.]+?)+/g);
4534 return parts.map(function (value) {
4535 var re = /^\[(\d+)\]$/, mArr = re.exec(value);
4536 if (mArr)
4537 return { i: parseFloat(mArr[1]) };
4538 else
4539 return { p: value.replace(/\\([.\[\]])/g, '$1') };
4540 });
4541}
4542/*!
4543 * ## _getPathValue(parsed, obj)
4544 *
4545 * Helper companion function for `.parsePath` that returns
4546 * the value located at the parsed address.
4547 *
4548 * var value = getPathValue(parsed, obj);
4549 *
4550 * @param {Object} parsed definition from `parsePath`.
4551 * @param {Object} object to search against
4552 * @param {Number} object to search against
4553 * @returns {Object|Undefined} value
4554 * @api private
4555 */
4556function _getPathValue(parsed, obj, index) {
4557 var tmp = obj, res;
4558 index = (index === undefined ? parsed.length : index);
4559 for (var i = 0, l = index; i < l; i++) {
4560 var part = parsed[i];
4561 if (tmp) {
4562 if ('undefined' !== typeof part.p)
4563 tmp = tmp[part.p];
4564 else if ('undefined' !== typeof part.i)
4565 tmp = tmp[part.i];
4566 if (i == (l - 1))
4567 res = tmp;
4568 }
4569 else {
4570 res = undefined;
4571 }
4572 }
4573 return res;
4574}
4575
4576},{"./hasProperty":29}],27:[function(require,module,exports){
4577/*!
4578 * Chai - getPathValue utility
4579 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4580 * @see https://github.com/logicalparadox/filtr
4581 * MIT Licensed
4582 */
4583var getPathInfo = require('./getPathInfo');
4584/**
4585 * ### .getPathValue(path, object)
4586 *
4587 * This allows the retrieval of values in an
4588 * object given a string path.
4589 *
4590 * var obj = {
4591 * prop1: {
4592 * arr: ['a', 'b', 'c']
4593 * , str: 'Hello'
4594 * }
4595 * , prop2: {
4596 * arr: [ { nested: 'Universe' } ]
4597 * , str: 'Hello again!'
4598 * }
4599 * }
4600 *
4601 * The following would be the results.
4602 *
4603 * getPathValue('prop1.str', obj); // Hello
4604 * getPathValue('prop1.att[2]', obj); // b
4605 * getPathValue('prop2.arr[0].nested', obj); // Universe
4606 *
4607 * @param {String} path
4608 * @param {Object} object
4609 * @returns {Object} value or `undefined`
4610 * @namespace Utils
4611 * @name getPathValue
4612 * @api public
4613 */
4614module.exports = function (path, obj) {
4615 var info = getPathInfo(path, obj);
4616 return info.value;
4617};
4618
4619},{"./getPathInfo":26}],28:[function(require,module,exports){
4620/*!
4621 * Chai - getProperties utility
4622 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4623 * MIT Licensed
4624 */
4625/**
4626 * ### .getProperties(object)
4627 *
4628 * This allows the retrieval of property names of an object, enumerable or not,
4629 * inherited or not.
4630 *
4631 * @param {Object} object
4632 * @returns {Array}
4633 * @namespace Utils
4634 * @name getProperties
4635 * @api public
4636 */
4637module.exports = function getProperties(object) {
4638 var result = Object.getOwnPropertyNames(object);
4639 function addProperty(property) {
4640 if (result.indexOf(property) === -1) {
4641 result.push(property);
4642 }
4643 }
4644 var proto = Object.getPrototypeOf(object);
4645 while (proto !== null) {
4646 Object.getOwnPropertyNames(proto).forEach(addProperty);
4647 proto = Object.getPrototypeOf(proto);
4648 }
4649 return result;
4650};
4651
4652},{}],29:[function(require,module,exports){
4653/*!
4654 * Chai - hasProperty utility
4655 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4656 * MIT Licensed
4657 */
4658var type = require('type-detect');
4659/**
4660 * ### .hasProperty(object, name)
4661 *
4662 * This allows checking whether an object has
4663 * named property or numeric array index.
4664 *
4665 * Basically does the same thing as the `in`
4666 * operator but works properly with natives
4667 * and null/undefined values.
4668 *
4669 * var obj = {
4670 * arr: ['a', 'b', 'c']
4671 * , str: 'Hello'
4672 * }
4673 *
4674 * The following would be the results.
4675 *
4676 * hasProperty('str', obj); // true
4677 * hasProperty('constructor', obj); // true
4678 * hasProperty('bar', obj); // false
4679 *
4680 * hasProperty('length', obj.str); // true
4681 * hasProperty(1, obj.str); // true
4682 * hasProperty(5, obj.str); // false
4683 *
4684 * hasProperty('length', obj.arr); // true
4685 * hasProperty(2, obj.arr); // true
4686 * hasProperty(3, obj.arr); // false
4687 *
4688 * @param {Objuect} object
4689 * @param {String|Number} name
4690 * @returns {Boolean} whether it exists
4691 * @namespace Utils
4692 * @name getPathInfo
4693 * @api public
4694 */
4695var literals = {
4696 'number': Number,
4697 'string': String
4698};
4699module.exports = function hasProperty(name, obj) {
4700 var ot = type(obj);
4701 // Bad Object, obviously no props at all
4702 if (ot === 'null' || ot === 'undefined')
4703 return false;
4704 // The `in` operator does not work with certain literals
4705 // box these before the check
4706 if (literals[ot] && typeof obj !== 'object')
4707 obj = new literals[ot](obj);
4708 return name in obj;
4709};
4710
4711},{"type-detect":53}],30:[function(require,module,exports){
4712/*!
4713 * chai
4714 * Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
4715 * MIT Licensed
4716 */
4717/*!
4718 * Main exports
4719 */
4720var exports = module.exports = {};
4721/*!
4722 * test utility
4723 */
4724exports.test = require('./test');
4725/*!
4726 * type utility
4727 */
4728exports.type = require('type-detect');
4729/*!
4730 * expectTypes utility
4731 */
4732exports.expectTypes = require('./expectTypes');
4733/*!
4734 * message utility
4735 */
4736exports.getMessage = require('./getMessage');
4737/*!
4738 * actual utility
4739 */
4740exports.getActual = require('./getActual');
4741/*!
4742 * Inspect util
4743 */
4744exports.inspect = require('./inspect');
4745/*!
4746 * Object Display util
4747 */
4748exports.objDisplay = require('./objDisplay');
4749/*!
4750 * Flag utility
4751 */
4752exports.flag = require('./flag');
4753/*!
4754 * Flag transferring utility
4755 */
4756exports.transferFlags = require('./transferFlags');
4757/*!
4758 * Deep equal utility
4759 */
4760exports.eql = require('deep-eql');
4761/*!
4762 * Deep path value
4763 */
4764exports.getPathValue = require('./getPathValue');
4765/*!
4766 * Deep path info
4767 */
4768exports.getPathInfo = require('./getPathInfo');
4769/*!
4770 * Check if a property exists
4771 */
4772exports.hasProperty = require('./hasProperty');
4773/*!
4774 * Function name
4775 */
4776exports.getName = require('./getName');
4777/*!
4778 * add Property
4779 */
4780exports.addProperty = require('./addProperty');
4781/*!
4782 * add Method
4783 */
4784exports.addMethod = require('./addMethod');
4785/*!
4786 * overwrite Property
4787 */
4788exports.overwriteProperty = require('./overwriteProperty');
4789/*!
4790 * overwrite Method
4791 */
4792exports.overwriteMethod = require('./overwriteMethod');
4793/*!
4794 * Add a chainable method
4795 */
4796exports.addChainableMethod = require('./addChainableMethod');
4797/*!
4798 * Overwrite chainable method
4799 */
4800exports.overwriteChainableMethod = require('./overwriteChainableMethod');
4801
4802},{"./addChainableMethod":17,"./addMethod":18,"./addProperty":19,"./expectTypes":20,"./flag":21,"./getActual":22,"./getMessage":24,"./getName":25,"./getPathInfo":26,"./getPathValue":27,"./hasProperty":29,"./inspect":31,"./objDisplay":32,"./overwriteChainableMethod":33,"./overwriteMethod":34,"./overwriteProperty":35,"./test":36,"./transferFlags":37,"deep-eql":38,"type-detect":53}],31:[function(require,module,exports){
4803// This is (almost) directly from Node.js utils
4804// https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
4805var getName = require('./getName');
4806var getProperties = require('./getProperties');
4807var getEnumerableProperties = require('./getEnumerableProperties');
4808module.exports = inspect;
4809/**
4810 * Echos the value of a value. Trys to print the value out
4811 * in the best way possible given the different types.
4812 *
4813 * @param {Object} obj The object to print out.
4814 * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
4815 * properties of objects.
4816 * @param {Number} depth Depth in which to descend in object. Default is 2.
4817 * @param {Boolean} colors Flag to turn on ANSI escape codes to color the
4818 * output. Default is false (no coloring).
4819 * @namespace Utils
4820 * @name inspect
4821 */
4822function inspect(obj, showHidden, depth, colors) {
4823 var ctx = {
4824 showHidden: showHidden,
4825 seen: [],
4826 stylize: function (str) { return str; }
4827 };
4828 return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
4829}
4830// Returns true if object is a DOM element.
4831var isDOMElement = function (object) {
4832 if (typeof HTMLElement === 'object') {
4833 return object instanceof HTMLElement;
4834 }
4835 else {
4836 return object &&
4837 typeof object === 'object' &&
4838 object.nodeType === 1 &&
4839 typeof object.nodeName === 'string';
4840 }
4841};
4842function formatValue(ctx, value, recurseTimes) {
4843 // Provide a hook for user-specified inspect functions.
4844 // Check that value is an object with an inspect function on it
4845 if (value && typeof value.inspect === 'function' &&
4846 // Filter out the util module, it's inspect function is special
4847 value.inspect !== exports.inspect &&
4848 // Also filter out any prototype objects using the circular check.
4849 !(value.constructor && value.constructor.prototype === value)) {
4850 var ret = value.inspect(recurseTimes);
4851 if (typeof ret !== 'string') {
4852 ret = formatValue(ctx, ret, recurseTimes);
4853 }
4854 return ret;
4855 }
4856 // Primitive types cannot have properties
4857 var primitive = formatPrimitive(ctx, value);
4858 if (primitive) {
4859 return primitive;
4860 }
4861 // If this is a DOM element, try to get the outer HTML.
4862 if (isDOMElement(value)) {
4863 if ('outerHTML' in value) {
4864 return value.outerHTML;
4865 }
4866 else {
4867 // Attempt to serialize it
4868 try {
4869 if (document.xmlVersion) {
4870 var xmlSerializer = new XMLSerializer();
4871 return xmlSerializer.serializeToString(value);
4872 }
4873 else {
4874 // Firefox 11- do not support outerHTML
4875 // It does, however, support innerHTML
4876 // Use the following to render the element
4877 var ns = "http://www.w3.org/1999/xhtml";
4878 var container = document.createElementNS(ns, '_');
4879 container.appendChild(value.cloneNode(false));
4880 html = container.innerHTML
4881 .replace('><', '>' + value.innerHTML + '<');
4882 container.innerHTML = '';
4883 return html;
4884 }
4885 }
4886 catch (err) {
4887 }
4888 }
4889 }
4890 // Look up the keys of the object.
4891 var visibleKeys = getEnumerableProperties(value);
4892 var keys = ctx.showHidden ? getProperties(value) : visibleKeys;
4893 // Some type of object without properties can be shortcutted.
4894 // In IE, errors have a single `stack` property, or if they are vanilla `Error`,
4895 // a `stack` plus `description` property; ignore those for consistency.
4896 if (keys.length === 0 || (isError(value) && ((keys.length === 1 && keys[0] === 'stack') ||
4897 (keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')))) {
4898 if (typeof value === 'function') {
4899 var name = getName(value);
4900 var nameSuffix = name ? ': ' + name : '';
4901 return ctx.stylize('[Function' + nameSuffix + ']', 'special');
4902 }
4903 if (isRegExp(value)) {
4904 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
4905 }
4906 if (isDate(value)) {
4907 return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
4908 }
4909 if (isError(value)) {
4910 return formatError(value);
4911 }
4912 }
4913 var base = '', array = false, braces = ['{', '}'];
4914 // Make Array say that they are Array
4915 if (isArray(value)) {
4916 array = true;
4917 braces = ['[', ']'];
4918 }
4919 // Make functions say that they are functions
4920 if (typeof value === 'function') {
4921 var name = getName(value);
4922 var nameSuffix = name ? ': ' + name : '';
4923 base = ' [Function' + nameSuffix + ']';
4924 }
4925 // Make RegExps say that they are RegExps
4926 if (isRegExp(value)) {
4927 base = ' ' + RegExp.prototype.toString.call(value);
4928 }
4929 // Make dates with properties first say the date
4930 if (isDate(value)) {
4931 base = ' ' + Date.prototype.toUTCString.call(value);
4932 }
4933 // Make error with message first say the error
4934 if (isError(value)) {
4935 return formatError(value);
4936 }
4937 if (keys.length === 0 && (!array || value.length == 0)) {
4938 return braces[0] + base + braces[1];
4939 }
4940 if (recurseTimes < 0) {
4941 if (isRegExp(value)) {
4942 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
4943 }
4944 else {
4945 return ctx.stylize('[Object]', 'special');
4946 }
4947 }
4948 ctx.seen.push(value);
4949 var output;
4950 if (array) {
4951 output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
4952 }
4953 else {
4954 output = keys.map(function (key) {
4955 return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
4956 });
4957 }
4958 ctx.seen.pop();
4959 return reduceToSingleString(output, base, braces);
4960}
4961function formatPrimitive(ctx, value) {
4962 switch (typeof value) {
4963 case 'undefined':
4964 return ctx.stylize('undefined', 'undefined');
4965 case 'string':
4966 var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
4967 .replace(/'/g, "\\'")
4968 .replace(/\\"/g, '"') + '\'';
4969 return ctx.stylize(simple, 'string');
4970 case 'number':
4971 if (value === 0 && (1 / value) === -Infinity) {
4972 return ctx.stylize('-0', 'number');
4973 }
4974 return ctx.stylize('' + value, 'number');
4975 case 'boolean':
4976 return ctx.stylize('' + value, 'boolean');
4977 }
4978 // For some reason typeof null is "object", so special case here.
4979 if (value === null) {
4980 return ctx.stylize('null', 'null');
4981 }
4982}
4983function formatError(value) {
4984 return '[' + Error.prototype.toString.call(value) + ']';
4985}
4986function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
4987 var output = [];
4988 for (var i = 0, l = value.length; i < l; ++i) {
4989 if (Object.prototype.hasOwnProperty.call(value, String(i))) {
4990 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true));
4991 }
4992 else {
4993 output.push('');
4994 }
4995 }
4996 keys.forEach(function (key) {
4997 if (!key.match(/^\d+$/)) {
4998 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true));
4999 }
5000 });
5001 return output;
5002}
5003function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
5004 var name, str;
5005 if (value.__lookupGetter__) {
5006 if (value.__lookupGetter__(key)) {
5007 if (value.__lookupSetter__(key)) {
5008 str = ctx.stylize('[Getter/Setter]', 'special');
5009 }
5010 else {
5011 str = ctx.stylize('[Getter]', 'special');
5012 }
5013 }
5014 else {
5015 if (value.__lookupSetter__(key)) {
5016 str = ctx.stylize('[Setter]', 'special');
5017 }
5018 }
5019 }
5020 if (visibleKeys.indexOf(key) < 0) {
5021 name = '[' + key + ']';
5022 }
5023 if (!str) {
5024 if (ctx.seen.indexOf(value[key]) < 0) {
5025 if (recurseTimes === null) {
5026 str = formatValue(ctx, value[key], null);
5027 }
5028 else {
5029 str = formatValue(ctx, value[key], recurseTimes - 1);
5030 }
5031 if (str.indexOf('\n') > -1) {
5032 if (array) {
5033 str = str.split('\n').map(function (line) {
5034 return ' ' + line;
5035 }).join('\n').substr(2);
5036 }
5037 else {
5038 str = '\n' + str.split('\n').map(function (line) {
5039 return ' ' + line;
5040 }).join('\n');
5041 }
5042 }
5043 }
5044 else {
5045 str = ctx.stylize('[Circular]', 'special');
5046 }
5047 }
5048 if (typeof name === 'undefined') {
5049 if (array && key.match(/^\d+$/)) {
5050 return str;
5051 }
5052 name = JSON.stringify('' + key);
5053 if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
5054 name = name.substr(1, name.length - 2);
5055 name = ctx.stylize(name, 'name');
5056 }
5057 else {
5058 name = name.replace(/'/g, "\\'")
5059 .replace(/\\"/g, '"')
5060 .replace(/(^"|"$)/g, "'");
5061 name = ctx.stylize(name, 'string');
5062 }
5063 }
5064 return name + ': ' + str;
5065}
5066function reduceToSingleString(output, base, braces) {
5067 var numLinesEst = 0;
5068 var length = output.reduce(function (prev, cur) {
5069 numLinesEst++;
5070 if (cur.indexOf('\n') >= 0)
5071 numLinesEst++;
5072 return prev + cur.length + 1;
5073 }, 0);
5074 if (length > 60) {
5075 return braces[0] +
5076 (base === '' ? '' : base + '\n ') +
5077 ' ' +
5078 output.join(',\n ') +
5079 ' ' +
5080 braces[1];
5081 }
5082 return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
5083}
5084function isArray(ar) {
5085 return Array.isArray(ar) ||
5086 (typeof ar === 'object' && objectToString(ar) === '[object Array]');
5087}
5088function isRegExp(re) {
5089 return typeof re === 'object' && objectToString(re) === '[object RegExp]';
5090}
5091function isDate(d) {
5092 return typeof d === 'object' && objectToString(d) === '[object Date]';
5093}
5094function isError(e) {
5095 return typeof e === 'object' && objectToString(e) === '[object Error]';
5096}
5097function objectToString(o) {
5098 return Object.prototype.toString.call(o);
5099}
5100
5101},{"./getEnumerableProperties":23,"./getName":25,"./getProperties":28}],32:[function(require,module,exports){
5102/*!
5103 * Chai - flag utility
5104 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
5105 * MIT Licensed
5106 */
5107/*!
5108 * Module dependancies
5109 */
5110var inspect = require('./inspect');
5111var config = require('../config');
5112/**
5113 * ### .objDisplay (object)
5114 *
5115 * Determines if an object or an array matches
5116 * criteria to be inspected in-line for error
5117 * messages or should be truncated.
5118 *
5119 * @param {Mixed} javascript object to inspect
5120 * @name objDisplay
5121 * @namespace Utils
5122 * @api public
5123 */
5124module.exports = function (obj) {
5125 var str = inspect(obj), type = Object.prototype.toString.call(obj);
5126 if (config.truncateThreshold && str.length >= config.truncateThreshold) {
5127 if (type === '[object Function]') {
5128 return !obj.name || obj.name === ''
5129 ? '[Function]'
5130 : '[Function: ' + obj.name + ']';
5131 }
5132 else if (type === '[object Array]') {
5133 return '[ Array(' + obj.length + ') ]';
5134 }
5135 else if (type === '[object Object]') {
5136 var keys = Object.keys(obj), kstr = keys.length > 2
5137 ? keys.splice(0, 2).join(', ') + ', ...'
5138 : keys.join(', ');
5139 return '{ Object (' + kstr + ') }';
5140 }
5141 else {
5142 return str;
5143 }
5144 }
5145 else {
5146 return str;
5147 }
5148};
5149
5150},{"../config":12,"./inspect":31}],33:[function(require,module,exports){
5151/*!
5152 * Chai - overwriteChainableMethod utility
5153 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
5154 * MIT Licensed
5155 */
5156/**
5157 * ### overwriteChainableMethod (ctx, name, method, chainingBehavior)
5158 *
5159 * Overwites an already existing chainable method
5160 * and provides access to the previous function or
5161 * property. Must return functions to be used for
5162 * name.
5163 *
5164 * utils.overwriteChainableMethod(chai.Assertion.prototype, 'length',
5165 * function (_super) {
5166 * }
5167 * , function (_super) {
5168 * }
5169 * );
5170 *
5171 * Can also be accessed directly from `chai.Assertion`.
5172 *
5173 * chai.Assertion.overwriteChainableMethod('foo', fn, fn);
5174 *
5175 * Then can be used as any other assertion.
5176 *
5177 * expect(myFoo).to.have.length(3);
5178 * expect(myFoo).to.have.length.above(3);
5179 *
5180 * @param {Object} ctx object whose method / property is to be overwritten
5181 * @param {String} name of method / property to overwrite
5182 * @param {Function} method function that returns a function to be used for name
5183 * @param {Function} chainingBehavior function that returns a function to be used for property
5184 * @namespace Utils
5185 * @name overwriteChainableMethod
5186 * @api public
5187 */
5188module.exports = function (ctx, name, method, chainingBehavior) {
5189 var chainableBehavior = ctx.__methods[name];
5190 var _chainingBehavior = chainableBehavior.chainingBehavior;
5191 chainableBehavior.chainingBehavior = function () {
5192 var result = chainingBehavior(_chainingBehavior).call(this);
5193 return result === undefined ? this : result;
5194 };
5195 var _method = chainableBehavior.method;
5196 chainableBehavior.method = function () {
5197 var result = method(_method).apply(this, arguments);
5198 return result === undefined ? this : result;
5199 };
5200};
5201
5202},{}],34:[function(require,module,exports){
5203/*!
5204 * Chai - overwriteMethod utility
5205 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
5206 * MIT Licensed
5207 */
5208/**
5209 * ### overwriteMethod (ctx, name, fn)
5210 *
5211 * Overwites an already existing method and provides
5212 * access to previous function. Must return function
5213 * to be used for name.
5214 *
5215 * utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
5216 * return function (str) {
5217 * var obj = utils.flag(this, 'object');
5218 * if (obj instanceof Foo) {
5219 * new chai.Assertion(obj.value).to.equal(str);
5220 * } else {
5221 * _super.apply(this, arguments);
5222 * }
5223 * }
5224 * });
5225 *
5226 * Can also be accessed directly from `chai.Assertion`.
5227 *
5228 * chai.Assertion.overwriteMethod('foo', fn);
5229 *
5230 * Then can be used as any other assertion.
5231 *
5232 * expect(myFoo).to.equal('bar');
5233 *
5234 * @param {Object} ctx object whose method is to be overwritten
5235 * @param {String} name of method to overwrite
5236 * @param {Function} method function that returns a function to be used for name
5237 * @namespace Utils
5238 * @name overwriteMethod
5239 * @api public
5240 */
5241module.exports = function (ctx, name, method) {
5242 var _method = ctx[name], _super = function () { return this; };
5243 if (_method && 'function' === typeof _method)
5244 _super = _method;
5245 ctx[name] = function () {
5246 var result = method(_super).apply(this, arguments);
5247 return result === undefined ? this : result;
5248 };
5249};
5250
5251},{}],35:[function(require,module,exports){
5252/*!
5253 * Chai - overwriteProperty utility
5254 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
5255 * MIT Licensed
5256 */
5257/**
5258 * ### overwriteProperty (ctx, name, fn)
5259 *
5260 * Overwites an already existing property getter and provides
5261 * access to previous value. Must return function to use as getter.
5262 *
5263 * utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
5264 * return function () {
5265 * var obj = utils.flag(this, 'object');
5266 * if (obj instanceof Foo) {
5267 * new chai.Assertion(obj.name).to.equal('bar');
5268 * } else {
5269 * _super.call(this);
5270 * }
5271 * }
5272 * });
5273 *
5274 *
5275 * Can also be accessed directly from `chai.Assertion`.
5276 *
5277 * chai.Assertion.overwriteProperty('foo', fn);
5278 *
5279 * Then can be used as any other assertion.
5280 *
5281 * expect(myFoo).to.be.ok;
5282 *
5283 * @param {Object} ctx object whose property is to be overwritten
5284 * @param {String} name of property to overwrite
5285 * @param {Function} getter function that returns a getter function to be used for name
5286 * @namespace Utils
5287 * @name overwriteProperty
5288 * @api public
5289 */
5290module.exports = function (ctx, name, getter) {
5291 var _get = Object.getOwnPropertyDescriptor(ctx, name), _super = function () { };
5292 if (_get && 'function' === typeof _get.get)
5293 _super = _get.get;
5294 Object.defineProperty(ctx, name, { get: function () {
5295 var result = getter(_super).call(this);
5296 return result === undefined ? this : result;
5297 },
5298 configurable: true
5299 });
5300};
5301
5302},{}],36:[function(require,module,exports){
5303/*!
5304 * Chai - test utility
5305 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
5306 * MIT Licensed
5307 */
5308/*!
5309 * Module dependancies
5310 */
5311var flag = require('./flag');
5312/**
5313 * # test(object, expression)
5314 *
5315 * Test and object for expression.
5316 *
5317 * @param {Object} object (constructed Assertion)
5318 * @param {Arguments} chai.Assertion.prototype.assert arguments
5319 * @namespace Utils
5320 * @name test
5321 */
5322module.exports = function (obj, args) {
5323 var negate = flag(obj, 'negate'), expr = args[0];
5324 return negate ? !expr : expr;
5325};
5326
5327},{"./flag":21}],37:[function(require,module,exports){
5328/*!
5329 * Chai - transferFlags utility
5330 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
5331 * MIT Licensed
5332 */
5333/**
5334 * ### transferFlags(assertion, object, includeAll = true)
5335 *
5336 * Transfer all the flags for `assertion` to `object`. If
5337 * `includeAll` is set to `false`, then the base Chai
5338 * assertion flags (namely `object`, `ssfi`, and `message`)
5339 * will not be transferred.
5340 *
5341 *
5342 * var newAssertion = new Assertion();
5343 * utils.transferFlags(assertion, newAssertion);
5344 *
5345 * var anotherAsseriton = new Assertion(myObj);
5346 * utils.transferFlags(assertion, anotherAssertion, false);
5347 *
5348 * @param {Assertion} assertion the assertion to transfer the flags from
5349 * @param {Object} object the object to transfer the flags to; usually a new assertion
5350 * @param {Boolean} includeAll
5351 * @namespace Utils
5352 * @name transferFlags
5353 * @api private
5354 */
5355module.exports = function (assertion, object, includeAll) {
5356 var flags = assertion.__flags || (assertion.__flags = Object.create(null));
5357 if (!object.__flags) {
5358 object.__flags = Object.create(null);
5359 }
5360 includeAll = arguments.length === 3 ? includeAll : true;
5361 for (var flag in flags) {
5362 if (includeAll ||
5363 (flag !== 'object' && flag !== 'ssfi' && flag != 'message')) {
5364 object.__flags[flag] = flags[flag];
5365 }
5366 }
5367};
5368
5369},{}],38:[function(require,module,exports){
5370module.exports = require('./lib/eql');
5371
5372},{"./lib/eql":39}],39:[function(require,module,exports){
5373/*!
5374 * deep-eql
5375 * Copyright(c) 2013 Jake Luer <jake@alogicalparadox.com>
5376 * MIT Licensed
5377 */
5378/*!
5379 * Module dependencies
5380 */
5381var type = require('type-detect');
5382/*!
5383 * Buffer.isBuffer browser shim
5384 */
5385var Buffer;
5386try {
5387 Buffer = require('buffer').Buffer;
5388}
5389catch (ex) {
5390 Buffer = {};
5391 Buffer.isBuffer = function () { return false; };
5392}
5393/*!
5394 * Primary Export
5395 */
5396module.exports = deepEqual;
5397/**
5398 * Assert super-strict (egal) equality between
5399 * two objects of any type.
5400 *
5401 * @param {Mixed} a
5402 * @param {Mixed} b
5403 * @param {Array} memoised (optional)
5404 * @return {Boolean} equal match
5405 */
5406function deepEqual(a, b, m) {
5407 if (sameValue(a, b)) {
5408 return true;
5409 }
5410 else if ('date' === type(a)) {
5411 return dateEqual(a, b);
5412 }
5413 else if ('regexp' === type(a)) {
5414 return regexpEqual(a, b);
5415 }
5416 else if (Buffer.isBuffer(a)) {
5417 return bufferEqual(a, b);
5418 }
5419 else if ('arguments' === type(a)) {
5420 return argumentsEqual(a, b, m);
5421 }
5422 else if (!typeEqual(a, b)) {
5423 return false;
5424 }
5425 else if (('object' !== type(a) && 'object' !== type(b))
5426 && ('array' !== type(a) && 'array' !== type(b))) {
5427 return sameValue(a, b);
5428 }
5429 else {
5430 return objectEqual(a, b, m);
5431 }
5432}
5433/*!
5434 * Strict (egal) equality test. Ensures that NaN always
5435 * equals NaN and `-0` does not equal `+0`.
5436 *
5437 * @param {Mixed} a
5438 * @param {Mixed} b
5439 * @return {Boolean} equal match
5440 */
5441function sameValue(a, b) {
5442 if (a === b)
5443 return a !== 0 || 1 / a === 1 / b;
5444 return a !== a && b !== b;
5445}
5446/*!
5447 * Compare the types of two given objects and
5448 * return if they are equal. Note that an Array
5449 * has a type of `array` (not `object`) and arguments
5450 * have a type of `arguments` (not `array`/`object`).
5451 *
5452 * @param {Mixed} a
5453 * @param {Mixed} b
5454 * @return {Boolean} result
5455 */
5456function typeEqual(a, b) {
5457 return type(a) === type(b);
5458}
5459/*!
5460 * Compare two Date objects by asserting that
5461 * the time values are equal using `saveValue`.
5462 *
5463 * @param {Date} a
5464 * @param {Date} b
5465 * @return {Boolean} result
5466 */
5467function dateEqual(a, b) {
5468 if ('date' !== type(b))
5469 return false;
5470 return sameValue(a.getTime(), b.getTime());
5471}
5472/*!
5473 * Compare two regular expressions by converting them
5474 * to string and checking for `sameValue`.
5475 *
5476 * @param {RegExp} a
5477 * @param {RegExp} b
5478 * @return {Boolean} result
5479 */
5480function regexpEqual(a, b) {
5481 if ('regexp' !== type(b))
5482 return false;
5483 return sameValue(a.toString(), b.toString());
5484}
5485/*!
5486 * Assert deep equality of two `arguments` objects.
5487 * Unfortunately, these must be sliced to arrays
5488 * prior to test to ensure no bad behavior.
5489 *
5490 * @param {Arguments} a
5491 * @param {Arguments} b
5492 * @param {Array} memoize (optional)
5493 * @return {Boolean} result
5494 */
5495function argumentsEqual(a, b, m) {
5496 if ('arguments' !== type(b))
5497 return false;
5498 a = [].slice.call(a);
5499 b = [].slice.call(b);
5500 return deepEqual(a, b, m);
5501}
5502/*!
5503 * Get enumerable properties of a given object.
5504 *
5505 * @param {Object} a
5506 * @return {Array} property names
5507 */
5508function enumerable(a) {
5509 var res = [];
5510 for (var key in a)
5511 res.push(key);
5512 return res;
5513}
5514/*!
5515 * Simple equality for flat iterable objects
5516 * such as Arrays or Node.js buffers.
5517 *
5518 * @param {Iterable} a
5519 * @param {Iterable} b
5520 * @return {Boolean} result
5521 */
5522function iterableEqual(a, b) {
5523 if (a.length !== b.length)
5524 return false;
5525 var i = 0;
5526 var match = true;
5527 for (; i < a.length; i++) {
5528 if (a[i] !== b[i]) {
5529 match = false;
5530 break;
5531 }
5532 }
5533 return match;
5534}
5535/*!
5536 * Extension to `iterableEqual` specifically
5537 * for Node.js Buffers.
5538 *
5539 * @param {Buffer} a
5540 * @param {Mixed} b
5541 * @return {Boolean} result
5542 */
5543function bufferEqual(a, b) {
5544 if (!Buffer.isBuffer(b))
5545 return false;
5546 return iterableEqual(a, b);
5547}
5548/*!
5549 * Block for `objectEqual` ensuring non-existing
5550 * values don't get in.
5551 *
5552 * @param {Mixed} object
5553 * @return {Boolean} result
5554 */
5555function isValue(a) {
5556 return a !== null && a !== undefined;
5557}
5558/*!
5559 * Recursively check the equality of two objects.
5560 * Once basic sameness has been established it will
5561 * defer to `deepEqual` for each enumerable key
5562 * in the object.
5563 *
5564 * @param {Mixed} a
5565 * @param {Mixed} b
5566 * @return {Boolean} result
5567 */
5568function objectEqual(a, b, m) {
5569 if (!isValue(a) || !isValue(b)) {
5570 return false;
5571 }
5572 if (a.prototype !== b.prototype) {
5573 return false;
5574 }
5575 var i;
5576 if (m) {
5577 for (i = 0; i < m.length; i++) {
5578 if ((m[i][0] === a && m[i][1] === b)
5579 || (m[i][0] === b && m[i][1] === a)) {
5580 return true;
5581 }
5582 }
5583 }
5584 else {
5585 m = [];
5586 }
5587 try {
5588 var ka = enumerable(a);
5589 var kb = enumerable(b);
5590 }
5591 catch (ex) {
5592 return false;
5593 }
5594 ka.sort();
5595 kb.sort();
5596 if (!iterableEqual(ka, kb)) {
5597 return false;
5598 }
5599 m.push([a, b]);
5600 var key;
5601 for (i = ka.length - 1; i >= 0; i--) {
5602 key = ka[i];
5603 if (!deepEqual(a[key], b[key], m)) {
5604 return false;
5605 }
5606 }
5607 return true;
5608}
5609
5610},{"buffer":63,"type-detect":40}],40:[function(require,module,exports){
5611module.exports = require('./lib/type');
5612
5613},{"./lib/type":41}],41:[function(require,module,exports){
5614/*!
5615 * type-detect
5616 * Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
5617 * MIT Licensed
5618 */
5619
5620/*!
5621 * Primary Exports
5622 */
5623
5624var exports = module.exports = getType;
5625
5626/*!
5627 * Detectable javascript natives
5628 */
5629
5630var natives = {
5631 '[object Array]': 'array'
5632 , '[object RegExp]': 'regexp'
5633 , '[object Function]': 'function'
5634 , '[object Arguments]': 'arguments'
5635 , '[object Date]': 'date'
5636};
5637
5638/**
5639 * ### typeOf (obj)
5640 *
5641 * Use several different techniques to determine
5642 * the type of object being tested.
5643 *
5644 *
5645 * @param {Mixed} object
5646 * @return {String} object type
5647 * @api public
5648 */
5649
5650function getType (obj) {
5651 var str = Object.prototype.toString.call(obj);
5652 if (natives[str]) return natives[str];
5653 if (obj === null) return 'null';
5654 if (obj === undefined) return 'undefined';
5655 if (obj === Object(obj)) return 'object';
5656 return typeof obj;
5657}
5658
5659exports.Library = Library;
5660
5661/**
5662 * ### Library
5663 *
5664 * Create a repository for custom type detection.
5665 *
5666 * ```js
5667 * var lib = new type.Library;
5668 * ```
5669 *
5670 */
5671
5672function Library () {
5673 this.tests = {};
5674}
5675
5676/**
5677 * #### .of (obj)
5678 *
5679 * Expose replacement `typeof` detection to the library.
5680 *
5681 * ```js
5682 * if ('string' === lib.of('hello world')) {
5683 * // ...
5684 * }
5685 * ```
5686 *
5687 * @param {Mixed} object to test
5688 * @return {String} type
5689 */
5690
5691Library.prototype.of = getType;
5692
5693/**
5694 * #### .define (type, test)
5695 *
5696 * Add a test to for the `.test()` assertion.
5697 *
5698 * Can be defined as a regular expression:
5699 *
5700 * ```js
5701 * lib.define('int', /^[0-9]+$/);
5702 * ```
5703 *
5704 * ... or as a function:
5705 *
5706 * ```js
5707 * lib.define('bln', function (obj) {
5708 * if ('boolean' === lib.of(obj)) return true;
5709 * var blns = [ 'yes', 'no', 'true', 'false', 1, 0 ];
5710 * if ('string' === lib.of(obj)) obj = obj.toLowerCase();
5711 * return !! ~blns.indexOf(obj);
5712 * });
5713 * ```
5714 *
5715 * @param {String} type
5716 * @param {RegExp|Function} test
5717 * @api public
5718 */
5719
5720Library.prototype.define = function (type, test) {
5721 if (arguments.length === 1) return this.tests[type];
5722 this.tests[type] = test;
5723 return this;
5724};
5725
5726/**
5727 * #### .test (obj, test)
5728 *
5729 * Assert that an object is of type. Will first
5730 * check natives, and if that does not pass it will
5731 * use the user defined custom tests.
5732 *
5733 * ```js
5734 * assert(lib.test('1', 'int'));
5735 * assert(lib.test('yes', 'bln'));
5736 * ```
5737 *
5738 * @param {Mixed} object
5739 * @param {String} type
5740 * @return {Boolean} result
5741 * @api public
5742 */
5743
5744Library.prototype.test = function (obj, type) {
5745 if (type === getType(obj)) return true;
5746 var test = this.tests[type];
5747
5748 if (test && 'regexp' === getType(test)) {
5749 return test.test(obj);
5750 } else if (test && 'function' === getType(test)) {
5751 return test(obj);
5752 } else {
5753 throw new ReferenceError('Type test "' + type + '" not defined or invalid.');
5754 }
5755};
5756
5757},{}],42:[function(require,module,exports){
5758'use strict';
5759/* eslint-disable no-unused-vars */
5760var hasOwnProperty = Object.prototype.hasOwnProperty;
5761var propIsEnumerable = Object.prototype.propertyIsEnumerable;
5762function toObject(val) {
5763 if (val === null || val === undefined) {
5764 throw new TypeError('Object.assign cannot be called with null or undefined');
5765 }
5766 return Object(val);
5767}
5768function shouldUseNative() {
5769 try {
5770 if (!Object.assign) {
5771 return false;
5772 }
5773 // Detect buggy property enumeration order in older V8 versions.
5774 // https://bugs.chromium.org/p/v8/issues/detail?id=4118
5775 var test1 = new String('abc'); // eslint-disable-line
5776 test1[5] = 'de';
5777 if (Object.getOwnPropertyNames(test1)[0] === '5') {
5778 return false;
5779 }
5780 // https://bugs.chromium.org/p/v8/issues/detail?id=3056
5781 var test2 = {};
5782 for (var i = 0; i < 10; i++) {
5783 test2['_' + String.fromCharCode(i)] = i;
5784 }
5785 var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
5786 return test2[n];
5787 });
5788 if (order2.join('') !== '0123456789') {
5789 return false;
5790 }
5791 // https://bugs.chromium.org/p/v8/issues/detail?id=3056
5792 var test3 = {};
5793 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
5794 test3[letter] = letter;
5795 });
5796 if (Object.keys(Object.assign({}, test3)).join('') !==
5797 'abcdefghijklmnopqrst') {
5798 return false;
5799 }
5800 return true;
5801 }
5802 catch (e) {
5803 // We don't expect any of the above to throw, but better to be safe.
5804 return false;
5805 }
5806}
5807module.exports = shouldUseNative() ? Object.assign : function (target, source) {
5808 var from;
5809 var to = toObject(target);
5810 var symbols;
5811 for (var s = 1; s < arguments.length; s++) {
5812 from = Object(arguments[s]);
5813 for (var key in from) {
5814 if (hasOwnProperty.call(from, key)) {
5815 to[key] = from[key];
5816 }
5817 }
5818 if (Object.getOwnPropertySymbols) {
5819 symbols = Object.getOwnPropertySymbols(from);
5820 for (var i = 0; i < symbols.length; i++) {
5821 if (propIsEnumerable.call(from, symbols[i])) {
5822 to[symbols[i]] = from[symbols[i]];
5823 }
5824 }
5825 }
5826 }
5827 return to;
5828};
5829
5830},{}],43:[function(require,module,exports){
5831/*
5832 * Copyright 2009-2011 Mozilla Foundation and contributors
5833 * Licensed under the New BSD license. See LICENSE.txt or:
5834 * http://opensource.org/licenses/BSD-3-Clause
5835 */
5836exports.SourceMapGenerator = require('./source-map/source-map-generator').SourceMapGenerator;
5837exports.SourceMapConsumer = require('./source-map/source-map-consumer').SourceMapConsumer;
5838exports.SourceNode = require('./source-map/source-node').SourceNode;
5839
5840},{"./source-map/source-map-consumer":48,"./source-map/source-map-generator":49,"./source-map/source-node":50}],44:[function(require,module,exports){
5841/* -*- Mode: js; js-indent-level: 2; -*- */
5842/*
5843 * Copyright 2011 Mozilla Foundation and contributors
5844 * Licensed under the New BSD license. See LICENSE or:
5845 * http://opensource.org/licenses/BSD-3-Clause
5846 */
5847if (typeof define !== 'function') {
5848 var define = require('amdefine')(module, require);
5849}
5850define(function (require, exports, module) {
5851
5852 var util = require('./util');
5853
5854 /**
5855 * A data structure which is a combination of an array and a set. Adding a new
5856 * member is O(1), testing for membership is O(1), and finding the index of an
5857 * element is O(1). Removing elements from the set is not supported. Only
5858 * strings are supported for membership.
5859 */
5860 function ArraySet() {
5861 this._array = [];
5862 this._set = {};
5863 }
5864
5865 /**
5866 * Static method for creating ArraySet instances from an existing array.
5867 */
5868 ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
5869 var set = new ArraySet();
5870 for (var i = 0, len = aArray.length; i < len; i++) {
5871 set.add(aArray[i], aAllowDuplicates);
5872 }
5873 return set;
5874 };
5875
5876 /**
5877 * Add the given string to this set.
5878 *
5879 * @param String aStr
5880 */
5881 ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
5882 var isDuplicate = this.has(aStr);
5883 var idx = this._array.length;
5884 if (!isDuplicate || aAllowDuplicates) {
5885 this._array.push(aStr);
5886 }
5887 if (!isDuplicate) {
5888 this._set[util.toSetString(aStr)] = idx;
5889 }
5890 };
5891
5892 /**
5893 * Is the given string a member of this set?
5894 *
5895 * @param String aStr
5896 */
5897 ArraySet.prototype.has = function ArraySet_has(aStr) {
5898 return Object.prototype.hasOwnProperty.call(this._set,
5899 util.toSetString(aStr));
5900 };
5901
5902 /**
5903 * What is the index of the given string in the array?
5904 *
5905 * @param String aStr
5906 */
5907 ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
5908 if (this.has(aStr)) {
5909 return this._set[util.toSetString(aStr)];
5910 }
5911 throw new Error('"' + aStr + '" is not in the set.');
5912 };
5913
5914 /**
5915 * What is the element at the given index?
5916 *
5917 * @param Number aIdx
5918 */
5919 ArraySet.prototype.at = function ArraySet_at(aIdx) {
5920 if (aIdx >= 0 && aIdx < this._array.length) {
5921 return this._array[aIdx];
5922 }
5923 throw new Error('No element indexed by ' + aIdx);
5924 };
5925
5926 /**
5927 * Returns the array representation of this set (which has the proper indices
5928 * indicated by indexOf). Note that this is a copy of the internal array used
5929 * for storing the members so that no one can mess with internal state.
5930 */
5931 ArraySet.prototype.toArray = function ArraySet_toArray() {
5932 return this._array.slice();
5933 };
5934
5935 exports.ArraySet = ArraySet;
5936
5937});
5938
5939},{"./util":51,"amdefine":7}],45:[function(require,module,exports){
5940/* -*- Mode: js; js-indent-level: 2; -*- */
5941/*
5942 * Copyright 2011 Mozilla Foundation and contributors
5943 * Licensed under the New BSD license. See LICENSE or:
5944 * http://opensource.org/licenses/BSD-3-Clause
5945 *
5946 * Based on the Base 64 VLQ implementation in Closure Compiler:
5947 * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
5948 *
5949 * Copyright 2011 The Closure Compiler Authors. All rights reserved.
5950 * Redistribution and use in source and binary forms, with or without
5951 * modification, are permitted provided that the following conditions are
5952 * met:
5953 *
5954 * * Redistributions of source code must retain the above copyright
5955 * notice, this list of conditions and the following disclaimer.
5956 * * Redistributions in binary form must reproduce the above
5957 * copyright notice, this list of conditions and the following
5958 * disclaimer in the documentation and/or other materials provided
5959 * with the distribution.
5960 * * Neither the name of Google Inc. nor the names of its
5961 * contributors may be used to endorse or promote products derived
5962 * from this software without specific prior written permission.
5963 *
5964 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5965 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5966 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
5967 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
5968 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
5969 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
5970 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
5971 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
5972 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5973 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5974 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5975 */
5976if (typeof define !== 'function') {
5977 var define = require('amdefine')(module, require);
5978}
5979define(function (require, exports, module) {
5980
5981 var base64 = require('./base64');
5982
5983 // A single base 64 digit can contain 6 bits of data. For the base 64 variable
5984 // length quantities we use in the source map spec, the first bit is the sign,
5985 // the next four bits are the actual value, and the 6th bit is the
5986 // continuation bit. The continuation bit tells us whether there are more
5987 // digits in this value following this digit.
5988 //
5989 // Continuation
5990 // | Sign
5991 // | |
5992 // V V
5993 // 101011
5994
5995 var VLQ_BASE_SHIFT = 5;
5996
5997 // binary: 100000
5998 var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
5999
6000 // binary: 011111
6001 var VLQ_BASE_MASK = VLQ_BASE - 1;
6002
6003 // binary: 100000
6004 var VLQ_CONTINUATION_BIT = VLQ_BASE;
6005
6006 /**
6007 * Converts from a two-complement value to a value where the sign bit is
6008 * is placed in the least significant bit. For example, as decimals:
6009 * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
6010 * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
6011 */
6012 function toVLQSigned(aValue) {
6013 return aValue < 0
6014 ? ((-aValue) << 1) + 1
6015 : (aValue << 1) + 0;
6016 }
6017
6018 /**
6019 * Converts to a two-complement value from a value where the sign bit is
6020 * is placed in the least significant bit. For example, as decimals:
6021 * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
6022 * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
6023 */
6024 function fromVLQSigned(aValue) {
6025 var isNegative = (aValue & 1) === 1;
6026 var shifted = aValue >> 1;
6027 return isNegative
6028 ? -shifted
6029 : shifted;
6030 }
6031
6032 /**
6033 * Returns the base 64 VLQ encoded value.
6034 */
6035 exports.encode = function base64VLQ_encode(aValue) {
6036 var encoded = "";
6037 var digit;
6038
6039 var vlq = toVLQSigned(aValue);
6040
6041 do {
6042 digit = vlq & VLQ_BASE_MASK;
6043 vlq >>>= VLQ_BASE_SHIFT;
6044 if (vlq > 0) {
6045 // There are still more digits in this value, so we must make sure the
6046 // continuation bit is marked.
6047 digit |= VLQ_CONTINUATION_BIT;
6048 }
6049 encoded += base64.encode(digit);
6050 } while (vlq > 0);
6051
6052 return encoded;
6053 };
6054
6055 /**
6056 * Decodes the next base 64 VLQ value from the given string and returns the
6057 * value and the rest of the string.
6058 */
6059 exports.decode = function base64VLQ_decode(aStr) {
6060 var i = 0;
6061 var strLen = aStr.length;
6062 var result = 0;
6063 var shift = 0;
6064 var continuation, digit;
6065
6066 do {
6067 if (i >= strLen) {
6068 throw new Error("Expected more digits in base 64 VLQ value.");
6069 }
6070 digit = base64.decode(aStr.charAt(i++));
6071 continuation = !!(digit & VLQ_CONTINUATION_BIT);
6072 digit &= VLQ_BASE_MASK;
6073 result = result + (digit << shift);
6074 shift += VLQ_BASE_SHIFT;
6075 } while (continuation);
6076
6077 return {
6078 value: fromVLQSigned(result),
6079 rest: aStr.slice(i)
6080 };
6081 };
6082
6083});
6084
6085},{"./base64":46,"amdefine":7}],46:[function(require,module,exports){
6086/* -*- Mode: js; js-indent-level: 2; -*- */
6087/*
6088 * Copyright 2011 Mozilla Foundation and contributors
6089 * Licensed under the New BSD license. See LICENSE or:
6090 * http://opensource.org/licenses/BSD-3-Clause
6091 */
6092if (typeof define !== 'function') {
6093 var define = require('amdefine')(module, require);
6094}
6095define(function (require, exports, module) {
6096
6097 var charToIntMap = {};
6098 var intToCharMap = {};
6099
6100 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
6101 .split('')
6102 .forEach(function (ch, index) {
6103 charToIntMap[ch] = index;
6104 intToCharMap[index] = ch;
6105 });
6106
6107 /**
6108 * Encode an integer in the range of 0 to 63 to a single base 64 digit.
6109 */
6110 exports.encode = function base64_encode(aNumber) {
6111 if (aNumber in intToCharMap) {
6112 return intToCharMap[aNumber];
6113 }
6114 throw new TypeError("Must be between 0 and 63: " + aNumber);
6115 };
6116
6117 /**
6118 * Decode a single base 64 digit to an integer.
6119 */
6120 exports.decode = function base64_decode(aChar) {
6121 if (aChar in charToIntMap) {
6122 return charToIntMap[aChar];
6123 }
6124 throw new TypeError("Not a valid base 64 digit: " + aChar);
6125 };
6126
6127});
6128
6129},{"amdefine":7}],47:[function(require,module,exports){
6130/* -*- Mode: js; js-indent-level: 2; -*- */
6131/*
6132 * Copyright 2011 Mozilla Foundation and contributors
6133 * Licensed under the New BSD license. See LICENSE or:
6134 * http://opensource.org/licenses/BSD-3-Clause
6135 */
6136if (typeof define !== 'function') {
6137 var define = require('amdefine')(module, require);
6138}
6139define(function (require, exports, module) {
6140
6141 /**
6142 * Recursive implementation of binary search.
6143 *
6144 * @param aLow Indices here and lower do not contain the needle.
6145 * @param aHigh Indices here and higher do not contain the needle.
6146 * @param aNeedle The element being searched for.
6147 * @param aHaystack The non-empty array being searched.
6148 * @param aCompare Function which takes two elements and returns -1, 0, or 1.
6149 */
6150 function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare) {
6151 // This function terminates when one of the following is true:
6152 //
6153 // 1. We find the exact element we are looking for.
6154 //
6155 // 2. We did not find the exact element, but we can return the next
6156 // closest element that is less than that element.
6157 //
6158 // 3. We did not find the exact element, and there is no next-closest
6159 // element which is less than the one we are searching for, so we
6160 // return null.
6161 var mid = Math.floor((aHigh - aLow) / 2) + aLow;
6162 var cmp = aCompare(aNeedle, aHaystack[mid], true);
6163 if (cmp === 0) {
6164 // Found the element we are looking for.
6165 return aHaystack[mid];
6166 }
6167 else if (cmp > 0) {
6168 // aHaystack[mid] is greater than our needle.
6169 if (aHigh - mid > 1) {
6170 // The element is in the upper half.
6171 return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare);
6172 }
6173 // We did not find an exact match, return the next closest one
6174 // (termination case 2).
6175 return aHaystack[mid];
6176 }
6177 else {
6178 // aHaystack[mid] is less than our needle.
6179 if (mid - aLow > 1) {
6180 // The element is in the lower half.
6181 return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare);
6182 }
6183 // The exact needle element was not found in this haystack. Determine if
6184 // we are in termination case (2) or (3) and return the appropriate thing.
6185 return aLow < 0
6186 ? null
6187 : aHaystack[aLow];
6188 }
6189 }
6190
6191 /**
6192 * This is an implementation of binary search which will always try and return
6193 * the next lowest value checked if there is no exact hit. This is because
6194 * mappings between original and generated line/col pairs are single points,
6195 * and there is an implicit region between each of them, so a miss just means
6196 * that you aren't on the very start of a region.
6197 *
6198 * @param aNeedle The element you are looking for.
6199 * @param aHaystack The array that is being searched.
6200 * @param aCompare A function which takes the needle and an element in the
6201 * array and returns -1, 0, or 1 depending on whether the needle is less
6202 * than, equal to, or greater than the element, respectively.
6203 */
6204 exports.search = function search(aNeedle, aHaystack, aCompare) {
6205 return aHaystack.length > 0
6206 ? recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, aCompare)
6207 : null;
6208 };
6209
6210});
6211
6212},{"amdefine":7}],48:[function(require,module,exports){
6213/* -*- Mode: js; js-indent-level: 2; -*- */
6214/*
6215 * Copyright 2011 Mozilla Foundation and contributors
6216 * Licensed under the New BSD license. See LICENSE or:
6217 * http://opensource.org/licenses/BSD-3-Clause
6218 */
6219if (typeof define !== 'function') {
6220 var define = require('amdefine')(module, require);
6221}
6222define(function (require, exports, module) {
6223
6224 var util = require('./util');
6225 var binarySearch = require('./binary-search');
6226 var ArraySet = require('./array-set').ArraySet;
6227 var base64VLQ = require('./base64-vlq');
6228
6229 /**
6230 * A SourceMapConsumer instance represents a parsed source map which we can
6231 * query for information about the original file positions by giving it a file
6232 * position in the generated source.
6233 *
6234 * The only parameter is the raw source map (either as a JSON string, or
6235 * already parsed to an object). According to the spec, source maps have the
6236 * following attributes:
6237 *
6238 * - version: Which version of the source map spec this map is following.
6239 * - sources: An array of URLs to the original source files.
6240 * - names: An array of identifiers which can be referrenced by individual mappings.
6241 * - sourceRoot: Optional. The URL root from which all sources are relative.
6242 * - sourcesContent: Optional. An array of contents of the original source files.
6243 * - mappings: A string of base64 VLQs which contain the actual mappings.
6244 * - file: The generated file this source map is associated with.
6245 *
6246 * Here is an example source map, taken from the source map spec[0]:
6247 *
6248 * {
6249 * version : 3,
6250 * file: "out.js",
6251 * sourceRoot : "",
6252 * sources: ["foo.js", "bar.js"],
6253 * names: ["src", "maps", "are", "fun"],
6254 * mappings: "AA,AB;;ABCDE;"
6255 * }
6256 *
6257 * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
6258 */
6259 function SourceMapConsumer(aSourceMap) {
6260 var sourceMap = aSourceMap;
6261 if (typeof aSourceMap === 'string') {
6262 sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
6263 }
6264
6265 var version = util.getArg(sourceMap, 'version');
6266 var sources = util.getArg(sourceMap, 'sources');
6267 // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
6268 // requires the array) to play nice here.
6269 var names = util.getArg(sourceMap, 'names', []);
6270 var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
6271 var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
6272 var mappings = util.getArg(sourceMap, 'mappings');
6273 var file = util.getArg(sourceMap, 'file', null);
6274
6275 // Once again, Sass deviates from the spec and supplies the version as a
6276 // string rather than a number, so we use loose equality checking here.
6277 if (version != this._version) {
6278 throw new Error('Unsupported version: ' + version);
6279 }
6280
6281 // Pass `true` below to allow duplicate names and sources. While source maps
6282 // are intended to be compressed and deduplicated, the TypeScript compiler
6283 // sometimes generates source maps with duplicates in them. See Github issue
6284 // #72 and bugzil.la/889492.
6285 this._names = ArraySet.fromArray(names, true);
6286 this._sources = ArraySet.fromArray(sources, true);
6287
6288 this.sourceRoot = sourceRoot;
6289 this.sourcesContent = sourcesContent;
6290 this._mappings = mappings;
6291 this.file = file;
6292 }
6293
6294 /**
6295 * Create a SourceMapConsumer from a SourceMapGenerator.
6296 *
6297 * @param SourceMapGenerator aSourceMap
6298 * The source map that will be consumed.
6299 * @returns SourceMapConsumer
6300 */
6301 SourceMapConsumer.fromSourceMap =
6302 function SourceMapConsumer_fromSourceMap(aSourceMap) {
6303 var smc = Object.create(SourceMapConsumer.prototype);
6304
6305 smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
6306 smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
6307 smc.sourceRoot = aSourceMap._sourceRoot;
6308 smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
6309 smc.sourceRoot);
6310 smc.file = aSourceMap._file;
6311
6312 smc.__generatedMappings = aSourceMap._mappings.slice()
6313 .sort(util.compareByGeneratedPositions);
6314 smc.__originalMappings = aSourceMap._mappings.slice()
6315 .sort(util.compareByOriginalPositions);
6316
6317 return smc;
6318 };
6319
6320 /**
6321 * The version of the source mapping spec that we are consuming.
6322 */
6323 SourceMapConsumer.prototype._version = 3;
6324
6325 /**
6326 * The list of original sources.
6327 */
6328 Object.defineProperty(SourceMapConsumer.prototype, 'sources', {
6329 get: function () {
6330 return this._sources.toArray().map(function (s) {
6331 return this.sourceRoot ? util.join(this.sourceRoot, s) : s;
6332 }, this);
6333 }
6334 });
6335
6336 // `__generatedMappings` and `__originalMappings` are arrays that hold the
6337 // parsed mapping coordinates from the source map's "mappings" attribute. They
6338 // are lazily instantiated, accessed via the `_generatedMappings` and
6339 // `_originalMappings` getters respectively, and we only parse the mappings
6340 // and create these arrays once queried for a source location. We jump through
6341 // these hoops because there can be many thousands of mappings, and parsing
6342 // them is expensive, so we only want to do it if we must.
6343 //
6344 // Each object in the arrays is of the form:
6345 //
6346 // {
6347 // generatedLine: The line number in the generated code,
6348 // generatedColumn: The column number in the generated code,
6349 // source: The path to the original source file that generated this
6350 // chunk of code,
6351 // originalLine: The line number in the original source that
6352 // corresponds to this chunk of generated code,
6353 // originalColumn: The column number in the original source that
6354 // corresponds to this chunk of generated code,
6355 // name: The name of the original symbol which generated this chunk of
6356 // code.
6357 // }
6358 //
6359 // All properties except for `generatedLine` and `generatedColumn` can be
6360 // `null`.
6361 //
6362 // `_generatedMappings` is ordered by the generated positions.
6363 //
6364 // `_originalMappings` is ordered by the original positions.
6365
6366 SourceMapConsumer.prototype.__generatedMappings = null;
6367 Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
6368 get: function () {
6369 if (!this.__generatedMappings) {
6370 this.__generatedMappings = [];
6371 this.__originalMappings = [];
6372 this._parseMappings(this._mappings, this.sourceRoot);
6373 }
6374
6375 return this.__generatedMappings;
6376 }
6377 });
6378
6379 SourceMapConsumer.prototype.__originalMappings = null;
6380 Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
6381 get: function () {
6382 if (!this.__originalMappings) {
6383 this.__generatedMappings = [];
6384 this.__originalMappings = [];
6385 this._parseMappings(this._mappings, this.sourceRoot);
6386 }
6387
6388 return this.__originalMappings;
6389 }
6390 });
6391
6392 /**
6393 * Parse the mappings in a string in to a data structure which we can easily
6394 * query (the ordered arrays in the `this.__generatedMappings` and
6395 * `this.__originalMappings` properties).
6396 */
6397 SourceMapConsumer.prototype._parseMappings =
6398 function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
6399 var generatedLine = 1;
6400 var previousGeneratedColumn = 0;
6401 var previousOriginalLine = 0;
6402 var previousOriginalColumn = 0;
6403 var previousSource = 0;
6404 var previousName = 0;
6405 var mappingSeparator = /^[,;]/;
6406 var str = aStr;
6407 var mapping;
6408 var temp;
6409
6410 while (str.length > 0) {
6411 if (str.charAt(0) === ';') {
6412 generatedLine++;
6413 str = str.slice(1);
6414 previousGeneratedColumn = 0;
6415 }
6416 else if (str.charAt(0) === ',') {
6417 str = str.slice(1);
6418 }
6419 else {
6420 mapping = {};
6421 mapping.generatedLine = generatedLine;
6422
6423 // Generated column.
6424 temp = base64VLQ.decode(str);
6425 mapping.generatedColumn = previousGeneratedColumn + temp.value;
6426 previousGeneratedColumn = mapping.generatedColumn;
6427 str = temp.rest;
6428
6429 if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
6430 // Original source.
6431 temp = base64VLQ.decode(str);
6432 mapping.source = this._sources.at(previousSource + temp.value);
6433 previousSource += temp.value;
6434 str = temp.rest;
6435 if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
6436 throw new Error('Found a source, but no line and column');
6437 }
6438
6439 // Original line.
6440 temp = base64VLQ.decode(str);
6441 mapping.originalLine = previousOriginalLine + temp.value;
6442 previousOriginalLine = mapping.originalLine;
6443 // Lines are stored 0-based
6444 mapping.originalLine += 1;
6445 str = temp.rest;
6446 if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
6447 throw new Error('Found a source and line, but no column');
6448 }
6449
6450 // Original column.
6451 temp = base64VLQ.decode(str);
6452 mapping.originalColumn = previousOriginalColumn + temp.value;
6453 previousOriginalColumn = mapping.originalColumn;
6454 str = temp.rest;
6455
6456 if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
6457 // Original name.
6458 temp = base64VLQ.decode(str);
6459 mapping.name = this._names.at(previousName + temp.value);
6460 previousName += temp.value;
6461 str = temp.rest;
6462 }
6463 }
6464
6465 this.__generatedMappings.push(mapping);
6466 if (typeof mapping.originalLine === 'number') {
6467 this.__originalMappings.push(mapping);
6468 }
6469 }
6470 }
6471
6472 this.__generatedMappings.sort(util.compareByGeneratedPositions);
6473 this.__originalMappings.sort(util.compareByOriginalPositions);
6474 };
6475
6476 /**
6477 * Find the mapping that best matches the hypothetical "needle" mapping that
6478 * we are searching for in the given "haystack" of mappings.
6479 */
6480 SourceMapConsumer.prototype._findMapping =
6481 function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
6482 aColumnName, aComparator) {
6483 // To return the position we are searching for, we must first find the
6484 // mapping for the given position and then return the opposite position it
6485 // points to. Because the mappings are sorted, we can use binary search to
6486 // find the best mapping.
6487
6488 if (aNeedle[aLineName] <= 0) {
6489 throw new TypeError('Line must be greater than or equal to 1, got '
6490 + aNeedle[aLineName]);
6491 }
6492 if (aNeedle[aColumnName] < 0) {
6493 throw new TypeError('Column must be greater than or equal to 0, got '
6494 + aNeedle[aColumnName]);
6495 }
6496
6497 return binarySearch.search(aNeedle, aMappings, aComparator);
6498 };
6499
6500 /**
6501 * Returns the original source, line, and column information for the generated
6502 * source's line and column positions provided. The only argument is an object
6503 * with the following properties:
6504 *
6505 * - line: The line number in the generated source.
6506 * - column: The column number in the generated source.
6507 *
6508 * and an object is returned with the following properties:
6509 *
6510 * - source: The original source file, or null.
6511 * - line: The line number in the original source, or null.
6512 * - column: The column number in the original source, or null.
6513 * - name: The original identifier, or null.
6514 */
6515 SourceMapConsumer.prototype.originalPositionFor =
6516 function SourceMapConsumer_originalPositionFor(aArgs) {
6517 var needle = {
6518 generatedLine: util.getArg(aArgs, 'line'),
6519 generatedColumn: util.getArg(aArgs, 'column')
6520 };
6521
6522 var mapping = this._findMapping(needle,
6523 this._generatedMappings,
6524 "generatedLine",
6525 "generatedColumn",
6526 util.compareByGeneratedPositions);
6527
6528 if (mapping) {
6529 var source = util.getArg(mapping, 'source', null);
6530 if (source && this.sourceRoot) {
6531 source = util.join(this.sourceRoot, source);
6532 }
6533 return {
6534 source: source,
6535 line: util.getArg(mapping, 'originalLine', null),
6536 column: util.getArg(mapping, 'originalColumn', null),
6537 name: util.getArg(mapping, 'name', null)
6538 };
6539 }
6540
6541 return {
6542 source: null,
6543 line: null,
6544 column: null,
6545 name: null
6546 };
6547 };
6548
6549 /**
6550 * Returns the original source content. The only argument is the url of the
6551 * original source file. Returns null if no original source content is
6552 * availible.
6553 */
6554 SourceMapConsumer.prototype.sourceContentFor =
6555 function SourceMapConsumer_sourceContentFor(aSource) {
6556 if (!this.sourcesContent) {
6557 return null;
6558 }
6559
6560 if (this.sourceRoot) {
6561 aSource = util.relative(this.sourceRoot, aSource);
6562 }
6563
6564 if (this._sources.has(aSource)) {
6565 return this.sourcesContent[this._sources.indexOf(aSource)];
6566 }
6567
6568 var url;
6569 if (this.sourceRoot
6570 && (url = util.urlParse(this.sourceRoot))) {
6571 // XXX: file:// URIs and absolute paths lead to unexpected behavior for
6572 // many users. We can help them out when they expect file:// URIs to
6573 // behave like it would if they were running a local HTTP server. See
6574 // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
6575 var fileUriAbsPath = aSource.replace(/^file:\/\//, "");
6576 if (url.scheme == "file"
6577 && this._sources.has(fileUriAbsPath)) {
6578 return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
6579 }
6580
6581 if ((!url.path || url.path == "/")
6582 && this._sources.has("/" + aSource)) {
6583 return this.sourcesContent[this._sources.indexOf("/" + aSource)];
6584 }
6585 }
6586
6587 throw new Error('"' + aSource + '" is not in the SourceMap.');
6588 };
6589
6590 /**
6591 * Returns the generated line and column information for the original source,
6592 * line, and column positions provided. The only argument is an object with
6593 * the following properties:
6594 *
6595 * - source: The filename of the original source.
6596 * - line: The line number in the original source.
6597 * - column: The column number in the original source.
6598 *
6599 * and an object is returned with the following properties:
6600 *
6601 * - line: The line number in the generated source, or null.
6602 * - column: The column number in the generated source, or null.
6603 */
6604 SourceMapConsumer.prototype.generatedPositionFor =
6605 function SourceMapConsumer_generatedPositionFor(aArgs) {
6606 var needle = {
6607 source: util.getArg(aArgs, 'source'),
6608 originalLine: util.getArg(aArgs, 'line'),
6609 originalColumn: util.getArg(aArgs, 'column')
6610 };
6611
6612 if (this.sourceRoot) {
6613 needle.source = util.relative(this.sourceRoot, needle.source);
6614 }
6615
6616 var mapping = this._findMapping(needle,
6617 this._originalMappings,
6618 "originalLine",
6619 "originalColumn",
6620 util.compareByOriginalPositions);
6621
6622 if (mapping) {
6623 return {
6624 line: util.getArg(mapping, 'generatedLine', null),
6625 column: util.getArg(mapping, 'generatedColumn', null)
6626 };
6627 }
6628
6629 return {
6630 line: null,
6631 column: null
6632 };
6633 };
6634
6635 SourceMapConsumer.GENERATED_ORDER = 1;
6636 SourceMapConsumer.ORIGINAL_ORDER = 2;
6637
6638 /**
6639 * Iterate over each mapping between an original source/line/column and a
6640 * generated line/column in this source map.
6641 *
6642 * @param Function aCallback
6643 * The function that is called with each mapping.
6644 * @param Object aContext
6645 * Optional. If specified, this object will be the value of `this` every
6646 * time that `aCallback` is called.
6647 * @param aOrder
6648 * Either `SourceMapConsumer.GENERATED_ORDER` or
6649 * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
6650 * iterate over the mappings sorted by the generated file's line/column
6651 * order or the original's source/line/column order, respectively. Defaults to
6652 * `SourceMapConsumer.GENERATED_ORDER`.
6653 */
6654 SourceMapConsumer.prototype.eachMapping =
6655 function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
6656 var context = aContext || null;
6657 var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
6658
6659 var mappings;
6660 switch (order) {
6661 case SourceMapConsumer.GENERATED_ORDER:
6662 mappings = this._generatedMappings;
6663 break;
6664 case SourceMapConsumer.ORIGINAL_ORDER:
6665 mappings = this._originalMappings;
6666 break;
6667 default:
6668 throw new Error("Unknown order of iteration.");
6669 }
6670
6671 var sourceRoot = this.sourceRoot;
6672 mappings.map(function (mapping) {
6673 var source = mapping.source;
6674 if (source && sourceRoot) {
6675 source = util.join(sourceRoot, source);
6676 }
6677 return {
6678 source: source,
6679 generatedLine: mapping.generatedLine,
6680 generatedColumn: mapping.generatedColumn,
6681 originalLine: mapping.originalLine,
6682 originalColumn: mapping.originalColumn,
6683 name: mapping.name
6684 };
6685 }).forEach(aCallback, context);
6686 };
6687
6688 exports.SourceMapConsumer = SourceMapConsumer;
6689
6690});
6691
6692},{"./array-set":44,"./base64-vlq":45,"./binary-search":47,"./util":51,"amdefine":7}],49:[function(require,module,exports){
6693/* -*- Mode: js; js-indent-level: 2; -*- */
6694/*
6695 * Copyright 2011 Mozilla Foundation and contributors
6696 * Licensed under the New BSD license. See LICENSE or:
6697 * http://opensource.org/licenses/BSD-3-Clause
6698 */
6699if (typeof define !== 'function') {
6700 var define = require('amdefine')(module, require);
6701}
6702define(function (require, exports, module) {
6703
6704 var base64VLQ = require('./base64-vlq');
6705 var util = require('./util');
6706 var ArraySet = require('./array-set').ArraySet;
6707
6708 /**
6709 * An instance of the SourceMapGenerator represents a source map which is
6710 * being built incrementally. To create a new one, you must pass an object
6711 * with the following properties:
6712 *
6713 * - file: The filename of the generated source.
6714 * - sourceRoot: An optional root for all URLs in this source map.
6715 */
6716 function SourceMapGenerator(aArgs) {
6717 this._file = util.getArg(aArgs, 'file');
6718 this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
6719 this._sources = new ArraySet();
6720 this._names = new ArraySet();
6721 this._mappings = [];
6722 this._sourcesContents = null;
6723 }
6724
6725 SourceMapGenerator.prototype._version = 3;
6726
6727 /**
6728 * Creates a new SourceMapGenerator based on a SourceMapConsumer
6729 *
6730 * @param aSourceMapConsumer The SourceMap.
6731 */
6732 SourceMapGenerator.fromSourceMap =
6733 function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
6734 var sourceRoot = aSourceMapConsumer.sourceRoot;
6735 var generator = new SourceMapGenerator({
6736 file: aSourceMapConsumer.file,
6737 sourceRoot: sourceRoot
6738 });
6739 aSourceMapConsumer.eachMapping(function (mapping) {
6740 var newMapping = {
6741 generated: {
6742 line: mapping.generatedLine,
6743 column: mapping.generatedColumn
6744 }
6745 };
6746
6747 if (mapping.source) {
6748 newMapping.source = mapping.source;
6749 if (sourceRoot) {
6750 newMapping.source = util.relative(sourceRoot, newMapping.source);
6751 }
6752
6753 newMapping.original = {
6754 line: mapping.originalLine,
6755 column: mapping.originalColumn
6756 };
6757
6758 if (mapping.name) {
6759 newMapping.name = mapping.name;
6760 }
6761 }
6762
6763 generator.addMapping(newMapping);
6764 });
6765 aSourceMapConsumer.sources.forEach(function (sourceFile) {
6766 var content = aSourceMapConsumer.sourceContentFor(sourceFile);
6767 if (content) {
6768 generator.setSourceContent(sourceFile, content);
6769 }
6770 });
6771 return generator;
6772 };
6773
6774 /**
6775 * Add a single mapping from original source line and column to the generated
6776 * source's line and column for this source map being created. The mapping
6777 * object should have the following properties:
6778 *
6779 * - generated: An object with the generated line and column positions.
6780 * - original: An object with the original line and column positions.
6781 * - source: The original source file (relative to the sourceRoot).
6782 * - name: An optional original token name for this mapping.
6783 */
6784 SourceMapGenerator.prototype.addMapping =
6785 function SourceMapGenerator_addMapping(aArgs) {
6786 var generated = util.getArg(aArgs, 'generated');
6787 var original = util.getArg(aArgs, 'original', null);
6788 var source = util.getArg(aArgs, 'source', null);
6789 var name = util.getArg(aArgs, 'name', null);
6790
6791 this._validateMapping(generated, original, source, name);
6792
6793 if (source && !this._sources.has(source)) {
6794 this._sources.add(source);
6795 }
6796
6797 if (name && !this._names.has(name)) {
6798 this._names.add(name);
6799 }
6800
6801 this._mappings.push({
6802 generatedLine: generated.line,
6803 generatedColumn: generated.column,
6804 originalLine: original != null && original.line,
6805 originalColumn: original != null && original.column,
6806 source: source,
6807 name: name
6808 });
6809 };
6810
6811 /**
6812 * Set the source content for a source file.
6813 */
6814 SourceMapGenerator.prototype.setSourceContent =
6815 function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
6816 var source = aSourceFile;
6817 if (this._sourceRoot) {
6818 source = util.relative(this._sourceRoot, source);
6819 }
6820
6821 if (aSourceContent !== null) {
6822 // Add the source content to the _sourcesContents map.
6823 // Create a new _sourcesContents map if the property is null.
6824 if (!this._sourcesContents) {
6825 this._sourcesContents = {};
6826 }
6827 this._sourcesContents[util.toSetString(source)] = aSourceContent;
6828 } else {
6829 // Remove the source file from the _sourcesContents map.
6830 // If the _sourcesContents map is empty, set the property to null.
6831 delete this._sourcesContents[util.toSetString(source)];
6832 if (Object.keys(this._sourcesContents).length === 0) {
6833 this._sourcesContents = null;
6834 }
6835 }
6836 };
6837
6838 /**
6839 * Applies the mappings of a sub-source-map for a specific source file to the
6840 * source map being generated. Each mapping to the supplied source file is
6841 * rewritten using the supplied source map. Note: The resolution for the
6842 * resulting mappings is the minimium of this map and the supplied map.
6843 *
6844 * @param aSourceMapConsumer The source map to be applied.
6845 * @param aSourceFile Optional. The filename of the source file.
6846 * If omitted, SourceMapConsumer's file property will be used.
6847 */
6848 SourceMapGenerator.prototype.applySourceMap =
6849 function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile) {
6850 // If aSourceFile is omitted, we will use the file property of the SourceMap
6851 if (!aSourceFile) {
6852 aSourceFile = aSourceMapConsumer.file;
6853 }
6854 var sourceRoot = this._sourceRoot;
6855 // Make "aSourceFile" relative if an absolute Url is passed.
6856 if (sourceRoot) {
6857 aSourceFile = util.relative(sourceRoot, aSourceFile);
6858 }
6859 // Applying the SourceMap can add and remove items from the sources and
6860 // the names array.
6861 var newSources = new ArraySet();
6862 var newNames = new ArraySet();
6863
6864 // Find mappings for the "aSourceFile"
6865 this._mappings.forEach(function (mapping) {
6866 if (mapping.source === aSourceFile && mapping.originalLine) {
6867 // Check if it can be mapped by the source map, then update the mapping.
6868 var original = aSourceMapConsumer.originalPositionFor({
6869 line: mapping.originalLine,
6870 column: mapping.originalColumn
6871 });
6872 if (original.source !== null) {
6873 // Copy mapping
6874 if (sourceRoot) {
6875 mapping.source = util.relative(sourceRoot, original.source);
6876 } else {
6877 mapping.source = original.source;
6878 }
6879 mapping.originalLine = original.line;
6880 mapping.originalColumn = original.column;
6881 if (original.name !== null && mapping.name !== null) {
6882 // Only use the identifier name if it's an identifier
6883 // in both SourceMaps
6884 mapping.name = original.name;
6885 }
6886 }
6887 }
6888
6889 var source = mapping.source;
6890 if (source && !newSources.has(source)) {
6891 newSources.add(source);
6892 }
6893
6894 var name = mapping.name;
6895 if (name && !newNames.has(name)) {
6896 newNames.add(name);
6897 }
6898
6899 }, this);
6900 this._sources = newSources;
6901 this._names = newNames;
6902
6903 // Copy sourcesContents of applied map.
6904 aSourceMapConsumer.sources.forEach(function (sourceFile) {
6905 var content = aSourceMapConsumer.sourceContentFor(sourceFile);
6906 if (content) {
6907 if (sourceRoot) {
6908 sourceFile = util.relative(sourceRoot, sourceFile);
6909 }
6910 this.setSourceContent(sourceFile, content);
6911 }
6912 }, this);
6913 };
6914
6915 /**
6916 * A mapping can have one of the three levels of data:
6917 *
6918 * 1. Just the generated position.
6919 * 2. The Generated position, original position, and original source.
6920 * 3. Generated and original position, original source, as well as a name
6921 * token.
6922 *
6923 * To maintain consistency, we validate that any new mapping being added falls
6924 * in to one of these categories.
6925 */
6926 SourceMapGenerator.prototype._validateMapping =
6927 function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
6928 aName) {
6929 if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
6930 && aGenerated.line > 0 && aGenerated.column >= 0
6931 && !aOriginal && !aSource && !aName) {
6932 // Case 1.
6933 return;
6934 }
6935 else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
6936 && aOriginal && 'line' in aOriginal && 'column' in aOriginal
6937 && aGenerated.line > 0 && aGenerated.column >= 0
6938 && aOriginal.line > 0 && aOriginal.column >= 0
6939 && aSource) {
6940 // Cases 2 and 3.
6941 return;
6942 }
6943 else {
6944 throw new Error('Invalid mapping: ' + JSON.stringify({
6945 generated: aGenerated,
6946 source: aSource,
6947 original: aOriginal,
6948 name: aName
6949 }));
6950 }
6951 };
6952
6953 /**
6954 * Serialize the accumulated mappings in to the stream of base 64 VLQs
6955 * specified by the source map format.
6956 */
6957 SourceMapGenerator.prototype._serializeMappings =
6958 function SourceMapGenerator_serializeMappings() {
6959 var previousGeneratedColumn = 0;
6960 var previousGeneratedLine = 1;
6961 var previousOriginalColumn = 0;
6962 var previousOriginalLine = 0;
6963 var previousName = 0;
6964 var previousSource = 0;
6965 var result = '';
6966 var mapping;
6967
6968 // The mappings must be guaranteed to be in sorted order before we start
6969 // serializing them or else the generated line numbers (which are defined
6970 // via the ';' separators) will be all messed up. Note: it might be more
6971 // performant to maintain the sorting as we insert them, rather than as we
6972 // serialize them, but the big O is the same either way.
6973 this._mappings.sort(util.compareByGeneratedPositions);
6974
6975 for (var i = 0, len = this._mappings.length; i < len; i++) {
6976 mapping = this._mappings[i];
6977
6978 if (mapping.generatedLine !== previousGeneratedLine) {
6979 previousGeneratedColumn = 0;
6980 while (mapping.generatedLine !== previousGeneratedLine) {
6981 result += ';';
6982 previousGeneratedLine++;
6983 }
6984 }
6985 else {
6986 if (i > 0) {
6987 if (!util.compareByGeneratedPositions(mapping, this._mappings[i - 1])) {
6988 continue;
6989 }
6990 result += ',';
6991 }
6992 }
6993
6994 result += base64VLQ.encode(mapping.generatedColumn
6995 - previousGeneratedColumn);
6996 previousGeneratedColumn = mapping.generatedColumn;
6997
6998 if (mapping.source) {
6999 result += base64VLQ.encode(this._sources.indexOf(mapping.source)
7000 - previousSource);
7001 previousSource = this._sources.indexOf(mapping.source);
7002
7003 // lines are stored 0-based in SourceMap spec version 3
7004 result += base64VLQ.encode(mapping.originalLine - 1
7005 - previousOriginalLine);
7006 previousOriginalLine = mapping.originalLine - 1;
7007
7008 result += base64VLQ.encode(mapping.originalColumn
7009 - previousOriginalColumn);
7010 previousOriginalColumn = mapping.originalColumn;
7011
7012 if (mapping.name) {
7013 result += base64VLQ.encode(this._names.indexOf(mapping.name)
7014 - previousName);
7015 previousName = this._names.indexOf(mapping.name);
7016 }
7017 }
7018 }
7019
7020 return result;
7021 };
7022
7023 SourceMapGenerator.prototype._generateSourcesContent =
7024 function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
7025 return aSources.map(function (source) {
7026 if (!this._sourcesContents) {
7027 return null;
7028 }
7029 if (aSourceRoot) {
7030 source = util.relative(aSourceRoot, source);
7031 }
7032 var key = util.toSetString(source);
7033 return Object.prototype.hasOwnProperty.call(this._sourcesContents,
7034 key)
7035 ? this._sourcesContents[key]
7036 : null;
7037 }, this);
7038 };
7039
7040 /**
7041 * Externalize the source map.
7042 */
7043 SourceMapGenerator.prototype.toJSON =
7044 function SourceMapGenerator_toJSON() {
7045 var map = {
7046 version: this._version,
7047 file: this._file,
7048 sources: this._sources.toArray(),
7049 names: this._names.toArray(),
7050 mappings: this._serializeMappings()
7051 };
7052 if (this._sourceRoot) {
7053 map.sourceRoot = this._sourceRoot;
7054 }
7055 if (this._sourcesContents) {
7056 map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
7057 }
7058
7059 return map;
7060 };
7061
7062 /**
7063 * Render the source map being generated to a string.
7064 */
7065 SourceMapGenerator.prototype.toString =
7066 function SourceMapGenerator_toString() {
7067 return JSON.stringify(this);
7068 };
7069
7070 exports.SourceMapGenerator = SourceMapGenerator;
7071
7072});
7073
7074},{"./array-set":44,"./base64-vlq":45,"./util":51,"amdefine":7}],50:[function(require,module,exports){
7075/* -*- Mode: js; js-indent-level: 2; -*- */
7076/*
7077 * Copyright 2011 Mozilla Foundation and contributors
7078 * Licensed under the New BSD license. See LICENSE or:
7079 * http://opensource.org/licenses/BSD-3-Clause
7080 */
7081if (typeof define !== 'function') {
7082 var define = require('amdefine')(module, require);
7083}
7084define(function (require, exports, module) {
7085
7086 var SourceMapGenerator = require('./source-map-generator').SourceMapGenerator;
7087 var util = require('./util');
7088
7089 /**
7090 * SourceNodes provide a way to abstract over interpolating/concatenating
7091 * snippets of generated JavaScript source code while maintaining the line and
7092 * column information associated with the original source code.
7093 *
7094 * @param aLine The original line number.
7095 * @param aColumn The original column number.
7096 * @param aSource The original source's filename.
7097 * @param aChunks Optional. An array of strings which are snippets of
7098 * generated JS, or other SourceNodes.
7099 * @param aName The original identifier.
7100 */
7101 function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
7102 this.children = [];
7103 this.sourceContents = {};
7104 this.line = aLine === undefined ? null : aLine;
7105 this.column = aColumn === undefined ? null : aColumn;
7106 this.source = aSource === undefined ? null : aSource;
7107 this.name = aName === undefined ? null : aName;
7108 if (aChunks != null) this.add(aChunks);
7109 }
7110
7111 /**
7112 * Creates a SourceNode from generated code and a SourceMapConsumer.
7113 *
7114 * @param aGeneratedCode The generated code
7115 * @param aSourceMapConsumer The SourceMap for the generated code
7116 */
7117 SourceNode.fromStringWithSourceMap =
7118 function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer) {
7119 // The SourceNode we want to fill with the generated code
7120 // and the SourceMap
7121 var node = new SourceNode();
7122
7123 // The generated code
7124 // Processed fragments are removed from this array.
7125 var remainingLines = aGeneratedCode.split('\n');
7126
7127 // We need to remember the position of "remainingLines"
7128 var lastGeneratedLine = 1, lastGeneratedColumn = 0;
7129
7130 // The generate SourceNodes we need a code range.
7131 // To extract it current and last mapping is used.
7132 // Here we store the last mapping.
7133 var lastMapping = null;
7134
7135 aSourceMapConsumer.eachMapping(function (mapping) {
7136 if (lastMapping === null) {
7137 // We add the generated code until the first mapping
7138 // to the SourceNode without any mapping.
7139 // Each line is added as separate string.
7140 while (lastGeneratedLine < mapping.generatedLine) {
7141 node.add(remainingLines.shift() + "\n");
7142 lastGeneratedLine++;
7143 }
7144 if (lastGeneratedColumn < mapping.generatedColumn) {
7145 var nextLine = remainingLines[0];
7146 node.add(nextLine.substr(0, mapping.generatedColumn));
7147 remainingLines[0] = nextLine.substr(mapping.generatedColumn);
7148 lastGeneratedColumn = mapping.generatedColumn;
7149 }
7150 } else {
7151 // We add the code from "lastMapping" to "mapping":
7152 // First check if there is a new line in between.
7153 if (lastGeneratedLine < mapping.generatedLine) {
7154 var code = "";
7155 // Associate full lines with "lastMapping"
7156 do {
7157 code += remainingLines.shift() + "\n";
7158 lastGeneratedLine++;
7159 lastGeneratedColumn = 0;
7160 } while (lastGeneratedLine < mapping.generatedLine);
7161 // When we reached the correct line, we add code until we
7162 // reach the correct column too.
7163 if (lastGeneratedColumn < mapping.generatedColumn) {
7164 var nextLine = remainingLines[0];
7165 code += nextLine.substr(0, mapping.generatedColumn);
7166 remainingLines[0] = nextLine.substr(mapping.generatedColumn);
7167 lastGeneratedColumn = mapping.generatedColumn;
7168 }
7169 // Create the SourceNode.
7170 addMappingWithCode(lastMapping, code);
7171 } else {
7172 // There is no new line in between.
7173 // Associate the code between "lastGeneratedColumn" and
7174 // "mapping.generatedColumn" with "lastMapping"
7175 var nextLine = remainingLines[0];
7176 var code = nextLine.substr(0, mapping.generatedColumn -
7177 lastGeneratedColumn);
7178 remainingLines[0] = nextLine.substr(mapping.generatedColumn -
7179 lastGeneratedColumn);
7180 lastGeneratedColumn = mapping.generatedColumn;
7181 addMappingWithCode(lastMapping, code);
7182 }
7183 }
7184 lastMapping = mapping;
7185 }, this);
7186 // We have processed all mappings.
7187 // Associate the remaining code in the current line with "lastMapping"
7188 // and add the remaining lines without any mapping
7189 addMappingWithCode(lastMapping, remainingLines.join("\n"));
7190
7191 // Copy sourcesContent into SourceNode
7192 aSourceMapConsumer.sources.forEach(function (sourceFile) {
7193 var content = aSourceMapConsumer.sourceContentFor(sourceFile);
7194 if (content) {
7195 node.setSourceContent(sourceFile, content);
7196 }
7197 });
7198
7199 return node;
7200
7201 function addMappingWithCode(mapping, code) {
7202 if (mapping === null || mapping.source === undefined) {
7203 node.add(code);
7204 } else {
7205 node.add(new SourceNode(mapping.originalLine,
7206 mapping.originalColumn,
7207 mapping.source,
7208 code,
7209 mapping.name));
7210 }
7211 }
7212 };
7213
7214 /**
7215 * Add a chunk of generated JS to this source node.
7216 *
7217 * @param aChunk A string snippet of generated JS code, another instance of
7218 * SourceNode, or an array where each member is one of those things.
7219 */
7220 SourceNode.prototype.add = function SourceNode_add(aChunk) {
7221 if (Array.isArray(aChunk)) {
7222 aChunk.forEach(function (chunk) {
7223 this.add(chunk);
7224 }, this);
7225 }
7226 else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
7227 if (aChunk) {
7228 this.children.push(aChunk);
7229 }
7230 }
7231 else {
7232 throw new TypeError(
7233 "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
7234 );
7235 }
7236 return this;
7237 };
7238
7239 /**
7240 * Add a chunk of generated JS to the beginning of this source node.
7241 *
7242 * @param aChunk A string snippet of generated JS code, another instance of
7243 * SourceNode, or an array where each member is one of those things.
7244 */
7245 SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
7246 if (Array.isArray(aChunk)) {
7247 for (var i = aChunk.length-1; i >= 0; i--) {
7248 this.prepend(aChunk[i]);
7249 }
7250 }
7251 else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
7252 this.children.unshift(aChunk);
7253 }
7254 else {
7255 throw new TypeError(
7256 "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
7257 );
7258 }
7259 return this;
7260 };
7261
7262 /**
7263 * Walk over the tree of JS snippets in this node and its children. The
7264 * walking function is called once for each snippet of JS and is passed that
7265 * snippet and the its original associated source's line/column location.
7266 *
7267 * @param aFn The traversal function.
7268 */
7269 SourceNode.prototype.walk = function SourceNode_walk(aFn) {
7270 var chunk;
7271 for (var i = 0, len = this.children.length; i < len; i++) {
7272 chunk = this.children[i];
7273 if (chunk instanceof SourceNode) {
7274 chunk.walk(aFn);
7275 }
7276 else {
7277 if (chunk !== '') {
7278 aFn(chunk, { source: this.source,
7279 line: this.line,
7280 column: this.column,
7281 name: this.name });
7282 }
7283 }
7284 }
7285 };
7286
7287 /**
7288 * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
7289 * each of `this.children`.
7290 *
7291 * @param aSep The separator.
7292 */
7293 SourceNode.prototype.join = function SourceNode_join(aSep) {
7294 var newChildren;
7295 var i;
7296 var len = this.children.length;
7297 if (len > 0) {
7298 newChildren = [];
7299 for (i = 0; i < len-1; i++) {
7300 newChildren.push(this.children[i]);
7301 newChildren.push(aSep);
7302 }
7303 newChildren.push(this.children[i]);
7304 this.children = newChildren;
7305 }
7306 return this;
7307 };
7308
7309 /**
7310 * Call String.prototype.replace on the very right-most source snippet. Useful
7311 * for trimming whitespace from the end of a source node, etc.
7312 *
7313 * @param aPattern The pattern to replace.
7314 * @param aReplacement The thing to replace the pattern with.
7315 */
7316 SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
7317 var lastChild = this.children[this.children.length - 1];
7318 if (lastChild instanceof SourceNode) {
7319 lastChild.replaceRight(aPattern, aReplacement);
7320 }
7321 else if (typeof lastChild === 'string') {
7322 this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
7323 }
7324 else {
7325 this.children.push(''.replace(aPattern, aReplacement));
7326 }
7327 return this;
7328 };
7329
7330 /**
7331 * Set the source content for a source file. This will be added to the SourceMapGenerator
7332 * in the sourcesContent field.
7333 *
7334 * @param aSourceFile The filename of the source file
7335 * @param aSourceContent The content of the source file
7336 */
7337 SourceNode.prototype.setSourceContent =
7338 function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
7339 this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
7340 };
7341
7342 /**
7343 * Walk over the tree of SourceNodes. The walking function is called for each
7344 * source file content and is passed the filename and source content.
7345 *
7346 * @param aFn The traversal function.
7347 */
7348 SourceNode.prototype.walkSourceContents =
7349 function SourceNode_walkSourceContents(aFn) {
7350 for (var i = 0, len = this.children.length; i < len; i++) {
7351 if (this.children[i] instanceof SourceNode) {
7352 this.children[i].walkSourceContents(aFn);
7353 }
7354 }
7355
7356 var sources = Object.keys(this.sourceContents);
7357 for (var i = 0, len = sources.length; i < len; i++) {
7358 aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
7359 }
7360 };
7361
7362 /**
7363 * Return the string representation of this source node. Walks over the tree
7364 * and concatenates all the various snippets together to one string.
7365 */
7366 SourceNode.prototype.toString = function SourceNode_toString() {
7367 var str = "";
7368 this.walk(function (chunk) {
7369 str += chunk;
7370 });
7371 return str;
7372 };
7373
7374 /**
7375 * Returns the string representation of this source node along with a source
7376 * map.
7377 */
7378 SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
7379 var generated = {
7380 code: "",
7381 line: 1,
7382 column: 0
7383 };
7384 var map = new SourceMapGenerator(aArgs);
7385 var sourceMappingActive = false;
7386 var lastOriginalSource = null;
7387 var lastOriginalLine = null;
7388 var lastOriginalColumn = null;
7389 var lastOriginalName = null;
7390 this.walk(function (chunk, original) {
7391 generated.code += chunk;
7392 if (original.source !== null
7393 && original.line !== null
7394 && original.column !== null) {
7395 if(lastOriginalSource !== original.source
7396 || lastOriginalLine !== original.line
7397 || lastOriginalColumn !== original.column
7398 || lastOriginalName !== original.name) {
7399 map.addMapping({
7400 source: original.source,
7401 original: {
7402 line: original.line,
7403 column: original.column
7404 },
7405 generated: {
7406 line: generated.line,
7407 column: generated.column
7408 },
7409 name: original.name
7410 });
7411 }
7412 lastOriginalSource = original.source;
7413 lastOriginalLine = original.line;
7414 lastOriginalColumn = original.column;
7415 lastOriginalName = original.name;
7416 sourceMappingActive = true;
7417 } else if (sourceMappingActive) {
7418 map.addMapping({
7419 generated: {
7420 line: generated.line,
7421 column: generated.column
7422 }
7423 });
7424 lastOriginalSource = null;
7425 sourceMappingActive = false;
7426 }
7427 chunk.split('').forEach(function (ch) {
7428 if (ch === '\n') {
7429 generated.line++;
7430 generated.column = 0;
7431 } else {
7432 generated.column++;
7433 }
7434 });
7435 });
7436 this.walkSourceContents(function (sourceFile, sourceContent) {
7437 map.setSourceContent(sourceFile, sourceContent);
7438 });
7439
7440 return { code: generated.code, map: map };
7441 };
7442
7443 exports.SourceNode = SourceNode;
7444
7445});
7446
7447},{"./source-map-generator":49,"./util":51,"amdefine":7}],51:[function(require,module,exports){
7448/* -*- Mode: js; js-indent-level: 2; -*- */
7449/*
7450 * Copyright 2011 Mozilla Foundation and contributors
7451 * Licensed under the New BSD license. See LICENSE or:
7452 * http://opensource.org/licenses/BSD-3-Clause
7453 */
7454if (typeof define !== 'function') {
7455 var define = require('amdefine')(module, require);
7456}
7457define(function (require, exports, module) {
7458
7459 /**
7460 * This is a helper function for getting values from parameter/options
7461 * objects.
7462 *
7463 * @param args The object we are extracting values from
7464 * @param name The name of the property we are getting.
7465 * @param defaultValue An optional value to return if the property is missing
7466 * from the object. If this is not specified and the property is missing, an
7467 * error will be thrown.
7468 */
7469 function getArg(aArgs, aName, aDefaultValue) {
7470 if (aName in aArgs) {
7471 return aArgs[aName];
7472 } else if (arguments.length === 3) {
7473 return aDefaultValue;
7474 } else {
7475 throw new Error('"' + aName + '" is a required argument.');
7476 }
7477 }
7478 exports.getArg = getArg;
7479
7480 var urlRegexp = /([\w+\-.]+):\/\/((\w+:\w+)@)?([\w.]+)?(:(\d+))?(\S+)?/;
7481 var dataUrlRegexp = /^data:.+\,.+/;
7482
7483 function urlParse(aUrl) {
7484 var match = aUrl.match(urlRegexp);
7485 if (!match) {
7486 return null;
7487 }
7488 return {
7489 scheme: match[1],
7490 auth: match[3],
7491 host: match[4],
7492 port: match[6],
7493 path: match[7]
7494 };
7495 }
7496 exports.urlParse = urlParse;
7497
7498 function urlGenerate(aParsedUrl) {
7499 var url = aParsedUrl.scheme + "://";
7500 if (aParsedUrl.auth) {
7501 url += aParsedUrl.auth + "@"
7502 }
7503 if (aParsedUrl.host) {
7504 url += aParsedUrl.host;
7505 }
7506 if (aParsedUrl.port) {
7507 url += ":" + aParsedUrl.port
7508 }
7509 if (aParsedUrl.path) {
7510 url += aParsedUrl.path;
7511 }
7512 return url;
7513 }
7514 exports.urlGenerate = urlGenerate;
7515
7516 function join(aRoot, aPath) {
7517 var url;
7518
7519 if (aPath.match(urlRegexp) || aPath.match(dataUrlRegexp)) {
7520 return aPath;
7521 }
7522
7523 if (aPath.charAt(0) === '/' && (url = urlParse(aRoot))) {
7524 url.path = aPath;
7525 return urlGenerate(url);
7526 }
7527
7528 return aRoot.replace(/\/$/, '') + '/' + aPath;
7529 }
7530 exports.join = join;
7531
7532 /**
7533 * Because behavior goes wacky when you set `__proto__` on objects, we
7534 * have to prefix all the strings in our set with an arbitrary character.
7535 *
7536 * See https://github.com/mozilla/source-map/pull/31 and
7537 * https://github.com/mozilla/source-map/issues/30
7538 *
7539 * @param String aStr
7540 */
7541 function toSetString(aStr) {
7542 return '$' + aStr;
7543 }
7544 exports.toSetString = toSetString;
7545
7546 function fromSetString(aStr) {
7547 return aStr.substr(1);
7548 }
7549 exports.fromSetString = fromSetString;
7550
7551 function relative(aRoot, aPath) {
7552 aRoot = aRoot.replace(/\/$/, '');
7553
7554 var url = urlParse(aRoot);
7555 if (aPath.charAt(0) == "/" && url && url.path == "/") {
7556 return aPath.slice(1);
7557 }
7558
7559 return aPath.indexOf(aRoot + '/') === 0
7560 ? aPath.substr(aRoot.length + 1)
7561 : aPath;
7562 }
7563 exports.relative = relative;
7564
7565 function strcmp(aStr1, aStr2) {
7566 var s1 = aStr1 || "";
7567 var s2 = aStr2 || "";
7568 return (s1 > s2) - (s1 < s2);
7569 }
7570
7571 /**
7572 * Comparator between two mappings where the original positions are compared.
7573 *
7574 * Optionally pass in `true` as `onlyCompareGenerated` to consider two
7575 * mappings with the same original source/line/column, but different generated
7576 * line and column the same. Useful when searching for a mapping with a
7577 * stubbed out mapping.
7578 */
7579 function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
7580 var cmp;
7581
7582 cmp = strcmp(mappingA.source, mappingB.source);
7583 if (cmp) {
7584 return cmp;
7585 }
7586
7587 cmp = mappingA.originalLine - mappingB.originalLine;
7588 if (cmp) {
7589 return cmp;
7590 }
7591
7592 cmp = mappingA.originalColumn - mappingB.originalColumn;
7593 if (cmp || onlyCompareOriginal) {
7594 return cmp;
7595 }
7596
7597 cmp = strcmp(mappingA.name, mappingB.name);
7598 if (cmp) {
7599 return cmp;
7600 }
7601
7602 cmp = mappingA.generatedLine - mappingB.generatedLine;
7603 if (cmp) {
7604 return cmp;
7605 }
7606
7607 return mappingA.generatedColumn - mappingB.generatedColumn;
7608 };
7609 exports.compareByOriginalPositions = compareByOriginalPositions;
7610
7611 /**
7612 * Comparator between two mappings where the generated positions are
7613 * compared.
7614 *
7615 * Optionally pass in `true` as `onlyCompareGenerated` to consider two
7616 * mappings with the same generated line and column, but different
7617 * source/name/original line and column the same. Useful when searching for a
7618 * mapping with a stubbed out mapping.
7619 */
7620 function compareByGeneratedPositions(mappingA, mappingB, onlyCompareGenerated) {
7621 var cmp;
7622
7623 cmp = mappingA.generatedLine - mappingB.generatedLine;
7624 if (cmp) {
7625 return cmp;
7626 }
7627
7628 cmp = mappingA.generatedColumn - mappingB.generatedColumn;
7629 if (cmp || onlyCompareGenerated) {
7630 return cmp;
7631 }
7632
7633 cmp = strcmp(mappingA.source, mappingB.source);
7634 if (cmp) {
7635 return cmp;
7636 }
7637
7638 cmp = mappingA.originalLine - mappingB.originalLine;
7639 if (cmp) {
7640 return cmp;
7641 }
7642
7643 cmp = mappingA.originalColumn - mappingB.originalColumn;
7644 if (cmp) {
7645 return cmp;
7646 }
7647
7648 return strcmp(mappingA.name, mappingB.name);
7649 };
7650 exports.compareByGeneratedPositions = compareByGeneratedPositions;
7651
7652});
7653
7654},{"amdefine":7}],52:[function(require,module,exports){
7655(function (process,Buffer){
7656var SourceMapConsumer = require('source-map').SourceMapConsumer;
7657var path = require('path');
7658var fs = require('fs');
7659// Only install once if called multiple times
7660var errorFormatterInstalled = false;
7661var uncaughtShimInstalled = false;
7662// If true, the caches are reset before a stack trace formatting operation
7663var emptyCacheBetweenOperations = false;
7664// Supports {browser, node, auto}
7665var environment = "auto";
7666// Maps a file path to a string containing the file contents
7667var fileContentsCache = {};
7668// Maps a file path to a source map for that file
7669var sourceMapCache = {};
7670// Regex for detecting source maps
7671var reSourceMap = /^data:application\/json[^,]+base64,/;
7672// Priority list of retrieve handlers
7673var retrieveFileHandlers = [];
7674var retrieveMapHandlers = [];
7675function isInBrowser() {
7676 if (environment === "browser")
7677 return true;
7678 if (environment === "node")
7679 return false;
7680 return ((typeof window !== 'undefined') && (typeof XMLHttpRequest === 'function'));
7681}
7682function hasGlobalProcessEventEmitter() {
7683 return ((typeof process === 'object') && (process !== null) && (typeof process.on === 'function'));
7684}
7685function handlerExec(list) {
7686 return function (arg) {
7687 for (var i = 0; i < list.length; i++) {
7688 var ret = list[i](arg);
7689 if (ret) {
7690 return ret;
7691 }
7692 }
7693 return null;
7694 };
7695}
7696var retrieveFile = handlerExec(retrieveFileHandlers);
7697retrieveFileHandlers.push(function (path) {
7698 // Trim the path to make sure there is no extra whitespace.
7699 path = path.trim();
7700 if (path in fileContentsCache) {
7701 return fileContentsCache[path];
7702 }
7703 try {
7704 // Use SJAX if we are in the browser
7705 if (isInBrowser()) {
7706 var xhr = new XMLHttpRequest();
7707 xhr.open('GET', path, false);
7708 xhr.send(null);
7709 var contents = null;
7710 if (xhr.readyState === 4 && xhr.status === 200) {
7711 contents = xhr.responseText;
7712 }
7713 }
7714 else {
7715 var contents = fs.readFileSync(path, 'utf8');
7716 }
7717 }
7718 catch (e) {
7719 var contents = null;
7720 }
7721 return fileContentsCache[path] = contents;
7722});
7723// Support URLs relative to a directory, but be careful about a protocol prefix
7724// in case we are in the browser (i.e. directories may start with "http://")
7725function supportRelativeURL(file, url) {
7726 if (!file)
7727 return url;
7728 var dir = path.dirname(file);
7729 var match = /^\w+:\/\/[^\/]*/.exec(dir);
7730 var protocol = match ? match[0] : '';
7731 return protocol + path.resolve(dir.slice(protocol.length), url);
7732}
7733function retrieveSourceMapURL(source) {
7734 var fileData;
7735 if (isInBrowser()) {
7736 var xhr = new XMLHttpRequest();
7737 xhr.open('GET', source, false);
7738 xhr.send(null);
7739 fileData = xhr.readyState === 4 ? xhr.responseText : null;
7740 // Support providing a sourceMappingURL via the SourceMap header
7741 var sourceMapHeader = xhr.getResponseHeader("SourceMap") ||
7742 xhr.getResponseHeader("X-SourceMap");
7743 if (sourceMapHeader) {
7744 return sourceMapHeader;
7745 }
7746 }
7747 // Get the URL of the source map
7748 fileData = retrieveFile(source);
7749 //
7750 var re = /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/)[ \t]*$)/mg;
7751 // Keep executing the search to find the *last* sourceMappingURL to avoid
7752 // picking up sourceMappingURLs from comments, strings, etc.
7753 var lastMatch, match;
7754 while (match = re.exec(fileData))
7755 lastMatch = match;
7756 if (!lastMatch)
7757 return null;
7758 return lastMatch[1];
7759}
7760;
7761// Can be overridden by the retrieveSourceMap option to install. Takes a
7762// generated source filename; returns a {map, optional url} object, or null if
7763// there is no source map. The map field may be either a string or the parsed
7764// JSON object (ie, it must be a valid argument to the SourceMapConsumer
7765// constructor).
7766var retrieveSourceMap = handlerExec(retrieveMapHandlers);
7767retrieveMapHandlers.push(function (source) {
7768 var sourceMappingURL = retrieveSourceMapURL(source);
7769 if (!sourceMappingURL)
7770 return null;
7771 // Read the contents of the source map
7772 var sourceMapData;
7773 if (reSourceMap.test(sourceMappingURL)) {
7774 // Support source map URL as a data url
7775 var rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(',') + 1);
7776 sourceMapData = new Buffer(rawData, "base64").toString();
7777 sourceMappingURL = null;
7778 }
7779 else {
7780 // Support source map URLs relative to the source URL
7781 sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
7782 sourceMapData = retrieveFile(sourceMappingURL);
7783 }
7784 if (!sourceMapData) {
7785 return null;
7786 }
7787 return {
7788 url: sourceMappingURL,
7789 map: sourceMapData
7790 };
7791});
7792function mapSourcePosition(position) {
7793 var sourceMap = sourceMapCache[position.source];
7794 if (!sourceMap) {
7795 // Call the (overrideable) retrieveSourceMap function to get the source map.
7796 var urlAndMap = retrieveSourceMap(position.source);
7797 if (urlAndMap) {
7798 sourceMap = sourceMapCache[position.source] = {
7799 url: urlAndMap.url,
7800 map: new SourceMapConsumer(urlAndMap.map)
7801 };
7802 // Load all sources stored inline with the source map into the file cache
7803 // to pretend like they are already loaded. They may not exist on disk.
7804 if (sourceMap.map.sourcesContent) {
7805 sourceMap.map.sources.forEach(function (source, i) {
7806 var contents = sourceMap.map.sourcesContent[i];
7807 if (contents) {
7808 var url = supportRelativeURL(sourceMap.url, source);
7809 fileContentsCache[url] = contents;
7810 }
7811 });
7812 }
7813 }
7814 else {
7815 sourceMap = sourceMapCache[position.source] = {
7816 url: null,
7817 map: null
7818 };
7819 }
7820 }
7821 // Resolve the source URL relative to the URL of the source map
7822 if (sourceMap && sourceMap.map) {
7823 var originalPosition = sourceMap.map.originalPositionFor(position);
7824 // Only return the original position if a matching line was found. If no
7825 // matching line is found then we return position instead, which will cause
7826 // the stack trace to print the path and line for the compiled file. It is
7827 // better to give a precise location in the compiled file than a vague
7828 // location in the original file.
7829 if (originalPosition.source !== null) {
7830 originalPosition.source = supportRelativeURL(sourceMap.url, originalPosition.source);
7831 return originalPosition;
7832 }
7833 }
7834 return position;
7835}
7836// Parses code generated by FormatEvalOrigin(), a function inside V8:
7837// https://code.google.com/p/v8/source/browse/trunk/src/messages.js
7838function mapEvalOrigin(origin) {
7839 // Most eval() calls are in this format
7840 var match = /^eval at ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(origin);
7841 if (match) {
7842 var position = mapSourcePosition({
7843 source: match[2],
7844 line: match[3],
7845 column: match[4] - 1
7846 });
7847 return 'eval at ' + match[1] + ' (' + position.source + ':' +
7848 position.line + ':' + (position.column + 1) + ')';
7849 }
7850 // Parse nested eval() calls using recursion
7851 match = /^eval at ([^(]+) \((.+)\)$/.exec(origin);
7852 if (match) {
7853 return 'eval at ' + match[1] + ' (' + mapEvalOrigin(match[2]) + ')';
7854 }
7855 // Make sure we still return useful information if we didn't find anything
7856 return origin;
7857}
7858// This is copied almost verbatim from the V8 source code at
7859// https://code.google.com/p/v8/source/browse/trunk/src/messages.js. The
7860// implementation of wrapCallSite() used to just forward to the actual source
7861// code of CallSite.prototype.toString but unfortunately a new release of V8
7862// did something to the prototype chain and broke the shim. The only fix I
7863// could find was copy/paste.
7864function CallSiteToString() {
7865 var fileName;
7866 var fileLocation = "";
7867 if (this.isNative()) {
7868 fileLocation = "native";
7869 }
7870 else {
7871 fileName = this.getScriptNameOrSourceURL();
7872 if (!fileName && this.isEval()) {
7873 fileLocation = this.getEvalOrigin();
7874 fileLocation += ", "; // Expecting source position to follow.
7875 }
7876 if (fileName) {
7877 fileLocation += fileName;
7878 }
7879 else {
7880 // Source code does not originate from a file and is not native, but we
7881 // can still get the source position inside the source string, e.g. in
7882 // an eval string.
7883 fileLocation += "<anonymous>";
7884 }
7885 var lineNumber = this.getLineNumber();
7886 if (lineNumber != null) {
7887 fileLocation += ":" + lineNumber;
7888 var columnNumber = this.getColumnNumber();
7889 if (columnNumber) {
7890 fileLocation += ":" + columnNumber;
7891 }
7892 }
7893 }
7894 var line = "";
7895 var functionName = this.getFunctionName();
7896 var addSuffix = true;
7897 var isConstructor = this.isConstructor();
7898 var isMethodCall = !(this.isToplevel() || isConstructor);
7899 if (isMethodCall) {
7900 var typeName = this.getTypeName();
7901 var methodName = this.getMethodName();
7902 if (functionName) {
7903 if (typeName && functionName.indexOf(typeName) != 0) {
7904 line += typeName + ".";
7905 }
7906 line += functionName;
7907 if (methodName && functionName.indexOf("." + methodName) != functionName.length - methodName.length - 1) {
7908 line += " [as " + methodName + "]";
7909 }
7910 }
7911 else {
7912 line += typeName + "." + (methodName || "<anonymous>");
7913 }
7914 }
7915 else if (isConstructor) {
7916 line += "new " + (functionName || "<anonymous>");
7917 }
7918 else if (functionName) {
7919 line += functionName;
7920 }
7921 else {
7922 line += fileLocation;
7923 addSuffix = false;
7924 }
7925 if (addSuffix) {
7926 line += " (" + fileLocation + ")";
7927 }
7928 return line;
7929}
7930function cloneCallSite(frame) {
7931 var object = {};
7932 Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach(function (name) {
7933 object[name] = /^(?:is|get)/.test(name) ? function () { return frame[name].call(frame); } : frame[name];
7934 });
7935 object.toString = CallSiteToString;
7936 return object;
7937}
7938function wrapCallSite(frame) {
7939 // Most call sites will return the source file from getFileName(), but code
7940 // passed to eval() ending in "//# sourceURL=..." will return the source file
7941 // from getScriptNameOrSourceURL() instead
7942 var source = frame.getFileName() || frame.getScriptNameOrSourceURL();
7943 if (source) {
7944 var line = frame.getLineNumber();
7945 var column = frame.getColumnNumber() - 1;
7946 // Fix position in Node where some (internal) code is prepended.
7947 // See https://github.com/evanw/node-source-map-support/issues/36
7948 if (line === 1 && !isInBrowser() && !frame.isEval()) {
7949 column -= 62;
7950 }
7951 var position = mapSourcePosition({
7952 source: source,
7953 line: line,
7954 column: column
7955 });
7956 frame = cloneCallSite(frame);
7957 frame.getFileName = function () { return position.source; };
7958 frame.getLineNumber = function () { return position.line; };
7959 frame.getColumnNumber = function () { return position.column + 1; };
7960 frame.getScriptNameOrSourceURL = function () { return position.source; };
7961 return frame;
7962 }
7963 // Code called using eval() needs special handling
7964 var origin = frame.isEval() && frame.getEvalOrigin();
7965 if (origin) {
7966 origin = mapEvalOrigin(origin);
7967 frame = cloneCallSite(frame);
7968 frame.getEvalOrigin = function () { return origin; };
7969 return frame;
7970 }
7971 // If we get here then we were unable to change the source position
7972 return frame;
7973}
7974// This function is part of the V8 stack trace API, for more info see:
7975// http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
7976function prepareStackTrace(error, stack) {
7977 if (emptyCacheBetweenOperations) {
7978 fileContentsCache = {};
7979 sourceMapCache = {};
7980 }
7981 return error + stack.map(function (frame) {
7982 return '\n at ' + wrapCallSite(frame);
7983 }).join('');
7984}
7985// Generate position and snippet of original source with pointer
7986function getErrorSource(error) {
7987 var match = /\n at [^(]+ \((.*):(\d+):(\d+)\)/.exec(error.stack);
7988 if (match) {
7989 var source = match[1];
7990 var line = +match[2];
7991 var column = +match[3];
7992 // Support the inline sourceContents inside the source map
7993 var contents = fileContentsCache[source];
7994 // Support files on disk
7995 if (!contents && fs.existsSync(source)) {
7996 contents = fs.readFileSync(source, 'utf8');
7997 }
7998 // Format the line from the original source code like node does
7999 if (contents) {
8000 var code = contents.split(/(?:\r\n|\r|\n)/)[line - 1];
8001 if (code) {
8002 return source + ':' + line + '\n' + code + '\n' +
8003 new Array(column).join(' ') + '^';
8004 }
8005 }
8006 }
8007 return null;
8008}
8009function printErrorAndExit(error) {
8010 var source = getErrorSource(error);
8011 if (source) {
8012 console.error();
8013 console.error(source);
8014 }
8015 console.error(error.stack);
8016 process.exit(1);
8017}
8018function shimEmitUncaughtException() {
8019 var origEmit = process.emit;
8020 process.emit = function (type) {
8021 if (type === 'uncaughtException') {
8022 var hasStack = (arguments[1] && arguments[1].stack);
8023 var hasListeners = (this.listeners(type).length > 0);
8024 if (hasStack && !hasListeners) {
8025 return printErrorAndExit(arguments[1]);
8026 }
8027 }
8028 return origEmit.apply(this, arguments);
8029 };
8030}
8031exports.wrapCallSite = wrapCallSite;
8032exports.getErrorSource = getErrorSource;
8033exports.mapSourcePosition = mapSourcePosition;
8034exports.retrieveSourceMap = retrieveSourceMap;
8035exports.install = function (options) {
8036 options = options || {};
8037 if (options.environment) {
8038 environment = options.environment;
8039 if (["node", "browser", "auto"].indexOf(environment) === -1) {
8040 throw new Error("environment " + environment + " was unknown. Available options are {auto, browser, node}");
8041 }
8042 }
8043 // Allow sources to be found by methods other than reading the files
8044 // directly from disk.
8045 if (options.retrieveFile) {
8046 if (options.overrideRetrieveFile) {
8047 retrieveFileHandlers.length = 0;
8048 }
8049 retrieveFileHandlers.unshift(options.retrieveFile);
8050 }
8051 // Allow source maps to be found by methods other than reading the files
8052 // directly from disk.
8053 if (options.retrieveSourceMap) {
8054 if (options.overrideRetrieveSourceMap) {
8055 retrieveMapHandlers.length = 0;
8056 }
8057 retrieveMapHandlers.unshift(options.retrieveSourceMap);
8058 }
8059 // Configure options
8060 if (!emptyCacheBetweenOperations) {
8061 emptyCacheBetweenOperations = 'emptyCacheBetweenOperations' in options ?
8062 options.emptyCacheBetweenOperations : false;
8063 }
8064 // Install the error reformatter
8065 if (!errorFormatterInstalled) {
8066 errorFormatterInstalled = true;
8067 Error.prepareStackTrace = prepareStackTrace;
8068 }
8069 if (!uncaughtShimInstalled) {
8070 var installHandler = 'handleUncaughtExceptions' in options ?
8071 options.handleUncaughtExceptions : true;
8072 // Provide the option to not install the uncaught exception handler. This is
8073 // to support other uncaught exception handlers (in test frameworks, for
8074 // example). If this handler is not installed and there are no other uncaught
8075 // exception handlers, uncaught exceptions will be caught by node's built-in
8076 // exception handler and the process will still be terminated. However, the
8077 // generated JavaScript code will be shown above the stack trace instead of
8078 // the original source code.
8079 if (installHandler && hasGlobalProcessEventEmitter()) {
8080 uncaughtShimInstalled = true;
8081 shimEmitUncaughtException();
8082 }
8083 }
8084};
8085
8086}).call(this,require('_process'),require("buffer").Buffer)
8087
8088},{"_process":67,"buffer":63,"fs":62,"path":66,"source-map":43}],53:[function(require,module,exports){
8089module.exports = require('./lib/type');
8090
8091},{"./lib/type":54}],54:[function(require,module,exports){
8092/*!
8093 * type-detect
8094 * Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
8095 * MIT Licensed
8096 */
8097/*!
8098 * Primary Exports
8099 */
8100var exports = module.exports = getType;
8101/**
8102 * ### typeOf (obj)
8103 *
8104 * Use several different techniques to determine
8105 * the type of object being tested.
8106 *
8107 *
8108 * @param {Mixed} object
8109 * @return {String} object type
8110 * @api public
8111 */
8112var objectTypeRegexp = /^\[object (.*)\]$/;
8113function getType(obj) {
8114 var type = Object.prototype.toString.call(obj).match(objectTypeRegexp)[1].toLowerCase();
8115 // Let "new String('')" return 'object'
8116 if (typeof Promise === 'function' && obj instanceof Promise)
8117 return 'promise';
8118 // PhantomJS has type "DOMWindow" for null
8119 if (obj === null)
8120 return 'null';
8121 // PhantomJS has type "DOMWindow" for undefined
8122 if (obj === undefined)
8123 return 'undefined';
8124 return type;
8125}
8126exports.Library = Library;
8127/**
8128 * ### Library
8129 *
8130 * Create a repository for custom type detection.
8131 *
8132 * ```js
8133 * var lib = new type.Library;
8134 * ```
8135 *
8136 */
8137function Library() {
8138 if (!(this instanceof Library))
8139 return new Library();
8140 this.tests = {};
8141}
8142/**
8143 * #### .of (obj)
8144 *
8145 * Expose replacement `typeof` detection to the library.
8146 *
8147 * ```js
8148 * if ('string' === lib.of('hello world')) {
8149 * // ...
8150 * }
8151 * ```
8152 *
8153 * @param {Mixed} object to test
8154 * @return {String} type
8155 */
8156Library.prototype.of = getType;
8157/**
8158 * #### .define (type, test)
8159 *
8160 * Add a test to for the `.test()` assertion.
8161 *
8162 * Can be defined as a regular expression:
8163 *
8164 * ```js
8165 * lib.define('int', /^[0-9]+$/);
8166 * ```
8167 *
8168 * ... or as a function:
8169 *
8170 * ```js
8171 * lib.define('bln', function (obj) {
8172 * if ('boolean' === lib.of(obj)) return true;
8173 * var blns = [ 'yes', 'no', 'true', 'false', 1, 0 ];
8174 * if ('string' === lib.of(obj)) obj = obj.toLowerCase();
8175 * return !! ~blns.indexOf(obj);
8176 * });
8177 * ```
8178 *
8179 * @param {String} type
8180 * @param {RegExp|Function} test
8181 * @api public
8182 */
8183Library.prototype.define = function (type, test) {
8184 if (arguments.length === 1)
8185 return this.tests[type];
8186 this.tests[type] = test;
8187 return this;
8188};
8189/**
8190 * #### .test (obj, test)
8191 *
8192 * Assert that an object is of type. Will first
8193 * check natives, and if that does not pass it will
8194 * use the user defined custom tests.
8195 *
8196 * ```js
8197 * assert(lib.test('1', 'int'));
8198 * assert(lib.test('yes', 'bln'));
8199 * ```
8200 *
8201 * @param {Mixed} object
8202 * @param {String} type
8203 * @return {Boolean} result
8204 * @api public
8205 */
8206Library.prototype.test = function (obj, type) {
8207 if (type === getType(obj))
8208 return true;
8209 var test = this.tests[type];
8210 if (test && 'regexp' === getType(test)) {
8211 return test.test(obj);
8212 }
8213 else if (test && 'function' === getType(test)) {
8214 return test(obj);
8215 }
8216 else {
8217 throw new ReferenceError('Type test "' + type + '" not defined or invalid.');
8218 }
8219};
8220
8221},{}],55:[function(require,module,exports){
8222
8223},{}],56:[function(require,module,exports){
8224(function (global){
8225"use strict";
8226var _1 = require("../");
8227var chai_1 = require("chai");
8228var isBrowser = !!global.document;
8229describe("The default component", function () {
8230 it("should be instantiable", function () {
8231 var inst = new _1.Component({});
8232 });
8233 it("should store the given data", function () {
8234 var inst = new _1.Component({ x: 5 });
8235 chai_1.expect(inst.$data.x).to.equal(5);
8236 });
8237 it("should produce HTML when asked", function () {
8238 var inst = new _1.Component({});
8239 var body = inst.toString();
8240 chai_1.expect(body).to.contain(_1.Component.$tagName);
8241 });
8242 it("should properly serialize data", function () {
8243 var inst = new _1.Component({ x: 5 });
8244 var serialized = inst.$serializeData();
8245 chai_1.expect(serialized.x).to.equal(inst.$data.x);
8246 chai_1.expect(serialized).to.not.equal(inst.$data);
8247 });
8248 it("should be deflatable", function () {
8249 var inst = new _1.Component({ x: 5 });
8250 var deflated = inst.$deflate();
8251 chai_1.expect(deflated.data.x).to.equal(5);
8252 });
8253 it("should be inflatable", function () {
8254 var inst = new _1.Component({ x: 5 });
8255 var deflated = inst.$deflate();
8256 var reinst = _1.Component.$inflate(deflated);
8257 chai_1.expect(reinst.$data.x).to.equal(5);
8258 });
8259 it("should expose a consistent identifier", function () {
8260 var inst = new _1.Component({});
8261 chai_1.expect(inst.$getIdentifier()).to.equal(_1.Component.$getIdentifier(inst.$label));
8262 });
8263 it("should properly nest", function () {
8264 var parent = new _1.Component({});
8265 var child = _1.Component.$for(parent, "", {});
8266 chai_1.expect(parent.$children).to.contain(child);
8267 });
8268 if (isBrowser) {
8269 it("should have an element after being ensured", function () {
8270 var inst = new _1.Component({});
8271 inst.$ensureElement();
8272 chai_1.expect(inst.$element).to.be.instanceof(Element);
8273 });
8274 it("should created an element when reified", function () {
8275 var inst = new _1.Component({});
8276 inst.$reify();
8277 chai_1.expect(inst.$element).to.be.instanceof(Element);
8278 });
8279 it("should attach to existing elements", function () {
8280 var inst = new _1.Component({});
8281 var el = document.createElement("arm-component");
8282 inst.$attachTo(el);
8283 chai_1.expect(inst.$element).to.equal(el);
8284 });
8285 }
8286});
8287
8288}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
8289
8290},{"../":6,"chai":9}],57:[function(require,module,exports){
8291"use strict";
8292require("source-map-support").install();
8293require("./default-component");
8294require("./simple-component");
8295require("./nesting-component");
8296
8297},{"./default-component":56,"./nesting-component":58,"./simple-component":59,"source-map-support":52}],58:[function(require,module,exports){
8298(function (global){
8299"use strict";
8300var __extends = (this && this.__extends) || function (d, b) {
8301 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
8302 function __() { this.constructor = d; }
8303 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
8304};
8305var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
8306 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
8307 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
8308 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8309 return c > 3 && r && Object.defineProperty(target, key, r), r;
8310};
8311var _1 = require("../");
8312var chai_1 = require("chai");
8313var isBrowser = !!global.document;
8314describe("A nesting component", function () {
8315 var template = function (component) { return ("\n\t\tThis is a child: " + Child.$for(component, "", null) + "\n\t"); };
8316 var Parent = (function (_super) {
8317 __extends(Parent, _super);
8318 function Parent(data) {
8319 _super.call(this, data);
8320 Child.$for(this, "", {});
8321 }
8322 Parent = __decorate([
8323 _1.TagName("parent-component"),
8324 _1.Template(template)
8325 ], Parent);
8326 return Parent;
8327 }(_1.Component));
8328 var Child = (function (_super) {
8329 __extends(Child, _super);
8330 function Child() {
8331 _super.apply(this, arguments);
8332 }
8333 Child = __decorate([
8334 _1.TagName("child-component")
8335 ], Child);
8336 return Child;
8337 }(_1.Component));
8338 it("should recall children correctly", function () {
8339 var parent = new Parent({});
8340 var child = Child.$for(parent, "", null);
8341 chai_1.expect(parent.$children[0]).to.equal(child);
8342 });
8343 if (isBrowser) {
8344 it("should reify without creating a new child component", function () {
8345 var parent = new Parent({});
8346 parent.$reify();
8347 chai_1.expect(parent.$children).to.have.length(1);
8348 });
8349 it("should be able to locate itself in the parent", function () {
8350 var parent = new Parent({});
8351 parent.$reify();
8352 var child = Child.$for(parent, "", null);
8353 chai_1.expect(child.$element).to.be.instanceof(Element);
8354 });
8355 }
8356});
8357
8358}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
8359
8360},{"../":6,"chai":9}],59:[function(require,module,exports){
8361(function (global){
8362"use strict";
8363var __extends = (this && this.__extends) || function (d, b) {
8364 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
8365 function __() { this.constructor = d; }
8366 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
8367};
8368var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
8369 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
8370 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
8371 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8372 return c > 3 && r && Object.defineProperty(target, key, r), r;
8373};
8374var _1 = require("../");
8375var chai_1 = require("chai");
8376var isBrowser = !!global.document;
8377describe("A simple component", function () {
8378 var template = function (component) { return ("\n\t\tWe have this: " + component.$data.x + "\n\t"); };
8379 var Simple = (function (_super) {
8380 __extends(Simple, _super);
8381 function Simple(params) {
8382 _super.call(this, params);
8383 }
8384 Simple = __decorate([
8385 _1.TagName("simple-component"),
8386 _1.Template(template)
8387 ], Simple);
8388 return Simple;
8389 }(_1.Component));
8390 if (isBrowser) {
8391 it("should render with the correct markup", function () {
8392 var inst = new Simple({ x: 5 });
8393 inst.$reify();
8394 chai_1.expect(inst.$element.innerHTML).to.equal(inst.$template(inst));
8395 });
8396 }
8397});
8398
8399}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
8400
8401},{"../":6,"chai":9}],60:[function(require,module,exports){
8402arguments[4][55][0].apply(exports,arguments)
8403},{"dup":55}],61:[function(require,module,exports){
8404'use strict'
8405
8406exports.toByteArray = toByteArray
8407exports.fromByteArray = fromByteArray
8408
8409var lookup = []
8410var revLookup = []
8411var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
8412
8413function init () {
8414 var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
8415 for (var i = 0, len = code.length; i < len; ++i) {
8416 lookup[i] = code[i]
8417 revLookup[code.charCodeAt(i)] = i
8418 }
8419
8420 revLookup['-'.charCodeAt(0)] = 62
8421 revLookup['_'.charCodeAt(0)] = 63
8422}
8423
8424init()
8425
8426function toByteArray (b64) {
8427 var i, j, l, tmp, placeHolders, arr
8428 var len = b64.length
8429
8430 if (len % 4 > 0) {
8431 throw new Error('Invalid string. Length must be a multiple of 4')
8432 }
8433
8434 // the number of equal signs (place holders)
8435 // if there are two placeholders, than the two characters before it
8436 // represent one byte
8437 // if there is only one, then the three characters before it represent 2 bytes
8438 // this is just a cheap hack to not do indexOf twice
8439 placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
8440
8441 // base64 is 4/3 + up to two characters of the original data
8442 arr = new Arr(len * 3 / 4 - placeHolders)
8443
8444 // if there are placeholders, only get up to the last complete 4 chars
8445 l = placeHolders > 0 ? len - 4 : len
8446
8447 var L = 0
8448
8449 for (i = 0, j = 0; i < l; i += 4, j += 3) {
8450 tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
8451 arr[L++] = (tmp >> 16) & 0xFF
8452 arr[L++] = (tmp >> 8) & 0xFF
8453 arr[L++] = tmp & 0xFF
8454 }
8455
8456 if (placeHolders === 2) {
8457 tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
8458 arr[L++] = tmp & 0xFF
8459 } else if (placeHolders === 1) {
8460 tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
8461 arr[L++] = (tmp >> 8) & 0xFF
8462 arr[L++] = tmp & 0xFF
8463 }
8464
8465 return arr
8466}
8467
8468function tripletToBase64 (num) {
8469 return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
8470}
8471
8472function encodeChunk (uint8, start, end) {
8473 var tmp
8474 var output = []
8475 for (var i = start; i < end; i += 3) {
8476 tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
8477 output.push(tripletToBase64(tmp))
8478 }
8479 return output.join('')
8480}
8481
8482function fromByteArray (uint8) {
8483 var tmp
8484 var len = uint8.length
8485 var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
8486 var output = ''
8487 var parts = []
8488 var maxChunkLength = 16383 // must be multiple of 3
8489
8490 // go through the array every three bytes, we'll deal with trailing stuff later
8491 for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
8492 parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
8493 }
8494
8495 // pad the end with zeros, but make sure to not forget the extra bytes
8496 if (extraBytes === 1) {
8497 tmp = uint8[len - 1]
8498 output += lookup[tmp >> 2]
8499 output += lookup[(tmp << 4) & 0x3F]
8500 output += '=='
8501 } else if (extraBytes === 2) {
8502 tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
8503 output += lookup[tmp >> 10]
8504 output += lookup[(tmp >> 4) & 0x3F]
8505 output += lookup[(tmp << 2) & 0x3F]
8506 output += '='
8507 }
8508
8509 parts.push(output)
8510
8511 return parts.join('')
8512}
8513
8514},{}],62:[function(require,module,exports){
8515arguments[4][55][0].apply(exports,arguments)
8516},{"dup":55}],63:[function(require,module,exports){
8517(function (global){
8518/*!
8519 * The buffer module from node.js, for the browser.
8520 *
8521 * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
8522 * @license MIT
8523 */
8524/* eslint-disable no-proto */
8525
8526'use strict'
8527
8528var base64 = require('base64-js')
8529var ieee754 = require('ieee754')
8530var isArray = require('isarray')
8531
8532exports.Buffer = Buffer
8533exports.SlowBuffer = SlowBuffer
8534exports.INSPECT_MAX_BYTES = 50
8535
8536/**
8537 * If `Buffer.TYPED_ARRAY_SUPPORT`:
8538 * === true Use Uint8Array implementation (fastest)
8539 * === false Use Object implementation (most compatible, even IE6)
8540 *
8541 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
8542 * Opera 11.6+, iOS 4.2+.
8543 *
8544 * Due to various browser bugs, sometimes the Object implementation will be used even
8545 * when the browser supports typed arrays.
8546 *
8547 * Note:
8548 *
8549 * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
8550 * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
8551 *
8552 * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
8553 *
8554 * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
8555 * incorrect length in some situations.
8556
8557 * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
8558 * get the Object implementation, which is slower but behaves correctly.
8559 */
8560Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
8561 ? global.TYPED_ARRAY_SUPPORT
8562 : typedArraySupport()
8563
8564/*
8565 * Export kMaxLength after typed array support is determined.
8566 */
8567exports.kMaxLength = kMaxLength()
8568
8569function typedArraySupport () {
8570 try {
8571 var arr = new Uint8Array(1)
8572 arr.foo = function () { return 42 }
8573 return arr.foo() === 42 && // typed array instances can be augmented
8574 typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
8575 arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
8576 } catch (e) {
8577 return false
8578 }
8579}
8580
8581function kMaxLength () {
8582 return Buffer.TYPED_ARRAY_SUPPORT
8583 ? 0x7fffffff
8584 : 0x3fffffff
8585}
8586
8587function createBuffer (that, length) {
8588 if (kMaxLength() < length) {
8589 throw new RangeError('Invalid typed array length')
8590 }
8591 if (Buffer.TYPED_ARRAY_SUPPORT) {
8592 // Return an augmented `Uint8Array` instance, for best performance
8593 that = new Uint8Array(length)
8594 that.__proto__ = Buffer.prototype
8595 } else {
8596 // Fallback: Return an object instance of the Buffer class
8597 if (that === null) {
8598 that = new Buffer(length)
8599 }
8600 that.length = length
8601 }
8602
8603 return that
8604}
8605
8606/**
8607 * The Buffer constructor returns instances of `Uint8Array` that have their
8608 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
8609 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
8610 * and the `Uint8Array` methods. Square bracket notation works as expected -- it
8611 * returns a single octet.
8612 *
8613 * The `Uint8Array` prototype remains unmodified.
8614 */
8615
8616function Buffer (arg, encodingOrOffset, length) {
8617 if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
8618 return new Buffer(arg, encodingOrOffset, length)
8619 }
8620
8621 // Common case.
8622 if (typeof arg === 'number') {
8623 if (typeof encodingOrOffset === 'string') {
8624 throw new Error(
8625 'If encoding is specified then the first argument must be a string'
8626 )
8627 }
8628 return allocUnsafe(this, arg)
8629 }
8630 return from(this, arg, encodingOrOffset, length)
8631}
8632
8633Buffer.poolSize = 8192 // not used by this implementation
8634
8635// TODO: Legacy, not needed anymore. Remove in next major version.
8636Buffer._augment = function (arr) {
8637 arr.__proto__ = Buffer.prototype
8638 return arr
8639}
8640
8641function from (that, value, encodingOrOffset, length) {
8642 if (typeof value === 'number') {
8643 throw new TypeError('"value" argument must not be a number')
8644 }
8645
8646 if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
8647 return fromArrayBuffer(that, value, encodingOrOffset, length)
8648 }
8649
8650 if (typeof value === 'string') {
8651 return fromString(that, value, encodingOrOffset)
8652 }
8653
8654 return fromObject(that, value)
8655}
8656
8657/**
8658 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
8659 * if value is a number.
8660 * Buffer.from(str[, encoding])
8661 * Buffer.from(array)
8662 * Buffer.from(buffer)
8663 * Buffer.from(arrayBuffer[, byteOffset[, length]])
8664 **/
8665Buffer.from = function (value, encodingOrOffset, length) {
8666 return from(null, value, encodingOrOffset, length)
8667}
8668
8669if (Buffer.TYPED_ARRAY_SUPPORT) {
8670 Buffer.prototype.__proto__ = Uint8Array.prototype
8671 Buffer.__proto__ = Uint8Array
8672 if (typeof Symbol !== 'undefined' && Symbol.species &&
8673 Buffer[Symbol.species] === Buffer) {
8674 // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
8675 Object.defineProperty(Buffer, Symbol.species, {
8676 value: null,
8677 configurable: true
8678 })
8679 }
8680}
8681
8682function assertSize (size) {
8683 if (typeof size !== 'number') {
8684 throw new TypeError('"size" argument must be a number')
8685 }
8686}
8687
8688function alloc (that, size, fill, encoding) {
8689 assertSize(size)
8690 if (size <= 0) {
8691 return createBuffer(that, size)
8692 }
8693 if (fill !== undefined) {
8694 // Only pay attention to encoding if it's a string. This
8695 // prevents accidentally sending in a number that would
8696 // be interpretted as a start offset.
8697 return typeof encoding === 'string'
8698 ? createBuffer(that, size).fill(fill, encoding)
8699 : createBuffer(that, size).fill(fill)
8700 }
8701 return createBuffer(that, size)
8702}
8703
8704/**
8705 * Creates a new filled Buffer instance.
8706 * alloc(size[, fill[, encoding]])
8707 **/
8708Buffer.alloc = function (size, fill, encoding) {
8709 return alloc(null, size, fill, encoding)
8710}
8711
8712function allocUnsafe (that, size) {
8713 assertSize(size)
8714 that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
8715 if (!Buffer.TYPED_ARRAY_SUPPORT) {
8716 for (var i = 0; i < size; i++) {
8717 that[i] = 0
8718 }
8719 }
8720 return that
8721}
8722
8723/**
8724 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
8725 * */
8726Buffer.allocUnsafe = function (size) {
8727 return allocUnsafe(null, size)
8728}
8729/**
8730 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
8731 */
8732Buffer.allocUnsafeSlow = function (size) {
8733 return allocUnsafe(null, size)
8734}
8735
8736function fromString (that, string, encoding) {
8737 if (typeof encoding !== 'string' || encoding === '') {
8738 encoding = 'utf8'
8739 }
8740
8741 if (!Buffer.isEncoding(encoding)) {
8742 throw new TypeError('"encoding" must be a valid string encoding')
8743 }
8744
8745 var length = byteLength(string, encoding) | 0
8746 that = createBuffer(that, length)
8747
8748 that.write(string, encoding)
8749 return that
8750}
8751
8752function fromArrayLike (that, array) {
8753 var length = checked(array.length) | 0
8754 that = createBuffer(that, length)
8755 for (var i = 0; i < length; i += 1) {
8756 that[i] = array[i] & 255
8757 }
8758 return that
8759}
8760
8761function fromArrayBuffer (that, array, byteOffset, length) {
8762 array.byteLength // this throws if `array` is not a valid ArrayBuffer
8763
8764 if (byteOffset < 0 || array.byteLength < byteOffset) {
8765 throw new RangeError('\'offset\' is out of bounds')
8766 }
8767
8768 if (array.byteLength < byteOffset + (length || 0)) {
8769 throw new RangeError('\'length\' is out of bounds')
8770 }
8771
8772 if (length === undefined) {
8773 array = new Uint8Array(array, byteOffset)
8774 } else {
8775 array = new Uint8Array(array, byteOffset, length)
8776 }
8777
8778 if (Buffer.TYPED_ARRAY_SUPPORT) {
8779 // Return an augmented `Uint8Array` instance, for best performance
8780 that = array
8781 that.__proto__ = Buffer.prototype
8782 } else {
8783 // Fallback: Return an object instance of the Buffer class
8784 that = fromArrayLike(that, array)
8785 }
8786 return that
8787}
8788
8789function fromObject (that, obj) {
8790 if (Buffer.isBuffer(obj)) {
8791 var len = checked(obj.length) | 0
8792 that = createBuffer(that, len)
8793
8794 if (that.length === 0) {
8795 return that
8796 }
8797
8798 obj.copy(that, 0, 0, len)
8799 return that
8800 }
8801
8802 if (obj) {
8803 if ((typeof ArrayBuffer !== 'undefined' &&
8804 obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
8805 if (typeof obj.length !== 'number' || isnan(obj.length)) {
8806 return createBuffer(that, 0)
8807 }
8808 return fromArrayLike(that, obj)
8809 }
8810
8811 if (obj.type === 'Buffer' && isArray(obj.data)) {
8812 return fromArrayLike(that, obj.data)
8813 }
8814 }
8815
8816 throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
8817}
8818
8819function checked (length) {
8820 // Note: cannot use `length < kMaxLength` here because that fails when
8821 // length is NaN (which is otherwise coerced to zero.)
8822 if (length >= kMaxLength()) {
8823 throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
8824 'size: 0x' + kMaxLength().toString(16) + ' bytes')
8825 }
8826 return length | 0
8827}
8828
8829function SlowBuffer (length) {
8830 if (+length != length) { // eslint-disable-line eqeqeq
8831 length = 0
8832 }
8833 return Buffer.alloc(+length)
8834}
8835
8836Buffer.isBuffer = function isBuffer (b) {
8837 return !!(b != null && b._isBuffer)
8838}
8839
8840Buffer.compare = function compare (a, b) {
8841 if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
8842 throw new TypeError('Arguments must be Buffers')
8843 }
8844
8845 if (a === b) return 0
8846
8847 var x = a.length
8848 var y = b.length
8849
8850 for (var i = 0, len = Math.min(x, y); i < len; ++i) {
8851 if (a[i] !== b[i]) {
8852 x = a[i]
8853 y = b[i]
8854 break
8855 }
8856 }
8857
8858 if (x < y) return -1
8859 if (y < x) return 1
8860 return 0
8861}
8862
8863Buffer.isEncoding = function isEncoding (encoding) {
8864 switch (String(encoding).toLowerCase()) {
8865 case 'hex':
8866 case 'utf8':
8867 case 'utf-8':
8868 case 'ascii':
8869 case 'binary':
8870 case 'base64':
8871 case 'raw':
8872 case 'ucs2':
8873 case 'ucs-2':
8874 case 'utf16le':
8875 case 'utf-16le':
8876 return true
8877 default:
8878 return false
8879 }
8880}
8881
8882Buffer.concat = function concat (list, length) {
8883 if (!isArray(list)) {
8884 throw new TypeError('"list" argument must be an Array of Buffers')
8885 }
8886
8887 if (list.length === 0) {
8888 return Buffer.alloc(0)
8889 }
8890
8891 var i
8892 if (length === undefined) {
8893 length = 0
8894 for (i = 0; i < list.length; i++) {
8895 length += list[i].length
8896 }
8897 }
8898
8899 var buffer = Buffer.allocUnsafe(length)
8900 var pos = 0
8901 for (i = 0; i < list.length; i++) {
8902 var buf = list[i]
8903 if (!Buffer.isBuffer(buf)) {
8904 throw new TypeError('"list" argument must be an Array of Buffers')
8905 }
8906 buf.copy(buffer, pos)
8907 pos += buf.length
8908 }
8909 return buffer
8910}
8911
8912function byteLength (string, encoding) {
8913 if (Buffer.isBuffer(string)) {
8914 return string.length
8915 }
8916 if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
8917 (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
8918 return string.byteLength
8919 }
8920 if (typeof string !== 'string') {
8921 string = '' + string
8922 }
8923
8924 var len = string.length
8925 if (len === 0) return 0
8926
8927 // Use a for loop to avoid recursion
8928 var loweredCase = false
8929 for (;;) {
8930 switch (encoding) {
8931 case 'ascii':
8932 case 'binary':
8933 // Deprecated
8934 case 'raw':
8935 case 'raws':
8936 return len
8937 case 'utf8':
8938 case 'utf-8':
8939 case undefined:
8940 return utf8ToBytes(string).length
8941 case 'ucs2':
8942 case 'ucs-2':
8943 case 'utf16le':
8944 case 'utf-16le':
8945 return len * 2
8946 case 'hex':
8947 return len >>> 1
8948 case 'base64':
8949 return base64ToBytes(string).length
8950 default:
8951 if (loweredCase) return utf8ToBytes(string).length // assume utf8
8952 encoding = ('' + encoding).toLowerCase()
8953 loweredCase = true
8954 }
8955 }
8956}
8957Buffer.byteLength = byteLength
8958
8959function slowToString (encoding, start, end) {
8960 var loweredCase = false
8961
8962 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
8963 // property of a typed array.
8964
8965 // This behaves neither like String nor Uint8Array in that we set start/end
8966 // to their upper/lower bounds if the value passed is out of range.
8967 // undefined is handled specially as per ECMA-262 6th Edition,
8968 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
8969 if (start === undefined || start < 0) {
8970 start = 0
8971 }
8972 // Return early if start > this.length. Done here to prevent potential uint32
8973 // coercion fail below.
8974 if (start > this.length) {
8975 return ''
8976 }
8977
8978 if (end === undefined || end > this.length) {
8979 end = this.length
8980 }
8981
8982 if (end <= 0) {
8983 return ''
8984 }
8985
8986 // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
8987 end >>>= 0
8988 start >>>= 0
8989
8990 if (end <= start) {
8991 return ''
8992 }
8993
8994 if (!encoding) encoding = 'utf8'
8995
8996 while (true) {
8997 switch (encoding) {
8998 case 'hex':
8999 return hexSlice(this, start, end)
9000
9001 case 'utf8':
9002 case 'utf-8':
9003 return utf8Slice(this, start, end)
9004
9005 case 'ascii':
9006 return asciiSlice(this, start, end)
9007
9008 case 'binary':
9009 return binarySlice(this, start, end)
9010
9011 case 'base64':
9012 return base64Slice(this, start, end)
9013
9014 case 'ucs2':
9015 case 'ucs-2':
9016 case 'utf16le':
9017 case 'utf-16le':
9018 return utf16leSlice(this, start, end)
9019
9020 default:
9021 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
9022 encoding = (encoding + '').toLowerCase()
9023 loweredCase = true
9024 }
9025 }
9026}
9027
9028// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
9029// Buffer instances.
9030Buffer.prototype._isBuffer = true
9031
9032function swap (b, n, m) {
9033 var i = b[n]
9034 b[n] = b[m]
9035 b[m] = i
9036}
9037
9038Buffer.prototype.swap16 = function swap16 () {
9039 var len = this.length
9040 if (len % 2 !== 0) {
9041 throw new RangeError('Buffer size must be a multiple of 16-bits')
9042 }
9043 for (var i = 0; i < len; i += 2) {
9044 swap(this, i, i + 1)
9045 }
9046 return this
9047}
9048
9049Buffer.prototype.swap32 = function swap32 () {
9050 var len = this.length
9051 if (len % 4 !== 0) {
9052 throw new RangeError('Buffer size must be a multiple of 32-bits')
9053 }
9054 for (var i = 0; i < len; i += 4) {
9055 swap(this, i, i + 3)
9056 swap(this, i + 1, i + 2)
9057 }
9058 return this
9059}
9060
9061Buffer.prototype.toString = function toString () {
9062 var length = this.length | 0
9063 if (length === 0) return ''
9064 if (arguments.length === 0) return utf8Slice(this, 0, length)
9065 return slowToString.apply(this, arguments)
9066}
9067
9068Buffer.prototype.equals = function equals (b) {
9069 if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
9070 if (this === b) return true
9071 return Buffer.compare(this, b) === 0
9072}
9073
9074Buffer.prototype.inspect = function inspect () {
9075 var str = ''
9076 var max = exports.INSPECT_MAX_BYTES
9077 if (this.length > 0) {
9078 str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
9079 if (this.length > max) str += ' ... '
9080 }
9081 return '<Buffer ' + str + '>'
9082}
9083
9084Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
9085 if (!Buffer.isBuffer(target)) {
9086 throw new TypeError('Argument must be a Buffer')
9087 }
9088
9089 if (start === undefined) {
9090 start = 0
9091 }
9092 if (end === undefined) {
9093 end = target ? target.length : 0
9094 }
9095 if (thisStart === undefined) {
9096 thisStart = 0
9097 }
9098 if (thisEnd === undefined) {
9099 thisEnd = this.length
9100 }
9101
9102 if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
9103 throw new RangeError('out of range index')
9104 }
9105
9106 if (thisStart >= thisEnd && start >= end) {
9107 return 0
9108 }
9109 if (thisStart >= thisEnd) {
9110 return -1
9111 }
9112 if (start >= end) {
9113 return 1
9114 }
9115
9116 start >>>= 0
9117 end >>>= 0
9118 thisStart >>>= 0
9119 thisEnd >>>= 0
9120
9121 if (this === target) return 0
9122
9123 var x = thisEnd - thisStart
9124 var y = end - start
9125 var len = Math.min(x, y)
9126
9127 var thisCopy = this.slice(thisStart, thisEnd)
9128 var targetCopy = target.slice(start, end)
9129
9130 for (var i = 0; i < len; ++i) {
9131 if (thisCopy[i] !== targetCopy[i]) {
9132 x = thisCopy[i]
9133 y = targetCopy[i]
9134 break
9135 }
9136 }
9137
9138 if (x < y) return -1
9139 if (y < x) return 1
9140 return 0
9141}
9142
9143function arrayIndexOf (arr, val, byteOffset, encoding) {
9144 var indexSize = 1
9145 var arrLength = arr.length
9146 var valLength = val.length
9147
9148 if (encoding !== undefined) {
9149 encoding = String(encoding).toLowerCase()
9150 if (encoding === 'ucs2' || encoding === 'ucs-2' ||
9151 encoding === 'utf16le' || encoding === 'utf-16le') {
9152 if (arr.length < 2 || val.length < 2) {
9153 return -1
9154 }
9155 indexSize = 2
9156 arrLength /= 2
9157 valLength /= 2
9158 byteOffset /= 2
9159 }
9160 }
9161
9162 function read (buf, i) {
9163 if (indexSize === 1) {
9164 return buf[i]
9165 } else {
9166 return buf.readUInt16BE(i * indexSize)
9167 }
9168 }
9169
9170 var foundIndex = -1
9171 for (var i = 0; byteOffset + i < arrLength; i++) {
9172 if (read(arr, byteOffset + i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
9173 if (foundIndex === -1) foundIndex = i
9174 if (i - foundIndex + 1 === valLength) return (byteOffset + foundIndex) * indexSize
9175 } else {
9176 if (foundIndex !== -1) i -= i - foundIndex
9177 foundIndex = -1
9178 }
9179 }
9180 return -1
9181}
9182
9183Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
9184 if (typeof byteOffset === 'string') {
9185 encoding = byteOffset
9186 byteOffset = 0
9187 } else if (byteOffset > 0x7fffffff) {
9188 byteOffset = 0x7fffffff
9189 } else if (byteOffset < -0x80000000) {
9190 byteOffset = -0x80000000
9191 }
9192 byteOffset >>= 0
9193
9194 if (this.length === 0) return -1
9195 if (byteOffset >= this.length) return -1
9196
9197 // Negative offsets start from the end of the buffer
9198 if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0)
9199
9200 if (typeof val === 'string') {
9201 val = Buffer.from(val, encoding)
9202 }
9203
9204 if (Buffer.isBuffer(val)) {
9205 // special case: looking for empty string/buffer always fails
9206 if (val.length === 0) {
9207 return -1
9208 }
9209 return arrayIndexOf(this, val, byteOffset, encoding)
9210 }
9211 if (typeof val === 'number') {
9212 if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') {
9213 return Uint8Array.prototype.indexOf.call(this, val, byteOffset)
9214 }
9215 return arrayIndexOf(this, [ val ], byteOffset, encoding)
9216 }
9217
9218 throw new TypeError('val must be string, number or Buffer')
9219}
9220
9221Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
9222 return this.indexOf(val, byteOffset, encoding) !== -1
9223}
9224
9225function hexWrite (buf, string, offset, length) {
9226 offset = Number(offset) || 0
9227 var remaining = buf.length - offset
9228 if (!length) {
9229 length = remaining
9230 } else {
9231 length = Number(length)
9232 if (length > remaining) {
9233 length = remaining
9234 }
9235 }
9236
9237 // must be an even number of digits
9238 var strLen = string.length
9239 if (strLen % 2 !== 0) throw new Error('Invalid hex string')
9240
9241 if (length > strLen / 2) {
9242 length = strLen / 2
9243 }
9244 for (var i = 0; i < length; i++) {
9245 var parsed = parseInt(string.substr(i * 2, 2), 16)
9246 if (isNaN(parsed)) return i
9247 buf[offset + i] = parsed
9248 }
9249 return i
9250}
9251
9252function utf8Write (buf, string, offset, length) {
9253 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
9254}
9255
9256function asciiWrite (buf, string, offset, length) {
9257 return blitBuffer(asciiToBytes(string), buf, offset, length)
9258}
9259
9260function binaryWrite (buf, string, offset, length) {
9261 return asciiWrite(buf, string, offset, length)
9262}
9263
9264function base64Write (buf, string, offset, length) {
9265 return blitBuffer(base64ToBytes(string), buf, offset, length)
9266}
9267
9268function ucs2Write (buf, string, offset, length) {
9269 return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
9270}
9271
9272Buffer.prototype.write = function write (string, offset, length, encoding) {
9273 // Buffer#write(string)
9274 if (offset === undefined) {
9275 encoding = 'utf8'
9276 length = this.length
9277 offset = 0
9278 // Buffer#write(string, encoding)
9279 } else if (length === undefined && typeof offset === 'string') {
9280 encoding = offset
9281 length = this.length
9282 offset = 0
9283 // Buffer#write(string, offset[, length][, encoding])
9284 } else if (isFinite(offset)) {
9285 offset = offset | 0
9286 if (isFinite(length)) {
9287 length = length | 0
9288 if (encoding === undefined) encoding = 'utf8'
9289 } else {
9290 encoding = length
9291 length = undefined
9292 }
9293 // legacy write(string, encoding, offset, length) - remove in v0.13
9294 } else {
9295 throw new Error(
9296 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
9297 )
9298 }
9299
9300 var remaining = this.length - offset
9301 if (length === undefined || length > remaining) length = remaining
9302
9303 if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
9304 throw new RangeError('Attempt to write outside buffer bounds')
9305 }
9306
9307 if (!encoding) encoding = 'utf8'
9308
9309 var loweredCase = false
9310 for (;;) {
9311 switch (encoding) {
9312 case 'hex':
9313 return hexWrite(this, string, offset, length)
9314
9315 case 'utf8':
9316 case 'utf-8':
9317 return utf8Write(this, string, offset, length)
9318
9319 case 'ascii':
9320 return asciiWrite(this, string, offset, length)
9321
9322 case 'binary':
9323 return binaryWrite(this, string, offset, length)
9324
9325 case 'base64':
9326 // Warning: maxLength not taken into account in base64Write
9327 return base64Write(this, string, offset, length)
9328
9329 case 'ucs2':
9330 case 'ucs-2':
9331 case 'utf16le':
9332 case 'utf-16le':
9333 return ucs2Write(this, string, offset, length)
9334
9335 default:
9336 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
9337 encoding = ('' + encoding).toLowerCase()
9338 loweredCase = true
9339 }
9340 }
9341}
9342
9343Buffer.prototype.toJSON = function toJSON () {
9344 return {
9345 type: 'Buffer',
9346 data: Array.prototype.slice.call(this._arr || this, 0)
9347 }
9348}
9349
9350function base64Slice (buf, start, end) {
9351 if (start === 0 && end === buf.length) {
9352 return base64.fromByteArray(buf)
9353 } else {
9354 return base64.fromByteArray(buf.slice(start, end))
9355 }
9356}
9357
9358function utf8Slice (buf, start, end) {
9359 end = Math.min(buf.length, end)
9360 var res = []
9361
9362 var i = start
9363 while (i < end) {
9364 var firstByte = buf[i]
9365 var codePoint = null
9366 var bytesPerSequence = (firstByte > 0xEF) ? 4
9367 : (firstByte > 0xDF) ? 3
9368 : (firstByte > 0xBF) ? 2
9369 : 1
9370
9371 if (i + bytesPerSequence <= end) {
9372 var secondByte, thirdByte, fourthByte, tempCodePoint
9373
9374 switch (bytesPerSequence) {
9375 case 1:
9376 if (firstByte < 0x80) {
9377 codePoint = firstByte
9378 }
9379 break
9380 case 2:
9381 secondByte = buf[i + 1]
9382 if ((secondByte & 0xC0) === 0x80) {
9383 tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
9384 if (tempCodePoint > 0x7F) {
9385 codePoint = tempCodePoint
9386 }
9387 }
9388 break
9389 case 3:
9390 secondByte = buf[i + 1]
9391 thirdByte = buf[i + 2]
9392 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
9393 tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
9394 if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
9395 codePoint = tempCodePoint
9396 }
9397 }
9398 break
9399 case 4:
9400 secondByte = buf[i + 1]
9401 thirdByte = buf[i + 2]
9402 fourthByte = buf[i + 3]
9403 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
9404 tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
9405 if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
9406 codePoint = tempCodePoint
9407 }
9408 }
9409 }
9410 }
9411
9412 if (codePoint === null) {
9413 // we did not generate a valid codePoint so insert a
9414 // replacement char (U+FFFD) and advance only 1 byte
9415 codePoint = 0xFFFD
9416 bytesPerSequence = 1
9417 } else if (codePoint > 0xFFFF) {
9418 // encode to utf16 (surrogate pair dance)
9419 codePoint -= 0x10000
9420 res.push(codePoint >>> 10 & 0x3FF | 0xD800)
9421 codePoint = 0xDC00 | codePoint & 0x3FF
9422 }
9423
9424 res.push(codePoint)
9425 i += bytesPerSequence
9426 }
9427
9428 return decodeCodePointsArray(res)
9429}
9430
9431// Based on http://stackoverflow.com/a/22747272/680742, the browser with
9432// the lowest limit is Chrome, with 0x10000 args.
9433// We go 1 magnitude less, for safety
9434var MAX_ARGUMENTS_LENGTH = 0x1000
9435
9436function decodeCodePointsArray (codePoints) {
9437 var len = codePoints.length
9438 if (len <= MAX_ARGUMENTS_LENGTH) {
9439 return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
9440 }
9441
9442 // Decode in chunks to avoid "call stack size exceeded".
9443 var res = ''
9444 var i = 0
9445 while (i < len) {
9446 res += String.fromCharCode.apply(
9447 String,
9448 codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
9449 )
9450 }
9451 return res
9452}
9453
9454function asciiSlice (buf, start, end) {
9455 var ret = ''
9456 end = Math.min(buf.length, end)
9457
9458 for (var i = start; i < end; i++) {
9459 ret += String.fromCharCode(buf[i] & 0x7F)
9460 }
9461 return ret
9462}
9463
9464function binarySlice (buf, start, end) {
9465 var ret = ''
9466 end = Math.min(buf.length, end)
9467
9468 for (var i = start; i < end; i++) {
9469 ret += String.fromCharCode(buf[i])
9470 }
9471 return ret
9472}
9473
9474function hexSlice (buf, start, end) {
9475 var len = buf.length
9476
9477 if (!start || start < 0) start = 0
9478 if (!end || end < 0 || end > len) end = len
9479
9480 var out = ''
9481 for (var i = start; i < end; i++) {
9482 out += toHex(buf[i])
9483 }
9484 return out
9485}
9486
9487function utf16leSlice (buf, start, end) {
9488 var bytes = buf.slice(start, end)
9489 var res = ''
9490 for (var i = 0; i < bytes.length; i += 2) {
9491 res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
9492 }
9493 return res
9494}
9495
9496Buffer.prototype.slice = function slice (start, end) {
9497 var len = this.length
9498 start = ~~start
9499 end = end === undefined ? len : ~~end
9500
9501 if (start < 0) {
9502 start += len
9503 if (start < 0) start = 0
9504 } else if (start > len) {
9505 start = len
9506 }
9507
9508 if (end < 0) {
9509 end += len
9510 if (end < 0) end = 0
9511 } else if (end > len) {
9512 end = len
9513 }
9514
9515 if (end < start) end = start
9516
9517 var newBuf
9518 if (Buffer.TYPED_ARRAY_SUPPORT) {
9519 newBuf = this.subarray(start, end)
9520 newBuf.__proto__ = Buffer.prototype
9521 } else {
9522 var sliceLen = end - start
9523 newBuf = new Buffer(sliceLen, undefined)
9524 for (var i = 0; i < sliceLen; i++) {
9525 newBuf[i] = this[i + start]
9526 }
9527 }
9528
9529 return newBuf
9530}
9531
9532/*
9533 * Need to make sure that buffer isn't trying to write out of bounds.
9534 */
9535function checkOffset (offset, ext, length) {
9536 if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
9537 if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
9538}
9539
9540Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
9541 offset = offset | 0
9542 byteLength = byteLength | 0
9543 if (!noAssert) checkOffset(offset, byteLength, this.length)
9544
9545 var val = this[offset]
9546 var mul = 1
9547 var i = 0
9548 while (++i < byteLength && (mul *= 0x100)) {
9549 val += this[offset + i] * mul
9550 }
9551
9552 return val
9553}
9554
9555Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
9556 offset = offset | 0
9557 byteLength = byteLength | 0
9558 if (!noAssert) {
9559 checkOffset(offset, byteLength, this.length)
9560 }
9561
9562 var val = this[offset + --byteLength]
9563 var mul = 1
9564 while (byteLength > 0 && (mul *= 0x100)) {
9565 val += this[offset + --byteLength] * mul
9566 }
9567
9568 return val
9569}
9570
9571Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
9572 if (!noAssert) checkOffset(offset, 1, this.length)
9573 return this[offset]
9574}
9575
9576Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
9577 if (!noAssert) checkOffset(offset, 2, this.length)
9578 return this[offset] | (this[offset + 1] << 8)
9579}
9580
9581Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
9582 if (!noAssert) checkOffset(offset, 2, this.length)
9583 return (this[offset] << 8) | this[offset + 1]
9584}
9585
9586Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
9587 if (!noAssert) checkOffset(offset, 4, this.length)
9588
9589 return ((this[offset]) |
9590 (this[offset + 1] << 8) |
9591 (this[offset + 2] << 16)) +
9592 (this[offset + 3] * 0x1000000)
9593}
9594
9595Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
9596 if (!noAssert) checkOffset(offset, 4, this.length)
9597
9598 return (this[offset] * 0x1000000) +
9599 ((this[offset + 1] << 16) |
9600 (this[offset + 2] << 8) |
9601 this[offset + 3])
9602}
9603
9604Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
9605 offset = offset | 0
9606 byteLength = byteLength | 0
9607 if (!noAssert) checkOffset(offset, byteLength, this.length)
9608
9609 var val = this[offset]
9610 var mul = 1
9611 var i = 0
9612 while (++i < byteLength && (mul *= 0x100)) {
9613 val += this[offset + i] * mul
9614 }
9615 mul *= 0x80
9616
9617 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
9618
9619 return val
9620}
9621
9622Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
9623 offset = offset | 0
9624 byteLength = byteLength | 0
9625 if (!noAssert) checkOffset(offset, byteLength, this.length)
9626
9627 var i = byteLength
9628 var mul = 1
9629 var val = this[offset + --i]
9630 while (i > 0 && (mul *= 0x100)) {
9631 val += this[offset + --i] * mul
9632 }
9633 mul *= 0x80
9634
9635 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
9636
9637 return val
9638}
9639
9640Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
9641 if (!noAssert) checkOffset(offset, 1, this.length)
9642 if (!(this[offset] & 0x80)) return (this[offset])
9643 return ((0xff - this[offset] + 1) * -1)
9644}
9645
9646Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
9647 if (!noAssert) checkOffset(offset, 2, this.length)
9648 var val = this[offset] | (this[offset + 1] << 8)
9649 return (val & 0x8000) ? val | 0xFFFF0000 : val
9650}
9651
9652Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
9653 if (!noAssert) checkOffset(offset, 2, this.length)
9654 var val = this[offset + 1] | (this[offset] << 8)
9655 return (val & 0x8000) ? val | 0xFFFF0000 : val
9656}
9657
9658Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
9659 if (!noAssert) checkOffset(offset, 4, this.length)
9660
9661 return (this[offset]) |
9662 (this[offset + 1] << 8) |
9663 (this[offset + 2] << 16) |
9664 (this[offset + 3] << 24)
9665}
9666
9667Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
9668 if (!noAssert) checkOffset(offset, 4, this.length)
9669
9670 return (this[offset] << 24) |
9671 (this[offset + 1] << 16) |
9672 (this[offset + 2] << 8) |
9673 (this[offset + 3])
9674}
9675
9676Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
9677 if (!noAssert) checkOffset(offset, 4, this.length)
9678 return ieee754.read(this, offset, true, 23, 4)
9679}
9680
9681Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
9682 if (!noAssert) checkOffset(offset, 4, this.length)
9683 return ieee754.read(this, offset, false, 23, 4)
9684}
9685
9686Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
9687 if (!noAssert) checkOffset(offset, 8, this.length)
9688 return ieee754.read(this, offset, true, 52, 8)
9689}
9690
9691Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
9692 if (!noAssert) checkOffset(offset, 8, this.length)
9693 return ieee754.read(this, offset, false, 52, 8)
9694}
9695
9696function checkInt (buf, value, offset, ext, max, min) {
9697 if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
9698 if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
9699 if (offset + ext > buf.length) throw new RangeError('Index out of range')
9700}
9701
9702Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
9703 value = +value
9704 offset = offset | 0
9705 byteLength = byteLength | 0
9706 if (!noAssert) {
9707 var maxBytes = Math.pow(2, 8 * byteLength) - 1
9708 checkInt(this, value, offset, byteLength, maxBytes, 0)
9709 }
9710
9711 var mul = 1
9712 var i = 0
9713 this[offset] = value & 0xFF
9714 while (++i < byteLength && (mul *= 0x100)) {
9715 this[offset + i] = (value / mul) & 0xFF
9716 }
9717
9718 return offset + byteLength
9719}
9720
9721Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
9722 value = +value
9723 offset = offset | 0
9724 byteLength = byteLength | 0
9725 if (!noAssert) {
9726 var maxBytes = Math.pow(2, 8 * byteLength) - 1
9727 checkInt(this, value, offset, byteLength, maxBytes, 0)
9728 }
9729
9730 var i = byteLength - 1
9731 var mul = 1
9732 this[offset + i] = value & 0xFF
9733 while (--i >= 0 && (mul *= 0x100)) {
9734 this[offset + i] = (value / mul) & 0xFF
9735 }
9736
9737 return offset + byteLength
9738}
9739
9740Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
9741 value = +value
9742 offset = offset | 0
9743 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
9744 if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
9745 this[offset] = (value & 0xff)
9746 return offset + 1
9747}
9748
9749function objectWriteUInt16 (buf, value, offset, littleEndian) {
9750 if (value < 0) value = 0xffff + value + 1
9751 for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) {
9752 buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
9753 (littleEndian ? i : 1 - i) * 8
9754 }
9755}
9756
9757Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
9758 value = +value
9759 offset = offset | 0
9760 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
9761 if (Buffer.TYPED_ARRAY_SUPPORT) {
9762 this[offset] = (value & 0xff)
9763 this[offset + 1] = (value >>> 8)
9764 } else {
9765 objectWriteUInt16(this, value, offset, true)
9766 }
9767 return offset + 2
9768}
9769
9770Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
9771 value = +value
9772 offset = offset | 0
9773 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
9774 if (Buffer.TYPED_ARRAY_SUPPORT) {
9775 this[offset] = (value >>> 8)
9776 this[offset + 1] = (value & 0xff)
9777 } else {
9778 objectWriteUInt16(this, value, offset, false)
9779 }
9780 return offset + 2
9781}
9782
9783function objectWriteUInt32 (buf, value, offset, littleEndian) {
9784 if (value < 0) value = 0xffffffff + value + 1
9785 for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) {
9786 buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
9787 }
9788}
9789
9790Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
9791 value = +value
9792 offset = offset | 0
9793 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
9794 if (Buffer.TYPED_ARRAY_SUPPORT) {
9795 this[offset + 3] = (value >>> 24)
9796 this[offset + 2] = (value >>> 16)
9797 this[offset + 1] = (value >>> 8)
9798 this[offset] = (value & 0xff)
9799 } else {
9800 objectWriteUInt32(this, value, offset, true)
9801 }
9802 return offset + 4
9803}
9804
9805Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
9806 value = +value
9807 offset = offset | 0
9808 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
9809 if (Buffer.TYPED_ARRAY_SUPPORT) {
9810 this[offset] = (value >>> 24)
9811 this[offset + 1] = (value >>> 16)
9812 this[offset + 2] = (value >>> 8)
9813 this[offset + 3] = (value & 0xff)
9814 } else {
9815 objectWriteUInt32(this, value, offset, false)
9816 }
9817 return offset + 4
9818}
9819
9820Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
9821 value = +value
9822 offset = offset | 0
9823 if (!noAssert) {
9824 var limit = Math.pow(2, 8 * byteLength - 1)
9825
9826 checkInt(this, value, offset, byteLength, limit - 1, -limit)
9827 }
9828
9829 var i = 0
9830 var mul = 1
9831 var sub = 0
9832 this[offset] = value & 0xFF
9833 while (++i < byteLength && (mul *= 0x100)) {
9834 if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
9835 sub = 1
9836 }
9837 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
9838 }
9839
9840 return offset + byteLength
9841}
9842
9843Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
9844 value = +value
9845 offset = offset | 0
9846 if (!noAssert) {
9847 var limit = Math.pow(2, 8 * byteLength - 1)
9848
9849 checkInt(this, value, offset, byteLength, limit - 1, -limit)
9850 }
9851
9852 var i = byteLength - 1
9853 var mul = 1
9854 var sub = 0
9855 this[offset + i] = value & 0xFF
9856 while (--i >= 0 && (mul *= 0x100)) {
9857 if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
9858 sub = 1
9859 }
9860 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
9861 }
9862
9863 return offset + byteLength
9864}
9865
9866Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
9867 value = +value
9868 offset = offset | 0
9869 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
9870 if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
9871 if (value < 0) value = 0xff + value + 1
9872 this[offset] = (value & 0xff)
9873 return offset + 1
9874}
9875
9876Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
9877 value = +value
9878 offset = offset | 0
9879 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
9880 if (Buffer.TYPED_ARRAY_SUPPORT) {
9881 this[offset] = (value & 0xff)
9882 this[offset + 1] = (value >>> 8)
9883 } else {
9884 objectWriteUInt16(this, value, offset, true)
9885 }
9886 return offset + 2
9887}
9888
9889Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
9890 value = +value
9891 offset = offset | 0
9892 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
9893 if (Buffer.TYPED_ARRAY_SUPPORT) {
9894 this[offset] = (value >>> 8)
9895 this[offset + 1] = (value & 0xff)
9896 } else {
9897 objectWriteUInt16(this, value, offset, false)
9898 }
9899 return offset + 2
9900}
9901
9902Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
9903 value = +value
9904 offset = offset | 0
9905 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
9906 if (Buffer.TYPED_ARRAY_SUPPORT) {
9907 this[offset] = (value & 0xff)
9908 this[offset + 1] = (value >>> 8)
9909 this[offset + 2] = (value >>> 16)
9910 this[offset + 3] = (value >>> 24)
9911 } else {
9912 objectWriteUInt32(this, value, offset, true)
9913 }
9914 return offset + 4
9915}
9916
9917Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
9918 value = +value
9919 offset = offset | 0
9920 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
9921 if (value < 0) value = 0xffffffff + value + 1
9922 if (Buffer.TYPED_ARRAY_SUPPORT) {
9923 this[offset] = (value >>> 24)
9924 this[offset + 1] = (value >>> 16)
9925 this[offset + 2] = (value >>> 8)
9926 this[offset + 3] = (value & 0xff)
9927 } else {
9928 objectWriteUInt32(this, value, offset, false)
9929 }
9930 return offset + 4
9931}
9932
9933function checkIEEE754 (buf, value, offset, ext, max, min) {
9934 if (offset + ext > buf.length) throw new RangeError('Index out of range')
9935 if (offset < 0) throw new RangeError('Index out of range')
9936}
9937
9938function writeFloat (buf, value, offset, littleEndian, noAssert) {
9939 if (!noAssert) {
9940 checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
9941 }
9942 ieee754.write(buf, value, offset, littleEndian, 23, 4)
9943 return offset + 4
9944}
9945
9946Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
9947 return writeFloat(this, value, offset, true, noAssert)
9948}
9949
9950Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
9951 return writeFloat(this, value, offset, false, noAssert)
9952}
9953
9954function writeDouble (buf, value, offset, littleEndian, noAssert) {
9955 if (!noAssert) {
9956 checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
9957 }
9958 ieee754.write(buf, value, offset, littleEndian, 52, 8)
9959 return offset + 8
9960}
9961
9962Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
9963 return writeDouble(this, value, offset, true, noAssert)
9964}
9965
9966Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
9967 return writeDouble(this, value, offset, false, noAssert)
9968}
9969
9970// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
9971Buffer.prototype.copy = function copy (target, targetStart, start, end) {
9972 if (!start) start = 0
9973 if (!end && end !== 0) end = this.length
9974 if (targetStart >= target.length) targetStart = target.length
9975 if (!targetStart) targetStart = 0
9976 if (end > 0 && end < start) end = start
9977
9978 // Copy 0 bytes; we're done
9979 if (end === start) return 0
9980 if (target.length === 0 || this.length === 0) return 0
9981
9982 // Fatal error conditions
9983 if (targetStart < 0) {
9984 throw new RangeError('targetStart out of bounds')
9985 }
9986 if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
9987 if (end < 0) throw new RangeError('sourceEnd out of bounds')
9988
9989 // Are we oob?
9990 if (end > this.length) end = this.length
9991 if (target.length - targetStart < end - start) {
9992 end = target.length - targetStart + start
9993 }
9994
9995 var len = end - start
9996 var i
9997
9998 if (this === target && start < targetStart && targetStart < end) {
9999 // descending copy from end
10000 for (i = len - 1; i >= 0; i--) {
10001 target[i + targetStart] = this[i + start]
10002 }
10003 } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
10004 // ascending copy from start
10005 for (i = 0; i < len; i++) {
10006 target[i + targetStart] = this[i + start]
10007 }
10008 } else {
10009 Uint8Array.prototype.set.call(
10010 target,
10011 this.subarray(start, start + len),
10012 targetStart
10013 )
10014 }
10015
10016 return len
10017}
10018
10019// Usage:
10020// buffer.fill(number[, offset[, end]])
10021// buffer.fill(buffer[, offset[, end]])
10022// buffer.fill(string[, offset[, end]][, encoding])
10023Buffer.prototype.fill = function fill (val, start, end, encoding) {
10024 // Handle string cases:
10025 if (typeof val === 'string') {
10026 if (typeof start === 'string') {
10027 encoding = start
10028 start = 0
10029 end = this.length
10030 } else if (typeof end === 'string') {
10031 encoding = end
10032 end = this.length
10033 }
10034 if (val.length === 1) {
10035 var code = val.charCodeAt(0)
10036 if (code < 256) {
10037 val = code
10038 }
10039 }
10040 if (encoding !== undefined && typeof encoding !== 'string') {
10041 throw new TypeError('encoding must be a string')
10042 }
10043 if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
10044 throw new TypeError('Unknown encoding: ' + encoding)
10045 }
10046 } else if (typeof val === 'number') {
10047 val = val & 255
10048 }
10049
10050 // Invalid ranges are not set to a default, so can range check early.
10051 if (start < 0 || this.length < start || this.length < end) {
10052 throw new RangeError('Out of range index')
10053 }
10054
10055 if (end <= start) {
10056 return this
10057 }
10058
10059 start = start >>> 0
10060 end = end === undefined ? this.length : end >>> 0
10061
10062 if (!val) val = 0
10063
10064 var i
10065 if (typeof val === 'number') {
10066 for (i = start; i < end; i++) {
10067 this[i] = val
10068 }
10069 } else {
10070 var bytes = Buffer.isBuffer(val)
10071 ? val
10072 : utf8ToBytes(new Buffer(val, encoding).toString())
10073 var len = bytes.length
10074 for (i = 0; i < end - start; i++) {
10075 this[i + start] = bytes[i % len]
10076 }
10077 }
10078
10079 return this
10080}
10081
10082// HELPER FUNCTIONS
10083// ================
10084
10085var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
10086
10087function base64clean (str) {
10088 // Node strips out invalid characters like \n and \t from the string, base64-js does not
10089 str = stringtrim(str).replace(INVALID_BASE64_RE, '')
10090 // Node converts strings with length < 2 to ''
10091 if (str.length < 2) return ''
10092 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
10093 while (str.length % 4 !== 0) {
10094 str = str + '='
10095 }
10096 return str
10097}
10098
10099function stringtrim (str) {
10100 if (str.trim) return str.trim()
10101 return str.replace(/^\s+|\s+$/g, '')
10102}
10103
10104function toHex (n) {
10105 if (n < 16) return '0' + n.toString(16)
10106 return n.toString(16)
10107}
10108
10109function utf8ToBytes (string, units) {
10110 units = units || Infinity
10111 var codePoint
10112 var length = string.length
10113 var leadSurrogate = null
10114 var bytes = []
10115
10116 for (var i = 0; i < length; i++) {
10117 codePoint = string.charCodeAt(i)
10118
10119 // is surrogate component
10120 if (codePoint > 0xD7FF && codePoint < 0xE000) {
10121 // last char was a lead
10122 if (!leadSurrogate) {
10123 // no lead yet
10124 if (codePoint > 0xDBFF) {
10125 // unexpected trail
10126 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
10127 continue
10128 } else if (i + 1 === length) {
10129 // unpaired lead
10130 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
10131 continue
10132 }
10133
10134 // valid lead
10135 leadSurrogate = codePoint
10136
10137 continue
10138 }
10139
10140 // 2 leads in a row
10141 if (codePoint < 0xDC00) {
10142 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
10143 leadSurrogate = codePoint
10144 continue
10145 }
10146
10147 // valid surrogate pair
10148 codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
10149 } else if (leadSurrogate) {
10150 // valid bmp char, but last char was a lead
10151 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
10152 }
10153
10154 leadSurrogate = null
10155
10156 // encode utf8
10157 if (codePoint < 0x80) {
10158 if ((units -= 1) < 0) break
10159 bytes.push(codePoint)
10160 } else if (codePoint < 0x800) {
10161 if ((units -= 2) < 0) break
10162 bytes.push(
10163 codePoint >> 0x6 | 0xC0,
10164 codePoint & 0x3F | 0x80
10165 )
10166 } else if (codePoint < 0x10000) {
10167 if ((units -= 3) < 0) break
10168 bytes.push(
10169 codePoint >> 0xC | 0xE0,
10170 codePoint >> 0x6 & 0x3F | 0x80,
10171 codePoint & 0x3F | 0x80
10172 )
10173 } else if (codePoint < 0x110000) {
10174 if ((units -= 4) < 0) break
10175 bytes.push(
10176 codePoint >> 0x12 | 0xF0,
10177 codePoint >> 0xC & 0x3F | 0x80,
10178 codePoint >> 0x6 & 0x3F | 0x80,
10179 codePoint & 0x3F | 0x80
10180 )
10181 } else {
10182 throw new Error('Invalid code point')
10183 }
10184 }
10185
10186 return bytes
10187}
10188
10189function asciiToBytes (str) {
10190 var byteArray = []
10191 for (var i = 0; i < str.length; i++) {
10192 // Node's code seems to be doing this and not & 0x7F..
10193 byteArray.push(str.charCodeAt(i) & 0xFF)
10194 }
10195 return byteArray
10196}
10197
10198function utf16leToBytes (str, units) {
10199 var c, hi, lo
10200 var byteArray = []
10201 for (var i = 0; i < str.length; i++) {
10202 if ((units -= 2) < 0) break
10203
10204 c = str.charCodeAt(i)
10205 hi = c >> 8
10206 lo = c % 256
10207 byteArray.push(lo)
10208 byteArray.push(hi)
10209 }
10210
10211 return byteArray
10212}
10213
10214function base64ToBytes (str) {
10215 return base64.toByteArray(base64clean(str))
10216}
10217
10218function blitBuffer (src, dst, offset, length) {
10219 for (var i = 0; i < length; i++) {
10220 if ((i + offset >= dst.length) || (i >= src.length)) break
10221 dst[i + offset] = src[i]
10222 }
10223 return i
10224}
10225
10226function isnan (val) {
10227 return val !== val // eslint-disable-line no-self-compare
10228}
10229
10230}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
10231
10232},{"base64-js":61,"ieee754":64,"isarray":65}],64:[function(require,module,exports){
10233exports.read = function (buffer, offset, isLE, mLen, nBytes) {
10234 var e, m
10235 var eLen = nBytes * 8 - mLen - 1
10236 var eMax = (1 << eLen) - 1
10237 var eBias = eMax >> 1
10238 var nBits = -7
10239 var i = isLE ? (nBytes - 1) : 0
10240 var d = isLE ? -1 : 1
10241 var s = buffer[offset + i]
10242
10243 i += d
10244
10245 e = s & ((1 << (-nBits)) - 1)
10246 s >>= (-nBits)
10247 nBits += eLen
10248 for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
10249
10250 m = e & ((1 << (-nBits)) - 1)
10251 e >>= (-nBits)
10252 nBits += mLen
10253 for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
10254
10255 if (e === 0) {
10256 e = 1 - eBias
10257 } else if (e === eMax) {
10258 return m ? NaN : ((s ? -1 : 1) * Infinity)
10259 } else {
10260 m = m + Math.pow(2, mLen)
10261 e = e - eBias
10262 }
10263 return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
10264}
10265
10266exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
10267 var e, m, c
10268 var eLen = nBytes * 8 - mLen - 1
10269 var eMax = (1 << eLen) - 1
10270 var eBias = eMax >> 1
10271 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
10272 var i = isLE ? 0 : (nBytes - 1)
10273 var d = isLE ? 1 : -1
10274 var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
10275
10276 value = Math.abs(value)
10277
10278 if (isNaN(value) || value === Infinity) {
10279 m = isNaN(value) ? 1 : 0
10280 e = eMax
10281 } else {
10282 e = Math.floor(Math.log(value) / Math.LN2)
10283 if (value * (c = Math.pow(2, -e)) < 1) {
10284 e--
10285 c *= 2
10286 }
10287 if (e + eBias >= 1) {
10288 value += rt / c
10289 } else {
10290 value += rt * Math.pow(2, 1 - eBias)
10291 }
10292 if (value * c >= 2) {
10293 e++
10294 c /= 2
10295 }
10296
10297 if (e + eBias >= eMax) {
10298 m = 0
10299 e = eMax
10300 } else if (e + eBias >= 1) {
10301 m = (value * c - 1) * Math.pow(2, mLen)
10302 e = e + eBias
10303 } else {
10304 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
10305 e = 0
10306 }
10307 }
10308
10309 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
10310
10311 e = (e << mLen) | m
10312 eLen += mLen
10313 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
10314
10315 buffer[offset + i - d] |= s * 128
10316}
10317
10318},{}],65:[function(require,module,exports){
10319var toString = {}.toString;
10320
10321module.exports = Array.isArray || function (arr) {
10322 return toString.call(arr) == '[object Array]';
10323};
10324
10325},{}],66:[function(require,module,exports){
10326(function (process){
10327// Copyright Joyent, Inc. and other Node contributors.
10328//
10329// Permission is hereby granted, free of charge, to any person obtaining a
10330// copy of this software and associated documentation files (the
10331// "Software"), to deal in the Software without restriction, including
10332// without limitation the rights to use, copy, modify, merge, publish,
10333// distribute, sublicense, and/or sell copies of the Software, and to permit
10334// persons to whom the Software is furnished to do so, subject to the
10335// following conditions:
10336//
10337// The above copyright notice and this permission notice shall be included
10338// in all copies or substantial portions of the Software.
10339//
10340// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
10341// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10342// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
10343// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
10344// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
10345// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
10346// USE OR OTHER DEALINGS IN THE SOFTWARE.
10347
10348// resolves . and .. elements in a path array with directory names there
10349// must be no slashes, empty elements, or device names (c:\) in the array
10350// (so also no leading and trailing slashes - it does not distinguish
10351// relative and absolute paths)
10352function normalizeArray(parts, allowAboveRoot) {
10353 // if the path tries to go above the root, `up` ends up > 0
10354 var up = 0;
10355 for (var i = parts.length - 1; i >= 0; i--) {
10356 var last = parts[i];
10357 if (last === '.') {
10358 parts.splice(i, 1);
10359 } else if (last === '..') {
10360 parts.splice(i, 1);
10361 up++;
10362 } else if (up) {
10363 parts.splice(i, 1);
10364 up--;
10365 }
10366 }
10367
10368 // if the path is allowed to go above the root, restore leading ..s
10369 if (allowAboveRoot) {
10370 for (; up--; up) {
10371 parts.unshift('..');
10372 }
10373 }
10374
10375 return parts;
10376}
10377
10378// Split a filename into [root, dir, basename, ext], unix version
10379// 'root' is just a slash, or nothing.
10380var splitPathRe =
10381 /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
10382var splitPath = function(filename) {
10383 return splitPathRe.exec(filename).slice(1);
10384};
10385
10386// path.resolve([from ...], to)
10387// posix version
10388exports.resolve = function() {
10389 var resolvedPath = '',
10390 resolvedAbsolute = false;
10391
10392 for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
10393 var path = (i >= 0) ? arguments[i] : process.cwd();
10394
10395 // Skip empty and invalid entries
10396 if (typeof path !== 'string') {
10397 throw new TypeError('Arguments to path.resolve must be strings');
10398 } else if (!path) {
10399 continue;
10400 }
10401
10402 resolvedPath = path + '/' + resolvedPath;
10403 resolvedAbsolute = path.charAt(0) === '/';
10404 }
10405
10406 // At this point the path should be resolved to a full absolute path, but
10407 // handle relative paths to be safe (might happen when process.cwd() fails)
10408
10409 // Normalize the path
10410 resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
10411 return !!p;
10412 }), !resolvedAbsolute).join('/');
10413
10414 return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
10415};
10416
10417// path.normalize(path)
10418// posix version
10419exports.normalize = function(path) {
10420 var isAbsolute = exports.isAbsolute(path),
10421 trailingSlash = substr(path, -1) === '/';
10422
10423 // Normalize the path
10424 path = normalizeArray(filter(path.split('/'), function(p) {
10425 return !!p;
10426 }), !isAbsolute).join('/');
10427
10428 if (!path && !isAbsolute) {
10429 path = '.';
10430 }
10431 if (path && trailingSlash) {
10432 path += '/';
10433 }
10434
10435 return (isAbsolute ? '/' : '') + path;
10436};
10437
10438// posix version
10439exports.isAbsolute = function(path) {
10440 return path.charAt(0) === '/';
10441};
10442
10443// posix version
10444exports.join = function() {
10445 var paths = Array.prototype.slice.call(arguments, 0);
10446 return exports.normalize(filter(paths, function(p, index) {
10447 if (typeof p !== 'string') {
10448 throw new TypeError('Arguments to path.join must be strings');
10449 }
10450 return p;
10451 }).join('/'));
10452};
10453
10454
10455// path.relative(from, to)
10456// posix version
10457exports.relative = function(from, to) {
10458 from = exports.resolve(from).substr(1);
10459 to = exports.resolve(to).substr(1);
10460
10461 function trim(arr) {
10462 var start = 0;
10463 for (; start < arr.length; start++) {
10464 if (arr[start] !== '') break;
10465 }
10466
10467 var end = arr.length - 1;
10468 for (; end >= 0; end--) {
10469 if (arr[end] !== '') break;
10470 }
10471
10472 if (start > end) return [];
10473 return arr.slice(start, end - start + 1);
10474 }
10475
10476 var fromParts = trim(from.split('/'));
10477 var toParts = trim(to.split('/'));
10478
10479 var length = Math.min(fromParts.length, toParts.length);
10480 var samePartsLength = length;
10481 for (var i = 0; i < length; i++) {
10482 if (fromParts[i] !== toParts[i]) {
10483 samePartsLength = i;
10484 break;
10485 }
10486 }
10487
10488 var outputParts = [];
10489 for (var i = samePartsLength; i < fromParts.length; i++) {
10490 outputParts.push('..');
10491 }
10492
10493 outputParts = outputParts.concat(toParts.slice(samePartsLength));
10494
10495 return outputParts.join('/');
10496};
10497
10498exports.sep = '/';
10499exports.delimiter = ':';
10500
10501exports.dirname = function(path) {
10502 var result = splitPath(path),
10503 root = result[0],
10504 dir = result[1];
10505
10506 if (!root && !dir) {
10507 // No dirname whatsoever
10508 return '.';
10509 }
10510
10511 if (dir) {
10512 // It has a dirname, strip trailing slash
10513 dir = dir.substr(0, dir.length - 1);
10514 }
10515
10516 return root + dir;
10517};
10518
10519
10520exports.basename = function(path, ext) {
10521 var f = splitPath(path)[2];
10522 // TODO: make this comparison case-insensitive on windows?
10523 if (ext && f.substr(-1 * ext.length) === ext) {
10524 f = f.substr(0, f.length - ext.length);
10525 }
10526 return f;
10527};
10528
10529
10530exports.extname = function(path) {
10531 return splitPath(path)[3];
10532};
10533
10534function filter (xs, f) {
10535 if (xs.filter) return xs.filter(f);
10536 var res = [];
10537 for (var i = 0; i < xs.length; i++) {
10538 if (f(xs[i], i, xs)) res.push(xs[i]);
10539 }
10540 return res;
10541}
10542
10543// String.prototype.substr - negative index don't work in IE8
10544var substr = 'ab'.substr(-1) === 'b'
10545 ? function (str, start, len) { return str.substr(start, len) }
10546 : function (str, start, len) {
10547 if (start < 0) start = str.length + start;
10548 return str.substr(start, len);
10549 }
10550;
10551
10552}).call(this,require('_process'))
10553
10554},{"_process":67}],67:[function(require,module,exports){
10555// shim for using process in browser
10556
10557var process = module.exports = {};
10558var queue = [];
10559var draining = false;
10560var currentQueue;
10561var queueIndex = -1;
10562
10563function cleanUpNextTick() {
10564 if (!draining || !currentQueue) {
10565 return;
10566 }
10567 draining = false;
10568 if (currentQueue.length) {
10569 queue = currentQueue.concat(queue);
10570 } else {
10571 queueIndex = -1;
10572 }
10573 if (queue.length) {
10574 drainQueue();
10575 }
10576}
10577
10578function drainQueue() {
10579 if (draining) {
10580 return;
10581 }
10582 var timeout = setTimeout(cleanUpNextTick);
10583 draining = true;
10584
10585 var len = queue.length;
10586 while(len) {
10587 currentQueue = queue;
10588 queue = [];
10589 while (++queueIndex < len) {
10590 if (currentQueue) {
10591 currentQueue[queueIndex].run();
10592 }
10593 }
10594 queueIndex = -1;
10595 len = queue.length;
10596 }
10597 currentQueue = null;
10598 draining = false;
10599 clearTimeout(timeout);
10600}
10601
10602process.nextTick = function (fun) {
10603 var args = new Array(arguments.length - 1);
10604 if (arguments.length > 1) {
10605 for (var i = 1; i < arguments.length; i++) {
10606 args[i - 1] = arguments[i];
10607 }
10608 }
10609 queue.push(new Item(fun, args));
10610 if (queue.length === 1 && !draining) {
10611 setTimeout(drainQueue, 0);
10612 }
10613};
10614
10615// v8 likes predictible objects
10616function Item(fun, array) {
10617 this.fun = fun;
10618 this.array = array;
10619}
10620Item.prototype.run = function () {
10621 this.fun.apply(null, this.array);
10622};
10623process.title = 'browser';
10624process.browser = true;
10625process.env = {};
10626process.argv = [];
10627process.version = ''; // empty string to avoid regexp issues
10628process.versions = {};
10629
10630function noop() {}
10631
10632process.on = noop;
10633process.addListener = noop;
10634process.once = noop;
10635process.off = noop;
10636process.removeListener = noop;
10637process.removeAllListeners = noop;
10638process.emit = noop;
10639
10640process.binding = function (name) {
10641 throw new Error('process.binding is not supported');
10642};
10643
10644process.cwd = function () { return '/' };
10645process.chdir = function (dir) {
10646 throw new Error('process.chdir is not supported');
10647};
10648process.umask = function() { return 0; };
10649
10650},{}]},{},[57,55,60])(60)
10651});
10652
10653
10654//# sourceMappingURL=test.js.map