├── mics.jpg ├── test ├── test-helper.js ├── index.html └── browser-source-map-support.js ├── .babelrc ├── .gitignore ├── mixins-are-classes-on-steroids.jpg ├── .travis.yml ├── .eslintrc.json ├── webpack.config.js ├── package.json ├── rollup.config.js ├── dist ├── mics.min.js ├── mics.es.js ├── mics.es.js.map ├── mics.cjs.js ├── mics.umd.js ├── mics.cjs.js.map ├── mics.umd.js.map └── mics.min.js.map ├── src ├── index.js └── index.spec.js ├── README.md └── LICENSE.md /mics.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/download/mics/develop/mics.jpg -------------------------------------------------------------------------------- /test/test-helper.js: -------------------------------------------------------------------------------- 1 | require('babel-register'); 2 | require('babel-polyfill'); 3 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["es2015", {modules: false}] 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | debug.log* 2 | npm-debug.log* 3 | node_modules 4 | 5 | # JetBrains 6 | .idea/ -------------------------------------------------------------------------------- /mixins-are-classes-on-steroids.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/download/mics/develop/mixins-are-classes-on-steroids.jpg -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | test 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "node" 4 | - "6" 5 | - "5" 6 | - "4" 7 | # https://github.com/greenkeeperio/greenkeeper-lockfile 8 | before_install: 9 | - npm install -g npm@5 10 | - npm install -g greenkeeper-lockfile@1 11 | before_script: greenkeeper-lockfile-update 12 | after_script: greenkeeper-lockfile-upload -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["eslint:recommended"], 3 | "parserOptions": { 4 | "ecmaVersion": 6, 5 | "sourceType": "module" 6 | }, 7 | "env": { 8 | "node": true, 9 | "es6": true, 10 | "browser": true, 11 | "mocha": true 12 | }, 13 | "rules": { 14 | "eol-last": ["error", "always"], 15 | "max-len": ["warn", { 16 | "code": 120 17 | }], 18 | "indent": ["warn", 4], 19 | "newline-per-chained-call": "warn", 20 | "one-var-declaration-per-line": "warn", 21 | "no-redeclare": "error", 22 | "object-curly-spacing": ["warn", "always"], 23 | "arrow-spacing": "warn", 24 | "no-multi-spaces": "warn", 25 | "no-multiple-empty-lines": "warn" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var webpack = require('webpack'); 3 | 4 | module.exports = { 5 | // The base directory (absolute path!) for resolving the entry option. 6 | // If output.pathinfo is set, the included pathinfo is shortened to this directory. 7 | context: path.resolve('src'), 8 | 9 | module: { 10 | loaders: [ 11 | { 12 | test: /\.js/, 13 | exclude: /node_modules/, 14 | loader: 'babel-loader', 15 | options: process.env['ES_MODULE'] ? { 16 | // Options to configure babel. overrides .babelrc with modules=false 17 | presets: [['es2015', {modules:false}]] 18 | } : {} 19 | }, 20 | ], 21 | noParse: /\.min\.js/, 22 | }, 23 | 24 | devtool: 'source-map', 25 | 26 | devServer: { 27 | stats: { 28 | chunks: false, 29 | } 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mics", 3 | "version": "0.7.0", 4 | "description": "Multiple Inheritance Class System: Intuitive mixins for ES6 classes", 5 | "main": "dist/mics.cjs.js", 6 | "module": "dist/mics.es.js", 7 | "scripts": { 8 | "test": "mocha \"dist/mics.spec.js\"", 9 | "dev": "webpack-dev-server --output-path test --output-filename index.spec.js \"mocha-loader!./index.spec.js\" --content-base test --port 8888", 10 | "build": "npm run build-cjs && npm run build-umd && npm run build-min && npm run build-es && npm run build-test", 11 | "build-cjs": "webpack --output-path dist --output-filename mics.cjs.js --output-library-target commonjs2 \"./index.js\" ", 12 | "build-es": "rollup -c -o dist/mics.es.js -f es ", 13 | "build-umd": "webpack --output-path dist --output-filename mics.umd.js --output-library-target umd \"./index.js\" ", 14 | "build-min": "webpack -p --output-path dist --output-filename mics.min.js --output-library-target umd \"./index.js\" ", 15 | "build-test": "webpack --output-path dist --output-filename mics.spec.js --target node \"./index.spec.js\"", 16 | "release": "npm run build && npm run test" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/download/mics.git" 21 | }, 22 | "keywords": [ 23 | "mixin", 24 | "mixwith", 25 | "es6-class", 26 | "microscopically small", 27 | "2kB" 28 | ], 29 | "author": { 30 | "name": "Stijn de Witt", 31 | "email": "StijnDeWitt@hotmail.com", 32 | "url": "https://StijnDeWitt.com" 33 | }, 34 | "contributors": [ 35 | { 36 | "name": "Marco Alka", 37 | "url": "https://marco-alka.de/" 38 | } 39 | ], 40 | "license": "CC-BY-4.0", 41 | "bugs": { 42 | "url": "https://github.com/download/mics/issues" 43 | }, 44 | "homepage": "https://github.com/download/mics", 45 | "devDependencies": { 46 | "babel-core": "^6.25.0", 47 | "babel-loader": "^7.1.1", 48 | "babel-plugin-external-helpers": "^6.22.0", 49 | "babel-polyfill": "^6.23.0", 50 | "babel-preset-es2015": "^6.24.1", 51 | "babel-register": "^6.24.1", 52 | "chai": "^4.0.2", 53 | "cross-env": "^5.0.1", 54 | "eslint": "^4.1.1", 55 | "mocha": "^3.4.2", 56 | "mocha-loader": "^1.1.1", 57 | "rollup": "^0.46.0", 58 | "rollup-plugin-babel": "^2.7.1", 59 | "rollup-plugin-commonjs": "^8.0.2", 60 | "rollup-plugin-node-resolve": "^3.0.0", 61 | "rollup-plugin-uglify": "^2.0.1", 62 | "sinon": "^3.0.0", 63 | "tcomb": "^3.2.21", 64 | "webpack": "^3.0.0", 65 | "webpack-dev-server": "^2.5.0" 66 | }, 67 | "dependencies": { 68 | "ulog": "^1.0.2" 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import commonjs from 'rollup-plugin-commonjs' 2 | import nodeResolve from 'rollup-plugin-node-resolve' 3 | import babel from 'rollup-plugin-babel' 4 | import uglify from 'rollup-plugin-uglify' 5 | 6 | export default { 7 | entry: 'src/index.js', 8 | sourceMap: true, 9 | 10 | plugins: [ 11 | nodeResolve({ 12 | 13 | // use "module" field for ES6 module if possible 14 | //module: true, // Default: true 15 | 16 | // use "jsnext:main" if possible 17 | // – see https://github.com/rollup/rollup/wiki/jsnext:main 18 | jsnext: true, // Default: false 19 | 20 | // use "main" field or index.js, even if it's not an ES6 module 21 | // (needs to be converted from CommonJS to ES6 22 | // – see https://github.com/rollup/rollup-plugin-commonjs 23 | //main: true, // Default: true 24 | 25 | // some package.json files have a `browser` field which 26 | // specifies alternative files to load for people bundling 27 | // for the browser. If that's you, use this option, otherwise 28 | // pkg.browser will be ignored 29 | browser: true, // Default: false 30 | 31 | // not all files you want to resolve are .js files 32 | // extensions: [ '.js', '.json' ], // Default: ['.js'] 33 | 34 | // whether to prefer built-in modules (e.g. `fs`, `path`) or 35 | // local ones with the same names 36 | // preferBuiltins: false, // Default: true 37 | 38 | // Lock the module search in this path (like a chroot). Module defined 39 | // outside this path will be mark has external 40 | //jail: '/my/jail/path', // Default: '/' 41 | 42 | // If true, inspect resolved files to check that they are 43 | // ES2015 modules 44 | //modulesOnly: true, // Default: false 45 | 46 | // Any additional options that should be passed through 47 | // to node-resolve 48 | //customResolveOptions: { 49 | // moduleDirectory: 'js_modules' 50 | //} 51 | }), 52 | 53 | commonjs({ 54 | // non-CommonJS modules will be ignored, but you can also 55 | // specifically include/exclude files 56 | //include: 'node_modules/**', // Default: undefined 57 | //exclude: [ 'node_modules/foo/**', 'node_modules/bar/**' ], // Default: undefined 58 | 59 | // search for files other than .js files (must already 60 | // be transpiled by a previous plugin!) 61 | //extensions: [ '.js', '.coffee' ], // Default: [ '.js' ] 62 | 63 | // if true then uses of `global` won't be dealt with by this plugin 64 | //ignoreGlobal: false, // Default: false 65 | 66 | // if false then skip sourceMap generation for CommonJS modules 67 | //sourceMap: false, // Default: true 68 | 69 | // explicitly specify unresolvable named exports 70 | // (see below for more details) 71 | //namedExports: { './module.js': ['foo', 'bar' ] }, // Default: undefined 72 | 73 | // sometimes you have to leave require statements 74 | // unconverted. Pass an array containing the IDs 75 | // or a `id => boolean` function. Only use this 76 | // option if you know what you're doing! 77 | //ignore: [ 'conditional-runtime-dependency' ] 78 | }), 79 | 80 | babel({ 81 | 82 | }) 83 | ].concat( 84 | process.env.NODE_ENV == 'production' ? [ 85 | uglify({ 86 | screw_ie8: true, 87 | }) 88 | ] : [] 89 | ) 90 | }; 91 | -------------------------------------------------------------------------------- /dist/mics.min.js: -------------------------------------------------------------------------------- 1 | !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var r in n)("object"==typeof exports?exports:t)[r]=n[r]}}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){"use strict";function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function u(){function t(e){var n=c(e,t)?e:i(e);return-1===t.classes.indexOf(n)&&t.classes.push(n),n}for(var e=arguments.length,n=Array(e),r=0;r class Looker extends superclass { 9 | * constructor() { 10 | * super() 11 | * console.info('A looker is born!') 12 | * } 13 | * look() { 14 | * console.info('Looking good!') 15 | * } 16 | * }) 17 | * 18 | * @param {function} args 19 | * Consists of the following three argument groups: 20 | * {function} superclass (optional) 21 | * {function} mixins... (0 or more) 22 | * {function} factory (optional) 23 | * @return {function} 24 | */ 25 | function mix(...args) { 26 | // todo: refactor to make const 27 | let superclass = !isFactory(args[0]) && args.shift() || baseclass 28 | let factory = (isFactory(args[args.length-1]) && args.pop()) || derive 29 | superclass = isMixin(superclass) ? superclass.class : derive(superclass) 30 | if (args.length) factory = (org => superclass => org(args.reduce((s,m) => m.mixin(s), superclass)))(factory) 31 | 32 | function mixin(superclass) { 33 | const result = is(superclass, mixin) ? superclass : factory(superclass) 34 | if (mixin.classes.indexOf(result) === -1) mixin.classes.push(result) 35 | return result 36 | } 37 | 38 | Object.defineProperties(mixin, { 39 | classes: { value:[], writable:false }, 40 | mixins: { value:args, writable:false }, 41 | }) 42 | const Class = mixin(superclass) 43 | const constructor = Class.hasOwnProperty('constructor') 44 | ? Class.constructor.bind(Class) 45 | : (...args) => new Class(...args) 46 | Object.getOwnPropertyNames(Class).forEach(k => Object.defineProperty(constructor, k, { value: Class[k] })) 47 | return Object.defineProperties(constructor, { 48 | mixin: { value:mixin, writable:false }, 49 | class: { value: Class, writable:false }, 50 | interface: { get:(x => () => x ? x : x = getInterface(Class.prototype))() }, 51 | }) 52 | } 53 | 54 | /** 55 | * Tests whether `x` is a type or extends from type. 56 | * Example: is(looker, Looker) 57 | * 58 | * @param {object|function} x 59 | * @param {function} type 60 | * @return {boolean} 61 | */ 62 | function is(x, type) { 63 | if (typeof x == 'object') { 64 | if (x instanceof type) return true 65 | if (type.class && x instanceof type.class) return true 66 | if (type.mixin && type.mixin.classes) return type.mixin.classes.reduce((f,c) => f || is(x,c), false) 67 | } 68 | else if (typeof x == 'function') { 69 | if (x.mixin && x.mixin.mixins.indexOf(type) !== -1) return true 70 | let c = x 71 | while (c !== Object) { 72 | if (c === type || c === type.class) return true 73 | if (type.mixin && type.mixin.classes && type.mixin.classes.indexOf(c) !== -1) return true 74 | c = Object.getPrototypeOf(c.prototype).constructor 75 | } 76 | } 77 | return false 78 | } 79 | 80 | /** 81 | * Often, we don't really care whether the object is a certain type, 82 | * we just want to know whether we can treat it like a certain type. 83 | * Use like(subject, type) to test whether a subject adheres to the same interface as is defined by type 84 | * Example: 85 | * 86 | * var Looker = mix(superclass => class Looker extends superclass { 87 | * look() {} 88 | * }) 89 | * 90 | * var Viewer = { 91 | * look() {} // same interface as Looker 92 | * } 93 | * 94 | * var viewer = new Viewer() 95 | * like(viewer, Looker) // true 96 | * 97 | * @param {object|function} x 98 | * @param {function} type 99 | * @return {boolean} 100 | */ 101 | function like(x, type) { 102 | if (is(x, type)) return true 103 | const itf = type.interface || ((typeof type == 'function') && getInterface(type.prototype)) 104 | const subject = typeof x == 'function' ? x.interface || getInterface(x.prototype) : x 105 | return itf && Object.keys(itf).reduce((f, k) => 106 | f && ((typeof itf[k] == 'function') ? (typeof subject[k] == 'function') : k in subject), true 107 | ) 108 | } 109 | 110 | /** 111 | * Get all parts of an interface as an array of strings 112 | * 113 | * @param {object} proto 114 | * @return {array} 115 | */ 116 | function getInterface(proto) { 117 | return getPropertyNames(proto).reduce((o,k) => { o[k] = proto[k]; return o }, {}) 118 | } 119 | 120 | /** 121 | * Get all properties of an object an an array of strings 122 | * 123 | * @param {object|function} proto 124 | * @return {array} 125 | */ 126 | function getPropertyNames(proto) { 127 | const results = [] 128 | while (proto !== Object.prototype) { 129 | Object.getOwnPropertyNames(proto).reduce((arr,k) => arr.indexOf(k) === -1 ? arr.push(k) && arr : arr, results) 130 | proto = Object.getPrototypeOf(proto).constructor.prototype 131 | } 132 | return results 133 | } 134 | 135 | function isMixin(x) { 136 | return (typeof x == 'function') && !!x.mixin 137 | } 138 | 139 | function isClass(x) { 140 | if (typeof x != 'function') return false 141 | const s = x.toString() 142 | return /^class\s/.test(s) || /^.*classCallCheck\(/.test(s.replace(/^[^{]*{\s*/,'').replace(/\s*}[^}]*$/,'')) 143 | } 144 | 145 | function isFactory(x) { 146 | return (typeof x == 'function') && !isMixin(x) && !isClass(x) && x.length == 1 147 | } 148 | 149 | 150 | const baseclass = class Object{} 151 | const derive = superclass => ({}[superclass.name || 'Object'] = class extends superclass {}) 152 | -------------------------------------------------------------------------------- /dist/mics.es.js: -------------------------------------------------------------------------------- 1 | var _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; }; 2 | 3 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } 4 | 5 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } 6 | 7 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 8 | 9 | /** 10 | * Accepts an optional superclass as the first argument, 11 | * then a bunch of mixins and an optional class factory as the last argument and returns a mixin. 12 | * Mostly, you will be using mix with a factory to create mixins, like this: 13 | * 14 | * var Looker = mix(superclass => class Looker extends superclass { 15 | * constructor() { 16 | * super() 17 | * console.info('A looker is born!') 18 | * } 19 | * look() { 20 | * console.info('Looking good!') 21 | * } 22 | * }) 23 | * 24 | * @param {function} args 25 | * Consists of the following three argument groups: 26 | * {function} superclass (optional) 27 | * {function} mixins... (0 or more) 28 | * {function} factory (optional) 29 | * @return {function} 30 | */ 31 | function mix() { 32 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 33 | args[_key] = arguments[_key]; 34 | } 35 | 36 | // todo: refactor to make const 37 | var superclass = !isFactory(args[0]) && args.shift() || baseclass; 38 | var factory = isFactory(args[args.length - 1]) && args.pop() || derive; 39 | superclass = isMixin(superclass) ? superclass.class : derive(superclass); 40 | if (args.length) factory = function (org) { 41 | return function (superclass) { 42 | return org(args.reduce(function (s, m) { 43 | return m.mixin(s); 44 | }, superclass)); 45 | }; 46 | }(factory); 47 | 48 | function mixin(superclass) { 49 | var result = is(superclass, mixin) ? superclass : factory(superclass); 50 | if (mixin.classes.indexOf(result) === -1) mixin.classes.push(result); 51 | return result; 52 | } 53 | 54 | Object.defineProperties(mixin, { 55 | classes: { value: [], writable: false }, 56 | mixins: { value: args, writable: false } 57 | }); 58 | var Class = mixin(superclass); 59 | var constructor = Class.hasOwnProperty('constructor') ? Class.constructor.bind(Class) : function () { 60 | for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 61 | args[_key2] = arguments[_key2]; 62 | } 63 | 64 | return new (Function.prototype.bind.apply(Class, [null].concat(args)))(); 65 | }; 66 | Object.getOwnPropertyNames(Class).forEach(function (k) { 67 | return Object.defineProperty(constructor, k, { value: Class[k] }); 68 | }); 69 | return Object.defineProperties(constructor, { 70 | mixin: { value: mixin, writable: false }, 71 | class: { value: Class, writable: false }, 72 | interface: { get: function (x) { 73 | return function () { 74 | return x ? x : x = getInterface(Class.prototype); 75 | }; 76 | }() } 77 | }); 78 | } 79 | 80 | /** 81 | * Tests whether `x` is a type or extends from type. 82 | * Example: is(looker, Looker) 83 | * 84 | * @param {object|function} x 85 | * @param {function} type 86 | * @return {boolean} 87 | */ 88 | function is(x, type) { 89 | if ((typeof x === 'undefined' ? 'undefined' : _typeof(x)) == 'object') { 90 | if (x instanceof type) return true; 91 | if (type.class && x instanceof type.class) return true; 92 | if (type.mixin && type.mixin.classes) return type.mixin.classes.reduce(function (f, c) { 93 | return f || is(x, c); 94 | }, false); 95 | } else if (typeof x == 'function') { 96 | if (x.mixin && x.mixin.mixins.indexOf(type) !== -1) return true; 97 | var c = x; 98 | while (c !== Object) { 99 | if (c === type || c === type.class) return true; 100 | if (type.mixin && type.mixin.classes && type.mixin.classes.indexOf(c) !== -1) return true; 101 | c = Object.getPrototypeOf(c.prototype).constructor; 102 | } 103 | } 104 | return false; 105 | } 106 | 107 | /** 108 | * Often, we don't really care whether the object is a certain type, 109 | * we just want to know whether we can treat it like a certain type. 110 | * Use like(subject, type) to test whether a subject adheres to the same interface as is defined by type 111 | * Example: 112 | * 113 | * var Looker = mix(superclass => class Looker extends superclass { 114 | * look() {} 115 | * }) 116 | * 117 | * var Viewer = { 118 | * look() {} // same interface as Looker 119 | * } 120 | * 121 | * var viewer = new Viewer() 122 | * like(viewer, Looker) // true 123 | * 124 | * @param {object|function} x 125 | * @param {function} type 126 | * @return {boolean} 127 | */ 128 | function like(x, type) { 129 | if (is(x, type)) return true; 130 | var itf = type.interface || typeof type == 'function' && getInterface(type.prototype); 131 | var subject = typeof x == 'function' ? x.interface || getInterface(x.prototype) : x; 132 | return itf && Object.keys(itf).reduce(function (f, k) { 133 | return f && (typeof itf[k] == 'function' ? typeof subject[k] == 'function' : k in subject); 134 | }, true); 135 | } 136 | 137 | /** 138 | * Get all parts of an interface as an array of strings 139 | * 140 | * @param {object} proto 141 | * @return {array} 142 | */ 143 | function getInterface(proto) { 144 | return getPropertyNames(proto).reduce(function (o, k) { 145 | o[k] = proto[k];return o; 146 | }, {}); 147 | } 148 | 149 | /** 150 | * Get all properties of an object an an array of strings 151 | * 152 | * @param {object|function} proto 153 | * @return {array} 154 | */ 155 | function getPropertyNames(proto) { 156 | var results = []; 157 | while (proto !== Object.prototype) { 158 | Object.getOwnPropertyNames(proto).reduce(function (arr, k) { 159 | return arr.indexOf(k) === -1 ? arr.push(k) && arr : arr; 160 | }, results); 161 | proto = Object.getPrototypeOf(proto).constructor.prototype; 162 | } 163 | return results; 164 | } 165 | 166 | function isMixin(x) { 167 | return typeof x == 'function' && !!x.mixin; 168 | } 169 | 170 | function isClass(x) { 171 | if (typeof x != 'function') return false; 172 | var s = x.toString(); 173 | return (/^class\s/.test(s) || /^.*classCallCheck\(/.test(s.replace(/^[^{]*{\s*/, '').replace(/\s*}[^}]*$/, '')) 174 | ); 175 | } 176 | 177 | function isFactory(x) { 178 | return typeof x == 'function' && !isMixin(x) && !isClass(x) && x.length == 1; 179 | } 180 | 181 | var baseclass = function Object() { 182 | _classCallCheck(this, Object); 183 | }; 184 | var derive = function derive(superclass) { 185 | return {}[superclass.name || 'Object'] = function (_superclass) { 186 | _inherits(_class, _superclass); 187 | 188 | function _class() { 189 | _classCallCheck(this, _class); 190 | 191 | return _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).apply(this, arguments)); 192 | } 193 | 194 | return _class; 195 | }(superclass); 196 | }; 197 | 198 | export { mix, is, like }; 199 | //# sourceMappingURL=mics.es.js.map 200 | -------------------------------------------------------------------------------- /dist/mics.es.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"mics.es.js","sources":["../src/index.js"],"sourcesContent":["export { mix, is, like }\r\n\r\n/**\r\n * Accepts an optional superclass as the first argument,\r\n * then a bunch of mixins and an optional class factory as the last argument and returns a mixin.\r\n * Mostly, you will be using mix with a factory to create mixins, like this:\r\n *\r\n * var Looker = mix(superclass => class Looker extends superclass {\r\n * constructor() {\r\n * super()\r\n * console.info('A looker is born!')\r\n * }\r\n * look() {\r\n * console.info('Looking good!')\r\n * }\r\n * })\r\n *\r\n * @param {function} args\r\n * Consists of the following three argument groups:\r\n * {function} superclass (optional)\r\n * {function} mixins... (0 or more)\r\n * {function} factory (optional)\r\n * @return {function}\r\n */\r\nfunction mix(...args) {\r\n // todo: refactor to make const\r\n let superclass = !isFactory(args[0]) && args.shift() || baseclass\r\n let factory = (isFactory(args[args.length-1]) && args.pop()) || derive\r\n superclass = isMixin(superclass) ? superclass.class : derive(superclass)\r\n if (args.length) factory = (org => superclass => org(args.reduce((s,m) => m.mixin(s), superclass)))(factory)\r\n\r\n function mixin(superclass) {\r\n const result = is(superclass, mixin) ? superclass : factory(superclass)\r\n if (mixin.classes.indexOf(result) === -1) mixin.classes.push(result)\r\n return result\r\n }\r\n\r\n Object.defineProperties(mixin, {\r\n classes: { value:[], writable:false },\r\n mixins: { value:args, writable:false },\r\n })\r\n const Class = mixin(superclass)\r\n const constructor = Class.hasOwnProperty('constructor')\r\n ? Class.constructor.bind(Class)\r\n : (...args) => new Class(...args)\r\n Object.getOwnPropertyNames(Class).forEach(k => Object.defineProperty(constructor, k, { value: Class[k] }))\r\n return Object.defineProperties(constructor, {\r\n mixin: { value:mixin, writable:false },\r\n class: { value: Class, writable:false },\r\n interface: { get:(x => () => x ? x : x = getInterface(Class.prototype))() },\r\n })\r\n}\r\n\r\n/**\r\n * Tests whether `x` is a type or extends from type.\r\n * Example: is(looker, Looker)\r\n *\r\n * @param {object|function} x\r\n * @param {function} type\r\n * @return {boolean}\r\n */\r\nfunction is(x, type) {\r\n if (typeof x == 'object') {\r\n if (x instanceof type) return true\r\n if (type.class && x instanceof type.class) return true\r\n if (type.mixin && type.mixin.classes) return type.mixin.classes.reduce((f,c) => f || is(x,c), false)\r\n }\r\n else if (typeof x == 'function') {\r\n if (x.mixin && x.mixin.mixins.indexOf(type) !== -1) return true\r\n let c = x\r\n while (c !== Object) {\r\n if (c === type || c === type.class) return true\r\n if (type.mixin && type.mixin.classes && type.mixin.classes.indexOf(c) !== -1) return true\r\n c = Object.getPrototypeOf(c.prototype).constructor\r\n }\r\n }\r\n return false\r\n}\r\n\r\n/**\r\n * Often, we don't really care whether the object is a certain type,\r\n * we just want to know whether we can treat it like a certain type.\r\n * Use like(subject, type) to test whether a subject adheres to the same interface as is defined by type\r\n * Example:\r\n *\r\n * var Looker = mix(superclass => class Looker extends superclass {\r\n * look() {}\r\n * })\r\n *\r\n * var Viewer = {\r\n * look() {} // same interface as Looker\r\n * }\r\n *\r\n * var viewer = new Viewer()\r\n * like(viewer, Looker) // true\r\n *\r\n * @param {object|function} x\r\n * @param {function} type\r\n * @return {boolean}\r\n */\r\nfunction like(x, type) {\r\n if (is(x, type)) return true\r\n const itf = type.interface || ((typeof type == 'function') && getInterface(type.prototype))\r\n const subject = typeof x == 'function' ? x.interface || getInterface(x.prototype) : x\r\n return itf && Object.keys(itf).reduce((f, k) => \r\n f && ((typeof itf[k] == 'function') ? (typeof subject[k] == 'function') : k in subject), true\r\n )\r\n}\r\n\r\n/**\r\n * Get all parts of an interface as an array of strings\r\n *\r\n * @param {object} proto\r\n * @return {array}\r\n */\r\nfunction getInterface(proto) {\r\n return getPropertyNames(proto).reduce((o,k) => { o[k] = proto[k]; return o }, {})\r\n}\r\n\r\n/**\r\n * Get all properties of an object an an array of strings\r\n *\r\n * @param {object|function} proto\r\n * @return {array}\r\n */\r\nfunction getPropertyNames(proto) {\r\n const results = []\r\n while (proto !== Object.prototype) {\r\n Object.getOwnPropertyNames(proto).reduce((arr,k) => arr.indexOf(k) === -1 ? arr.push(k) && arr : arr, results)\r\n proto = Object.getPrototypeOf(proto).constructor.prototype\r\n }\r\n return results\r\n}\r\n\r\nfunction isMixin(x) {\r\n return (typeof x == 'function') && !!x.mixin\r\n}\r\n\r\nfunction isClass(x) {\r\n if (typeof x != 'function') return false\r\n const s = x.toString()\r\n return /^class\\s/.test(s) || /^.*classCallCheck\\(/.test(s.replace(/^[^{]*{\\s*/,'').replace(/\\s*}[^}]*$/,''))\r\n}\r\n\r\nfunction isFactory(x) {\r\n return (typeof x == 'function') && !isMixin(x) && !isClass(x) && x.length == 1\r\n}\r\n\r\n\r\nconst baseclass = class Object{}\r\nconst derive = superclass => ({}[superclass.name || 'Object'] = class extends superclass {})\r\n"],"names":["mix","args","superclass","isFactory","shift","baseclass","factory","length","pop","derive","isMixin","class","org","reduce","s","m","mixin","result","is","classes","indexOf","push","defineProperties","value","writable","Class","constructor","hasOwnProperty","bind","getOwnPropertyNames","forEach","Object","defineProperty","k","get","x","getInterface","prototype","type","f","c","mixins","getPrototypeOf","like","itf","interface","subject","keys","proto","getPropertyNames","o","results","arr","isClass","toString","test","replace","name"],"mappings":";;;;;;;;AAAA,AAEA;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAASA,GAAT,GAAsB;sCAANC,IAAM;YAAA;;;;QAEdC,aAAa,CAACC,UAAUF,KAAK,CAAL,CAAV,CAAD,IAAuBA,KAAKG,KAAL,EAAvB,IAAuCC,SAAxD;QACIC,UAAWH,UAAUF,KAAKA,KAAKM,MAAL,GAAY,CAAjB,CAAV,KAAkCN,KAAKO,GAAL,EAAnC,IAAkDC,MAAhE;iBACaC,QAAQR,UAAR,IAAsBA,WAAWS,KAAjC,GAAyCF,OAAOP,UAAP,CAAtD;QACID,KAAKM,MAAT,EAAiBD,UAAW;eAAO;mBAAcM,IAAIX,KAAKY,MAAL,CAAY,UAACC,CAAD,EAAGC,CAAH;uBAASA,EAAEC,KAAF,CAAQF,CAAR,CAAT;aAAZ,EAAiCZ,UAAjC,CAAJ,CAAd;SAAP;KAAD,CAAyEI,OAAzE,CAAV;;aAERU,KAAT,CAAed,UAAf,EAA2B;YACjBe,SAASC,GAAGhB,UAAH,EAAec,KAAf,IAAwBd,UAAxB,GAAqCI,QAAQJ,UAAR,CAApD;YACIc,MAAMG,OAAN,CAAcC,OAAd,CAAsBH,MAAtB,MAAkC,CAAC,CAAvC,EAA0CD,MAAMG,OAAN,CAAcE,IAAd,CAAmBJ,MAAnB;eACnCA,MAAP;;;WAGGK,gBAAP,CAAwBN,KAAxB,EAA+B;iBAClB,EAAEO,OAAM,EAAR,EAAYC,UAAS,KAArB,EADkB;gBAEnB,EAAED,OAAMtB,IAAR,EAAcuB,UAAS,KAAvB;KAFZ;QAIMC,QAAQT,MAAMd,UAAN,CAAd;QACMwB,cAAcD,MAAME,cAAN,CAAqB,aAArB,IACdF,MAAM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BG,UAAU,EAAhB;WACOH,UAAUjB,OAAOM,SAAxB,EAAmC;eACxBR,mBAAP,CAA2BmB,KAA3B,EAAkCnC,MAAlC,CAAyC,UAACuC,GAAD,EAAKnB,CAAL;mBAAWmB,IAAIhC,OAAJ,CAAYa,CAAZ,MAAmB,CAAC,CAApB,GAAwBmB,IAAI/B,IAAJ,CAASY,CAAT,KAAemB,GAAvC,GAA6CA,GAAxD;SAAzC,EAAsGD,OAAtG;gBACQpB,OAAOW,cAAP,CAAsBM,KAAtB,EAA6BtB,WAA7B,CAAyCW,SAAjD;;WAEGc,OAAP;;;AAGJ,SAASzC,OAAT,CAAiByB,CAAjB,EAAoB;WACR,OAAOA,CAAP,IAAY,UAAb,IAA4B,CAAC,CAACA,EAAEnB,KAAvC;;;AAGJ,SAASqC,OAAT,CAAiBlB,CAAjB,EAAoB;QACZ,OAAOA,CAAP,IAAY,UAAhB,EAA4B,OAAO,KAAP;QACtBrB,IAAIqB,EAAEmB,QAAF,EAAV;uBACkBC,IAAX,CAAgBzC,CAAhB,KAAsB,sBAAsByC,IAAtB,CAA2BzC,EAAE0C,OAAF,CAAU,YAAV,EAAuB,EAAvB,EAA2BA,OAA3B,CAAmC,YAAnC,EAAgD,EAAhD,CAA3B;;;;AAGjC,SAASrD,SAAT,CAAmBgC,CAAnB,EAAsB;WACV,OAAOA,CAAP,IAAY,UAAb,IAA4B,CAACzB,QAAQyB,CAAR,CAA7B,IAA2C,CAACkB,QAAQlB,CAAR,CAA5C,IAA0DA,EAAE5B,MAAF,IAAY,CAA7E;;;AAIJ,IAAMF;;CAAN;AACA,IAAMI,SAAS,SAATA,MAAS;WAAe,GAAGP,WAAWuD,IAAX,IAAmB,QAAtB;;;;;;;;;;MAAgDvD,UAAhD,CAAf;CAAf;;;;"} -------------------------------------------------------------------------------- /dist/mics.cjs.js: -------------------------------------------------------------------------------- 1 | module.exports = 2 | /******/ (function(modules) { // webpackBootstrap 3 | /******/ // The module cache 4 | /******/ var installedModules = {}; 5 | /******/ 6 | /******/ // The require function 7 | /******/ function __webpack_require__(moduleId) { 8 | /******/ 9 | /******/ // Check if module is in cache 10 | /******/ if(installedModules[moduleId]) { 11 | /******/ return installedModules[moduleId].exports; 12 | /******/ } 13 | /******/ // Create a new module (and put it into the cache) 14 | /******/ var module = installedModules[moduleId] = { 15 | /******/ i: moduleId, 16 | /******/ l: false, 17 | /******/ exports: {} 18 | /******/ }; 19 | /******/ 20 | /******/ // Execute the module function 21 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 22 | /******/ 23 | /******/ // Flag the module as loaded 24 | /******/ module.l = true; 25 | /******/ 26 | /******/ // Return the exports of the module 27 | /******/ return module.exports; 28 | /******/ } 29 | /******/ 30 | /******/ 31 | /******/ // expose the modules object (__webpack_modules__) 32 | /******/ __webpack_require__.m = modules; 33 | /******/ 34 | /******/ // expose the module cache 35 | /******/ __webpack_require__.c = installedModules; 36 | /******/ 37 | /******/ // define getter function for harmony exports 38 | /******/ __webpack_require__.d = function(exports, name, getter) { 39 | /******/ if(!__webpack_require__.o(exports, name)) { 40 | /******/ Object.defineProperty(exports, name, { 41 | /******/ configurable: false, 42 | /******/ enumerable: true, 43 | /******/ get: getter 44 | /******/ }); 45 | /******/ } 46 | /******/ }; 47 | /******/ 48 | /******/ // getDefaultExport function for compatibility with non-harmony modules 49 | /******/ __webpack_require__.n = function(module) { 50 | /******/ var getter = module && module.__esModule ? 51 | /******/ function getDefault() { return module['default']; } : 52 | /******/ function getModuleExports() { return module; }; 53 | /******/ __webpack_require__.d(getter, 'a', getter); 54 | /******/ return getter; 55 | /******/ }; 56 | /******/ 57 | /******/ // Object.prototype.hasOwnProperty.call 58 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 59 | /******/ 60 | /******/ // __webpack_public_path__ 61 | /******/ __webpack_require__.p = ""; 62 | /******/ 63 | /******/ // Load entry module and return exports 64 | /******/ return __webpack_require__(__webpack_require__.s = 0); 65 | /******/ }) 66 | /************************************************************************/ 67 | /******/ ([ 68 | /* 0 */ 69 | /***/ (function(module, __webpack_exports__, __webpack_require__) { 70 | 71 | "use strict"; 72 | Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); 73 | /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "mix", function() { return mix; }); 74 | /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "is", function() { return is; }); 75 | /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "like", function() { return like; }); 76 | var _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; }; 77 | 78 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } 79 | 80 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } 81 | 82 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 83 | 84 | 85 | 86 | /** 87 | * Accepts an optional superclass as the first argument, 88 | * then a bunch of mixins and an optional class factory as the last argument and returns a mixin. 89 | * Mostly, you will be using mix with a factory to create mixins, like this: 90 | * 91 | * var Looker = mix(superclass => class Looker extends superclass { 92 | * constructor() { 93 | * super() 94 | * console.info('A looker is born!') 95 | * } 96 | * look() { 97 | * console.info('Looking good!') 98 | * } 99 | * }) 100 | * 101 | * @param {function} args 102 | * Consists of the following three argument groups: 103 | * {function} superclass (optional) 104 | * {function} mixins... (0 or more) 105 | * {function} factory (optional) 106 | * @return {function} 107 | */ 108 | function mix() { 109 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 110 | args[_key] = arguments[_key]; 111 | } 112 | 113 | // todo: refactor to make const 114 | var superclass = !isFactory(args[0]) && args.shift() || baseclass; 115 | var factory = isFactory(args[args.length - 1]) && args.pop() || derive; 116 | superclass = isMixin(superclass) ? superclass.class : derive(superclass); 117 | if (args.length) factory = function (org) { 118 | return function (superclass) { 119 | return org(args.reduce(function (s, m) { 120 | return m.mixin(s); 121 | }, superclass)); 122 | }; 123 | }(factory); 124 | 125 | function mixin(superclass) { 126 | var result = is(superclass, mixin) ? superclass : factory(superclass); 127 | if (mixin.classes.indexOf(result) === -1) mixin.classes.push(result); 128 | return result; 129 | } 130 | 131 | Object.defineProperties(mixin, { 132 | classes: { value: [], writable: false }, 133 | mixins: { value: args, writable: false } 134 | }); 135 | var Class = mixin(superclass); 136 | var constructor = Class.hasOwnProperty('constructor') ? Class.constructor.bind(Class) : function () { 137 | for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 138 | args[_key2] = arguments[_key2]; 139 | } 140 | 141 | return new (Function.prototype.bind.apply(Class, [null].concat(args)))(); 142 | }; 143 | Object.getOwnPropertyNames(Class).forEach(function (k) { 144 | return Object.defineProperty(constructor, k, { value: Class[k] }); 145 | }); 146 | return Object.defineProperties(constructor, { 147 | mixin: { value: mixin, writable: false }, 148 | class: { value: Class, writable: false }, 149 | interface: { get: function (x) { 150 | return function () { 151 | return x ? x : x = getInterface(Class.prototype); 152 | }; 153 | }() } 154 | }); 155 | } 156 | 157 | /** 158 | * Tests whether `x` is a type or extends from type. 159 | * Example: is(looker, Looker) 160 | * 161 | * @param {object|function} x 162 | * @param {function} type 163 | * @return {boolean} 164 | */ 165 | function is(x, type) { 166 | if ((typeof x === 'undefined' ? 'undefined' : _typeof(x)) == 'object') { 167 | if (x instanceof type) return true; 168 | if (type.class && x instanceof type.class) return true; 169 | if (type.mixin && type.mixin.classes) return type.mixin.classes.reduce(function (f, c) { 170 | return f || is(x, c); 171 | }, false); 172 | } else if (typeof x == 'function') { 173 | if (x.mixin && x.mixin.mixins.indexOf(type) !== -1) return true; 174 | var c = x; 175 | while (c !== Object) { 176 | if (c === type || c === type.class) return true; 177 | if (type.mixin && type.mixin.classes && type.mixin.classes.indexOf(c) !== -1) return true; 178 | c = Object.getPrototypeOf(c.prototype).constructor; 179 | } 180 | } 181 | return false; 182 | } 183 | 184 | /** 185 | * Often, we don't really care whether the object is a certain type, 186 | * we just want to know whether we can treat it like a certain type. 187 | * Use like(subject, type) to test whether a subject adheres to the same interface as is defined by type 188 | * Example: 189 | * 190 | * var Looker = mix(superclass => class Looker extends superclass { 191 | * look() {} 192 | * }) 193 | * 194 | * var Viewer = { 195 | * look() {} // same interface as Looker 196 | * } 197 | * 198 | * var viewer = new Viewer() 199 | * like(viewer, Looker) // true 200 | * 201 | * @param {object|function} x 202 | * @param {function} type 203 | * @return {boolean} 204 | */ 205 | function like(x, type) { 206 | if (is(x, type)) return true; 207 | var itf = type.interface || typeof type == 'function' && getInterface(type.prototype); 208 | var subject = typeof x == 'function' ? x.interface || getInterface(x.prototype) : x; 209 | return itf && Object.keys(itf).reduce(function (f, k) { 210 | return f && (typeof itf[k] == 'function' ? typeof subject[k] == 'function' : k in subject); 211 | }, true); 212 | } 213 | 214 | /** 215 | * Get all parts of an interface as an array of strings 216 | * 217 | * @param {object} proto 218 | * @return {array} 219 | */ 220 | function getInterface(proto) { 221 | return getPropertyNames(proto).reduce(function (o, k) { 222 | o[k] = proto[k];return o; 223 | }, {}); 224 | } 225 | 226 | /** 227 | * Get all properties of an object an an array of strings 228 | * 229 | * @param {object|function} proto 230 | * @return {array} 231 | */ 232 | function getPropertyNames(proto) { 233 | var results = []; 234 | while (proto !== Object.prototype) { 235 | Object.getOwnPropertyNames(proto).reduce(function (arr, k) { 236 | return arr.indexOf(k) === -1 ? arr.push(k) && arr : arr; 237 | }, results); 238 | proto = Object.getPrototypeOf(proto).constructor.prototype; 239 | } 240 | return results; 241 | } 242 | 243 | function isMixin(x) { 244 | return typeof x == 'function' && !!x.mixin; 245 | } 246 | 247 | function isClass(x) { 248 | if (typeof x != 'function') return false; 249 | var s = x.toString(); 250 | return (/^class\s/.test(s) || /^.*classCallCheck\(/.test(s.replace(/^[^{]*{\s*/, '').replace(/\s*}[^}]*$/, '')) 251 | ); 252 | } 253 | 254 | function isFactory(x) { 255 | return typeof x == 'function' && !isMixin(x) && !isClass(x) && x.length == 1; 256 | } 257 | 258 | var baseclass = function Object() { 259 | _classCallCheck(this, Object); 260 | }; 261 | var derive = function derive(superclass) { 262 | return {}[superclass.name || 'Object'] = function (_superclass) { 263 | _inherits(_class, _superclass); 264 | 265 | function _class() { 266 | _classCallCheck(this, _class); 267 | 268 | return _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).apply(this, arguments)); 269 | } 270 | 271 | return _class; 272 | }(superclass); 273 | }; 274 | 275 | /***/ }) 276 | /******/ ]); 277 | //# sourceMappingURL=mics.cjs.js.map -------------------------------------------------------------------------------- /dist/mics.umd.js: -------------------------------------------------------------------------------- 1 | (function webpackUniversalModuleDefinition(root, factory) { 2 | if(typeof exports === 'object' && typeof module === 'object') 3 | module.exports = factory(); 4 | else if(typeof define === 'function' && define.amd) 5 | define([], factory); 6 | else { 7 | var a = factory(); 8 | for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; 9 | } 10 | })(this, function() { 11 | return /******/ (function(modules) { // webpackBootstrap 12 | /******/ // The module cache 13 | /******/ var installedModules = {}; 14 | /******/ 15 | /******/ // The require function 16 | /******/ function __webpack_require__(moduleId) { 17 | /******/ 18 | /******/ // Check if module is in cache 19 | /******/ if(installedModules[moduleId]) { 20 | /******/ return installedModules[moduleId].exports; 21 | /******/ } 22 | /******/ // Create a new module (and put it into the cache) 23 | /******/ var module = installedModules[moduleId] = { 24 | /******/ i: moduleId, 25 | /******/ l: false, 26 | /******/ exports: {} 27 | /******/ }; 28 | /******/ 29 | /******/ // Execute the module function 30 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 31 | /******/ 32 | /******/ // Flag the module as loaded 33 | /******/ module.l = true; 34 | /******/ 35 | /******/ // Return the exports of the module 36 | /******/ return module.exports; 37 | /******/ } 38 | /******/ 39 | /******/ 40 | /******/ // expose the modules object (__webpack_modules__) 41 | /******/ __webpack_require__.m = modules; 42 | /******/ 43 | /******/ // expose the module cache 44 | /******/ __webpack_require__.c = installedModules; 45 | /******/ 46 | /******/ // define getter function for harmony exports 47 | /******/ __webpack_require__.d = function(exports, name, getter) { 48 | /******/ if(!__webpack_require__.o(exports, name)) { 49 | /******/ Object.defineProperty(exports, name, { 50 | /******/ configurable: false, 51 | /******/ enumerable: true, 52 | /******/ get: getter 53 | /******/ }); 54 | /******/ } 55 | /******/ }; 56 | /******/ 57 | /******/ // getDefaultExport function for compatibility with non-harmony modules 58 | /******/ __webpack_require__.n = function(module) { 59 | /******/ var getter = module && module.__esModule ? 60 | /******/ function getDefault() { return module['default']; } : 61 | /******/ function getModuleExports() { return module; }; 62 | /******/ __webpack_require__.d(getter, 'a', getter); 63 | /******/ return getter; 64 | /******/ }; 65 | /******/ 66 | /******/ // Object.prototype.hasOwnProperty.call 67 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 68 | /******/ 69 | /******/ // __webpack_public_path__ 70 | /******/ __webpack_require__.p = ""; 71 | /******/ 72 | /******/ // Load entry module and return exports 73 | /******/ return __webpack_require__(__webpack_require__.s = 0); 74 | /******/ }) 75 | /************************************************************************/ 76 | /******/ ([ 77 | /* 0 */ 78 | /***/ (function(module, __webpack_exports__, __webpack_require__) { 79 | 80 | "use strict"; 81 | Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); 82 | /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "mix", function() { return mix; }); 83 | /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "is", function() { return is; }); 84 | /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "like", function() { return like; }); 85 | var _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; }; 86 | 87 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } 88 | 89 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } 90 | 91 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 92 | 93 | 94 | 95 | /** 96 | * Accepts an optional superclass as the first argument, 97 | * then a bunch of mixins and an optional class factory as the last argument and returns a mixin. 98 | * Mostly, you will be using mix with a factory to create mixins, like this: 99 | * 100 | * var Looker = mix(superclass => class Looker extends superclass { 101 | * constructor() { 102 | * super() 103 | * console.info('A looker is born!') 104 | * } 105 | * look() { 106 | * console.info('Looking good!') 107 | * } 108 | * }) 109 | * 110 | * @param {function} args 111 | * Consists of the following three argument groups: 112 | * {function} superclass (optional) 113 | * {function} mixins... (0 or more) 114 | * {function} factory (optional) 115 | * @return {function} 116 | */ 117 | function mix() { 118 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 119 | args[_key] = arguments[_key]; 120 | } 121 | 122 | // todo: refactor to make const 123 | var superclass = !isFactory(args[0]) && args.shift() || baseclass; 124 | var factory = isFactory(args[args.length - 1]) && args.pop() || derive; 125 | superclass = isMixin(superclass) ? superclass.class : derive(superclass); 126 | if (args.length) factory = function (org) { 127 | return function (superclass) { 128 | return org(args.reduce(function (s, m) { 129 | return m.mixin(s); 130 | }, superclass)); 131 | }; 132 | }(factory); 133 | 134 | function mixin(superclass) { 135 | var result = is(superclass, mixin) ? superclass : factory(superclass); 136 | if (mixin.classes.indexOf(result) === -1) mixin.classes.push(result); 137 | return result; 138 | } 139 | 140 | Object.defineProperties(mixin, { 141 | classes: { value: [], writable: false }, 142 | mixins: { value: args, writable: false } 143 | }); 144 | var Class = mixin(superclass); 145 | var constructor = Class.hasOwnProperty('constructor') ? Class.constructor.bind(Class) : function () { 146 | for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 147 | args[_key2] = arguments[_key2]; 148 | } 149 | 150 | return new (Function.prototype.bind.apply(Class, [null].concat(args)))(); 151 | }; 152 | Object.getOwnPropertyNames(Class).forEach(function (k) { 153 | return Object.defineProperty(constructor, k, { value: Class[k] }); 154 | }); 155 | return Object.defineProperties(constructor, { 156 | mixin: { value: mixin, writable: false }, 157 | class: { value: Class, writable: false }, 158 | interface: { get: function (x) { 159 | return function () { 160 | return x ? x : x = getInterface(Class.prototype); 161 | }; 162 | }() } 163 | }); 164 | } 165 | 166 | /** 167 | * Tests whether `x` is a type or extends from type. 168 | * Example: is(looker, Looker) 169 | * 170 | * @param {object|function} x 171 | * @param {function} type 172 | * @return {boolean} 173 | */ 174 | function is(x, type) { 175 | if ((typeof x === 'undefined' ? 'undefined' : _typeof(x)) == 'object') { 176 | if (x instanceof type) return true; 177 | if (type.class && x instanceof type.class) return true; 178 | if (type.mixin && type.mixin.classes) return type.mixin.classes.reduce(function (f, c) { 179 | return f || is(x, c); 180 | }, false); 181 | } else if (typeof x == 'function') { 182 | if (x.mixin && x.mixin.mixins.indexOf(type) !== -1) return true; 183 | var c = x; 184 | while (c !== Object) { 185 | if (c === type || c === type.class) return true; 186 | if (type.mixin && type.mixin.classes && type.mixin.classes.indexOf(c) !== -1) return true; 187 | c = Object.getPrototypeOf(c.prototype).constructor; 188 | } 189 | } 190 | return false; 191 | } 192 | 193 | /** 194 | * Often, we don't really care whether the object is a certain type, 195 | * we just want to know whether we can treat it like a certain type. 196 | * Use like(subject, type) to test whether a subject adheres to the same interface as is defined by type 197 | * Example: 198 | * 199 | * var Looker = mix(superclass => class Looker extends superclass { 200 | * look() {} 201 | * }) 202 | * 203 | * var Viewer = { 204 | * look() {} // same interface as Looker 205 | * } 206 | * 207 | * var viewer = new Viewer() 208 | * like(viewer, Looker) // true 209 | * 210 | * @param {object|function} x 211 | * @param {function} type 212 | * @return {boolean} 213 | */ 214 | function like(x, type) { 215 | if (is(x, type)) return true; 216 | var itf = type.interface || typeof type == 'function' && getInterface(type.prototype); 217 | var subject = typeof x == 'function' ? x.interface || getInterface(x.prototype) : x; 218 | return itf && Object.keys(itf).reduce(function (f, k) { 219 | return f && (typeof itf[k] == 'function' ? typeof subject[k] == 'function' : k in subject); 220 | }, true); 221 | } 222 | 223 | /** 224 | * Get all parts of an interface as an array of strings 225 | * 226 | * @param {object} proto 227 | * @return {array} 228 | */ 229 | function getInterface(proto) { 230 | return getPropertyNames(proto).reduce(function (o, k) { 231 | o[k] = proto[k];return o; 232 | }, {}); 233 | } 234 | 235 | /** 236 | * Get all properties of an object an an array of strings 237 | * 238 | * @param {object|function} proto 239 | * @return {array} 240 | */ 241 | function getPropertyNames(proto) { 242 | var results = []; 243 | while (proto !== Object.prototype) { 244 | Object.getOwnPropertyNames(proto).reduce(function (arr, k) { 245 | return arr.indexOf(k) === -1 ? arr.push(k) && arr : arr; 246 | }, results); 247 | proto = Object.getPrototypeOf(proto).constructor.prototype; 248 | } 249 | return results; 250 | } 251 | 252 | function isMixin(x) { 253 | return typeof x == 'function' && !!x.mixin; 254 | } 255 | 256 | function isClass(x) { 257 | if (typeof x != 'function') return false; 258 | var s = x.toString(); 259 | return (/^class\s/.test(s) || /^.*classCallCheck\(/.test(s.replace(/^[^{]*{\s*/, '').replace(/\s*}[^}]*$/, '')) 260 | ); 261 | } 262 | 263 | function isFactory(x) { 264 | return typeof x == 'function' && !isMixin(x) && !isClass(x) && x.length == 1; 265 | } 266 | 267 | var baseclass = function Object() { 268 | _classCallCheck(this, Object); 269 | }; 270 | var derive = function derive(superclass) { 271 | return {}[superclass.name || 'Object'] = function (_superclass) { 272 | _inherits(_class, _superclass); 273 | 274 | function _class() { 275 | _classCallCheck(this, _class); 276 | 277 | return _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).apply(this, arguments)); 278 | } 279 | 280 | return _class; 281 | }(superclass); 282 | }; 283 | 284 | /***/ }) 285 | /******/ ]); 286 | }); 287 | //# sourceMappingURL=mics.umd.js.map -------------------------------------------------------------------------------- /dist/mics.cjs.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///webpack/bootstrap abfa6d14b55ce37333ef","webpack:///./index.js"],"names":["mix","args","superclass","isFactory","shift","baseclass","factory","length","pop","derive","isMixin","class","org","reduce","s","m","mixin","result","is","classes","indexOf","push","Object","defineProperties","value","writable","mixins","Class","constructor","hasOwnProperty","bind","getOwnPropertyNames","forEach","defineProperty","k","interface","get","x","getInterface","prototype","type","f","c","getPrototypeOf","like","itf","subject","keys","proto","getPropertyNames","o","results","arr","isClass","toString","test","replace","name"],"mappings":";;AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;AAEA;AACA;;;;;;;;;;;;;;;;;;;;AC7DA;;AAEA;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAASA,GAAT,GAAsB;AAAA,sCAANC,IAAM;AAANA,YAAM;AAAA;;AAClB;AACA,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AGD,IAAMF;AAAA;AAAA,CAAN;AACA,IAAMI,SAAS,SAATA,MAAS;AAAA,WAAe,GAAGP,WAAWuD,IAAX,IAAmB,QAAtB;AAAA;;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA,MAAgDvD,UAAhD,CAAf;AAAA,CAAf,C","file":"mics.cjs.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap abfa6d14b55ce37333ef","export { mix, is, like }\r\n\r\n/**\r\n * Accepts an optional superclass as the first argument,\r\n * then a bunch of mixins and an optional class factory as the last argument and returns a mixin.\r\n * Mostly, you will be using mix with a factory to create mixins, like this:\r\n *\r\n * var Looker = mix(superclass => class Looker extends superclass {\r\n * constructor() {\r\n * super()\r\n * console.info('A looker is born!')\r\n * }\r\n * look() {\r\n * console.info('Looking good!')\r\n * }\r\n * })\r\n *\r\n * @param {function} args\r\n * Consists of the following three argument groups:\r\n * {function} superclass (optional)\r\n * {function} mixins... (0 or more)\r\n * {function} factory (optional)\r\n * @return {function}\r\n */\r\nfunction mix(...args) {\r\n // todo: refactor to make const\r\n let superclass = !isFactory(args[0]) && args.shift() || baseclass\r\n let factory = (isFactory(args[args.length-1]) && args.pop()) || derive\r\n superclass = isMixin(superclass) ? superclass.class : derive(superclass)\r\n if (args.length) factory = (org => superclass => org(args.reduce((s,m) => m.mixin(s), superclass)))(factory)\r\n\r\n function mixin(superclass) {\r\n const result = is(superclass, mixin) ? superclass : factory(superclass)\r\n if (mixin.classes.indexOf(result) === -1) mixin.classes.push(result)\r\n return result\r\n }\r\n\r\n Object.defineProperties(mixin, {\r\n classes: { value:[], writable:false },\r\n mixins: { value:args, writable:false },\r\n })\r\n const Class = mixin(superclass)\r\n const constructor = Class.hasOwnProperty('constructor')\r\n ? Class.constructor.bind(Class)\r\n : (...args) => new Class(...args)\r\n Object.getOwnPropertyNames(Class).forEach(k => Object.defineProperty(constructor, k, { value: Class[k] }))\r\n return Object.defineProperties(constructor, {\r\n mixin: { value:mixin, writable:false },\r\n class: { value: Class, writable:false },\r\n interface: { get:(x => () => x ? x : x = getInterface(Class.prototype))() },\r\n })\r\n}\r\n\r\n/**\r\n * Tests whether `x` is a type or extends from type.\r\n * Example: is(looker, Looker)\r\n *\r\n * @param {object|function} x\r\n * @param {function} type\r\n * @return {boolean}\r\n */\r\nfunction is(x, type) {\r\n if (typeof x == 'object') {\r\n if (x instanceof type) return true\r\n if (type.class && x instanceof type.class) return true\r\n if (type.mixin && type.mixin.classes) return type.mixin.classes.reduce((f,c) => f || is(x,c), false)\r\n }\r\n else if (typeof x == 'function') {\r\n if (x.mixin && x.mixin.mixins.indexOf(type) !== -1) return true\r\n let c = x\r\n while (c !== Object) {\r\n if (c === type || c === type.class) return true\r\n if (type.mixin && type.mixin.classes && type.mixin.classes.indexOf(c) !== -1) return true\r\n c = Object.getPrototypeOf(c.prototype).constructor\r\n }\r\n }\r\n return false\r\n}\r\n\r\n/**\r\n * Often, we don't really care whether the object is a certain type,\r\n * we just want to know whether we can treat it like a certain type.\r\n * Use like(subject, type) to test whether a subject adheres to the same interface as is defined by type\r\n * Example:\r\n *\r\n * var Looker = mix(superclass => class Looker extends superclass {\r\n * look() {}\r\n * })\r\n *\r\n * var Viewer = {\r\n * look() {} // same interface as Looker\r\n * }\r\n *\r\n * var viewer = new Viewer()\r\n * like(viewer, Looker) // true\r\n *\r\n * @param {object|function} x\r\n * @param {function} type\r\n * @return {boolean}\r\n */\r\nfunction like(x, type) {\r\n if (is(x, type)) return true\r\n const itf = type.interface || ((typeof type == 'function') && getInterface(type.prototype))\r\n const subject = typeof x == 'function' ? x.interface || getInterface(x.prototype) : x\r\n return itf && Object.keys(itf).reduce((f, k) => \r\n f && ((typeof itf[k] == 'function') ? (typeof subject[k] == 'function') : k in subject), true\r\n )\r\n}\r\n\r\n/**\r\n * Get all parts of an interface as an array of strings\r\n *\r\n * @param {object} proto\r\n * @return {array}\r\n */\r\nfunction getInterface(proto) {\r\n return getPropertyNames(proto).reduce((o,k) => { o[k] = proto[k]; return o }, {})\r\n}\r\n\r\n/**\r\n * Get all properties of an object an an array of strings\r\n *\r\n * @param {object|function} proto\r\n * @return {array}\r\n */\r\nfunction getPropertyNames(proto) {\r\n const results = []\r\n while (proto !== Object.prototype) {\r\n Object.getOwnPropertyNames(proto).reduce((arr,k) => arr.indexOf(k) === -1 ? arr.push(k) && arr : arr, results)\r\n proto = Object.getPrototypeOf(proto).constructor.prototype\r\n }\r\n return results\r\n}\r\n\r\nfunction isMixin(x) {\r\n return (typeof x == 'function') && !!x.mixin\r\n}\r\n\r\nfunction isClass(x) {\r\n if (typeof x != 'function') return false\r\n const s = x.toString()\r\n return /^class\\s/.test(s) || /^.*classCallCheck\\(/.test(s.replace(/^[^{]*{\\s*/,'').replace(/\\s*}[^}]*$/,''))\r\n}\r\n\r\nfunction isFactory(x) {\r\n return (typeof x == 'function') && !isMixin(x) && !isClass(x) && x.length == 1\r\n}\r\n\r\n\r\nconst baseclass = class Object{}\r\nconst derive = superclass => ({}[superclass.name || 'Object'] = class extends superclass {})\r\n\n\n\n// WEBPACK FOOTER //\n// ./index.js"],"sourceRoot":""} -------------------------------------------------------------------------------- /dist/mics.umd.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 3e9f1e3a1533743fa2b8","webpack:///./index.js"],"names":["mix","args","superclass","isFactory","shift","baseclass","factory","length","pop","derive","isMixin","class","org","reduce","s","m","mixin","result","is","classes","indexOf","push","Object","defineProperties","value","writable","mixins","Class","constructor","hasOwnProperty","bind","getOwnPropertyNames","forEach","defineProperty","k","interface","get","x","getInterface","prototype","type","f","c","getPrototypeOf","like","itf","subject","keys","proto","getPropertyNames","o","results","arr","isClass","toString","test","replace","name"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe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7B;AACH;;AAED,SAASrD,SAAT,CAAmBkC,CAAnB,EAAsB;AAClB,WAAQ,OAAOA,CAAP,IAAY,UAAb,IAA4B,CAAC3B,QAAQ2B,CAAR,CAA7B,IAA2C,CAACgB,QAAQhB,CAAR,CAA5C,IAA0DA,EAAE9B,MAAF,IAAY,CAA7E;AACH;;AAGD,IAAMF;AAAA;AAAA,CAAN;AACA,IAAMI,SAAS,SAATA,MAAS;AAAA,WAAe,GAAGP,WAAWuD,IAAX,IAAmB,QAAtB;AAAA;;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA,MAAgDvD,UAAhD,CAAf;AAAA,CAAf,C","file":"mics.umd.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 3e9f1e3a1533743fa2b8","export { mix, is, like }\r\n\r\n/**\r\n * Accepts an optional superclass as the first argument,\r\n * then a bunch of mixins and an optional class factory as the last argument and returns a mixin.\r\n * Mostly, you will be using mix with a factory to create mixins, like this:\r\n *\r\n * var Looker = mix(superclass => class Looker extends superclass {\r\n * constructor() {\r\n * super()\r\n * console.info('A looker is born!')\r\n * }\r\n * look() {\r\n * console.info('Looking good!')\r\n * }\r\n * })\r\n *\r\n * @param {function} args\r\n * Consists of the following three argument groups:\r\n * {function} superclass (optional)\r\n * {function} mixins... (0 or more)\r\n * {function} factory (optional)\r\n * @return {function}\r\n */\r\nfunction mix(...args) {\r\n // todo: refactor to make const\r\n let superclass = !isFactory(args[0]) && args.shift() || baseclass\r\n let factory = (isFactory(args[args.length-1]) && args.pop()) || derive\r\n superclass = isMixin(superclass) ? superclass.class : derive(superclass)\r\n if (args.length) factory = (org => superclass => org(args.reduce((s,m) => m.mixin(s), superclass)))(factory)\r\n\r\n function mixin(superclass) {\r\n const result = is(superclass, mixin) ? superclass : factory(superclass)\r\n if (mixin.classes.indexOf(result) === -1) mixin.classes.push(result)\r\n return result\r\n }\r\n\r\n Object.defineProperties(mixin, {\r\n classes: { value:[], writable:false },\r\n mixins: { value:args, writable:false },\r\n })\r\n const Class = mixin(superclass)\r\n const constructor = Class.hasOwnProperty('constructor')\r\n ? Class.constructor.bind(Class)\r\n : (...args) => new Class(...args)\r\n Object.getOwnPropertyNames(Class).forEach(k => Object.defineProperty(constructor, k, { value: Class[k] }))\r\n return Object.defineProperties(constructor, {\r\n mixin: { value:mixin, writable:false },\r\n class: { value: Class, writable:false },\r\n interface: { get:(x => () => x ? x : x = getInterface(Class.prototype))() },\r\n })\r\n}\r\n\r\n/**\r\n * Tests whether `x` is a type or extends from type.\r\n * Example: is(looker, Looker)\r\n *\r\n * @param {object|function} x\r\n * @param {function} type\r\n * @return {boolean}\r\n */\r\nfunction is(x, type) {\r\n if (typeof x == 'object') {\r\n if (x instanceof type) return true\r\n if (type.class && x instanceof type.class) return true\r\n if (type.mixin && type.mixin.classes) return type.mixin.classes.reduce((f,c) => f || is(x,c), false)\r\n }\r\n else if (typeof x == 'function') {\r\n if (x.mixin && x.mixin.mixins.indexOf(type) !== -1) return true\r\n let c = x\r\n while (c !== Object) {\r\n if (c === type || c === type.class) return true\r\n if (type.mixin && type.mixin.classes && type.mixin.classes.indexOf(c) !== -1) return true\r\n c = Object.getPrototypeOf(c.prototype).constructor\r\n }\r\n }\r\n return false\r\n}\r\n\r\n/**\r\n * Often, we don't really care whether the object is a certain type,\r\n * we just want to know whether we can treat it like a certain type.\r\n * Use like(subject, type) to test whether a subject adheres to the same interface as is defined by type\r\n * Example:\r\n *\r\n * var Looker = mix(superclass => class Looker extends superclass {\r\n * look() {}\r\n * })\r\n *\r\n * var Viewer = {\r\n * look() {} // same interface as Looker\r\n * }\r\n *\r\n * var viewer = new Viewer()\r\n * like(viewer, Looker) // true\r\n *\r\n * @param {object|function} x\r\n * @param {function} type\r\n * @return {boolean}\r\n */\r\nfunction like(x, type) {\r\n if (is(x, type)) return true\r\n const itf = type.interface || ((typeof type == 'function') && getInterface(type.prototype))\r\n const subject = typeof x == 'function' ? x.interface || getInterface(x.prototype) : x\r\n return itf && Object.keys(itf).reduce((f, k) => \r\n f && ((typeof itf[k] == 'function') ? (typeof subject[k] == 'function') : k in subject), true\r\n )\r\n}\r\n\r\n/**\r\n * Get all parts of an interface as an array of strings\r\n *\r\n * @param {object} proto\r\n * @return {array}\r\n */\r\nfunction getInterface(proto) {\r\n return getPropertyNames(proto).reduce((o,k) => { o[k] = proto[k]; return o }, {})\r\n}\r\n\r\n/**\r\n * Get all properties of an object an an array of strings\r\n *\r\n * @param {object|function} proto\r\n * @return {array}\r\n */\r\nfunction getPropertyNames(proto) {\r\n const results = []\r\n while (proto !== Object.prototype) {\r\n Object.getOwnPropertyNames(proto).reduce((arr,k) => arr.indexOf(k) === -1 ? arr.push(k) && arr : arr, results)\r\n proto = Object.getPrototypeOf(proto).constructor.prototype\r\n }\r\n return results\r\n}\r\n\r\nfunction isMixin(x) {\r\n return (typeof x == 'function') && !!x.mixin\r\n}\r\n\r\nfunction isClass(x) {\r\n if (typeof x != 'function') return false\r\n const s = x.toString()\r\n return /^class\\s/.test(s) || /^.*classCallCheck\\(/.test(s.replace(/^[^{]*{\\s*/,'').replace(/\\s*}[^}]*$/,''))\r\n}\r\n\r\nfunction isFactory(x) {\r\n return (typeof x == 'function') && !isMixin(x) && !isClass(x) && x.length == 1\r\n}\r\n\r\n\r\nconst baseclass = class Object{}\r\nconst derive = superclass => ({}[superclass.name || 'Object'] = class extends superclass {})\r\n\n\n\n// WEBPACK FOOTER //\n// ./index.js"],"sourceRoot":""} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mics 0.7.0 2 | ### Multiple Inheritance Class System 3 | 4 | [![Greenkeeper badge](https://badges.greenkeeper.io/Download/mics.svg)](https://greenkeeper.io/) 5 | **Intuitive mixins for ES6 classes** 6 | 7 | [![npm](https://img.shields.io/npm/v/mics.svg)](https://npmjs.com/package/mics) 8 | [![license](https://img.shields.io/npm/l/mics.svg)](https://creativecommons.org/licenses/by/4.0/) 9 | [![travis](https://img.shields.io/travis/Download/mics.svg)](https://travis-ci.org/Download/mics) 10 | [![greenkeeper](https://img.shields.io/david/Download/mics.svg)](https://greenkeeper.io/) 11 | ![mind BLOWN](https://img.shields.io/badge/mind-BLOWN-ff69b4.svg) 12 | 13 | ![MICS logo](https://cdn.rawgit.com/download/mics/0.6.3/mics.jpg) 14 | 15 | > Multiple Inheritance is like a parachute. You don't often need it, but when you do, you really need it. 16 | *Grady Booch* 17 | 18 | ## What is it 19 | **mics** *(pronounce: mix)* is a library that makes multiple inheritance in Javascript a breeze. 20 | Inspired by the excellent blog post ["Real" Mixins with Javascript Classes](http://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/) 21 | by Justin Fagnani, **mics** tries to build a minimal library around the concept of using class 22 | expressions (factories) as mixins. **mics** extends the concepts presented in the blog post by 23 | making the mixins first-class citizens that can be directly used to instantiate objects and can 24 | be mixed in with other mixins instead of just with classes. 25 | 26 | 27 | ## Install with NPM 28 | ```sh 29 | npm install --save mics 30 | ``` 31 | 32 | ## Direct download 33 | * [mics.umd.js](https://cdn.rawgit.com/download/mics/0.7.0/dist/mics.umd.js) (universal module works in browser and node) 34 | * [mics.min.js](https://cdn.rawgit.com/download/mics/0.7.0/dist/mics.min.js) (minified version of universal module file) 35 | 36 | 37 | ## Include in your app 38 | 39 | ### import 40 | ```js 41 | import { mix, is, like } from 'mics' 42 | ``` 43 | 44 | ### require 45 | ```js 46 | var mix = require('mics').mix 47 | var is = require('mics').is 48 | var like = require('mics').like 49 | ``` 50 | 51 | ### AMD 52 | ```js 53 | define(['mics'], function(mics){ 54 | var mix = mics.mix 55 | var is = mics.is 56 | var like = mics.like 57 | }); 58 | ``` 59 | 60 | ### Script tag 61 | ```html 62 | 63 | 68 | ``` 69 | 70 | ## Usage 71 | ### Creating a mixin 72 | ![](https://raw.githubusercontent.com/download/mics/0.6.3/mixins-are-classes-on-steroids.jpg) 73 | 74 | Mixins are like classes on steroids. They look and feel a lot like ES6 classes, 75 | but they have some additional capabilities that ES6 classes do not have: 76 | * They can 'extend' from multiple other mixins including (at most one) ES6 class 77 | * They have an explicit `interface` which can be inspected and tested at runtime 78 | * They *have* an ES6 `class` that is used to create instances 79 | * They have a `mixin` function that mixes in their class body into another type. 80 | * They can be invoked without `new` to create new instances 81 | 82 | > **mixin**: An ES5 constructor function that has properties `mixin`, `class` and `interface`. 83 | 84 | You create mixins with the `mix` function. 85 | 86 | #### mix([superclass] [, ...mixins] [, factory]) 87 | `mix` accepts an optional *superclass* as the first argument, then a bunch of *mixin*s 88 | and an optional *class factory* as the last argument and returns a mixin. 89 | 90 | Mostly, you will be using `mix` with a factory to create mixins, like this: 91 | 92 | ```js 93 | import { mix, is, like } from 'mics' 94 | 95 | var Looker = mix(superclass => class Looker extends superclass { 96 | constructor() { 97 | super() 98 | console.info('A looker is born!') 99 | } 100 | look() { 101 | console.info('Looking good!') 102 | } 103 | }) 104 | 105 | typeof Looker // 'function' 106 | typeof Looker.mixin // 'function' 107 | typeof Looker.class // 'function' 108 | typeof Looker.interface // 'object' 109 | ``` 110 | 111 | Notice that the argument to `mix` is an arrow function that accepts a superclass and 112 | returns a class that extends the given superclass. The body of the mixin is defined in 113 | the returned class. We call this a *class factory*. 114 | 115 | > **Class factory**: An arrow function that accepts a `superclass` and returns a `class extends superclass`. 116 | 117 | The `mix` function creates a mixing function based on the given mixins and the class 118 | factory and invokes it with the given superclass to create the ES6 class backing the mixin. 119 | It then creates an ES5 constructor function that uses the ES6 class to create and return 120 | new instances of the mixin. Finally it constructs the mixin's interface from the class 121 | prototype and attaches the `mixin` function, the `class` and the `interface` to the ES5 122 | constructor function, creating what in the context of **mics** we call a mixin. 123 | 124 | 125 | ### Creating instances of mixins 126 | We can directly use the created mixin to create instances, because it is just a constructor function: 127 | 128 | ```js 129 | var looker = new Looker() // > A looker is born! 130 | looker.look() // > Looking good! 131 | looker instanceof Looker // true 132 | ``` 133 | 134 | And because it's an ES5 constructor function, we are allowed to invoke it without `new`: 135 | 136 | ```js 137 | var looker = Looker() // > A looker is born! 138 | looker.look() // > Looking good! 139 | ``` 140 | 141 | > ES6 made newless invocation of constructors throw an error for ES6 classes, because 142 | > in ES5 it was often a cause for bugs when programmers forgot `new` with constructors 143 | > that assumed `new` was used. However I (with many others) believe that not using `new` 144 | > is actually better for writing maintainable code. So mics makes sure that it's 145 | > constructors work whether you use `new` on them or not, because the backing ES6 class 146 | > is always invoked with `new` as it should be. Whether you want to write `new` or not 147 | > in your code is up to you. 148 | 149 | ### Mixing multiple mixins into a new mixin 150 | Let us define mixins `Walker` and `Talker` to supplement our `Looker`: 151 | 152 | ```js 153 | var Walker = mix(superclass => class Walker extends superclass { 154 | walk() { 155 | console.info('Step, step, step') 156 | } 157 | }) 158 | 159 | var Talker = mix(superclass => class Talker extends superclass{ 160 | talk(){ 161 | console.info('Blah, blah, blah') 162 | } 163 | }) 164 | ``` 165 | 166 | Now that we have a bunch of mixins, we can start to use them to achieve multiple inheritance: 167 | 168 | ```js 169 | var Duck = mix(Looker, Walker, Talker, superclass => class Duck extends superclass { 170 | talk() { 171 | var org = super.talk() 172 | console.info('Quack, quack, quack (Duckian for "' + org + '")') 173 | } 174 | }) 175 | 176 | var donald = Duck() 177 | donald.talk() // > Quack, quack, quack (Duckian for "Blah, blah, blah") 178 | ``` 179 | 180 | As you can see, we can override methods and use `super` to call the superclass method, 181 | just like we can with normal ES6 classes. 182 | 183 | ### Testing if an object is (like) a mixin or class 184 | `instanceof` works for mixin instances like it does for ES6 classes. But, like ES6 185 | classes, it does not support multiple inheritance. In the example above, `Looker` 186 | is effectively the superclass for `Duck`. `Walker` and `Talker` are mixed into `Duck` 187 | by dynamically creating *new* classes and injecting them into the inheritance chain 188 | between `Looker` and `Duck`. Because these are *new* classes, instances of them are 189 | not recognized by `instanceof` as instances of `Walker` and `Talker`. 190 | 191 | Fortunately, **mics** gives us an `is` function, which does understand multiple inheritance. 192 | 193 | #### is(subject, type) 194 | Tests whether `subject` is-a `type` or extends from `type`. 195 | The first parameter to `is` defines the subject to test. This can be an instance or 196 | a type. The second parameter is either a type (constructor function, ES6 class or mixin) 197 | or a type string. 198 | 199 | ```js 200 | duck instanceof Duck // true 201 | duck instanceof Looker // true, but: 202 | duck instanceof Walker // false! mix created a *new class* based on the factory 203 | 204 | // `is` to the rescue! 205 | is(duck, Walker) // true 206 | // we can also test the type 207 | is(Duck, Walker) // true 208 | is(Talker, Walker) // false 209 | ``` 210 | 211 | #### like(subject, type) 212 | Often, we don't really care whether the object *is* a certain type, we just want to know 213 | whether we can treat it *like* a certain type. Use `like(subject, type)` to test whether 214 | a subject adheres to the same interface as is defined by `type`: 215 | 216 | ```js 217 | var viewer = { // create an object with the 218 | look(){} // same interface as Looker 219 | } 220 | is(viewer, Looker) // false, but 221 | like(viewer, Looker) // true 222 | ``` 223 | 224 | A good example of how this might be useful can be found in the new ES6 feature Promises. 225 | Here we have the concept of a 'thenable'. This is any object that has a `then` method on 226 | it. Methods in the Promise API often accept thenables instead of promise instances. Have 227 | a look at `Promise.resolve` for example: 228 | 229 | > Promise.resolve(value) 230 | > Returns a Promise object that is resolved with the given value. If the value is a 231 | > thenable (i.e. has a `then` method), the returned promise will "follow" that thenable, 232 | > adopting its eventual state; otherwise the returned promise will be fulfilled with the value. 233 | [mdn](https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/Promise) 234 | 235 | Using `mix` to define an interface and `like` to test for it, we can very naturally 236 | express the concept of a thenable from the Promise spec in code: 237 | 238 | ```js 239 | /** Defines a Thenable */ 240 | var Thenable = mix(superclass => class Thenable extends superclass { 241 | then() {} 242 | }) 243 | /** Some mixin which can be treated as a Thenable */ 244 | var MyPromise = mix(superclass => class MyPromise extends superclass { 245 | then(resolve, reject) { 246 | resolve('Hello, World!') 247 | } 248 | } 249 | // We can check whether the class is thenable using like 250 | like(MyPromise, Thenable) // true 251 | // we can also check instances 252 | var promise = new MyPromise() 253 | like(promise, Thenable) // true 254 | // Ok, that means we can use Promise.resolve! 255 | Promise.resolve(promise).then((result) => { 256 | console.info(result) // > 'Hello, World!' 257 | }) 258 | ``` 259 | 260 | ### Using a custom ES5 constructor 261 | The default constructor returned from `mix` is a one-liner that invokes the ES6 262 | class with `new`. But there could be reasons to use a different function instead. 263 | `mix` allows you to supply a custom constructor to be used instead. You do this 264 | by providing a `static constructor` in the class body: 265 | 266 | ```js 267 | var Custom = mix(superclass => class Custom extends superclass{ 268 | static constructor(...args){ 269 | console.info('Custom constructor called!') 270 | return new this(...args) 271 | } 272 | }) 273 | 274 | var test = Custom() // > 'Custom constructor called!' 275 | is(test, Custom) // true 276 | ``` 277 | 278 | ### Bonus 279 | As a bonus, you can use `is()` to do some simple type tests by passing a 280 | string for the type: 281 | 282 | ```js 283 | class X {} 284 | var factory = superclass => class Y extends superclass {} 285 | var Y = mix(factory) 286 | var Z = mix(X, Y) 287 | 288 | is(X, 'function') // true 289 | is(X, 'class') // true 290 | is(X, 'mixin') // false 291 | is(X, 'factory') // false 292 | 293 | is(factory, 'function') // true 294 | is(factory, 'class') // false 295 | is(factory, 'mixin') // false 296 | is(factory, 'factory') // true 297 | 298 | is(Y, 'function') // true 299 | is(Y, 'class') // false 300 | is(Y, 'mixin') // true 301 | is(Y, 'factory') // false 302 | 303 | is(Z, 'function') // true 304 | is(Z, 'class') // false 305 | is(Z, 'mixin') // true 306 | is(Z, 'factory') // false 307 | ``` 308 | 309 | Supported type strings: `"class"`, `"mixin"`, `"factory"`, and any type strings 310 | that can be passed to `typeof`. 311 | * class: x is a (possibly Babel-transpiled) ES6 class 312 | * mixin: x is a mixin that is the result of calling `mix` 313 | * factory: x is a class factory function 314 | 315 | ## Issues 316 | Add an issue in this project's [issue tracker](https://github.com/download/mics/issues) 317 | to let me know of any problems you find, or questions you may have. 318 | 319 | ## Credits 320 | Credits go to [Justin Fagnani](http://justinfagnani.com) for his excellent blog post ["Real" Mixins with JavaScript Classes](http://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/) and the accompanying library 321 | [mixwith.js](https://github.com/justinfagnani/mixwith.js). 322 | 323 | ## Contributors 324 | Many thanks to [Marco Alka](https://marco-alka.de/) for his contributions to this project. 325 | 326 | ## Copyright 327 | Copyright 2017 by [Stijn de Witt](https://StijnDeWitt.com) and contributors. Some rights reserved. 328 | 329 | ## License 330 | Licensed under the [Creative Commons Attribution 4.0 International (CC-BY-4.0)](https://creativecommons.org/licenses/by/4.0/) Open Source license. 331 | -------------------------------------------------------------------------------- /src/index.spec.js: -------------------------------------------------------------------------------- 1 | import ulog from 'ulog' 2 | import { expect } from 'chai' 3 | import { spy } from 'sinon' 4 | import t from 'tcomb' 5 | 6 | import { mix, is, like } from './' 7 | 8 | const log = ulog('mics:spec') 9 | 10 | describe('mix([superclass] [, ...mixins] [, factory])', function() { 11 | it('is a function', function(){ 12 | expect(mix).to.be.a('function') 13 | }) 14 | 15 | it('creates a mixin from a class factory', function(){ 16 | const M = mix(superclass => class M extends superclass {}) 17 | 18 | expect(M).to.be.a('function') 19 | }) 20 | 21 | it('creates a mixin from other mixins and a class factory', function(){ 22 | const X = mix(superclass => class X extends superclass {}) 23 | const Y = mix(superclass => class X extends superclass {}) 24 | const M = mix(X, Y, superclass => class M extends superclass {}) 25 | 26 | expect(M).to.be.a('function') 27 | }) 28 | 29 | it('creates a mixin from other mixins', function(){ 30 | const X = mix(superclass => class X extends superclass {}) 31 | const Y = mix(superclass => class X extends superclass {}) 32 | const M = mix(X, Y) 33 | 34 | expect(isMixin(M)).to.eq(true) 35 | }) 36 | 37 | it('creates a mix from a superclass', function(){ 38 | let C = mix(class Base {}) 39 | 40 | expect(C).to.be.a('function') 41 | expect(isMixin(C)).to.eq(true) 42 | // special case: class with one-arg constructor looks like a factory 43 | class Base {constructor(){}} 44 | C = mix(Base) 45 | expect(C).to.be.a('function') 46 | expect(isMixin(C)).to.eq(true) 47 | expect(new C() instanceof Base).to.eq(true) 48 | }) 49 | 50 | it('creates a mix from a mixed superclass', function(){ 51 | const C = mix(class Base {}) 52 | const D = mix(C) 53 | 54 | expect(isMixin(C)).to.eq(true) 55 | expect(isMixin(D)).to.eq(true) 56 | expect(new D() instanceof D).to.eq(true) 57 | }) 58 | 59 | it('created mixins can be invoked with new to instantiate instances', function(){ 60 | const M = mix(superclass => class M extends superclass {}) 61 | const m = new M() 62 | 63 | expect(m).to.be.an('object') 64 | }) 65 | 66 | it('created mixins can be invoked without new to instantiate instances', function(){ 67 | const M = mix(superclass => class M extends superclass {}) 68 | const m = M() 69 | 70 | expect(m).to.be.an('object') 71 | }) 72 | 73 | it('arguments passed when invoking the mixin with new are passed on to the constructor', function(){ 74 | let xarg,yarg,zarg 75 | const M = mix(superclass => class M extends superclass { 76 | constructor(x, y, z) { 77 | super() 78 | xarg = x 79 | yarg = y 80 | zarg = z 81 | } 82 | }) 83 | 84 | new M('x','y','z') 85 | 86 | expect(xarg).to.eq('x') 87 | expect(yarg).to.eq('y') 88 | expect(zarg).to.eq('z') 89 | }) 90 | 91 | it('arguments passed when invoking the mixin without new are passed on to the constructor', function(){ 92 | let xarg,yarg,zarg 93 | const M = mix(superclass => class M extends superclass { 94 | constructor(x, y, z) { 95 | super() 96 | xarg = x 97 | yarg = y 98 | zarg = z 99 | } 100 | }) 101 | 102 | new M('x','y','z') 103 | expect(xarg).to.eq('x') 104 | expect(yarg).to.eq('y') 105 | expect(zarg).to.eq('z') 106 | }) 107 | 108 | it('var args in constructor has correct length when invoking with new', function(){ 109 | let argsarg 110 | const M = mix(superclass => class M extends superclass { 111 | constructor(...args) { 112 | super() 113 | argsarg = args 114 | } 115 | }) 116 | 117 | new M('x','y','z') 118 | expect(argsarg.length).to.eq(3) 119 | 120 | new M() 121 | expect(argsarg.length).to.eq(0) 122 | }) 123 | 124 | it('var args in constructor has correct length when invoking without new', function(){ 125 | let argsarg 126 | const M = mix(superclass => class M extends superclass { 127 | constructor(...args) { 128 | super() 129 | argsarg = args 130 | } 131 | }) 132 | 133 | M('x','y','z') 134 | expect(argsarg.length).to.eq(3) 135 | 136 | M() 137 | expect(argsarg.length).to.eq(0) 138 | }) 139 | 140 | it('result of invoking constructor with new is instanceof mixin', function(){ 141 | const M = mix(superclass => class M extends superclass {}) 142 | const m = new M('x','y','z') 143 | 144 | expect(m instanceof M).to.eq(true) 145 | }) 146 | 147 | it('result of invoking constructor without new is instanceof mixin', function(){ 148 | const M = mix(superclass => class M extends superclass {}) 149 | const m = M('x','y','z') 150 | 151 | expect(m instanceof M).to.eq(true) 152 | }) 153 | 154 | it('picks up a static class method `constructor` and uses it in place of the default constructor', function(){ 155 | const check = spy() 156 | const M = mix(superclass => class M extends superclass { 157 | static constructor(...args) { 158 | // todo: missing superclass constructor invocation? 159 | // stijn: this is not a normal constructor but a 'static' constructor... 160 | // It is the ES5 function that is returned by `mix`, can be invoked without 161 | // `new` and in turn calls the 'real' ES6 constructor. 162 | // Unless you make a static constructor like in this test, `mix` will 163 | // generate an ES5 constructor function for you on the fly. This mechanism 164 | // allows you to customize that. The call to `new this(...args)` will 165 | // call the ES6 constructor which will call super as usual. 166 | log.log('Custom constructor') 167 | check() 168 | return new this(...args) 169 | } 170 | }) 171 | 172 | M() 173 | expect(check.called).to.eq(true) 174 | }) 175 | 176 | it('has no side effects on it\'s arguments', function(){ 177 | class Test{} 178 | expect(isMixin(Test)).to.eq(false) 179 | const M = mix(Test) 180 | 181 | expect(isMixin(M)).to.eq(true) 182 | expect(isMixin(Test)).to.eq(false) 183 | const N = mix(Test, superclass => class N extends superclass {}) 184 | 185 | expect(isMixin(N)).to.eq(true) 186 | expect(isMixin(Test)).to.eq(false) 187 | }) 188 | }) 189 | 190 | 191 | describe('is(x , type)', function(){ 192 | it('is a function', function(){ 193 | expect(is).to.be.a('function') 194 | }) 195 | 196 | it('accepts one or two arguments', function(){ 197 | expect(is.length).to.eq(2) 198 | }) 199 | 200 | it('tests whether object `x` implements `type`', function(){ 201 | const X = mix(superclass => class X extends superclass {}) 202 | const x = new X() 203 | 204 | expect(is(x, X)).to.eq(true) 205 | expect(is(x, Date)).to.eq(false) 206 | }) 207 | it('tests whether class `x` implements `type`', function(){ 208 | const Y = mix(superclass => class Y extends superclass {}) 209 | const X = class X extends mix(Y) {} 210 | 211 | expect(is(X, Y)).to.eq(true) 212 | }) 213 | it('tests whether mixin `x` implements `type`', function(){ 214 | const Y = mix(superclass => class Y extends superclass {}) 215 | const X = mix(Y, superclass => class X extends superclass {}) 216 | 217 | expect(is(X, Y)).to.eq(true) 218 | }) 219 | }) 220 | 221 | describe('like(type)', function(){ 222 | it('is a function', function(){ 223 | expect(like).to.be.a('function') 224 | }) 225 | it('tests whether `x` can be treated as `type` (has the same interface)', function(){ 226 | const Looker = mix(superclass => class Looker extends superclass { 227 | look(){} 228 | }) 229 | 230 | expect(like('Hi', Looker)).to.eq(false) 231 | expect(like(8, Looker)).to.eq(false) 232 | expect(like({}, Looker)).to.eq(false) 233 | expect(like(new Looker(), Looker)).to.eq(true) 234 | expect(like({ look(){} }, Looker)).to.eq(true) 235 | expect(like({ walk(){} }, Looker)).to.eq(false) 236 | class Base {look(){}} 237 | expect(like(Base, Looker)).to.eq(true) 238 | expect(like(new Base(), Looker)).to.eq(true) 239 | class Derived extends Base {} 240 | expect(like(Derived, Looker)).to.eq(true) 241 | expect(like(new Derived(), Looker)).to.eq(true) 242 | }) 243 | 244 | it('allows mixins to be used as interfaces', (done) => { 245 | const expected = 'Hello, World!' 246 | const Thenable = mix(superclass => class Thenable extends superclass { 247 | then() {} 248 | }) 249 | 250 | class MyPromise { 251 | then(resolve) { 252 | resolve(expected) 253 | } 254 | } 255 | 256 | const promise = new MyPromise() 257 | 258 | expect(like(promise, Thenable)).to.eq(true) 259 | Promise.resolve(promise).then((result) => { 260 | expect(result).to.eq(expected) 261 | done() 262 | }) 263 | }) 264 | }) 265 | 266 | describe('mix example', function(){ 267 | it ('shows how to create a mixin using an es6 class', function(){ 268 | const constr = spy() 269 | const look = spy() 270 | 271 | const Looker = mix(superclass => class Looker extends superclass { 272 | constructor() { 273 | super() 274 | log.log('A looker is born!') 275 | constr() 276 | } 277 | look() { 278 | log.log('Looking good!') 279 | look() 280 | } 281 | }) 282 | 283 | expect(Looker).to.be.a('function') 284 | 285 | const looker = new Looker() 286 | 287 | expect(looker).to.be.an('object') 288 | expect(constr.called).to.eq(true) 289 | 290 | expect(looker).to.have.a.property('look') 291 | expect(looker.look).to.be.a('function') 292 | 293 | looker.look() 294 | 295 | expect(look.called).to.eq(true) 296 | }) 297 | 298 | it('shows how to composes multiple mixins', function(){ 299 | const look = spy() 300 | const walk = spy() 301 | const talk = spy() 302 | const Looker = mix(superclass => class Looker extends superclass { 303 | look(){ 304 | log.log('Looking good!') 305 | look() 306 | } 307 | }) 308 | 309 | const Walker = mix(superclass => class Walker extends superclass { 310 | walk(){ 311 | log.log('Step, step, step...') 312 | walk() 313 | } 314 | }) 315 | 316 | const Talker = mix(superclass => class Talker extends superclass { 317 | talk(){ 318 | log.log('Blah, blah, blah...') 319 | talk() 320 | } 321 | }) 322 | 323 | const duckTalk = spy() 324 | 325 | const Duck = mix(Looker, Walker, Talker, superclass => class Duck extends superclass { 326 | talk(){ 327 | log.log('Quack, quack, quack!') 328 | duckTalk() 329 | super.talk() 330 | } 331 | }) 332 | 333 | const duck = new Duck() 334 | 335 | expect(duck).to.be.an('object') 336 | expect(duck instanceof Duck).to.eq(true) 337 | expect(duck instanceof Looker).to.eq(true) 338 | expect(duck instanceof Walker).to.eq(false) 339 | 340 | 341 | expect(duck).to.have.a.property('look') 342 | expect(duck.look).to.be.a('function') 343 | duck.look() 344 | expect(look.called).to.eq(true) 345 | 346 | expect(duck).to.have.a.property('walk') 347 | expect(duck.walk).to.be.a('function') 348 | duck.walk() 349 | expect(walk.called).to.eq(true) 350 | 351 | expect(duck).to.have.a.property('talk') 352 | expect(duck.talk).to.be.a('function') 353 | duck.talk() 354 | expect(talk.called).to.eq(true) 355 | expect(duckTalk.called).to.eq(true) 356 | }) 357 | }) 358 | 359 | 360 | describe('type checked mixins with tcomb', function(){ 361 | it ('shows how to create an immutable, type-checked mixin with tcomb', function(){ 362 | // This is experimental... I think it shows we need to be able to hook into the 363 | // mixin process itself. To enable this example I already added a hook for the 364 | // ES5 constructor function: the `static constructor` will be picked up by `mix` 365 | // and used as the result instead of the default generated constructor. 366 | const a = spy() 367 | const b = spy() 368 | const Person = mix(superclass => class Person extends superclass { 369 | static get type() { 370 | if (!this._tcomb) this._tcomb = t.struct({ 371 | name: t.String, // required string 372 | surname: t.maybe(t.String), // optional string 373 | age: t.Integer, // required integer 374 | tags: t.list(t.String) // a list of strings 375 | }, 'Person') 376 | return this._tcomb 377 | } 378 | 379 | static testA() { 380 | a() 381 | log.log('A') 382 | } 383 | 384 | static testB() { 385 | this.testA() 386 | b() 387 | log.log('B') 388 | } 389 | 390 | static constructor(...args) { 391 | // todo: missing superclass constructor call? 392 | return this.type(new this(...args)) 393 | } 394 | 395 | constructor(...args) { 396 | super(...args) 397 | Object.assign(this, ...args) 398 | } 399 | }) 400 | 401 | expect(function(){ 402 | Person({ 403 | surname: 'Canti' 404 | }); 405 | }).to.throw(TypeError) // required fields missing 406 | 407 | expect(function(){ 408 | Person({ 409 | name: 'Stijn', 410 | age: 40, 411 | tags: ['developer'] 412 | }); 413 | }).to.not.throw() // ok 414 | 415 | expect(function(){ 416 | const person = Person({ 417 | name: 'Stijn', 418 | age: 40, 419 | tags: ['developer'] 420 | }); 421 | 422 | person.age = 41 423 | }).to.throw(TypeError) // immutable 424 | 425 | expect(function(){ 426 | Person.testB() 427 | expect (a.called).to.eq(true) 428 | expect (b.called).to.eq(true) 429 | }).to.not.throw() // ok 430 | }) 431 | }) 432 | 433 | // Helper copied straight from `mics`. Was used in some tests so this is easiest 434 | function isMixin(x) { 435 | return (typeof x == 'function') && !!x.mixin 436 | } 437 | 438 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ## creative commons 2 | 3 | # Attribution 4.0 International 4 | 5 | Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible. 6 | 7 | ### Using Creative Commons Public Licenses 8 | 9 | Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses. 10 | 11 | * __Considerations for licensors:__ Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC-licensed material, or material used under an exception or limitation to copyright. [More considerations for licensors](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensors). 12 | 13 | * __Considerations for the public:__ By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor’s permission is not necessary for any reason–for example, because of any applicable exception or limitation to copyright–then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. [More considerations for the public](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensees). 14 | 15 | ## Creative Commons Attribution 4.0 International Public License 16 | 17 | By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. 18 | 19 | ### Section 1 – Definitions. 20 | 21 | a. __Adapted Material__ means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. 22 | 23 | b. __Adapter's License__ means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. 24 | 25 | c. __Copyright and Similar Rights__ means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 26 | 27 | d. __Effective Technological Measures__ means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. 28 | 29 | e. __Exceptions and Limitations__ means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. 30 | 31 | f. __Licensed Material__ means the artistic or literary work, database, or other material to which the Licensor applied this Public License. 32 | 33 | g. __Licensed Rights__ means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. 34 | 35 | h. __Licensor__ means the individual(s) or entity(ies) granting rights under this Public License. 36 | 37 | i. __Share__ means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. 38 | 39 | j. __Sui Generis Database Rights__ means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. 40 | 41 | k. __You__ means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. 42 | 43 | ### Section 2 – Scope. 44 | 45 | a. ___License grant.___ 46 | 47 | 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: 48 | 49 | A. reproduce and Share the Licensed Material, in whole or in part; and 50 | 51 | B. produce, reproduce, and Share Adapted Material. 52 | 53 | 2. __Exceptions and Limitations.__ For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. 54 | 55 | 3. __Term.__ The term of this Public License is specified in Section 6(a). 56 | 57 | 4. __Media and formats; technical modifications allowed.__ The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. 58 | 59 | 5. __Downstream recipients.__ 60 | 61 | A. __Offer from the Licensor – Licensed Material.__ Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. 62 | 63 | B. __No downstream restrictions.__ You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 64 | 65 | 6. __No endorsement.__ Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). 66 | 67 | b. ___Other rights.___ 68 | 69 | 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 70 | 71 | 2. Patent and trademark rights are not licensed under this Public License. 72 | 73 | 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties. 74 | 75 | ### Section 3 – License Conditions. 76 | 77 | Your exercise of the Licensed Rights is expressly made subject to the following conditions. 78 | 79 | a. ___Attribution.___ 80 | 81 | 1. If You Share the Licensed Material (including in modified form), You must: 82 | 83 | A. retain the following if it is supplied by the Licensor with the Licensed Material: 84 | 85 | i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); 86 | 87 | ii. a copyright notice; 88 | 89 | iii. a notice that refers to this Public License; 90 | 91 | iv. a notice that refers to the disclaimer of warranties; 92 | 93 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 94 | 95 | B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and 96 | 97 | C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 98 | 99 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 100 | 101 | 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. 102 | 103 | 4. If You Share Adapted Material You produce, the Adapter's License You apply must not prevent recipients of the Adapted Material from complying with this Public License. 104 | 105 | ### Section 4 – Sui Generis Database Rights. 106 | 107 | Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: 108 | 109 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database; 110 | 111 | b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material; and 112 | 113 | c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. 114 | 115 | For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. 116 | 117 | ### Section 5 – Disclaimer of Warranties and Limitation of Liability. 118 | 119 | a. __Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.__ 120 | 121 | b. __To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.__ 122 | 123 | c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. 124 | 125 | ### Section 6 – Term and Termination. 126 | 127 | a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. 128 | 129 | b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: 130 | 131 | 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 132 | 133 | 2. upon express reinstatement by the Licensor. 134 | 135 | For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. 136 | 137 | c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. 138 | 139 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 140 | 141 | ### Section 7 – Other Terms and Conditions. 142 | 143 | a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. 144 | 145 | b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. 146 | 147 | ### Section 8 – Interpretation. 148 | 149 | *a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. 150 | 151 | b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. 152 | 153 | c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. 154 | 155 | d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. 156 | 157 | ``` 158 | Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at [creativecommons.org/policies](http://creativecommons.org/policies), Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. 159 | 160 | Creative Commons may be contacted at creativecommons.org 161 | ``` -------------------------------------------------------------------------------- /dist/mics.min.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///mics.min.js","webpack:///webpack/bootstrap f11b09d4bce329eb33c7","webpack:///./index.js"],"names":["root","factory","exports","module","define","amd","a","i","this","modules","__webpack_require__","moduleId","installedModules","l","call","m","c","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","__webpack_exports__","_possibleConstructorReturn","self","ReferenceError","_inherits","subClass","superClass","TypeError","create","constructor","value","writable","setPrototypeOf","__proto__","_classCallCheck","instance","Constructor","mix","mixin","superclass","result","is","classes","indexOf","push","_len","arguments","length","args","Array","_key","isFactory","shift","baseclass","pop","derive","isMixin","class","org","reduce","defineProperties","mixins","Class","bind","_len2","_key2","Function","apply","concat","getOwnPropertyNames","forEach","k","interface","x","getInterface","type","_typeof","f","getPrototypeOf","like","itf","subject","keys","proto","getPropertyNames","results","arr","isClass","toString","test","replace","Symbol","iterator","obj","_superclass","_class"],"mappings":"CAAA,SAAAA,EAAAC,GACA,mBAAAC,UAAA,gBAAAC,QACAA,OAAAD,QAAAD,QACA,sBAAAG,gBAAAC,IACAD,UAAAH,OACA,CACA,GAAAK,GAAAL,GACA,QAAAM,KAAAD,IAAA,gBAAAJ,iBAAAF,GAAAO,GAAAD,EAAAC,KAECC,KAAA,WACD,MCAgB,UAAUC,GCN1B,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAT,OAGA,IAAAC,GAAAS,EAAAD,IACAJ,EAAAI,EACAE,GAAA,EACAX,WAUA,OANAO,GAAAE,GAAAG,KAAAX,EAAAD,QAAAC,IAAAD,QAAAQ,GAGAP,EAAAU,GAAA,EAGAV,EAAAD,QAvBA,GAAAU,KA4DA,OAhCAF,GAAAK,EAAAN,EAGAC,EAAAM,EAAAJ,EAGAF,EAAAO,EAAA,SAAAf,EAAAgB,EAAAC,GACAT,EAAAU,EAAAlB,EAAAgB,IACAG,OAAAC,eAAApB,EAAAgB,GACAK,cAAA,EACAC,YAAA,EACAC,IAAAN,KAMAT,EAAAgB,EAAA,SAAAvB,GACA,GAAAgB,GAAAhB,KAAAwB,WACA,WAA2B,MAAAxB,GAAA,SAC3B,WAAiC,MAAAA,GAEjC,OADAO,GAAAO,EAAAE,EAAA,IAAAA,GACAA,GAIAT,EAAAU,EAAA,SAAAQ,EAAAC,GAAsD,MAAAR,QAAAS,UAAAC,eAAAjB,KAAAc,EAAAC,IAGtDnB,EAAAsB,EAAA,GAGAtB,IAAAuB,EAAA,KDgBM,SAAU9B,EAAQ+B,EAAqBxB,GAE7C,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KACtEzC,EAAoBO,EAAEiB,EAAqB,KAAM,WAAa,MAAOqB,KACrE7C,EAAoBO,EAAEiB,EAAqB,OAAQ,WAAa,MAAO2D,IACtG,IAAIH,GAA4B,kBAAXe,SAAoD,gBAApBA,QAAOC,SAAwB,SAAUC,GAAO,aAAcA,IAAS,SAAUA,GAAO,MAAOA,IAAyB,kBAAXF,SAAyBE,EAAIhE,cAAgB8D,QAAUE,IAAQF,OAAO3E,UAAY,eAAkB6E,IEiEhQxC,eAAAnB,EAAAxC,KAAAa,IACAgD,EAAS,SAAAhB,GAAA,SAAkBA,EAAWnC,MAAQ,UAAtB,SAAA0F,GAAA,QAAAC,KAAA,MAAA7D,GAAAxC,KAAAqG,GAAA1E,EAAA3B,MAAAqG,EAAA9D,WAAA1B,OAAAuE,eAAAiB,IAAA5B,MAAAzE,KAAAoD,YAAA,MAAAtB,GAAAuE,EAAAD,GAAAC,GAAgDxD","file":"mics.min.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition","(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(this, function() {\nreturn /******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId]) {\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\ti: moduleId,\n/******/ \t\t\tl: false,\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.l = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// define getter function for harmony exports\n/******/ \t__webpack_require__.d = function(exports, name, getter) {\n/******/ \t\tif(!__webpack_require__.o(exports, name)) {\n/******/ \t\t\tObject.defineProperty(exports, name, {\n/******/ \t\t\t\tconfigurable: false,\n/******/ \t\t\t\tenumerable: true,\n/******/ \t\t\t\tget: getter\n/******/ \t\t\t});\n/******/ \t\t}\n/******/ \t};\n/******/\n/******/ \t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t__webpack_require__.n = function(module) {\n/******/ \t\tvar getter = module && module.__esModule ?\n/******/ \t\t\tfunction getDefault() { return module['default']; } :\n/******/ \t\t\tfunction getModuleExports() { return module; };\n/******/ \t\t__webpack_require__.d(getter, 'a', getter);\n/******/ \t\treturn getter;\n/******/ \t};\n/******/\n/******/ \t// Object.prototype.hasOwnProperty.call\n/******/ \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = 0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\nObject.defineProperty(__webpack_exports__, \"__esModule\", { value: true });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"mix\", function() { return mix; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"is\", function() { return is; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"like\", function() { return like; });\nvar _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; };\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n\n\n/**\r\n * Accepts an optional superclass as the first argument,\r\n * then a bunch of mixins and an optional class factory as the last argument and returns a mixin.\r\n * Mostly, you will be using mix with a factory to create mixins, like this:\r\n *\r\n * var Looker = mix(superclass => class Looker extends superclass {\r\n * constructor() {\r\n * super()\r\n * console.info('A looker is born!')\r\n * }\r\n * look() {\r\n * console.info('Looking good!')\r\n * }\r\n * })\r\n *\r\n * @param {function} args\r\n * Consists of the following three argument groups:\r\n * {function} superclass (optional)\r\n * {function} mixins... (0 or more)\r\n * {function} factory (optional)\r\n * @return {function}\r\n */\nfunction mix() {\n for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n\n // todo: refactor to make const\n var superclass = !isFactory(args[0]) && args.shift() || baseclass;\n var factory = isFactory(args[args.length - 1]) && args.pop() || derive;\n superclass = isMixin(superclass) ? superclass.class : derive(superclass);\n if (args.length) factory = function (org) {\n return function (superclass) {\n return org(args.reduce(function (s, m) {\n return m.mixin(s);\n }, superclass));\n };\n }(factory);\n\n function mixin(superclass) {\n var result = is(superclass, mixin) ? superclass : factory(superclass);\n if (mixin.classes.indexOf(result) === -1) mixin.classes.push(result);\n return result;\n }\n\n Object.defineProperties(mixin, {\n classes: { value: [], writable: false },\n mixins: { value: args, writable: false }\n });\n var Class = mixin(superclass);\n var constructor = Class.hasOwnProperty('constructor') ? Class.constructor.bind(Class) : function () {\n for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {\n args[_key2] = arguments[_key2];\n }\n\n return new (Function.prototype.bind.apply(Class, [null].concat(args)))();\n };\n Object.getOwnPropertyNames(Class).forEach(function (k) {\n return Object.defineProperty(constructor, k, { value: Class[k] });\n });\n return Object.defineProperties(constructor, {\n mixin: { value: mixin, writable: false },\n class: { value: Class, writable: false },\n interface: { get: function (x) {\n return function () {\n return x ? x : x = getInterface(Class.prototype);\n };\n }() }\n });\n}\n\n/**\r\n * Tests whether `x` is a type or extends from type.\r\n * Example: is(looker, Looker)\r\n *\r\n * @param {object|function} x\r\n * @param {function} type\r\n * @return {boolean}\r\n */\nfunction is(x, type) {\n if ((typeof x === 'undefined' ? 'undefined' : _typeof(x)) == 'object') {\n if (x instanceof type) return true;\n if (type.class && x instanceof type.class) return true;\n if (type.mixin && type.mixin.classes) return type.mixin.classes.reduce(function (f, c) {\n return f || is(x, c);\n }, false);\n } else if (typeof x == 'function') {\n if (x.mixin && x.mixin.mixins.indexOf(type) !== -1) return true;\n var c = x;\n while (c !== Object) {\n if (c === type || c === type.class) return true;\n if (type.mixin && type.mixin.classes && type.mixin.classes.indexOf(c) !== -1) return true;\n c = Object.getPrototypeOf(c.prototype).constructor;\n }\n }\n return false;\n}\n\n/**\r\n * Often, we don't really care whether the object is a certain type,\r\n * we just want to know whether we can treat it like a certain type.\r\n * Use like(subject, type) to test whether a subject adheres to the same interface as is defined by type\r\n * Example:\r\n *\r\n * var Looker = mix(superclass => class Looker extends superclass {\r\n * look() {}\r\n * })\r\n *\r\n * var Viewer = {\r\n * look() {} // same interface as Looker\r\n * }\r\n *\r\n * var viewer = new Viewer()\r\n * like(viewer, Looker) // true\r\n *\r\n * @param {object|function} x\r\n * @param {function} type\r\n * @return {boolean}\r\n */\nfunction like(x, type) {\n if (is(x, type)) return true;\n var itf = type.interface || typeof type == 'function' && getInterface(type.prototype);\n var subject = typeof x == 'function' ? x.interface || getInterface(x.prototype) : x;\n return itf && Object.keys(itf).reduce(function (f, k) {\n return f && (typeof itf[k] == 'function' ? typeof subject[k] == 'function' : k in subject);\n }, true);\n}\n\n/**\r\n * Get all parts of an interface as an array of strings\r\n *\r\n * @param {object} proto\r\n * @return {array}\r\n */\nfunction getInterface(proto) {\n return getPropertyNames(proto).reduce(function (o, k) {\n o[k] = proto[k];return o;\n }, {});\n}\n\n/**\r\n * Get all properties of an object an an array of strings\r\n *\r\n * @param {object|function} proto\r\n * @return {array}\r\n */\nfunction getPropertyNames(proto) {\n var results = [];\n while (proto !== Object.prototype) {\n Object.getOwnPropertyNames(proto).reduce(function (arr, k) {\n return arr.indexOf(k) === -1 ? arr.push(k) && arr : arr;\n }, results);\n proto = Object.getPrototypeOf(proto).constructor.prototype;\n }\n return results;\n}\n\nfunction isMixin(x) {\n return typeof x == 'function' && !!x.mixin;\n}\n\nfunction isClass(x) {\n if (typeof x != 'function') return false;\n var s = x.toString();\n return (/^class\\s/.test(s) || /^.*classCallCheck\\(/.test(s.replace(/^[^{]*{\\s*/, '').replace(/\\s*}[^}]*$/, ''))\n );\n}\n\nfunction isFactory(x) {\n return typeof x == 'function' && !isMixin(x) && !isClass(x) && x.length == 1;\n}\n\nvar baseclass = function Object() {\n _classCallCheck(this, Object);\n};\nvar derive = function derive(superclass) {\n return {}[superclass.name || 'Object'] = function (_superclass) {\n _inherits(_class, _superclass);\n\n function _class() {\n _classCallCheck(this, _class);\n\n return _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).apply(this, arguments));\n }\n\n return _class;\n }(superclass);\n};\n\n/***/ })\n/******/ ]);\n});\n\n\n// WEBPACK FOOTER //\n// mics.min.js"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap f11b09d4bce329eb33c7","export { mix, is, like }\r\n\r\n/**\r\n * Accepts an optional superclass as the first argument,\r\n * then a bunch of mixins and an optional class factory as the last argument and returns a mixin.\r\n * Mostly, you will be using mix with a factory to create mixins, like this:\r\n *\r\n * var Looker = mix(superclass => class Looker extends superclass {\r\n * constructor() {\r\n * super()\r\n * console.info('A looker is born!')\r\n * }\r\n * look() {\r\n * console.info('Looking good!')\r\n * }\r\n * })\r\n *\r\n * @param {function} args\r\n * Consists of the following three argument groups:\r\n * {function} superclass (optional)\r\n * {function} mixins... (0 or more)\r\n * {function} factory (optional)\r\n * @return {function}\r\n */\r\nfunction mix(...args) {\r\n // todo: refactor to make const\r\n let superclass = !isFactory(args[0]) && args.shift() || baseclass\r\n let factory = (isFactory(args[args.length-1]) && args.pop()) || derive\r\n superclass = isMixin(superclass) ? superclass.class : derive(superclass)\r\n if (args.length) factory = (org => superclass => org(args.reduce((s,m) => m.mixin(s), superclass)))(factory)\r\n\r\n function mixin(superclass) {\r\n const result = is(superclass, mixin) ? superclass : factory(superclass)\r\n if (mixin.classes.indexOf(result) === -1) mixin.classes.push(result)\r\n return result\r\n }\r\n\r\n Object.defineProperties(mixin, {\r\n classes: { value:[], writable:false },\r\n mixins: { value:args, writable:false },\r\n })\r\n const Class = mixin(superclass)\r\n const constructor = Class.hasOwnProperty('constructor')\r\n ? Class.constructor.bind(Class)\r\n : (...args) => new Class(...args)\r\n Object.getOwnPropertyNames(Class).forEach(k => Object.defineProperty(constructor, k, { value: Class[k] }))\r\n return Object.defineProperties(constructor, {\r\n mixin: { value:mixin, writable:false },\r\n class: { value: Class, writable:false },\r\n interface: { get:(x => () => x ? x : x = getInterface(Class.prototype))() },\r\n })\r\n}\r\n\r\n/**\r\n * Tests whether `x` is a type or extends from type.\r\n * Example: is(looker, Looker)\r\n *\r\n * @param {object|function} x\r\n * @param {function} type\r\n * @return {boolean}\r\n */\r\nfunction is(x, type) {\r\n if (typeof x == 'object') {\r\n if (x instanceof type) return true\r\n if (type.class && x instanceof type.class) return true\r\n if (type.mixin && type.mixin.classes) return type.mixin.classes.reduce((f,c) => f || is(x,c), false)\r\n }\r\n else if (typeof x == 'function') {\r\n if (x.mixin && x.mixin.mixins.indexOf(type) !== -1) return true\r\n let c = x\r\n while (c !== Object) {\r\n if (c === type || c === type.class) return true\r\n if (type.mixin && type.mixin.classes && type.mixin.classes.indexOf(c) !== -1) return true\r\n c = Object.getPrototypeOf(c.prototype).constructor\r\n }\r\n }\r\n return false\r\n}\r\n\r\n/**\r\n * Often, we don't really care whether the object is a certain type,\r\n * we just want to know whether we can treat it like a certain type.\r\n * Use like(subject, type) to test whether a subject adheres to the same interface as is defined by type\r\n * Example:\r\n *\r\n * var Looker = mix(superclass => class Looker extends superclass {\r\n * look() {}\r\n * })\r\n *\r\n * var Viewer = {\r\n * look() {} // same interface as Looker\r\n * }\r\n *\r\n * var viewer = new Viewer()\r\n * like(viewer, Looker) // true\r\n *\r\n * @param {object|function} x\r\n * @param {function} type\r\n * @return {boolean}\r\n */\r\nfunction like(x, type) {\r\n if (is(x, type)) return true\r\n const itf = type.interface || ((typeof type == 'function') && getInterface(type.prototype))\r\n const subject = typeof x == 'function' ? x.interface || getInterface(x.prototype) : x\r\n return itf && Object.keys(itf).reduce((f, k) => \r\n f && ((typeof itf[k] == 'function') ? (typeof subject[k] == 'function') : k in subject), true\r\n )\r\n}\r\n\r\n/**\r\n * Get all parts of an interface as an array of strings\r\n *\r\n * @param {object} proto\r\n * @return {array}\r\n */\r\nfunction getInterface(proto) {\r\n return getPropertyNames(proto).reduce((o,k) => { o[k] = proto[k]; return o }, {})\r\n}\r\n\r\n/**\r\n * Get all properties of an object an an array of strings\r\n *\r\n * @param {object|function} proto\r\n * @return {array}\r\n */\r\nfunction getPropertyNames(proto) {\r\n const results = []\r\n while (proto !== Object.prototype) {\r\n Object.getOwnPropertyNames(proto).reduce((arr,k) => arr.indexOf(k) === -1 ? arr.push(k) && arr : arr, results)\r\n proto = Object.getPrototypeOf(proto).constructor.prototype\r\n }\r\n return results\r\n}\r\n\r\nfunction isMixin(x) {\r\n return (typeof x == 'function') && !!x.mixin\r\n}\r\n\r\nfunction isClass(x) {\r\n if (typeof x != 'function') return false\r\n const s = x.toString()\r\n return /^class\\s/.test(s) || /^.*classCallCheck\\(/.test(s.replace(/^[^{]*{\\s*/,'').replace(/\\s*}[^}]*$/,''))\r\n}\r\n\r\nfunction isFactory(x) {\r\n return (typeof x == 'function') && !isMixin(x) && !isClass(x) && x.length == 1\r\n}\r\n\r\n\r\nconst baseclass = class Object{}\r\nconst derive = superclass => ({}[superclass.name || 'Object'] = class extends superclass {})\r\n\n\n\n// WEBPACK FOOTER //\n// ./index.js"],"sourceRoot":""} -------------------------------------------------------------------------------- /test/browser-source-map-support.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Support for source maps in V8 stack traces 3 | * https://github.com/evanw/node-source-map-support 4 | */ 5 | (this.define||function(K,N){this.sourceMapSupport=N()})("browser-source-map-support",function(K){(function n(w,t,e){function r(g,b){if(!t[g]){if(!w[g]){var f="function"==typeof require&&require;if(!b&&f)return f(g,!0);if(l)return l(g,!0);throw Error("Cannot find module '"+g+"'");}f=t[g]={exports:{}};w[g][0].call(f.exports,function(b){var a=w[g][1][b];return r(a?a:b)},f,f.exports,n,w,t,e)}return t[g].exports}for(var l="function"==typeof require&&require,m=0;me)return-1;if(58>e)return e-48+52;if(91>e)return e-65;if(123>e)return e-97+26}var l="undefined"!==typeof Uint8Array?Uint8Array:Array;e.toByteArray=function(e){function g(a){c[d++]=a}var b,f,k,a,c;if(0>18&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k>>12&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k>>6&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k&63),f+=k;switch(b){case 1:k=e[e.length-1];f+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k>>2);f+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k<< 13 | 4&63);f+="==";break;case 2:k=(e[e.length-2]<<8)+e[e.length-1],f+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k>>10),f+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k>>4&63),f+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k<<2&63),f+="="}return f}})("undefined"===typeof t?this.base64js={}:t)},{}],4:[function(n,w,t){},{}],5:[function(n,w,t){function e(h,q,c){if(!(this instanceof e))return new e(h,q,c);var a=typeof h; 14 | if("base64"===q&&"string"===a)for(h=h.trim?h.trim():h.replace(/^\s+|\s+$/g,"");0!==h.length%4;)h+="=";var d;if("number"===a)d=F(h);else if("string"===a)d=e.byteLength(h,q);else if("object"===a)d=F(h.length);else throw Error("First argument needs to be a number, array or string.");var b;e._useTypedArrays?b=e._augment(new Uint8Array(d)):(b=this,b.length=d,b._isBuffer=!0);if(e._useTypedArrays&&"number"===typeof h.byteLength)b._set(h);else{var f=h;if(E(f)||e.isBuffer(f)||f&&"object"===typeof f&&"number"=== 15 | typeof f.length)for(q=0;q=a))return c?(c=h[q],q+ 16 | 1=a)){var d;c?(q+2>>0)):(q+1>>0);return d}}function g(h,q,a,c){c||(p("boolean"===typeof a,"missing or invalid endian"), 17 | p(void 0!==q&&null!==q,"missing offset"),p(q+1=h.length))return h=l(h,q,a,!0),h&32768?-1*(65535-h+1):h}function b(h,q,a,c){c||(p("boolean"===typeof a,"missing or invalid endian"),p(void 0!==q&&null!==q,"missing offset"),p(q+3=h.length))return h=m(h,q,a,!0),h&2147483648?-1*(4294967295-h+1):h}function f(h,q,a,c){c||(p("boolean"===typeof a,"missing or invalid endian"),p(q+3=f))for(b=0,f=Math.min(f-c,2);b>>8* 19 | (d?b:1-b)}function c(h,a,c,d,b){b||(p(void 0!==a&&null!==a,"missing value"),p("boolean"===typeof d,"missing or invalid endian"),p(void 0!==c&&null!==c,"missing offset"),p(c+3=f))for(b=0,f=Math.min(f-c,4);b>>8*(d?b:3-b)&255}function d(h,c,d,b,f){f||(p(void 0!==c&&null!==c,"missing value"),p("boolean"===typeof b,"missing or invalid endian"),p(void 0!==d&&null!==d,"missing offset"),p(d+1=h.length||(0<=c?a(h,c,d,b,f):a(h,65535+c+1,d,b,f))}function y(h,a,d,b,f){f||(p(void 0!==a&&null!==a,"missing value"),p("boolean"===typeof b,"missing or invalid endian"),p(void 0!==d&&null!==d,"missing offset"),p(d+3=h.length||(0<=a?c(h,a,d,b,f):c(h,4294967295+a+1,d,b,f))}function x(h,a,c,d,b){b||(p(void 0!==a&&null!==a,"missing value"),p("boolean"===typeof d, 21 | "missing or invalid endian"),p(void 0!==c&&null!==c,"missing offset"),p(c+3=h.length||I.write(h,a,c,d,23,4)}function A(h,c,a,d,b){b||(p(void 0!==c&&null!==c,"missing value"),p("boolean"===typeof d,"missing or invalid endian"),p(void 0!==a&&null!==a,"missing offset"),p(a+7=h.length||I.write(h, 22 | c,a,d,52,8)}function B(h,a,c){if("number"!==typeof h)return c;h=~~h;if(h>=a)return a;if(0<=h)return h;h+=a;return 0<=h?h:0}function F(h){h=~~Math.ceil(+h);return 0>h?0:h}function E(h){return(Array.isArray||function(h){return"[object Array]"===Object.prototype.toString.call(h)})(h)}function G(h){return 16>h?"0"+h.toString(16):h.toString(16)}function u(h){for(var a=[],c=0;c=d)a.push(h.charCodeAt(c));else{var b=c;55296<=d&&57343>=d&&c++;d=encodeURIComponent(h.slice(b, 23 | c+1)).substr(1).split("%");for(b=0;b=c.length||b>=h.length);b++)c[b+a]=h[b];return b}function D(h){try{return decodeURIComponent(h)}catch(c){return String.fromCharCode(65533)}}function H(h,c){p("number"===typeof h,"cannot write a non-number as a number");p(0<=h,"specified a negative value for writing an unsigned value");p(h<= 24 | c,"value is larger than maximum value for type");p(Math.floor(h)===h,"value has a fractional component")}function L(h,c,a){p("number"===typeof h,"cannot write a non-number as a number");p(h<=c,"value larger than maximum allowed value");p(h>=a,"value smaller than minimum allowed value");p(Math.floor(h)===h,"value has a fractional component")}function M(h,c,a){p("number"===typeof h,"cannot write a non-number as a number");p(h<=c,"value larger than maximum allowed value");p(h>=a,"value smaller than minimum allowed value")} 25 | function p(h,c){if(!h)throw Error(c||"Failed assertion");}var J=n("base64-js"),I=n("ieee754");t.Buffer=e;t.SlowBuffer=e;t.INSPECT_MAX_BYTES=50;e.poolSize=8192;e._useTypedArrays=function(){try{var h=new ArrayBuffer(0),c=new Uint8Array(h);c.foo=function(){return 42};return 42===c.foo()&&"function"===typeof c.subarray}catch(a){return!1}}();e.isEncoding=function(h){switch(String(h).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!0; 26 | default:return!1}};e.isBuffer=function(h){return!(null===h||void 0===h||!h._isBuffer)};e.byteLength=function(h,c){var a;h+="";switch(c||"utf8"){case "hex":a=h.length/2;break;case "utf8":case "utf-8":a=u(h).length;break;case "ascii":case "binary":case "raw":a=h.length;break;case "base64":a=J.toByteArray(h).length;break;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":a=2*h.length;break;default:throw Error("Unknown encoding");}return a};e.concat=function(h,c){p(E(h),"Usage: Buffer.concat(list, [totalLength])\nlist should be an Array."); 27 | if(0===h.length)return new e(0);if(1===h.length)return h[0];var a;if("number"!==typeof c)for(a=c=0;ab&&(a=b)):a=b;d=String(d||"utf8").toLowerCase();switch(d){case "hex":c=Number(c)||0;d=this.length-c;a?(a=Number(a),a>d&&(a=d)):a=d;d= 28 | h.length;p(0===d%2,"Invalid hex string");a>d/2&&(a=d/2);for(d=0;d>8,f%=256,b.push(f),b.push(d);h=e._charsWritten=z(b,this,c,a);break;default:throw Error("Unknown encoding");}return h};e.prototype.toString=function(a,c,d){a=String(a||"utf8").toLowerCase();c=Number(c)||0;d=void 0!==d?Number(d):d=this.length;if(d===c)return"";switch(a){case "hex":a=this.length;if(!c||0>c)c=0;if(!d||0>d||d>a)d=a;for(a="";c=this[c]?(a+=D(b)+String.fromCharCode(this[c]), 30 | b=""):b+="%"+this[c].toString(16);d=a+D(b);break;case "ascii":d=r(this,c,d);break;case "binary":d=r(this,c,d);break;case "base64":d=0===c&&d===this.length?J.fromByteArray(this):J.fromByteArray(this.slice(c,d));break;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":d=this.slice(c,d);c="";for(a=0;a=d,"sourceEnd < sourceStart"),p(0<=c&&cthis.length&&(b=this.length),a.length-cb||!e._useTypedArrays)for(var f=0;f=this.length))return this[a]};e.prototype.readUInt16LE=function(a,c){return l(this,a,!0,c)};e.prototype.readUInt16BE=function(a,c){return l(this,a,!1,c)};e.prototype.readUInt32LE=function(a,c){return m(this,a,!0,c)};e.prototype.readUInt32BE=function(a,c){return m(this,a,!1,c)};e.prototype.readInt8=function(a,c){c||(p(void 0!==a&&null!==a,"missing offset"),p(a= 34 | this.length))return this[a]&128?-1*(255-this[a]+1):this[a]};e.prototype.readInt16LE=function(a,c){return g(this,a,!0,c)};e.prototype.readInt16BE=function(a,c){return g(this,a,!1,c)};e.prototype.readInt32LE=function(a,c){return b(this,a,!0,c)};e.prototype.readInt32BE=function(a,c){return b(this,a,!1,c)};e.prototype.readFloatLE=function(a,c){return f(this,a,!0,c)};e.prototype.readFloatBE=function(a,c){return f(this,a,!1,c)};e.prototype.readDoubleLE=function(a,c){return k(this,a,!0,c)};e.prototype.readDoubleBE= 35 | function(a,c){return k(this,a,!1,c)};e.prototype.writeUInt8=function(a,c,d){d||(p(void 0!==a&&null!==a,"missing value"),p(void 0!==c&&null!==c,"missing offset"),p(c=this.length||(this[c]=a)};e.prototype.writeUInt16LE=function(c,d,b){a(this,c,d,!0,b)};e.prototype.writeUInt16BE=function(c,d,b){a(this,c,d,!1,b)};e.prototype.writeUInt32LE=function(a,d,b){c(this,a,d,!0,b)};e.prototype.writeUInt32BE=function(a,d,b){c(this,a,d,!1,b)};e.prototype.writeInt8= 36 | function(a,c,d){d||(p(void 0!==a&&null!==a,"missing value"),p(void 0!==c&&null!==c,"missing offset"),p(c=this.length||(0<=a?this.writeUInt8(a,c,d):this.writeUInt8(255+a+1,c,d))};e.prototype.writeInt16LE=function(a,c,b){d(this,a,c,!0,b)};e.prototype.writeInt16BE=function(a,c,b){d(this,a,c,!1,b)};e.prototype.writeInt32LE=function(a,c,d){y(this,a,c,!0,d)};e.prototype.writeInt32BE=function(a,c,d){y(this,a,c,!1,d)};e.prototype.writeFloatLE= 37 | function(a,c,d){x(this,a,c,!0,d)};e.prototype.writeFloatBE=function(a,c,d){x(this,a,c,!1,d)};e.prototype.writeDoubleLE=function(a,c,d){A(this,a,c,!0,d)};e.prototype.writeDoubleBE=function(a,c,d){A(this,a,c,!1,d)};e.prototype.fill=function(a,c,d){a||(a=0);c||(c=0);d||(d=this.length);"string"===typeof a&&(a=a.charCodeAt(0));p("number"===typeof a&&!isNaN(a),"value is not a number");p(d>=c,"end < start");if(d!==c&&0!==this.length)for(p(0<=c&&c"};e.prototype.toArrayBuffer=function(){if("undefined"!==typeof Uint8Array){if(e._useTypedArrays)return(new e(this)).buffer;for(var a=new Uint8Array(this.length),c=0,d=a.length;c>1,a=-7;g=l?g-1:0;var c=l?-1:1,d=e[r+g];g+=c;l=d&(1<<-a)-1;d>>=-a;for(a+=b;0>=-a;for(a+=m;0>1,d=23===g?Math.pow(2,-24)-Math.pow(2,-77):0;b=m?0:b-1;var y=m?1:-1,x=0>r||0===r&&0>1/r?1:0;r=Math.abs(r);isNaN(r)||Infinity===r?(r=isNaN(r)?1:0,m=a):(m=Math.floor(Math.log(r)/Math.LN2),1>r*(f=Math.pow(2,-m))&&(m--,f*=2),r=1<=m+c?r+d/f:r+d*Math.pow(2,1-c),2<=r*f&&(m++,f/=2),m+c>=a?(r=0,m=a):1<=m+c?(r=(r*f-1)*Math.pow(2,g),m+=c):(r=r*Math.pow(2,c-1)*Math.pow(2,g),m=0));for(;8<=g;e[l+b]=r&255,b+=y,r/=256,g-=8);m=m<d?[]:a.slice(c,d-c+1)}b=t.resolve(b).substr(1);f=t.resolve(f).substr(1);for(var a=e(b.split("/")),c=e(f.split("/")),d=Math.min(a.length,c.length),g=d,x=0;xf&&(f=b.length+f);return b.substr(f,e)}}).call(this,n("node_modules/process/browser.js"))}, 47 | {"node_modules/process/browser.js":8}],8:[function(n,w,t){function e(){}n=w.exports={};n.nextTick=function(){if("undefined"!==typeof window&&window.setImmediate)return function(e){return window.setImmediate(e)};if("undefined"!==typeof window&&window.postMessage&&window.addEventListener){var e=[];window.addEventListener("message",function(l){var m=l.source;m!==window&&null!==m||"process-tick"!==l.data||(l.stopPropagation(),0b?(-b<<1)+1:(b<<1)+0;do b=k&31,k>>>=5,0=k)throw Error("Expected more digits in base 64 VLQ value.");y=g.decode(b.charAt(e++));d=!!(y&32);y&=31;a+=y<>1;return{value:1===(a&1)?-k:k,rest:b.slice(e)}}})},{"./base64":12,amdefine:2}],12:[function(n,w,t){if("function"!==typeof e)var e=n("amdefine")(w,n);e(function(e,l,m){var g={},b={};"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("").forEach(function(e, 52 | k){g[e]=k;b[k]=e});l.encode=function(e){if(e in b)return b[e];throw new TypeError("Must be between 0 and 63: "+e);};l.decode=function(b){if(b in g)return g[b];throw new TypeError("Not a valid base 64 digit: "+b);}})},{amdefine:2}],13:[function(n,w,t){if("function"!==typeof e)var e=n("amdefine")(w,n);e(function(e,l,m){function g(b,e,k,a,c){var d=Math.floor((e-b)/2)+b,y=c(k,a[d],!0);return 0===y?a[d]:0b?null:a[b]}l.search=function(b,e,k){return 0=a[b])throw new TypeError("Line must be greater than or equal to 1, got "+a[b]);if(0>a[e])throw new TypeError("Column must be greater than or equal to 0, got "+ 59 | a[e]);return f.search(a,d,g)};g.prototype.originalPositionFor=function(a){a={generatedLine:b.getArg(a,"line"),generatedColumn:b.getArg(a,"column")};if(a=this._findMapping(a,this._generatedMappings,"generatedLine","generatedColumn",b.compareByGeneratedPositions)){var d=b.getArg(a,"source",null);d&&this.sourceRoot&&(d=b.join(this.sourceRoot,d));return{source:d,line:b.getArg(a,"originalLine",null),column:b.getArg(a,"originalColumn",null),name:b.getArg(a,"name",null)}}return{source:null,line:null,column:null, 60 | name:null}};g.prototype.sourceContentFor=function(a){if(!this.sourcesContent)return null;this.sourceRoot&&(a=b.relative(this.sourceRoot,a));if(this._sources.has(a))return this.sourcesContent[this._sources.indexOf(a)];var d;if(this.sourceRoot&&(d=b.urlParse(this.sourceRoot))){var e=a.replace(/^file:\/\//,"");if("file"==d.scheme&&this._sources.has(e))return this.sourcesContent[this._sources.indexOf(e)];if((!d.path||"/"==d.path)&&this._sources.has("/"+a))return this.sourcesContent[this._sources.indexOf("/"+ 61 | a)]}throw Error('"'+a+'" is not in the SourceMap.');};g.prototype.generatedPositionFor=function(a){a={source:b.getArg(a,"source"),originalLine:b.getArg(a,"line"),originalColumn:b.getArg(a,"column")};this.sourceRoot&&(a.source=b.relative(this.sourceRoot,a.source));return(a=this._findMapping(a,this._originalMappings,"originalLine","originalColumn",b.compareByOriginalPositions))?{line:b.getArg(a,"generatedLine",null),column:b.getArg(a,"generatedColumn",null)}:{line:null,column:null}};g.GENERATED_ORDER= 62 | 1;g.ORIGINAL_ORDER=2;g.prototype.eachMapping=function(a,d,e){d=d||null;switch(e||g.GENERATED_ORDER){case g.GENERATED_ORDER:e=this._generatedMappings;break;case g.ORIGINAL_ORDER:e=this._originalMappings;break;default:throw Error("Unknown order of iteration.");}var f=this.sourceRoot;e.map(function(a){var c=a.source;c&&f&&(c=b.join(f,c));return{source:c,generatedLine:a.generatedLine,generatedColumn:a.generatedColumn,originalLine:a.originalLine,originalColumn:a.originalColumn,name:a.name}}).forEach(a, 63 | d)};l.SourceMapConsumer=g})},{"./array-set":10,"./base64-vlq":11,"./binary-search":13,"./util":17,amdefine:2}],15:[function(n,w,t){if("function"!==typeof e)var e=n("amdefine")(w,n);e(function(e,l,m){function g(a){this._file=f.getArg(a,"file");this._sourceRoot=f.getArg(a,"sourceRoot",null);this._sources=new k;this._names=new k;this._mappings=[];this._sourcesContents=null}var b=e("./base64-vlq"),f=e("./util"),k=e("./array-set").ArraySet;g.prototype._version=3;g.fromSourceMap=function(a){var c=a.sourceRoot, 64 | d=new g({file:a.file,sourceRoot:c});a.eachMapping(function(a){var b={generated:{line:a.generatedLine,column:a.generatedColumn}};a.source&&(b.source=a.source,c&&(b.source=f.relative(c,b.source)),b.original={line:a.originalLine,column:a.originalColumn},a.name&&(b.name=a.name));d.addMapping(b)});a.sources.forEach(function(c){var b=a.sourceContentFor(c);b&&d.setSourceContent(c,b)});return d};g.prototype.addMapping=function(a){var c=f.getArg(a,"generated"),d=f.getArg(a,"original",null),b=f.getArg(a,"source", 65 | null);a=f.getArg(a,"name",null);this._validateMapping(c,d,b,a);b&&!this._sources.has(b)&&this._sources.add(b);a&&!this._names.has(a)&&this._names.add(a);this._mappings.push({generatedLine:c.line,generatedColumn:c.column,originalLine:null!=d&&d.line,originalColumn:null!=d&&d.column,source:b,name:a})};g.prototype.setSourceContent=function(a,c){var d=a;this._sourceRoot&&(d=f.relative(this._sourceRoot,d));null!==c?(this._sourcesContents||(this._sourcesContents={}),this._sourcesContents[f.toSetString(d)]= 66 | c):(delete this._sourcesContents[f.toSetString(d)],0===Object.keys(this._sourcesContents).length&&(this._sourcesContents=null))};g.prototype.applySourceMap=function(a,c){c||(c=a.file);var d=this._sourceRoot;d&&(c=f.relative(d,c));var b=new k,e=new k;this._mappings.forEach(function(g){if(g.source===c&&g.originalLine){var k=a.originalPositionFor({line:g.originalLine,column:g.originalColumn});null!==k.source&&(g.source=d?f.relative(d,k.source):k.source,g.originalLine=k.line,g.originalColumn=k.column, 67 | null!==k.name&&null!==g.name&&(g.name=k.name))}(k=g.source)&&!b.has(k)&&b.add(k);(g=g.name)&&!e.has(g)&&e.add(g)},this);this._sources=b;this._names=e;a.sources.forEach(function(c){var b=a.sourceContentFor(c);b&&(d&&(c=f.relative(d,c)),this.setSourceContent(c,b))},this)};g.prototype._validateMapping=function(a,c,d,b){if(!(a&&"line"in a&&"column"in a&&0f)-(e",a=this.getLineNumber(),null!=a&&(b+=":"+a,(a=this.getColumnNumber())&&(b+=":"+a)));a="";var c=this.getFunctionName(),d=!0,e=this.isConstructor();if(this.isToplevel()||e)e?a+="new "+(c||""):c?a+=c:(a+=b,d=!1);else{var e=this.getTypeName(),f=this.getMethodName();c?(e&&0!=c.indexOf(e)&&(a+=e+"."),a+=c,f&&c.indexOf("."+ 85 | f)!=c.length-f.length-1&&(a+=" [as "+f+"]")):a+=e+"."+(f||"")}d&&(a+=" ("+b+")");return a}function c(b){var c={};Object.getOwnPropertyNames(Object.getPrototypeOf(b)).forEach(function(a){c[a]=/^(?:is|get)/.test(a)?function(){return b[a].call(b)}:b[a]});c.toString=a;return c}function d(a){var b=a.getFileName()||a.getScriptNameOrSourceURL();if(b){var d=a.getLineNumber(),e=a.getColumnNumber()-1;1!==d||l()||a.isEval()||(e-=62);var g=f({source:b,line:d,column:e});a=c(a);a.getFileName=function(){return g.source}; 86 | a.getLineNumber=function(){return g.line};a.getColumnNumber=function(){return g.column+1};a.getScriptNameOrSourceURL=function(){return g.source};return a}var m=a.isEval()&&a.getEvalOrigin();m&&(m=k(m),a=c(a),a.getEvalOrigin=function(){return m});return a}function w(a,b){u&&(z={},D={});return a+b.map(function(a){return"\n at "+d(a)}).join("")}function x(a){var b=/\n at [^(]+ \((.*):(\d+):(\d+)\)/.exec(a.stack);if(b){a=b[1];var c=+b[2],b=+b[3],d=z[a];!d&&E.existsSync(a)&&(d=E.readFileSync(a,"utf8")); 87 | if(d&&(d=d.split(/(?:\r\n|\r|\n)/)[c-1]))return a+":"+c+"\n"+d+"\n"+Array(b).join(" ")+"^"}return null}function A(){var a=e.emit;e.emit=function(b){if("uncaughtException"===b){var c=arguments[1]&&arguments[1].stack,d=0