UNPKG

react-as-suggest

Version:
1,487 lines (1,267 loc) 1.15 MB
/******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports, __webpack_require__) { module.exports = __webpack_require__(1); /***/ }, /* 1 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; __webpack_require__(2); var _index = __webpack_require__(31); var _index2 = _interopRequireDefault(_index); var _reactDom = __webpack_require__(192); var _reactDom2 = _interopRequireDefault(_reactDom); var _react = __webpack_require__(36); var _react2 = _interopRequireDefault(_react); var _jquery = __webpack_require__(198); var _jquery2 = _interopRequireDefault(_jquery); var _reactAddonsTestUtils = __webpack_require__(200); var _reactAddonsTestUtils2 = _interopRequireDefault(_reactAddonsTestUtils); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } mocha.ui('bdd'); describe('test', function () { var container = document.createElement('div'); document.body.appendChild(container); afterEach(function () { _reactDom2.default.unmountComponentAtNode(container); }); it('Should render', function () { var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { suggests: ['aaa', 'bbb', 'ccc'] }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); (0, _jquery2.default)(_reactDom2.default.findDOMNode(cp)).attr('class').should.be.eql('ra-suggest'); }); it('Should show suggest when focus', function () { var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { suggests: ['aaa', 'bbb', 'ccc'] }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); _reactAddonsTestUtils2.default.Simulate.focus(input); (0, _jquery2.default)(_reactDom2.default.findDOMNode(cp)).hasClass('show').should.be.true(); }); it('Should not show suggests when disabled', function () { var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { disabled: true, suggests: ['aaa', 'bbb', 'ccc'] }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); _reactAddonsTestUtils2.default.Simulate.focus(input); (0, _jquery2.default)(_reactDom2.default.findDOMNode(cp)).hasClass('show').should.be.false(); }); it('Should not show suggests when readonly', function () { var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { readOnly: true, suggests: ['aaa', 'bbb', 'ccc'] }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); _reactAddonsTestUtils2.default.Simulate.focus(input); (0, _jquery2.default)(_reactDom2.default.findDOMNode(cp)).hasClass('show').should.be.false(); }); it('Should change value when suggest clicked', function () { var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { suggests: ['value1', 'value2', 'value3'] }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); _reactAddonsTestUtils2.default.Simulate.focus(input); var suggestItems = _reactAddonsTestUtils2.default.scryRenderedDOMComponentsWithClass(cp, 'ra-suggest-item'); _reactAddonsTestUtils2.default.Simulate.mouseDown(suggestItems[0]); (0, _jquery2.default)(input).val().should.be.eql('value1'); }); it('Should hide when suggest clicked', function () { var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { suggests: ['value1', 'value2', 'value3'] }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); _reactAddonsTestUtils2.default.Simulate.focus(input); var suggestItems = _reactAddonsTestUtils2.default.scryRenderedDOMComponentsWithClass(cp, 'ra-suggest-item'); _reactAddonsTestUtils2.default.Simulate.mouseDown(suggestItems[0]); (0, _jquery2.default)(_reactDom2.default.findDOMNode(cp)).hasClass('show').should.be.false(); }); it('Should auto filter suggest', function () { var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { suggests: ['abc', 'abd', 'fff'], value: 'ab' }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); _reactAddonsTestUtils2.default.Simulate.focus(input); var suggestItems = _reactAddonsTestUtils2.default.scryRenderedDOMComponentsWithClass(cp, 'ra-suggest-item'); suggestItems.length.should.be.eql(2); }); it('Should not auto filter suggest when useFilter is false', function () { var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { suggests: ['abc', 'abd', 'fff'], useFilter: false, value: 'ab' }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); _reactAddonsTestUtils2.default.Simulate.focus(input); var suggestItems = _reactAddonsTestUtils2.default.scryRenderedDOMComponentsWithClass(cp, 'ra-suggest-item'); suggestItems.length.should.be.eql(3); }); it('Should set width', function () { var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { suggests: ['abc', 'abd', 'fff'], width: 200 }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); (0, _jquery2.default)(input).outerWidth().should.be.eql(200); }); it('Should set skin', function () { var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { skin: 'success', suggests: ['abc', 'abd', 'fff'], width: 200 }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); (0, _jquery2.default)(input).hasClass('success').should.be.true(); }); it('Should change value when input value changed', function (done) { var cb = function cb(value) { value.should.be.eql('abc'); done(); }; var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { onChange: cb, skin: 'success', suggests: ['abc', 'abd', 'fff'], width: 200 }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); input.value = 'abc'; _reactAddonsTestUtils2.default.Simulate.change(input); }); it('Should handle blur when suggest clicked', function (done) { var cb = function cb(value) { value.should.be.eql('abc'); done(); }; var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { onBlur: cb, skin: 'success', suggests: ['abc', 'abd', 'fff'], width: 200 }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); _reactAddonsTestUtils2.default.Simulate.focus(input); var suggestItems = _reactAddonsTestUtils2.default.scryRenderedDOMComponentsWithClass(cp, 'ra-suggest-item'); _reactAddonsTestUtils2.default.Simulate.mouseDown(suggestItems[0]); }); it('Should handle blur when document clicked', function (done) { var cb = function cb(value) { value.should.be.eql('aabbcc'); done(); }; var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { onBlur: cb, suggests: ['abc', 'abd', 'fff'], useFilter: false, value: 'aabbcc' }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); _reactAddonsTestUtils2.default.Simulate.focus(input); cp._handleDocClick({}); }); it('Should use arrow down to select the suggest', function () { var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { suggests: ['abc', 'abd', 'fff'], useFilter: false, value: 'aabbcc' }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); _reactAddonsTestUtils2.default.Simulate.focus(input); _reactAddonsTestUtils2.default.Simulate.keyDown(input, { key: 'Down', keyCode: 40, which: 40 }); _reactAddonsTestUtils2.default.Simulate.keyDown(input, { key: 'Down', keyCode: 40, which: 40 }); _reactAddonsTestUtils2.default.Simulate.keyDown(input, { key: 'Enter', keyCode: 13, which: 13 }); input.value.should.be.eql('abd'); }); it('Should use arrow up to select the suggest', function () { var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { suggests: ['abc', 'abd', 'fff'] }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); _reactAddonsTestUtils2.default.Simulate.focus(input); _reactAddonsTestUtils2.default.Simulate.keyDown(input, { key: 'Up', keyCode: 38, which: 38 }); _reactAddonsTestUtils2.default.Simulate.keyDown(input, { key: 'Up', keyCode: 38, which: 38 }); _reactAddonsTestUtils2.default.Simulate.keyDown(input, { key: 'Enter', keyCode: 13, which: 13 }); input.value.should.be.eql('abd'); }); it('Should use arrow and hover to select the suggest', function () { var cp = _reactDom2.default.render(_react2.default.createElement(_index2.default, { suggests: ['zzz', 'abc', 'abd', 'fff'], value: 'ab' }), container); cp = _reactAddonsTestUtils2.default.findRenderedComponentWithType(cp, _index2.default); var input = _reactAddonsTestUtils2.default.findRenderedDOMComponentWithClass(cp, 'ra-input'); _reactAddonsTestUtils2.default.Simulate.focus(input); var suggestItems = _reactAddonsTestUtils2.default.scryRenderedDOMComponentsWithClass(cp, 'ra-suggest-item'); _reactAddonsTestUtils2.default.Simulate.mouseEnter(suggestItems[0]); _reactAddonsTestUtils2.default.Simulate.keyDown(input, { key: 'Down', keyCode: 40, which: 40 }); _reactAddonsTestUtils2.default.Simulate.keyDown(input, { key: 'Enter', keyCode: 13, which: 13 }); input.value.should.be.eql('abd'); }); }); if (window.mochaPhantomJS) { window.mochaPhantomJS.run(); } else { mocha.run(); } /***/ }, /* 2 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var should = __webpack_require__(3); var defaultProto = Object.prototype; var defaultProperty = 'should'; //Expose api via `Object#should`. try { var prevShould = should.extend(defaultProperty, defaultProto); should._prevShould = prevShould; } catch (e) { //ignore errors } module.exports = should; /***/ }, /* 3 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; /* * Should * Copyright(c) 2010-2015 TJ Holowaychuk <tj@vision-media.ca> * MIT Licensed */ var util = __webpack_require__(4); /** * Our function should * * @param {*} obj Object to assert * @returns {should.Assertion} Returns new Assertion for beginning assertion chain * @example * * var should = require('should'); * should('abc').be.a.String(); */ function should(obj) { return new should.Assertion(obj); } should.AssertionError = __webpack_require__(14); should.Assertion = __webpack_require__(15); should.format = util.format; should.type = __webpack_require__(5); should.util = util; /** * Object with configuration. * It contains such properties: * * `checkProtoEql` boolean - Affect if `.eql` will check objects prototypes * * `plusZeroAndMinusZeroEqual` boolean - Affect if `.eql` will treat +0 and -0 as equal * Also it can contain options for should-format. * * @type {Object} * @memberOf should * @static * @example * * var a = { a: 10 }, b = Object.create(null); * b.a = 10; * * a.should.be.eql(b); * //not throws * * should.config.checkProtoEql = true; * a.should.be.eql(b); * //throws AssertionError: expected { a: 10 } to equal { a: 10 } (because A and B have different prototypes) */ should.config = __webpack_require__(11); // Expose should to external world. exports = module.exports = should; /** * Allow to extend given prototype with should property using given name. This getter will **unwrap** all standard wrappers like `Number`, `Boolean`, `String`. * Using `should(obj)` is the equivalent of using `obj.should` with known issues (like nulls and method calls etc). * * To add new assertions, need to use Assertion.add method. * * @param {string} [propertyName] Name of property to add. Default is `'should'`. * @param {Object} [proto] Prototype to extend with. Default is `Object.prototype`. * @memberOf should * @returns {{ name: string, descriptor: Object, proto: Object }} Descriptor enough to return all back * @static * @example * * var prev = should.extend('must', Object.prototype); * * 'abc'.must.startWith('a'); * * var should = should.noConflict(prev); * should.not.exist(Object.prototype.must); */ should.extend = function (propertyName, proto) { propertyName = propertyName || 'should'; proto = proto || Object.prototype; var prevDescriptor = Object.getOwnPropertyDescriptor(proto, propertyName); Object.defineProperty(proto, propertyName, { set: function set() {}, get: function get() { return should(util.isWrapperType(this) ? this.valueOf() : this); }, configurable: true }); return { name: propertyName, descriptor: prevDescriptor, proto: proto }; }; /** * Delete previous extension. If `desc` missing it will remove default extension. * * @param {{ name: string, descriptor: Object, proto: Object }} [desc] Returned from `should.extend` object * @memberOf should * @returns {Function} Returns should function * @static * @example * * var should = require('should').noConflict(); * * should(Object.prototype).not.have.property('should'); * * var prev = should.extend('must', Object.prototype); * 'abc'.must.startWith('a'); * should.noConflict(prev); * * should(Object.prototype).not.have.property('must'); */ should.noConflict = function (desc) { desc = desc || should._prevShould; if (desc) { delete desc.proto[desc.name]; if (desc.descriptor) { Object.defineProperty(desc.proto, desc.name, desc.descriptor); } } return should; }; /** * Simple utility function for a bit more easier should assertion extension * @param {Function} f So called plugin function. It should accept 2 arguments: `should` function and `Assertion` constructor * @memberOf should * @returns {Function} Returns `should` function * @static * @example * * should.use(function(should, Assertion) { * Assertion.add('asset', function() { * this.params = { operator: 'to be asset' }; * * this.obj.should.have.property('id').which.is.a.Number(); * this.obj.should.have.property('path'); * }) * }) */ should.use = function (f) { f(should, should.Assertion); return this; }; should.use(__webpack_require__(16)).use(__webpack_require__(20)).use(__webpack_require__(21)).use(__webpack_require__(22)).use(__webpack_require__(23)).use(__webpack_require__(24)).use(__webpack_require__(25)).use(__webpack_require__(26)).use(__webpack_require__(27)).use(__webpack_require__(28)).use(__webpack_require__(29)).use(__webpack_require__(30)); /***/ }, /* 4 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; /* * Should * Copyright(c) 2010-2015 TJ Holowaychuk <tj@vision-media.ca> * MIT Licensed */ var type = __webpack_require__(5); var config = __webpack_require__(11); /** * Check if given obj just a primitive type wrapper * @param {Object} obj * @returns {boolean} * @private */ exports.isWrapperType = function (obj) { return obj instanceof Number || obj instanceof String || obj instanceof Boolean; }; exports.merge = function (a, b) { if (a && b) { for (var key in b) { a[key] = b[key]; } } return a; }; var hasOwnProperty = Object.prototype.hasOwnProperty; exports.forEach = function forEach(obj, f, context) { if (exports.isGeneratorFunction(obj)) { return forEach(obj(), f, context); } else if (exports.isGeneratorObject(obj)) { var value = obj.next(); while (!value.done) { if (f.call(context, value.value, 'value', obj) === false) return; value = obj.next(); } } else { for (var prop in obj) { if (hasOwnProperty.call(obj, prop)) { if (f.call(context, obj[prop], prop, obj) === false) return; } } } }; exports.some = function (obj, f, context) { var res = false; exports.forEach(obj, function (value, key) { if (f.call(context, value, key, obj)) { res = true; return false; } }, context); return res; }; exports.isEmptyObject = function (obj) { for (var prop in obj) { if (hasOwnProperty.call(obj, prop)) { return false; } } return true; }; exports.isIndexable = function (obj) { var t = type(obj); return t.type === type.OBJECT && t.cls === type.ARRAY || t.type === type.OBJECT && t.cls === type.BUFFER || t.type === type.OBJECT && t.cls === type.ARGUMENTS || t.type === type.OBJECT && t.cls === type.ARRAY_BUFFER || t.type === type.OBJECT && t.cls === type.TYPED_ARRAY || t.type === type.OBJECT && t.cls === type.DATA_VIEW || t.type === type.OBJECT && t.cls === type.STRING || t.type === type.STRING; }; exports.length = function (obj) { var t = type(obj); switch (t.type) { case type.STRING: return obj.length; case type.OBJECT: switch (t.cls) { case type.ARRAY_BUFFER: case type.TYPED_ARRAY: case type.DATA_VIEW: return obj.byteLength; case type.ARRAY: case type.BUFFER: case type.ARGUMENTS: case type.FUNCTION: return obj.length; } } }; exports.convertPropertyName = function (name) { if ((typeof name === 'undefined' ? 'undefined' : _typeof(name)) == 'symbol') { return name; } else { return String(name); } }; exports.isGeneratorObject = function (obj) { if (!obj) return false; return typeof obj.next == 'function' && typeof obj[Symbol.iterator] == 'function' && obj[Symbol.iterator]() === obj; }; //TODO find better way exports.isGeneratorFunction = function (f) { if (typeof f != 'function') return false; return (/^function\s*\*\s*/.test(f.toString()) ); }; exports.format = function (value, opts) { return config.getFormatter(opts).format(value); }; exports.functionName = __webpack_require__(12).Formatter.functionName; exports.formatProp = function (value) { return config.getFormatter().formatPropertyName(String(value)); }; /***/ }, /* 5 */ /***/ function(module, exports, __webpack_require__) { /* WEBPACK VAR INJECTION */(function(Buffer) {'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; var toString = Object.prototype.toString; var types = __webpack_require__(10); /** * Simple data function to store type information * @param {string} type Usually what is returned from typeof * @param {string} cls Sanitized @Class via Object.prototype.toString * @param {string} sub If type and cls the same, and need to specify somehow * @private * @example * * //for null * new Type('null'); * * //for Date * new Type('object', 'date'); * * //for Uint8Array * * new Type('object', 'typed-array', 'uint8'); */ function Type(type, cls, sub) { this.type = type; this.cls = cls; this.sub = sub; } /** * Function to store type checks * @private */ function TypeChecker() { this.checks = []; } TypeChecker.prototype = { add: function add(func) { this.checks.push(func); return this; }, addTypeOf: function addTypeOf(type, res) { return this.add(function (obj, tpeOf) { if (tpeOf === type) { return new Type(res); } }); }, addClass: function addClass(cls, res, sub) { return this.add(function (obj, tpeOf, objCls) { if (objCls === cls) { return new Type(types.OBJECT, res, sub); } }); }, getType: function getType(obj) { var typeOf = typeof obj === 'undefined' ? 'undefined' : _typeof(obj); var cls = toString.call(obj); for (var i = 0, l = this.checks.length; i < l; i++) { var res = this.checks[i].call(this, obj, typeOf, cls); if (typeof res !== 'undefined') return res; } } }; var main = new TypeChecker(); //TODO add iterators main.addTypeOf(types.NUMBER, types.NUMBER).addTypeOf(types.UNDEFINED, types.UNDEFINED).addTypeOf(types.STRING, types.STRING).addTypeOf(types.BOOLEAN, types.BOOLEAN).addTypeOf(types.FUNCTION, types.FUNCTION).addTypeOf(types.SYMBOL, types.SYMBOL).add(function (obj, tpeOf) { if (obj === null) return new Type(types.NULL); }).addClass('[object String]', types.STRING).addClass('[object Boolean]', types.BOOLEAN).addClass('[object Number]', types.NUMBER).addClass('[object Array]', types.ARRAY).addClass('[object RegExp]', types.REGEXP).addClass('[object Error]', types.ERROR).addClass('[object Date]', types.DATE).addClass('[object Arguments]', types.ARGUMENTS).addClass('[object Math]').addClass('[object JSON]').addClass('[object ArrayBuffer]', types.ARRAY_BUFFER).addClass('[object Int8Array]', types.TYPED_ARRAY, 'int8').addClass('[object Uint8Array]', types.TYPED_ARRAY, 'uint8').addClass('[object Uint8ClampedArray]', types.TYPED_ARRAY, 'uint8clamped').addClass('[object Int16Array]', types.TYPED_ARRAY, 'int16').addClass('[object Uint16Array]', types.TYPED_ARRAY, 'uint16').addClass('[object Int32Array]', types.TYPED_ARRAY, 'int32').addClass('[object Uint32Array]', types.TYPED_ARRAY, 'uint32').addClass('[object Float32Array]', types.TYPED_ARRAY, 'float32').addClass('[object Float64Array]', types.TYPED_ARRAY, 'float64').addClass('[object DataView]', types.DATA_VIEW).addClass('[object Map]', types.MAP).addClass('[object WeakMap]', types.WEAK_MAP).addClass('[object Set]', types.SET).addClass('[object WeakSet]', types.WEAK_SET).addClass('[object Promise]', types.PROMISE).addClass('[object Blob]', types.BLOB).addClass('[object File]', types.FILE).addClass('[object FileList]', types.FILE_LIST).addClass('[object XMLHttpRequest]', types.XHR).add(function (obj) { if ((typeof Promise === 'undefined' ? 'undefined' : _typeof(Promise)) === types.FUNCTION && obj instanceof Promise || _typeof(obj.then) === types.FUNCTION) { return new Type(types.OBJECT, types.PROMISE); } }).add(function (obj) { if (typeof Buffer !== 'undefined' && obj instanceof Buffer) { return new Type(types.OBJECT, types.BUFFER); } }).add(function (obj) { if (typeof Node !== 'undefined' && obj instanceof Node) { return new Type(types.OBJECT, types.HTML_ELEMENT, obj.nodeName); } }).add(function (obj) { // probably at the begginging should be enough these checks if (obj.Boolean === Boolean && obj.Number === Number && obj.String === String && obj.Date === Date) { return new Type(types.OBJECT, types.HOST); } }).add(function () { return new Type(types.OBJECT); }); /** * Get type information of anything * * @param {any} obj Anything that could require type information * @return {Type} type info */ function getGlobalType(obj) { return main.getType(obj); } getGlobalType.checker = main; getGlobalType.TypeChecker = TypeChecker; getGlobalType.Type = Type; Object.keys(types).forEach(function (typeName) { getGlobalType[typeName] = types[typeName]; }); module.exports = getGlobalType; /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(6).Buffer)) /***/ }, /* 6 */ /***/ function(module, exports, __webpack_require__) { /* WEBPACK VAR INJECTION */(function(Buffer, global) {/*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> * @license MIT */ /* eslint-disable no-proto */ 'use strict'; var base64 = __webpack_require__(7); var ieee754 = __webpack_require__(8); var isArray = __webpack_require__(9); exports.Buffer = Buffer; exports.SlowBuffer = SlowBuffer; exports.INSPECT_MAX_BYTES = 50; Buffer.poolSize = 8192; // not used by this implementation var rootParent = {}; /** * If `Buffer.TYPED_ARRAY_SUPPORT`: * === true Use Uint8Array implementation (fastest) * === false Use Object implementation (most compatible, even IE6) * * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, * Opera 11.6+, iOS 4.2+. * * Due to various browser bugs, sometimes the Object implementation will be used even * when the browser supports typed arrays. * * Note: * * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. * * - Safari 5-7 lacks support for changing the `Object.prototype.constructor` property * on objects. * * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. * * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of * incorrect length in some situations. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they * get the Object implementation, which is slower but behaves correctly. */ Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined ? global.TYPED_ARRAY_SUPPORT : typedArraySupport(); function typedArraySupport() { function Bar() {} try { var arr = new Uint8Array(1); arr.foo = function () { return 42; }; arr.constructor = Bar; return arr.foo() === 42 && // typed array instances can be augmented arr.constructor === Bar && // constructor can be set typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` arr.subarray(1, 1).byteLength === 0; // ie10 has broken `subarray` } catch (e) { return false; } } function kMaxLength() { return Buffer.TYPED_ARRAY_SUPPORT ? 0x7fffffff : 0x3fffffff; } /** * Class: Buffer * ============= * * The Buffer constructor returns instances of `Uint8Array` that are augmented * with function properties for all the node `Buffer` API functions. We use * `Uint8Array` so that square bracket notation works as expected -- it returns * a single octet. * * By augmenting the instances, we can avoid modifying the `Uint8Array` * prototype. */ function Buffer(arg) { if (!(this instanceof Buffer)) { // Avoid going through an ArgumentsAdaptorTrampoline in the common case. if (arguments.length > 1) return new Buffer(arg, arguments[1]); return new Buffer(arg); } if (!Buffer.TYPED_ARRAY_SUPPORT) { this.length = 0; this.parent = undefined; } // Common case. if (typeof arg === 'number') { return fromNumber(this, arg); } // Slightly less common case. if (typeof arg === 'string') { return fromString(this, arg, arguments.length > 1 ? arguments[1] : 'utf8'); } // Unusual. return fromObject(this, arg); } function fromNumber(that, length) { that = allocate(that, length < 0 ? 0 : checked(length) | 0); if (!Buffer.TYPED_ARRAY_SUPPORT) { for (var i = 0; i < length; i++) { that[i] = 0; } } return that; } function fromString(that, string, encoding) { if (typeof encoding !== 'string' || encoding === '') encoding = 'utf8'; // Assumption: byteLength() return value is always < kMaxLength. var length = byteLength(string, encoding) | 0; that = allocate(that, length); that.write(string, encoding); return that; } function fromObject(that, object) { if (Buffer.isBuffer(object)) return fromBuffer(that, object); if (isArray(object)) return fromArray(that, object); if (object == null) { throw new TypeError('must start with number, buffer, array or string'); } if (typeof ArrayBuffer !== 'undefined') { if (object.buffer instanceof ArrayBuffer) { return fromTypedArray(that, object); } if (object instanceof ArrayBuffer) { return fromArrayBuffer(that, object); } } if (object.length) return fromArrayLike(that, object); return fromJsonObject(that, object); } function fromBuffer(that, buffer) { var length = checked(buffer.length) | 0; that = allocate(that, length); buffer.copy(that, 0, 0, length); return that; } function fromArray(that, array) { var length = checked(array.length) | 0; that = allocate(that, length); for (var i = 0; i < length; i += 1) { that[i] = array[i] & 255; } return that; } // Duplicate of fromArray() to keep fromArray() monomorphic. function fromTypedArray(that, array) { var length = checked(array.length) | 0; that = allocate(that, length); // Truncating the elements is probably not what people expect from typed // arrays with BYTES_PER_ELEMENT > 1 but it's compatible with the behavior // of the old Buffer constructor. for (var i = 0; i < length; i += 1) { that[i] = array[i] & 255; } return that; } function fromArrayBuffer(that, array) { if (Buffer.TYPED_ARRAY_SUPPORT) { // Return an augmented `Uint8Array` instance, for best performance array.byteLength; that = Buffer._augment(new Uint8Array(array)); } else { // Fallback: Return an object instance of the Buffer class that = fromTypedArray(that, new Uint8Array(array)); } return that; } function fromArrayLike(that, array) { var length = checked(array.length) | 0; that = allocate(that, length); for (var i = 0; i < length; i += 1) { that[i] = array[i] & 255; } return that; } // Deserialize { type: 'Buffer', data: [1,2,3,...] } into a Buffer object. // Returns a zero-length buffer for inputs that don't conform to the spec. function fromJsonObject(that, object) { var array; var length = 0; if (object.type === 'Buffer' && isArray(object.data)) { array = object.data; length = checked(array.length) | 0; } that = allocate(that, length); for (var i = 0; i < length; i += 1) { that[i] = array[i] & 255; } return that; } if (Buffer.TYPED_ARRAY_SUPPORT) { Buffer.prototype.__proto__ = Uint8Array.prototype; Buffer.__proto__ = Uint8Array; } else { // pre-set for values that may exist in the future Buffer.prototype.length = undefined; Buffer.prototype.parent = undefined; } function allocate(that, length) { if (Buffer.TYPED_ARRAY_SUPPORT) { // Return an augmented `Uint8Array` instance, for best performance that = Buffer._augment(new Uint8Array(length)); that.__proto__ = Buffer.prototype; } else { // Fallback: Return an object instance of the Buffer class that.length = length; that._isBuffer = true; } var fromPool = length !== 0 && length <= Buffer.poolSize >>> 1; if (fromPool) that.parent = rootParent; return that; } function checked(length) { // Note: cannot use `length < kMaxLength` here because that fails when // length is NaN (which is otherwise coerced to zero.) if (length >= kMaxLength()) { throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + kMaxLength().toString(16) + ' bytes'); } return length | 0; } function SlowBuffer(subject, encoding) { if (!(this instanceof SlowBuffer)) return new SlowBuffer(subject, encoding); var buf = new Buffer(subject, encoding); delete buf.parent; return buf; } Buffer.isBuffer = function isBuffer(b) { return !!(b != null && b._isBuffer); }; Buffer.compare = function compare(a, b) { if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { throw new TypeError('Arguments must be Buffers'); } if (a === b) return 0; var x = a.length; var y = b.length; var i = 0; var len = Math.min(x, y); while (i < len) { if (a[i] !== b[i]) break; ++i; } if (i !== len) { x = a[i]; y = b[i]; } if (x < y) return -1; if (y < x) return 1; return 0; }; Buffer.isEncoding = function isEncoding(encoding) { switch (String(encoding).toLowerCase()) { case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'raw': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return true; default: return false; } }; Buffer.concat = function concat(list, length) { if (!isArray(list)) throw new TypeError('list argument must be an Array of Buffers.'); if (list.length === 0) { return new Buffer(0); } var i; if (length === undefined) { length = 0; for (i = 0; i < list.length; i++) { length += list[i].length; } } var buf = new Buffer(length); var pos = 0; for (i = 0; i < list.length; i++) { var item = list[i]; item.copy(buf, pos); pos += item.length; } return buf; }; function byteLength(string, encoding) { if (typeof string !== 'string') string = '' + string; var len = string.length; if (len === 0) return 0; // Use a for loop to avoid recursion var loweredCase = false; for (;;) { switch (encoding) { case 'ascii': case 'binary': // Deprecated case 'raw': case 'raws': return len; case 'utf8': case 'utf-8': return utf8ToBytes(string).length; case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return len * 2; case 'hex': return len >>> 1; case 'base64': return base64ToBytes(string).length; default: if (loweredCase) return utf8ToBytes(string).length; // assume utf8 encoding = ('' + encoding).toLowerCase(); loweredCase = true; } } } Buffer.byteLength = byteLength; function slowToString(encoding, start, end) { var loweredCase = false; start = start | 0; end = end === undefined || end === Infinity ? this.length : end | 0; if (!encoding) encoding = 'utf8'; if (start < 0) start = 0; if (end > this.length) end = this.length; if (end <= start) return ''; while (true) { switch (encoding) { case 'hex': return hexSlice(this, start, end); case 'utf8': case 'utf-8': return utf8Slice(this, start, end); case 'ascii': return asciiSlice(this, start, end); case 'binary': return binarySlice(this, start, end); case 'base64': return base64Slice(this, start, end); case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return utf16leSlice(this, start, end); default: if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); encoding = (encoding + '').toLowerCase(); loweredCase = true; } } } Buffer.prototype.toString = function toString() { var length = this.length | 0; if (length === 0) return ''; if (arguments.length === 0) return utf8Slice(this, 0, length); return slowToString.apply(this, arguments); }; Buffer.prototype.equals = function equals(b) { if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer'); if (this === b) return true; return Buffer.compare(this, b) === 0; }; Buffer.prototype.inspect = function inspect() { var str = ''; var max = exports.INSPECT_MAX_BYTES; if (this.length > 0) { str = this.toString('hex', 0, max).match(/.{2}/g).join(' '); if (this.length > max) str += ' ... '; } return '<Buffer ' + str + '>'; }; Buffer.prototype.compare = function compare(b) { if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer'); if (this === b) return 0; return Buffer.compare(this, b); }; Buffer.prototype.indexOf = function indexOf(val, byteOffset) { if (byteOffset > 0x7fffffff) byteOffset = 0x7fffffff;else if (byteOffset < -0x80000000) byteOffset = -0x80000000; byteOffset >>= 0; if (this.length === 0) return -1; if (byteOffset >= this.length) return -1; // Negative offsets start from the end of the buffer if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0); if (typeof val === 'string') { if (val.length === 0) return -1; // special case: looking for empty string always fails return String.prototype.indexOf.call(this, val, byteOffset); } if (Buffer.isBuffer(val)) { return arrayIndexOf(this, val, byteOffset); } if (typeof val === 'number') { if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') { return Uint8Array.prototype.indexOf.call(this, val, byteOffset); } return arrayIndexOf(this, [val], byteOffset); } function arrayIndexOf(arr, val, byteOffset) { var foundIndex = -1; for (var i = 0; byteOffset + i < arr.length; i++) { if (arr[byteOffset + i] === val[foundIndex === -1 ? 0 : i - foundIndex]) { if (foundIndex === -1) foundIndex = i; if (i - foundIndex + 1 === val.length) return byteOffset + foundIndex; } else { foundIndex = -1; } } return -1; } throw new TypeError('val must be string, number or Buffer'); }; // `get` is deprecated Buffer.prototype.get = function get(offset) { console.log('.get() is deprecated. Access using array indexes instead.'); return this.readUInt8(offset); }; // `set` is deprecated Buffer.prototype.set = function set(v, offset) { console.log('.set() is deprecated. Access using array indexes instead.'); return this.writeUInt8(v, offset); }; function hexWrite(buf, string, offset, length) { offset = Number(offset) || 0; var remaining = buf.length - offset; if (!length) { length = remaining; } else { length = Number(length); if (length > remaining) { length = remaining; } } // must be an even number of digits var strLen = string.length; if (strLen % 2 !== 0) throw new Error('Invalid hex string'); if (length > strLen / 2) { length = strLen / 2; } for (var i = 0; i < length; i++) { var parsed = parseInt(string.substr(i * 2, 2), 16); if (isNaN(parsed)) throw new Error('Invalid hex string'); buf[offset + i] = parsed; } return i; } function utf8Write(buf, string, offset, length) { return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length); } function asciiWrite(buf, string, offset, length) { return blitBuffer(asciiToBytes(string), buf, offset, length); } function binaryWrite(buf, string, offset, length) { return asciiWrite(buf, string, offset, length); } function base64Write(buf, string, offset, length) { return blitBuffer(base64ToBytes(string), buf, offset, length); } function ucs2Write(buf, string, offset, length) { return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length); } Buffer.prototype.write = function write(string, offset, length, encoding) { // Buffer#write(string) if (offset === undefined) { encoding = 'utf8'; length = this.length; offset = 0; // Buffer#write(string, encoding) } else if (length === undefined && typeof offset === 'string') { encoding = offset; length = this.length; offset = 0; // Buffer#write(string, offset[, length][, encoding]) } else if (isFinite(offset)) { offset = offset | 0; if (isFinite(length)) { length = length | 0; if (encoding === undefined) encoding = 'utf8'; } else { encoding = length; length = undefined; } // legacy write(string, encoding, offset, length) - remove in v0.13 } else { var swap = encoding; encoding = offset; offset = length | 0; length = swap; } var remaining = this.length - offset; if (length === undefined || length > remaining) length = remaining; if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) { throw new RangeError('attempt to write outside buffer bounds'); } if (!encoding) encoding = 'utf8'; var loweredCase = false; for (;;) { switch (encoding) { case 'hex': return hexWrite(this, string, offset, length); case 'utf8': case 'utf-8': return utf8Write(this, string, offset, length); case 'ascii': return asciiWrite(this, string, offset, length); case 'binary': return binaryWrite(this, string, offset, length); case 'base64': // Warning: maxLength not taken into account in base64Write return base64Write(this, string, offset, length); case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return ucs2Write(this, string, offset, length); default: if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); encoding = ('' + encoding).toLowerCase(); loweredCase = true; } } }; Buffer.prototype.toJSON = function toJSON() { return { type: 'Buffer', data: Array.prototype.slice.call(this._arr || this, 0) }; }; function base64Slice(buf, start, end) { if (start === 0 && end === buf.length) { return base64.fromByteArray(buf); } else { return base64.fromByteArray(buf.slice(start, end)); } } function utf8Slice(buf, start, end) { end = Math.min(buf.length, end); var res = []; var i = start; while (i < end) { var firstByte = buf[i]; var codePoint = null; var bytesPerSequence = firstByte > 0xEF ? 4 : firstByte > 0xDF ? 3 : firstByte > 0xBF ? 2 : 1; if (i + bytesPerSequence <= end) { var secondByte, thirdByte, fourthByte, tempCodePoint; switch (bytesPerSequence) { case 1: if (firstByte < 0x80) { codePoint = firstByte; } break; case 2: secondByte = buf[i + 1]; if ((secondByte & 0xC0) === 0x80) { tempCodePoint = (firstByte & 0x1F) << 0x6 | secondByte & 0x3F; if (tempCodePoint > 0x7F) { codePoint = tempCodePoint; } } break; case 3: secondByte = buf[i + 1]; thirdByte = buf[i + 2]; if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | thirdByte & 0x3F; if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { codePoint = tempCodePoint; } } break; case 4: secondByte = buf[i + 1]; thirdByte = buf[i + 2]; fourthByte = buf[i + 3]; if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | fourthByte & 0x3F; if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { codePoint = tempCodePoint; } } } } if (codePoint === null) { // we did not generate a valid codePoint so insert a // replacement char (U+FFFD) and advance only 1 byte codePoint = 0xFFFD; bytesPerSequence = 1; } else if (codePoint > 0xFFFF) { // encode to utf16 (surrogate pair dance) codePoint -= 0x10000; res.push(codePoint >>> 10 & 0x3FF | 0xD800); codePoint = 0xDC00 | codePoint & 0x3FF; } res.push(codePoint); i += bytesPerSequence; } return decodeCodePointsArray(res); } // Based on http://stackoverflow.com/a/22747272/680742, the browser with // the lowest limit is Chrome, with 0x10000 args. // We go 1 magnitude less, for safety var MAX_ARGUMENTS_LENGTH = 0x1000; function decodeCodePointsArray(codePoints) { var len = codePoints.length; if (len <= MAX_ARGUMENTS_LENGTH) { return String.fromCharCode.apply(String, codePoints); // avoid extra slice() } // Decode in chunks to avoid "call stack size exceeded". var res = ''; var i = 0; while (i < len) { res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)); } return res; } function asciiSlice(buf, start, end) { var ret = ''; end = Math.min(buf.length, end); for (var i = start; i < end; i++) { ret += String.fromCharCode(buf[i] & 0x7F); } return ret; } function binarySlice(buf, start, end) { var ret = ''; end = Math.min(buf.length, end); for (var i = start; i < end; i++) { ret += String.fromCharCode(buf[i]); } return ret; } function hexSlice(buf, start, end) { var len = buf.length; if (!start || start < 0) start = 0; if (!end || end < 0 || end > len) end = len; var out = ''; for (var i = start; i < end; i++) { out += toHex(buf[i]); } return out; } function utf16leSlice(buf, start, end) { var bytes = buf.slice(start, end); var res = ''; for (var i = 0; i < bytes.length; i += 2) { res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); } return res; } Buffer.prototype.slice = function slice(start, end) { var len = this.length; start = ~ ~start; end = end === undefined ? len : ~ ~end; if (start < 0) { start += len; if (start < 0) start = 0; } else if (start > len) { start = len; } if (end < 0) { end += len; if (end < 0) end = 0; } else if (end > len) { end = len; } if (end < start) end = start; var newBuf; if (Buffer.TYPED_ARRAY_SUPPORT) { newBuf = Buffer._augment(this.subarray(start, end)); } else { var sliceLen = end - start; newBuf = new Buffer(sliceLen, undefined); for (var i = 0; i < sliceLen; i++) { newBuf[i] = this[i + start]; } } if (newBuf.length) newBuf.parent = this.parent || this; return newBuf; }; /* * Need to make sure that buffer isn't trying to write out of bounds. */ function checkOffset(offset, ext, length) { if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint'); if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length'); } Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) { offset = offset | 0; byteLength = byteLength | 0; if (!noAssert) checkOffset(offset, byteLength, this.length); var val = this[offset];