!function(e){if(“object”==typeof exports)module.exports=e();else if(“function”==typeof define&&define.amd)define(e);else{var f;“undefined”!=typeof window?f=window:“undefined”!=typeof global?f=global:“undefined”!=typeof self&&(f=self),f.stampit=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n){if(!t){var a=typeof require==“function”&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error(“Cannot find module '”o
“'”)}var f=n={exports:{}};t[0].call(f.exports,function(e){var n=t[1];return s(n?n:e)},f,f.exports,e,t,n,r)}return n.exports}var i=typeof require==“function”&&require;for(var o=0;o
function copyProp(val, key){
this[key] = val;
}
module.exports = function mixInChain(target, objects){
var i = 0, n = arguments.length, obj; while(++i < n){ obj = arguments[i]; if (obj != null) { forIn(obj, copyProp, target); } } return target;
};
},{“mout/object/forIn”:14}],2:[function(dereq,module,exports){
/** * Array forEach */ function forEach(arr, callback, thisObj) { if (arr == null) { return; } var i = -1, len = arr.length; while (++i < len) { // we iterate over sparse items since there is no way to make it // work properly on IE 7-8. see #64 if ( callback.call(thisObj, arr[i], i, arr) === false ) { break; } } } module.exports = forEach;
},{}],3:[function(dereq,module,exports){ var forEach = dereq('./forEach'); var makeIterator = dereq('../function/makeIterator_');
/** * Array map */ function map(arr, callback, thisObj) { callback = makeIterator(callback, thisObj); var results = []; if (arr == null){ return results; } var i = -1, len = arr.length; while (++i < len) { results[i] = callback(arr[i], i, arr); } return results; } module.exports = map;
},{“../function/makeIterator_”:4,“./forEach”:2}],4:[function(dereq,module,exports){ var prop = dereq('./prop'); var deepMatches = dereq('../object/deepMatches');
/** * Converts argument into a valid iterator. * Used internally on most array/object/collection methods that receives a * callback/iterator providing a shortcut syntax. */ function makeIterator(src, thisObj){ switch(typeof src) { case 'object': // typeof null == "object" return (src != null)? function(val, key, target){ return deepMatches(val, src); } : src; case 'string': case 'number': return prop(src); case 'function': if (typeof thisObj === 'undefined') { return src; } else { return function(val, i, arr){ return src.call(thisObj, val, i, arr); }; } default: return src; } } module.exports = makeIterator;
},{“../object/deepMatches”:13,“./prop”:5}],5:[function(dereq,module,exports){
/** * Returns a function that gets a property of the passed object */ function prop(name){ return function(obj){ return obj[name]; }; } module.exports = prop;
},{}],6:[function(dereq,module,exports){ var kindOf = dereq('./kindOf'); var isPlainObject = dereq('./isPlainObject'); var mixIn = dereq('../object/mixIn');
/** * Clone native types. */ function clone(val){ switch (kindOf(val)) { case 'Object': return cloneObject(val); case 'Array': return cloneArray(val); case 'RegExp': return cloneRegExp(val); case 'Date': return cloneDate(val); default: return val; } } function cloneObject(source) { if (isPlainObject(source)) { return mixIn({}, source); } else { return source; } } function cloneRegExp(r) { var flags = ''; flags += r.multiline ? 'm' : ''; flags += r.global ? 'g' : ''; flags += r.ignorecase ? 'i' : ''; return new RegExp(r.source, flags); } function cloneDate(date) { return new Date(+date); } function cloneArray(arr) { return arr.slice(); } module.exports = clone;
},{“../object/mixIn”:18,“./isPlainObject”:11,“./kindOf”:12}],7:[function(dereq,module,exports){ var clone = dereq('./clone'); var forOwn = dereq('../object/forOwn'); var kindOf = dereq('./kindOf'); var isPlainObject = dereq('./isPlainObject');
/** * Recursively clone native types. */ function deepClone(val, instanceClone) { switch ( kindOf(val) ) { case 'Object': return cloneObject(val, instanceClone); case 'Array': return cloneArray(val, instanceClone); default: return clone(val); } } function cloneObject(source, instanceClone) { if (isPlainObject(source)) { var out = {}; forOwn(source, function(val, key) { this[key] = deepClone(val, instanceClone); }, out); return out; } else if (instanceClone) { return instanceClone(source); } else { return source; } } function cloneArray(arr, instanceClone) { var out = [], i = -1, n = arr.length, val; while (++i < n) { out[i] = deepClone(arr[i], instanceClone); } return out; } module.exports = deepClone;
},{“../object/forOwn”:15,“./clone”:6,“./isPlainObject”:11,“./kindOf”:12}],8:[function(dereq,module,exports){ var isKind = dereq('./isKind');
/** */ var isArray = Array.isArray || function (val) { return isKind(val, 'Array'); }; module.exports = isArray;
},{“./isKind”:9}],9:[function(dereq,module,exports){ var kindOf = dereq('./kindOf');
/** * Check if value is from a specific "kind". */ function isKind(val, kind){ return kindOf(val) === kind; } module.exports = isKind;
},{“./kindOf”:12}],10:[function(dereq,module,exports){ var isKind = dereq('./isKind');
/** */ function isObject(val) { return isKind(val, 'Object'); } module.exports = isObject;
},{“./isKind”:9}],11:[function(dereq,module,exports){
/** * Checks if the value is created by the `Object` constructor. */ function isPlainObject(value) { return (!!value && typeof value === 'object' && value.constructor === Object); } module.exports = isPlainObject;
},{}],12:[function(dereq,module,exports){
var _rKind = /^\[object (.*)\]$/, _toString = Object.prototype.toString, UNDEF; /** * Gets the "kind" of value. (e.g. "String", "Number", etc) */ function kindOf(val) { if (val === null) { return 'Null'; } else if (val === UNDEF) { return 'Undefined'; } else { return _rKind.exec( _toString.call(val) )[1]; } } module.exports = kindOf;
},{}],13:[function(dereq,module,exports){ var forOwn = dereq('./forOwn'); var isArray = dereq('../lang/isArray');
function containsMatch(array, pattern) { var i = -1, length = array.length; while (++i < length) { if (deepMatches(array[i], pattern)) { return true; } } return false; } function matchArray(target, pattern) { var i = -1, patternLength = pattern.length; while (++i < patternLength) { if (!containsMatch(target, pattern[i])) { return false; } } return true; } function matchObject(target, pattern) { var result = true; forOwn(pattern, function(val, key) { if (!deepMatches(target[key], val)) { // Return false to break out of forOwn early return (result = false); } }); return result; } /** * Recursively check if the objects match. */ function deepMatches(target, pattern){ if (target && typeof target === 'object') { if (isArray(target) && isArray(pattern)) { return matchArray(target, pattern); } else { return matchObject(target, pattern); } } else { return target === pattern; } } module.exports = deepMatches;
},{“../lang/isArray”:8,“./forOwn”:15}],14:[function(dereq,module,exports){
var _hasDontEnumBug, _dontEnums; function checkDontEnum(){ _dontEnums = [ 'toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'constructor' ]; _hasDontEnumBug = true; for (var key in {'toString': null}) { _hasDontEnumBug = false; } } /** * Similar to Array/forEach but works over object properties and fixes Don't * Enum bug on IE. * based on: http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation */ function forIn(obj, fn, thisObj){ var key, i = 0; // no need to check if argument is a real object that way we can use // it for arrays, functions, date, etc. //post-pone check till needed if (_hasDontEnumBug == null) checkDontEnum(); for (key in obj) { if (exec(fn, obj, key, thisObj) === false) { break; } } if (_hasDontEnumBug) { while (key = _dontEnums[i++]) { // since we aren't using hasOwn check we need to make sure the // property was overwritten if (obj[key] !== Object.prototype[key]) { if (exec(fn, obj, key, thisObj) === false) { break; } } } } } function exec(fn, obj, key, thisObj){ return fn.call(thisObj, obj[key], key, obj); } module.exports = forIn;
},{}],15:[function(dereq,module,exports){ var hasOwn = dereq('./hasOwn'); var forIn = dereq('./forIn');
/** * Similar to Array/forEach but works over object properties and fixes Don't * Enum bug on IE. * based on: http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation */ function forOwn(obj, fn, thisObj){ forIn(obj, function(val, key){ if (hasOwn(obj, key)) { return fn.call(thisObj, obj[key], key, obj); } }); } module.exports = forOwn;
},{“./forIn”:14,“./hasOwn”:16}],16:[function(dereq,module,exports){
/** * Safer Object.hasOwnProperty */ function hasOwn(obj, prop){ return Object.prototype.hasOwnProperty.call(obj, prop); } module.exports = hasOwn;
},{}],17:[function(dereq,module,exports){ var hasOwn = dereq('./hasOwn'); var deepClone = dereq('../lang/deepClone'); var isObject = dereq('../lang/isObject');
/** * Deep merge objects. */ function merge() { var i = 1, key, val, obj, target; // make sure we don't modify source element and it's properties // objects are passed by reference target = deepClone( arguments[0] ); while (obj = arguments[i++]) { for (key in obj) { if ( ! hasOwn(obj, key) ) { continue; } val = obj[key]; if ( isObject(val) && isObject(target[key]) ){ // inception, deep merge objects target[key] = merge(target[key], val); } else { // make sure arrays, regexp, date, objects are cloned target[key] = deepClone(val); } } } return target; } module.exports = merge;
},{“../lang/deepClone”:7,“../lang/isObject”:10,“./hasOwn”:16}],18:[function(dereq,module,exports){ var forOwn = dereq('./forOwn');
/** * Combine properties from all the objects into first one. * - This method affects target object in place, if you want to create a new Object pass an empty object as first param. * @param {object} target Target Object * @param {...object} objects Objects to be combined (0...n objects). * @return {object} Target Object. */ function mixIn(target, objects){ var i = 0, n = arguments.length, obj; while(++i < n){ obj = arguments[i]; if (obj != null) { forOwn(obj, copyProp, target); } } return target; } function copyProp(val, key){ this[key] = val; } module.exports = mixIn;
},{“./forOwn”:15}],19:[function(dereq,module,exports){ /**
* Stampit ** * Create objects from reusable, composable behaviors. ** * Copyright (c) 2013 Eric Elliott * http://opensource.org/licenses/MIT **/
'use strict'; var forEach = dereq('mout/array/forEach'); var mixIn = dereq('mout/object/mixIn'); var merge = dereq('mout/object/merge'); var map = dereq('mout/array/map'); var forOwn = dereq('mout/object/forOwn'); var mixInChain = dereq('./mixinchain.js'); var slice = [].slice;
var create = function (o) {
if (arguments.length > 1) { throw new Error('Object.create implementation only accepts the first parameter.'); } function F() {} F.prototype = o; return new F();
};
if(!Array.isArray) {
Array.isArray = function (vArg) { return Object.prototype.toString.call(vArg) === "[object Array]"; };
}
var extractFunctions = function extractFunctions(arg) {
var arr = [], args = [].slice.call(arguments); if (typeof arg === 'function') { arr = map(args, function (fn) { if (typeof fn === 'function') { return fn; } }); } else if (typeof arg === 'object') { forEach(args, function (obj) { forOwn(obj, function (fn) { arr.push(fn); }); }); } else if ( Array.isArray(arg) ) { forEach(arg, function (fn) { arr.push(fn); }); } return arr;
};
/**
* Return a factory function that will produce new objects using the * prototypes that are passed in or composed. * * @param {Object} [methods] A map of method names and bodies for delegation. * @param {Object} [state] A map of property names and values to clone for each new object. * @param {Function} [enclose] A closure (function) used to create private data and privileged methods. * @return {Function} factory A factory to produce objects using the given prototypes. * @return {Function} factory.create Just like calling the factory function. * @return {Object} factory.fixed An object map containing the fixed prototypes. * @return {Function} factory.methods Add methods to the methods prototype. Chainable. * @return {Function} factory.state Add properties to the state prototype. Chainable. * @return {Function} factory.enclose Add or replace the closure prototype. Not chainable. */
var stampit = function stampit(methods, state, enclose) {
var fixed = { methods: methods || {}, state: state, enclose: extractFunctions(enclose) }, factory = function factory(properties) { var state = merge({}, fixed.state), instance = mixIn(create(fixed.methods || {}), state, properties), closures = fixed.enclose, args = slice.call(arguments, 1); forEach(closures, function (fn) { if (typeof fn === 'function') { instance = fn.apply(instance, args) || instance; } }); return instance; }; return mixIn(factory, { create: factory, fixed: fixed, /** * Take n objects and add them to the methods prototype. * @return {Object} stamp The factory in question (`this`). */ methods: function stampMethods() { var obj = fixed.methods || {}, args = [obj].concat([].slice.call(arguments)); fixed.methods = mixInChain.apply(this, args); return this; }, /** * Take n objects and add them to the state prototype. * @return {Object} stamp The factory in question (`this`). */ state: function stampState() { var obj = fixed.state || {}, args = [obj].concat([].slice.call(arguments)); fixed.state = mixIn.apply(this, args); return this; }, /** * Take n functions, an array of functions, or n objects and add * the functions to the enclose prototype. * @return {Object} stamp The factory in question (`this`). */ enclose: function stampEnclose() { fixed.enclose = fixed.enclose .concat( extractFunctions.apply(null, arguments) ); return this; } });
};
/**
* Take two or more factories produced from stampit() and * combine them to produce a new factory. Combining overrides * properties with last-in priority. * * @param {...Function} factory A factory produced by stampit(). * @return {Function} A new stampit factory composed from arguments. */
var compose = function compose() {
var args = [].slice.call(arguments), obj = stampit(); forEach(args, function (source) { if (source) { if (source.fixed.methods) { obj.fixed.methods = mixInChain({}, obj.fixed.methods, source.fixed.methods); } if (source.fixed.state) { obj.fixed.state = mixIn({}, obj.fixed.state, source.fixed.state); } if (source.fixed.enclose) { obj.fixed.enclose = obj.fixed.enclose .concat(source.fixed.enclose); } } }); return stampit(obj.fixed.methods, obj.fixed.state, obj.fixed.enclose);
};
/**
* Take an old-fashioned JS constructor and return a stampit stamp * that you can freely compose with other stamps. * @param {Function} Constructor * @return {Function} A composable stampit factory * (aka stamp). */
var convertConstructor = function convertConstructor(Constructor) {
return stampit().methods(Constructor.prototype).enclose(Constructor);
};
module.exports = mixIn(stampit, {
compose: compose, /** * Alias for mixIn */ extend: mixIn, /** * Take a destination object followed by one or more source objects, * and copy the source object properties to the destination object, * with last in priority overrides. * @param {Object} destination An object to copy properties to. * @param {...Object} source An object to copy properties from. * @returns {Object} */ mixIn: mixIn, convertConstructor: convertConstructor
});
},{“./mixinchain.js”:1,“mout/array/forEach”:2,“mout/array/map”:3,“mout/object/forOwn”:15,“mout/object/merge”:17,“mout/object/mixIn”:18}]},{},[19]) (19) });