UNPKG

1.67 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
8
9exports.isType = isType;
10exports.componentType = componentType;
11/**
12 * Tries to determine if the objectToTest is of the given type.
13 * Will normalize things like String/'string' inconsistencies
14 * as well as ES6 class & traditional prototype inheritance.
15 * NOTE: This ALSO tests the prototype hierarchy if objectToTest
16 * is a Function.
17 */
18function isType(objectToTest, type) {
19 var o = objectToTest;
20 if ((typeof o === 'undefined' ? 'undefined' : _typeof(o)) === type) {
21 return true;
22 }
23 if (type === String || type === 'string') {
24 return o instanceof String;
25 }
26 if (type === Function || type === 'function') {
27 return o instanceof Function;
28 }
29 if (type === Object || type === 'object') {
30 return o instanceof Object;
31 }
32 if (objectToTest instanceof Function) {
33 var proto = objectToTest;
34 while (proto) {
35 if (proto === type) {
36 return true;
37 }
38 proto = Object.getPrototypeOf(proto);
39 }
40 }
41 return objectToTest instanceof type;
42}
43
44function componentType(componentType) {
45 return function (extensions, onload) {
46 extensions = extensions.filter(function (e) {
47 return isType(e.instance, componentType);
48 });
49 onload(extensions);
50 };
51}
\No newline at end of file