Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update package.json

  • Loading branch information...
commit 71c74a43d8c4c7d5d6d2046a357b417d3a5ed4b9 1 parent 2af7e28
@ericelliott authored
Showing with 80 additions and 53 deletions.
  1. +79 −52 lib/applitude.bundle.js
  2. +1 −1  package.json
View
131 lib/applitude.bundle.js
@@ -555,35 +555,40 @@
*/
/*global exports */
-// Shim .forEach()
-if (!Array.prototype.forEach) {
- Array.prototype.forEach = function (fn, scope) {
- var i,
- length = this.length;
- for (i = 0, length; i < length; ++i) {
- fn.call(scope || this, this[i], i, this);
- }
- };
-}
-// Shim Object.create()
-if (!Object.create) {
- Object.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();
- };
-}
+// Polyfills
+(function () {
+ 'use strict';
+ // Shim .forEach()
+ if (!Array.prototype.forEach) {
+ Array.prototype.forEach = function (fn, scope) {
+ var i,
+ length = this.length;
+ for (i = 0, length; i < length; ++i) {
+ fn.call(scope || this, this[i], i, this);
+ }
+ };
+ }
-// Shim String.prototype.trim()
-if(!String.prototype.trim) {
- String.prototype.trim = function () {
- return this.replace(/^\s+|\s+$/g,'');
- };
-}
+ // Shim Object.create()
+ if (!Object.create) {
+ Object.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();
+ };
+ }
+
+ // Shim String.prototype.trim()
+ if(!String.prototype.trim) {
+ String.prototype.trim = function () {
+ return this.replace(/^\s+|\s+$/g,'');
+ };
+ }
+}());
(function (exports) {
'use strict';
@@ -622,6 +627,11 @@ if(!String.prototype.trim) {
return proto;
},
+
+ copy = function copy(input) {
+ return JSON.parse(JSON.stringify(input));
+ },
+
o,
api,
defaultInit = function init() {
@@ -639,20 +649,29 @@ if(!String.prototype.trim) {
*/
mapOptions = function mapOptions(optionNames) {
var config = {}, // New config object
+
// Comma separated string to Array
- names = optionNames.split(','),
- // Turn arguments into array, starting at index 1
- args = [].slice.call(arguments, 1);
+ names = optionNames.split(/\s*\,\s*/),
- names.forEach(function (optionName, index) {
- // Strip whitespace
- optionName = optionName.trim();
+ // Turn arguments into array, starting at index 1
+ args = [].slice.call(arguments, 1),
+ isHash;
+ names.forEach(function (optionName) {
// Use first argument as params object...
- config[optionName] = (args[0] && args[0][optionName]) ||
- args[index]; // or grab the formal parameter.
+ if (args[0] && args[0][optionName]) {
+ config[optionName] = args[0][optionName];
+ isHash = true;
+ }
});
+ // Or, grab the options from the arguments
+ if (!isHash) {
+ names.forEach(function (optionName, index) {
+ config[optionName] = args[index];
+ });
+ }
+
return config;
};
@@ -694,22 +713,23 @@ if(!String.prototype.trim) {
/**
* Returns an object factory that stamps out objects
* using a specified shared prototype and init.
- *
- * @param {object} sharedProperties Prototype
- * @param {object} defaultProperties Instance safe
- * @param {function} initFunction Init and privacy
- *
- * @return {function} A new object factory.
+ *
+ * @param {Object} sharedProperties prototype
+ * @param {Object} defaultProperties instance properties
+ * @param {Function} instanceInit instance level init
+ * @param {Function} factoryInit factory level init
+ * @param {Boolean} ignoreOptions ignore instance options?
+ * @return {Function} factory function
*/
factory: function factory(sharedProperties, defaultProperties,
- instanceInit, factoryInit) {
+ instanceInit, factoryInit, ignoreOptions) {
var optionNames = 'sharedProperties, defaultProperties,' +
- ' instanceInit, factoryInit',
+ ' instanceInit, factoryInit, ignoreOptions',
config,
initObj = o();
config = mapOptions(optionNames, sharedProperties,
- defaultProperties, instanceInit, factoryInit);
+ defaultProperties, instanceInit, factoryInit, ignoreOptions);
config.instanceInit = config.instanceInit || defaultInit;
// factoryInit can be used to initialize shared private state.
@@ -718,13 +738,20 @@ if(!String.prototype.trim) {
}
return bless(function (options) {
- var defaultProperties = config.defaultProperties || {},
- sharedProperties = extend(config.sharedProperties || {}, initObj),
- instance = extend(defaultProperties, options),
- obj = extend(o(sharedProperties, instance)),
- init = config.instanceInit;
+ var defaultProperties = copy(config.defaultProperties || {},
+ sharedProperties = extend(config.sharedProperties ||
+ {}, initObj)),
+ instance = (config.ignoreOptions) ?
+ defaultProperties :
+ extend({}, defaultProperties, options),
+ obj,
+ init;
+
+ obj = extend(o(sharedProperties, instance));
+ init = config.instanceInit;
+
return ((typeof init === 'function') ?
- init.call(obj)
+ init.call(obj, options)
: obj);
});
},
@@ -751,8 +778,8 @@ if(!String.prototype.trim) {
* http://opensource.org/licenses/MIT
*/
-/*global jQuery, EventEmitter2, odotjs, window, setTimeout,
-console, exports, navigator */
+/*global jQuery, EventEmitter2, odotjs, window,
+console, exports */
(function (root, $, o, events) {
'use strict';
var namespace = 'applitude',
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "cuid",
- "version": "1.1.7",
+ "version": "1.1.8",
"description": "Collission-resistant ids optimized for horizontal scaling and performance. For node and browsers.",
"author": {
"name": "Eric Elliott",
Please sign in to comment.
Something went wrong with that request. Please try again.