Merge pull request #58 from humphd/shrinkage
Remove need for encoding-indexes.js, trim bits of lodash.js we don't need. Fixes #57
This commit is contained in:
commit
35e2db6116
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -45,9 +45,10 @@ module.exports = function(grunt) {
|
||||||
endFile: 'build/wrap.end'
|
endFile: 'build/wrap.end'
|
||||||
},
|
},
|
||||||
shim: {
|
shim: {
|
||||||
// TextEncoder and TextDecoder shims. encoding-indexes must get loaded first.
|
// TextEncoder and TextDecoder shims. encoding-indexes must get loaded first,
|
||||||
|
// and we use a fake one for reduced size, since we only care about utf8.
|
||||||
"encoding": {
|
"encoding": {
|
||||||
deps: ["encoding-indexes"]
|
deps: ["encoding-indexes-shim"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
// Hack to allow using encoding.js with only utf8.
|
||||||
|
// Right now there's a bug where it expects global['encoding-indexes']:
|
||||||
|
//
|
||||||
|
// function index(name) {
|
||||||
|
// if (!('encoding-indexes' in global))
|
||||||
|
// throw new Error("Indexes missing. Did you forget to include encoding-indexes.js?");
|
||||||
|
// return global['encoding-indexes'][name];
|
||||||
|
// }
|
||||||
|
(function(global) {
|
||||||
|
global['encoding-indexes'] = global['encoding-indexes'] || [];
|
||||||
|
}(this));
|
File diff suppressed because one or more lines are too long
4201
lib/lodash.js
4201
lib/lodash.js
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,102 @@
|
||||||
|
// Cherry-picked bits of underscore.js, lodash.js
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lo-Dash 2.4.0 <http://lodash.com/>
|
||||||
|
* Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/>
|
||||||
|
* Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE>
|
||||||
|
* Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
||||||
|
* Available under MIT license <http://lodash.com/license>
|
||||||
|
*/
|
||||||
|
|
||||||
|
define(function(require) {
|
||||||
|
|
||||||
|
var ArrayProto = Array.prototype;
|
||||||
|
var nativeForEach = ArrayProto.forEach;
|
||||||
|
var nativeIndexOf = ArrayProto.indexOf;
|
||||||
|
var nativeSome = ArrayProto.some;
|
||||||
|
|
||||||
|
var ObjProto = Object.prototype;
|
||||||
|
var hasOwnProperty = ObjProto.hasOwnProperty;
|
||||||
|
var nativeKeys = Object.keys;
|
||||||
|
|
||||||
|
var breaker = {};
|
||||||
|
|
||||||
|
function has(obj, key) {
|
||||||
|
return hasOwnProperty.call(obj, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
var keys = nativeKeys || function(obj) {
|
||||||
|
if (obj !== Object(obj)) throw new TypeError('Invalid object');
|
||||||
|
var keys = [];
|
||||||
|
for (var key in obj) if (has(obj, key)) keys.push(key);
|
||||||
|
return keys;
|
||||||
|
};
|
||||||
|
|
||||||
|
function size(obj) {
|
||||||
|
if (obj == null) return 0;
|
||||||
|
return (obj.length === +obj.length) ? obj.length : keys(obj).length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function identity(value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function each(obj, iterator, context) {
|
||||||
|
var i, length;
|
||||||
|
if (obj == null) return;
|
||||||
|
if (nativeForEach && obj.forEach === nativeForEach) {
|
||||||
|
obj.forEach(iterator, context);
|
||||||
|
} else if (obj.length === +obj.length) {
|
||||||
|
for (i = 0, length = obj.length; i < length; i++) {
|
||||||
|
if (iterator.call(context, obj[i], i, obj) === breaker) return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var keys = keys(obj);
|
||||||
|
for (i = 0, length = keys.length; i < length; i++) {
|
||||||
|
if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function any(obj, iterator, context) {
|
||||||
|
iterator || (iterator = identity);
|
||||||
|
var result = false;
|
||||||
|
if (obj == null) return result;
|
||||||
|
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
|
||||||
|
each(obj, function(value, index, list) {
|
||||||
|
if (result || (result = iterator.call(context, value, index, list))) return breaker;
|
||||||
|
});
|
||||||
|
return !!result;
|
||||||
|
};
|
||||||
|
|
||||||
|
function contains(obj, target) {
|
||||||
|
if (obj == null) return false;
|
||||||
|
if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
|
||||||
|
return any(obj, function(value) {
|
||||||
|
return value === target;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function Wrapped(value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
Wrapped.prototype.has = function(key) {
|
||||||
|
return has(this.value, key);
|
||||||
|
};
|
||||||
|
Wrapped.prototype.contains = function(target) {
|
||||||
|
return contains(this.value, target);
|
||||||
|
};
|
||||||
|
Wrapped.prototype.size = function() {
|
||||||
|
return size(this.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
function nodash(value) {
|
||||||
|
// don't wrap if already wrapped, even if wrapped by a different `lodash` constructor
|
||||||
|
return (value && typeof value == 'object' && !Array.isArray(value) && hasOwnProperty.call(value, '__wrapped__'))
|
||||||
|
? value
|
||||||
|
: new Wrapped(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodash;
|
||||||
|
|
||||||
|
});
|
|
@ -1,6 +1,6 @@
|
||||||
define(function(require) {
|
define(function(require) {
|
||||||
|
|
||||||
var _ = require('lodash');
|
var _ = require('nodash');
|
||||||
|
|
||||||
// TextEncoder and TextDecoder will either already be present, or use this shim.
|
// TextEncoder and TextDecoder will either already be present, or use this shim.
|
||||||
// Because of the way the spec is defined, we need to get them off the global.
|
// Because of the way the spec is defined, we need to get them off the global.
|
||||||
|
|
|
@ -13,9 +13,10 @@ require.config({
|
||||||
baseUrl: "../lib",
|
baseUrl: "../lib",
|
||||||
optimize: "none",
|
optimize: "none",
|
||||||
shim: {
|
shim: {
|
||||||
// TextEncoder and TextDecoder shims. encoding-indexes must get loaded first.
|
// TextEncoder and TextDecoder shims. encoding-indexes must get loaded first,
|
||||||
|
// and we use a fake one for reduced size, since we only care about utf8.
|
||||||
"encoding": {
|
"encoding": {
|
||||||
deps: ["encoding-indexes"]
|
deps: ["encoding-indexes-shim"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue