From e74b9fbb2e4434361f142af96589607758beabf4 Mon Sep 17 00:00:00 2001 From: Diego Fernandez Date: Fri, 5 Jul 2013 17:26:11 -0300 Subject: [PATCH] Update of barman to version 0.3.0 --- ajax/libs/barman/0.3.0/barman.js | 501 +++++++++++++++++++++++++++ ajax/libs/barman/0.3.0/barman.min.js | 5 + ajax/libs/barman/package.json | 2 +- 3 files changed, 507 insertions(+), 1 deletion(-) create mode 100644 ajax/libs/barman/0.3.0/barman.js create mode 100644 ajax/libs/barman/0.3.0/barman.min.js diff --git a/ajax/libs/barman/0.3.0/barman.js b/ajax/libs/barman/0.3.0/barman.js new file mode 100644 index 00000000000000..1701c3b3d35eb4 --- /dev/null +++ b/ajax/libs/barman/0.3.0/barman.js @@ -0,0 +1,501 @@ +// barman 0.3.0 +// https://github.com/dfernandez79/barman +// Copyright (c) 2013 Diego Fernandez +// Barman may be freely distributed under the MIT license. + +(function () { + + 'use strict'; + + function factory() { + var ArrayProto = Array.prototype, + nativeForEach = ArrayProto.forEach, + slice = ArrayProto.slice; + + // + // Common helper functions + // ----------------------- + // These common helper functions are based on _underscore_ and _lodash_ implementations. + // + // Why these are included inline? Why not having a dependency to some _underscore_ compatible library? + // + // Because *barman* uses only a few functions, and the additional dependency made the setup hard. + // So after evaluating the trade-offs, they were included here. + // + + // #### isUndefined( _value_ ) + // + // A shortcut for `typeof`. + // + function isUndefined( value ) { + return typeof value == 'undefined'; + } + + // #### isFunction( _value_ ) + // + // A shortcut for `typeof`. + // + function isFunction( value ) { + return typeof value === 'function'; + } + + // #### has( _object_, _property_ ) + // + // A _safe_ version of `hasOwnProperty`. + // + function has( object, property ) { + return object ? Object.prototype.hasOwnProperty.call(object, property) : false; + } + + // #### isObject( _value_ ) + // + // Check if _value_ it's an object. It handles the _null_ corner case better than `typeof`. + // + function isObject( value ) { + return value === Object(value); + } + + + // ### Each helper functions + // + // Of all the common helper functions `each` is the only one that differs from _underscore_ or + // _lodash_. The main difference is that it ensures to iterate over the JScript (IE < 9) hidden + // object properties. + // + // JScript has a known bug in `for.. in` loops that ignores some redefined `Object` properties. The + // `JSCRIPT_NON_ENUMERABLE` array contains those ignored properties, so we iterate over them in the `each` + // function. + // + var JSCRIPT_NON_ENUMERABLE = [ 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', + 'toLocaleString', 'toString', 'valueOf' ]; + + // #### eachKey( _obj_, _func_, _context_ ) + // + // The special case for JScript is handled by different implementations of the `eachKey` internal function. + // + + // + // **eachKeyStd** is the _standard_ implementation of _eachKey_. + // + function eachKeyStd( obj, func, context ) { + for ( var key in obj ) { + func.call(context, obj[key], key, obj); + } + } + + // + // **eachKeyFix** is an implementation of _eachKey_ that uses a workaround for JScript buggy enumeration. + // + function eachKeyFix( obj, func, context ) { + var i, len; + + eachKeyStd(obj, func, context); + + for ( i = 0, len = JSCRIPT_NON_ENUMERABLE.length; i < len; i++ ) { + if ( has(obj, JSCRIPT_NON_ENUMERABLE[i]) ) { + func.call(context, obj[JSCRIPT_NON_ENUMERABLE[i]], JSCRIPT_NON_ENUMERABLE[i], obj); + } + } + } + + // The proper `eachKey` implementation is defined according to `enumObjectOverrides`. + var enumObjectOverrides = (function () { + var obj = {constructor: 1}; + for ( var key in obj ) { if ( has(obj, key) ) { return true; } } + return false; + })(), + eachKey = enumObjectOverrides ? eachKeyStd : eachKeyFix; + + // #### each( _obj_, _func_, _context_ ) + // + // Same as but takes account of the special JScript case. + // + function each( obj, func, context ) { + var i, len; + + if ( obj === null ) { + return; + } + + if ( nativeForEach && obj.forEach === nativeForEach ) { + obj.forEach(func, context); + } else if ( obj.length === +obj.length ) { + for ( i = 0, len = obj.length; i < len; i++ ) { + func.call(context, obj[i], i, obj); + } + } else { + eachKey(obj, func, context); + } + } + + // #### extend( _obj_, ... ) + // + // Same as but uses `each` to iterate, so we handle the JScript special case + // properly. + // + function extend( obj ) { + each(slice.call(arguments, 1), function ( source ) { + if ( source ) { + each(source, function ( value, prop ) { obj[prop] = value; }); + } + }); + return obj; + } + + // #### clone( _obj_ ) + // + // Makes a shallow clone on an object. If the JavaScript engine implements `Object.create` we use it. If not + // we fallback to the usual "clone by using new" approach. + // + var clone = has(Object, 'create') ? Object.create : function ( proto ) { + function Empty() {} + + Empty.prototype = proto; + return new Empty(); + }; + + // #### defineSpecialProperty( _obj_, _name_, _value_ ) + // + // Defines a property that will be used internally by the framework. + // The property will be non-enumerable, non-writable and non-configurable + // (if the JS engine supports property descriptors). + // + + function defineSpecialPropertyStd( obj, name, value ) { + Object.defineProperty(obj, name, {value: value, writable: false, enumerable: false, configurable: false}); + return obj; + } + + function defineSpecialPropertyFix( obj, name, value ) { + obj[name] = value; + return obj; + } + + // The proper `defineSpecialProperty` implementation is if the engine supports non-enumerable properties + var defineSpecialProperty = (typeof Object.getOwnPropertyNames === 'function') ? + defineSpecialPropertyStd : defineSpecialPropertyFix; + + + // Merge + // ----- + + // `merge` is one of the main functions of *barman*. + // + // It's similar to the commonly used `extend({}, o1,...,oN)`, but it uses the following strategy + // for overwriting properties: + // + // * if values are different, the destination property is marked as `conflict` + // * if one of the values is marked as `required`, the destination property uses the value not marked as + // required + + + // ### Merge helper functions + + // #### mapProperties(_srcObj_, _iterator_, _result_) + // + // Returns a new object where each property is the result of applying the `iterator` function over `srcObj`: + // + // result.prop = iterator(srcObj.prop, 'prop'); + // + // _result_ is optional, and an empty object will be used if it's omitted. + // + function mapProperties( srcObj, iterator, result ) { + + if ( !result || !srcObj ) { result = {}; } + + each(srcObj, function ( value, prop ) { + + result[prop] = iterator.call(this, value, prop); + + }, result); + + return result; + } + + // #### conflict() + // + // Throws an error. Used to indicate _merge conflicts_. + // + function conflict() { + throw new Error( + 'This property was defined by multiple merged objects, override it with the proper implementation'); + } + + // #### required() + // + // Throws an error. Used to indicate that an implementation is required. + // + function required() { + throw new Error('An implementation is required'); + } + + // #### mergeProperty(_value_, _prop_) + // + // Used by `merge` to map each property. + // + function mergeProperty( value, prop ) { + + /*jshint validthis:true */ + + // The `this` context is set to the merge destination object, while + // the arguments `value` and `prop` contains the property-value pair to merge. + var thisValue = has(this, prop) ? this[prop] : undefined; + + if ( isUndefined(thisValue) || thisValue === value || thisValue === required ) { + // If the property is not defined directly in the target object (note the target object always starts + // as {} so if is not defined there directly is an property defined by Object.prototype), + // or both values are the same, + // or the target value is the `required` marker; use the given `value`. + + return value; + + } else if ( value === required ) { + // If the given `value` is the `required` marker, use the existing property value. + + return thisValue; + + } else { + // If both values are different, but not undefined or required, return the `conflict` marker. + + return conflict; + } + } + + // #### merge(_object_,...) + // + // Returns a new object, that is the result of merging the properties of each one of the given objects. + // + function merge() { + + var result = {}; + + each(arguments, function ( obj ) { + + mapProperties(obj, mergeProperty, result); + + }); + + return result; + } + + + // Nil + // --- + + // `Nil` is the root of the *barman* _class hierarchy_. + function Nil() { } + + // Every *barman* _class_ has a `__super__` property that returns the parent prototype. + // The parent of `Nil` is `Nil`. This is for compatibility with other frameworks (ie. CoffeeScript, Backbone). + defineSpecialProperty(Nil, '__super__', Nil.prototype); + + + // Default class factory + // --------------------- + + // Extension and creation of _classes_ is delegated to _ClassFactory_ objects. + // + // Those objects are marked with the special attribute `CLASS_FACTORY_ATTRIBUTE`, so they can be distinguished + // by _Class.create_ and _Nil.extend_. + // + var CLASS_FACTORY_ATTRIBUTE = '*classFactory*'; + + // #### markAsClassFactory(_obj_) + // + // Adds the `CLASS_FACTORY_ATTRIBUTE` to an object. + // + function markAsClassFactory( obj ) { + return defineSpecialProperty(obj, CLASS_FACTORY_ATTRIBUTE, true); + } + + // #### isClassFactory(_obj_) + // + // Returns true if the object is marked as a class factory. + // + function isClassFactory( obj ) { + return isObject(obj) && obj[CLASS_FACTORY_ATTRIBUTE] === true; + } + + // ### defaultClassFactory object + // + // It's the default implementation of a _ClassFactory_, and one of the _core_ functions of *barman*. + // + var defaultClassFactory = markAsClassFactory({ + + // #### createClass( _Parent_, _instanceMethods_, _staticMethods_ ) + // + createClass: function ( Parent, instanceMethods, staticMethods ) { + + // * Clone the `Parent.prototype` and extend it with the sub-class methods. + var proto = extend(clone(Parent.prototype), instanceMethods); + + // * Check if we define a _constructor_, if not define one that calls the parent constructor. + if ( !has(proto, 'constructor') ) { + + proto.constructor = function () { Parent.apply(this, arguments); }; + + } else if ( !isFunction(proto.constructor) ) { + + throw new TypeError('The constructor property must be a function'); + + } + + // * Extend the constructor function with the `staticMethods`. + var ctor = extend(proto.constructor, staticMethods); + + // * Add the `__super__` property to the constructor + defineSpecialProperty(ctor, '__super__', Parent.prototype); + + // * Finally ensure that the constructor has the right prototype and `extend` function. Note that + // you can't redefine `extend` with the `staticMethods`, if you want to customize `extend` use a + // _ClassFactory_. + ctor.prototype = proto; + ctor.extend = Nil.extend; + + return ctor; + } + + }); + + + // Convenience class creation functions + // ------------------------------------ + + // #### Nil.extend( _\[classFactory\]_, _args_ ) + // + // If no `classFactory` is given it uses `defaultClassFactory`. The interpretation of the rest arguments depends + // on the _ClassFactory_, see `defaultClassFactory.createClass`. + // + Nil.extend = function () { + var args = slice.call(arguments), + classFactory = (isClassFactory(args[0])) ? args.shift() : defaultClassFactory; + + args.unshift(this); + + return classFactory.createClass.apply(classFactory, args); + }; + + // #### Class.create( _\[classFactory\]_, _args_ ) + // + // It's a shortcut to `Nil.extend`. + // + var Class = { + create: function () { + return Nil.extend.apply(Nil, arguments); + } + }; + + // #### subclassOf( _Parent_, _args_ ) + // + // A shortcut to `Nil.extend`, that makes easy to sub-class non-barman classes. + // + function subclassOf( Parent ) { + return Nil.extend.apply(Parent, slice.call(arguments, 1)); + } + + // AbstractClassFactory + // -------------------- + + // Base class for custom class factories. It defines the class factory marker attribute, and provides + // a convenience method to call the `defaultClassFactory`. + // + var AbstractClassFactory = Class.create({ + + defaultCreateClass: function () { + return defaultClassFactory.createClass.apply(defaultClassFactory, arguments); + }, + + createClass: required + + }); + markAsClassFactory(AbstractClassFactory.prototype); + + + // TraitsClassFactory + // ------------------ + // + // A _ClassFactory_ that composes objects using _traits_. + // For more information about _traits_ see the [Design Notes](../docs/notes.md). + // + var TraitsClassFactory = AbstractClassFactory.extend({ + + constructor: function ( traits ) { this.traits = traits; }, + + createClass: function ( Parent, instanceMethods, staticMethods ) { + + var traitComposition = merge.apply(null, this.traits), + newClass = this.defaultCreateClass(Parent, extend(traitComposition, instanceMethods), staticMethods); + + this._assertNoConflict(newClass.prototype); + + return newClass; + + }, + + _assertNoConflict: function ( obj ) { + var conflicts = []; + each(obj, function ( value, name ) { if ( value === conflict ) { conflicts.push(name); } }); + + if ( conflicts.length > 0 ) { + throw new Error('There is a merge conflict for the following properties: ' + + conflicts.sort().join(',')); + } + } + + }); + + // #### include( _trait_, ... ) + // + // A nice way to create a `TraitsClassFactory` instance. + // + function include() { + return new TraitsClassFactory(slice.call(arguments)); + } + + + // Public function and objects + // --------------------------- + + return { + clone: clone, + extend: extend, + merge: merge, + conflict: conflict, + + Nil: Nil, + + markAsClassFactory: markAsClassFactory, + isClassFactory: isClassFactory, + AbstractClassFactory: AbstractClassFactory, + + defaultClassFactory: defaultClassFactory, + Class: Class, + subclassOf: subclassOf, + + required: required, + + include: include + }; + + } + + // Module export + // ------------- + + // Barman can be used in different contexts: + // + if ( typeof define === 'function' && define.amd ) { + // * If _define_ is a function for AMD, export barman using define. + define([], factory); + + } else if ( typeof module !== 'undefined' && module.exports ) { + // * If _module.exports_ is available (Node.js), export barman using it. + module.exports = factory(); + + } else { + // * Otherwise, assume a browser environment and use the _window_ global to export the _barman_ variable. + + window.barman = factory(); + } + +})(); \ No newline at end of file diff --git a/ajax/libs/barman/0.3.0/barman.min.js b/ajax/libs/barman/0.3.0/barman.min.js new file mode 100644 index 00000000000000..1b70bfd1715ff6 --- /dev/null +++ b/ajax/libs/barman/0.3.0/barman.min.js @@ -0,0 +1,5 @@ +// barman 0.3.0 +// https://github.com/dfernandez79/barman +// Copyright (c) 2013 Diego Fernandez +(function(){"use strict";function t(){function t(t){return t===void 0}function r(t){return"function"==typeof t}function e(t,r){return t?Object.prototype.hasOwnProperty.call(t,r):!1}function n(t){return t===Object(t)}function o(t,r,e){for(var n in t)r.call(e,t[n],n,t)}function c(t,r,n){var c,u;for(o(t,r,n),c=0,u=_.length;u>c;c++)e(t,_[c])&&r.call(n,t[_[c]],_[c],t)}function u(t,r,e){var n,o;if(null!==t)if(C&&t.forEach===C)t.forEach(r,e);else if(t.length===+t.length)for(n=0,o=t.length;o>n;n++)r.call(e,t[n],n,t);else j(t,r,e)}function i(t){return u(O.call(arguments,1),function(r){r&&u(r,function(r,e){t[e]=r})}),t}function a(t,r,e){return Object.defineProperty(t,r,{value:e,writable:!1,enumerable:!1,configurable:!1}),t}function s(t,r,e){return t[r]=e,t}function f(t,r,e){return e&&t||(e={}),u(t,function(t,n){e[n]=r.call(this,t,n)},e),e}function l(){throw Error("This property was defined by multiple merged objects, override it with the proper implementation")}function p(){throw Error("An implementation is required")}function y(r,n){var o=e(this,n)?this[n]:void 0;return t(o)||o===r||o===p?r:r===p?o:l}function h(){var t={};return u(arguments,function(r){f(r,y,t)}),t}function d(){}function m(t){return F(t,P,!0)}function g(t){return n(t)&&t[P]===!0}function v(t){return d.extend.apply(t,O.call(arguments,1))}function b(){return new q(O.call(arguments))}var w=Array.prototype,C=w.forEach,O=w.slice,_=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],x=function(){var t={constructor:1};for(var r in t)if(e(t,r))return!0;return!1}(),j=x?o:c,E=e(Object,"create")?Object.create:function(t){function r(){}return r.prototype=t,new r},F="function"==typeof Object.getOwnPropertyNames?a:s;F(d,"__super__",d.prototype);var P="*classFactory*",A=m({createClass:function(t,n,o){var c=i(E(t.prototype),n);if(e(c,"constructor")){if(!r(c.constructor))throw new TypeError("The constructor property must be a function")}else c.constructor=function(){t.apply(this,arguments)};var u=i(c.constructor,o);return F(u,"__super__",t.prototype),u.prototype=c,u.extend=d.extend,u}});d.extend=function(){var t=O.call(arguments),r=g(t[0])?t.shift():A;return t.unshift(this),r.createClass.apply(r,t)};var N={create:function(){return d.extend.apply(d,arguments)}},T=N.create({defaultCreateClass:function(){return A.createClass.apply(A,arguments)},createClass:p});m(T.prototype);var q=T.extend({constructor:function(t){this.traits=t},createClass:function(t,r,e){var n=h.apply(null,this.traits),o=this.defaultCreateClass(t,i(n,r),e);return this._assertNoConflict(o.prototype),o},_assertNoConflict:function(t){var r=[];if(u(t,function(t,e){t===l&&r.push(e)}),r.length>0)throw Error("There is a merge conflict for the following properties: "+r.sort().join(","))}});return{clone:E,extend:i,merge:h,conflict:l,Nil:d,markAsClassFactory:m,isClassFactory:g,AbstractClassFactory:T,defaultClassFactory:A,Class:N,subclassOf:v,required:p,include:b}}"function"==typeof define&&define.amd?define([],t):"undefined"!=typeof module&&module.exports?module.exports=t():window.barman=t()})(); +//@ sourceMappingURL=https://raw.github.com/dfernandez79/barman/v0.3.0/dist/barman.min.js.map \ No newline at end of file diff --git a/ajax/libs/barman/package.json b/ajax/libs/barman/package.json index 4a80ea876b8520..d9f8da05ab50f0 100644 --- a/ajax/libs/barman/package.json +++ b/ajax/libs/barman/package.json @@ -1,7 +1,7 @@ { "name": "barman", "description": "A small library to brew JavaScript objects.", - "version": "0.2.4", + "version": "0.3.0", "homepage": "https://github.com/dfernandez79/barman", "author": { "name": "Diego Fernandez",