aboutsummaryrefslogtreecommitdiff
path: root/node_modules/utila/lib
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/utila/lib
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/utila/lib')
-rw-r--r--node_modules/utila/lib/Emitter.js137
-rw-r--r--node_modules/utila/lib/_common.js111
-rw-r--r--node_modules/utila/lib/array.js165
-rw-r--r--node_modules/utila/lib/classic.js86
-rw-r--r--node_modules/utila/lib/object.js158
-rw-r--r--node_modules/utila/lib/string.js14
-rw-r--r--node_modules/utila/lib/utila.js10
7 files changed, 681 insertions, 0 deletions
diff --git a/node_modules/utila/lib/Emitter.js b/node_modules/utila/lib/Emitter.js
new file mode 100644
index 00000000..3a67ed19
--- /dev/null
+++ b/node_modules/utila/lib/Emitter.js
@@ -0,0 +1,137 @@
+// Generated by CoffeeScript 1.6.3
+var Emitter, array;
+
+array = require('./array');
+
+module.exports = Emitter = (function() {
+ function Emitter() {
+ this._listeners = {};
+ this._listenersForAnyEvent = [];
+ this._disabledEmitters = {};
+ }
+
+ Emitter.prototype.on = function(eventName, listener) {
+ if (this._listeners[eventName] == null) {
+ this._listeners[eventName] = [];
+ }
+ this._listeners[eventName].push(listener);
+ return this;
+ };
+
+ Emitter.prototype.once = function(eventName, listener) {
+ var cb, ran,
+ _this = this;
+ ran = false;
+ cb = function() {
+ if (ran) {
+ return;
+ }
+ ran = true;
+ listener();
+ return setTimeout(function() {
+ return _this.removeEvent(eventName, cb);
+ }, 0);
+ };
+ this.on(eventName, cb);
+ return this;
+ };
+
+ Emitter.prototype.onAnyEvent = function(listener) {
+ this._listenersForAnyEvent.push(listener);
+ return this;
+ };
+
+ Emitter.prototype.removeEvent = function(eventName, listener) {
+ if (this._listeners[eventName] == null) {
+ return this;
+ }
+ array.pluckOneItem(this._listeners[eventName], listener);
+ return this;
+ };
+
+ Emitter.prototype.removeListeners = function(eventName) {
+ if (this._listeners[eventName] == null) {
+ return this;
+ }
+ this._listeners[eventName].length = 0;
+ return this;
+ };
+
+ Emitter.prototype.removeAllListeners = function() {
+ var listeners, name, _ref;
+ _ref = this._listeners;
+ for (name in _ref) {
+ listeners = _ref[name];
+ listeners.length = 0;
+ }
+ return this;
+ };
+
+ Emitter.prototype._emit = function(eventName, data) {
+ var listener, _i, _j, _len, _len1, _ref, _ref1;
+ _ref = this._listenersForAnyEvent;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ listener = _ref[_i];
+ listener.call(this, data, eventName);
+ }
+ if (this._listeners[eventName] == null) {
+ return;
+ }
+ _ref1 = this._listeners[eventName];
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
+ listener = _ref1[_j];
+ listener.call(this, data);
+ }
+ };
+
+ Emitter.prototype._throttleEmitterMethod = function(fnName, time) {
+ var lastCallArgs, originalFn, pend, pending, runIt, timer,
+ _this = this;
+ if (time == null) {
+ time = 1000;
+ }
+ originalFn = this[fnName];
+ if (typeof originalFn !== 'function') {
+ throw Error("this class does not have a method called '" + fnName + "'");
+ }
+ lastCallArgs = null;
+ pending = false;
+ timer = null;
+ this[fnName] = function() {
+ lastCallArgs = arguments;
+ return pend();
+ };
+ pend = function() {
+ if (pending) {
+ clearTimeout(timer);
+ }
+ timer = setTimeout(runIt, time);
+ return pending = true;
+ };
+ return runIt = function() {
+ pending = false;
+ return originalFn.apply(_this, lastCallArgs);
+ };
+ };
+
+ Emitter.prototype._disableEmitter = function(fnName) {
+ if (this._disabledEmitters[fnName] != null) {
+ throw Error("" + fnName + " is already a disabled emitter");
+ }
+ this._disabledEmitters[fnName] = this[fnName];
+ return this[fnName] = function() {};
+ };
+
+ Emitter.prototype._enableEmitter = function(fnName) {
+ var fn;
+ fn = this._disabledEmitters[fnName];
+ if (fn == null) {
+ throw Error("" + fnName + " is not a disabled emitter");
+ }
+ this[fnName] = fn;
+ return delete this._disabledEmitters[fnName];
+ };
+
+ return Emitter;
+
+})();
diff --git a/node_modules/utila/lib/_common.js b/node_modules/utila/lib/_common.js
new file mode 100644
index 00000000..b5eb5036
--- /dev/null
+++ b/node_modules/utila/lib/_common.js
@@ -0,0 +1,111 @@
+// Generated by CoffeeScript 1.6.3
+var common;
+
+module.exports = common = {
+ /*
+ Checks to see if o is an object, and it isn't an instance
+ of some class.
+ */
+
+ isBareObject: function(o) {
+ if ((o != null) && o.constructor === Object) {
+ return true;
+ }
+ return false;
+ },
+ /*
+ Returns type of an object, including:
+ undefined, null, string, number, array,
+ arguments, element, textnode, whitespace, and object
+ */
+
+ typeOf: function(item) {
+ var _ref;
+ if (item === null) {
+ return 'null';
+ }
+ if (typeof item !== 'object') {
+ return typeof item;
+ }
+ if (Array.isArray(item)) {
+ return 'array';
+ }
+ if (item.nodeName) {
+ if (item.nodeType === 1) {
+ return 'element';
+ }
+ if (item.nodeType === 3) {
+ return (_ref = /\S/.test(item.nodeValue)) != null ? _ref : {
+ 'textnode': 'whitespace'
+ };
+ }
+ } else if (typeof item.length === 'number') {
+ if (item.callee) {
+ return 'arguments';
+ }
+ }
+ return typeof item;
+ },
+ clone: function(item, includePrototype) {
+ if (includePrototype == null) {
+ includePrototype = false;
+ }
+ switch (common.typeOf(item)) {
+ case 'array':
+ return common._cloneArray(item, includePrototype);
+ case 'object':
+ return common._cloneObject(item, includePrototype);
+ default:
+ return item;
+ }
+ },
+ /*
+ Deep clone of an object.
+ From MooTools
+ */
+
+ _cloneObject: function(o, includePrototype) {
+ var clone, key;
+ if (includePrototype == null) {
+ includePrototype = false;
+ }
+ if (common.isBareObject(o)) {
+ clone = {};
+ for (key in o) {
+ clone[key] = common.clone(o[key], includePrototype);
+ }
+ return clone;
+ } else {
+ if (!includePrototype) {
+ return o;
+ }
+ if (o instanceof Function) {
+ return o;
+ }
+ clone = Object.create(o.constructor.prototype);
+ for (key in o) {
+ if (o.hasOwnProperty(key)) {
+ clone[key] = common.clone(o[key], includePrototype);
+ }
+ }
+ return clone;
+ }
+ },
+ /*
+ Deep clone of an array.
+ From MooTools
+ */
+
+ _cloneArray: function(a, includePrototype) {
+ var clone, i;
+ if (includePrototype == null) {
+ includePrototype = false;
+ }
+ i = a.length;
+ clone = new Array(i);
+ while (i--) {
+ clone[i] = common.clone(a[i], includePrototype);
+ }
+ return clone;
+ }
+};
diff --git a/node_modules/utila/lib/array.js b/node_modules/utila/lib/array.js
new file mode 100644
index 00000000..3873d3ef
--- /dev/null
+++ b/node_modules/utila/lib/array.js
@@ -0,0 +1,165 @@
+// Generated by CoffeeScript 1.6.3
+var array;
+
+module.exports = array = {
+ /*
+ Tries to turn anything into an array.
+ */
+
+ from: function(r) {
+ return Array.prototype.slice.call(r);
+ },
+ /*
+ Clone of an array. Properties will be shallow copies.
+ */
+
+ simpleClone: function(a) {
+ return a.slice(0);
+ },
+ shallowEqual: function(a1, a2) {
+ var i, val, _i, _len;
+ if (!(Array.isArray(a1) && Array.isArray(a2) && a1.length === a2.length)) {
+ return false;
+ }
+ for (i = _i = 0, _len = a1.length; _i < _len; i = ++_i) {
+ val = a1[i];
+ if (a2[i] !== val) {
+ return false;
+ }
+ }
+ return true;
+ },
+ pluck: function(a, i) {
+ var index, value, _i, _len;
+ if (a.length < 1) {
+ return a;
+ }
+ for (index = _i = 0, _len = a.length; _i < _len; index = ++_i) {
+ value = a[index];
+ if (index > i) {
+ a[index - 1] = a[index];
+ }
+ }
+ a.length = a.length - 1;
+ return a;
+ },
+ pluckItem: function(a, item) {
+ var index, removed, value, _i, _len;
+ if (a.length < 1) {
+ return a;
+ }
+ removed = 0;
+ for (index = _i = 0, _len = a.length; _i < _len; index = ++_i) {
+ value = a[index];
+ if (value === item) {
+ removed++;
+ continue;
+ }
+ if (removed !== 0) {
+ a[index - removed] = a[index];
+ }
+ }
+ if (removed > 0) {
+ a.length = a.length - removed;
+ }
+ return a;
+ },
+ pluckOneItem: function(a, item) {
+ var index, reached, value, _i, _len;
+ if (a.length < 1) {
+ return a;
+ }
+ reached = false;
+ for (index = _i = 0, _len = a.length; _i < _len; index = ++_i) {
+ value = a[index];
+ if (!reached) {
+ if (value === item) {
+ reached = true;
+ continue;
+ }
+ } else {
+ a[index - 1] = a[index];
+ }
+ }
+ if (reached) {
+ a.length = a.length - 1;
+ }
+ return a;
+ },
+ pluckByCallback: function(a, cb) {
+ var index, removed, value, _i, _len;
+ if (a.length < 1) {
+ return a;
+ }
+ removed = 0;
+ for (index = _i = 0, _len = a.length; _i < _len; index = ++_i) {
+ value = a[index];
+ if (cb(value, index)) {
+ removed++;
+ continue;
+ }
+ if (removed !== 0) {
+ a[index - removed] = a[index];
+ }
+ }
+ if (removed > 0) {
+ a.length = a.length - removed;
+ }
+ return a;
+ },
+ pluckMultiple: function(array, indexesToRemove) {
+ var i, removedSoFar, _i, _len;
+ if (array.length < 1) {
+ return array;
+ }
+ removedSoFar = 0;
+ indexesToRemove.sort();
+ for (_i = 0, _len = indexesToRemove.length; _i < _len; _i++) {
+ i = indexesToRemove[_i];
+ this.pluck(array, i - removedSoFar);
+ removedSoFar++;
+ }
+ return array;
+ },
+ injectByCallback: function(a, toInject, shouldInject) {
+ var i, len, val, valA, valB, _i, _len;
+ valA = null;
+ valB = null;
+ len = a.length;
+ if (len < 1) {
+ a.push(toInject);
+ return a;
+ }
+ for (i = _i = 0, _len = a.length; _i < _len; i = ++_i) {
+ val = a[i];
+ valA = valB;
+ valB = val;
+ if (shouldInject(valA, valB, toInject)) {
+ return a.splice(i, 0, toInject);
+ }
+ }
+ a.push(toInject);
+ return a;
+ },
+ injectInIndex: function(a, index, toInject) {
+ var i, len, toPut, toPutNext;
+ len = a.length;
+ i = index;
+ if (len < 1) {
+ a.push(toInject);
+ return a;
+ }
+ toPut = toInject;
+ toPutNext = null;
+ for(; i <= len; i++){
+
+ toPutNext = a[i];
+
+ a[i] = toPut;
+
+ toPut = toPutNext;
+
+ };
+ return null;
+ }
+};
diff --git a/node_modules/utila/lib/classic.js b/node_modules/utila/lib/classic.js
new file mode 100644
index 00000000..a77bd328
--- /dev/null
+++ b/node_modules/utila/lib/classic.js
@@ -0,0 +1,86 @@
+// Generated by CoffeeScript 1.6.3
+var classic,
+ __slice = [].slice;
+
+module.exports = classic = {};
+
+classic.implement = function() {
+ var classProto, classReference, desc, member, mixin, mixins, _i, _j, _len;
+ mixins = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), classReference = arguments[_i++];
+ for (_j = 0, _len = mixins.length; _j < _len; _j++) {
+ mixin = mixins[_j];
+ classProto = classReference.prototype;
+ for (member in mixin.prototype) {
+ if (!Object.getOwnPropertyDescriptor(classProto, member)) {
+ desc = Object.getOwnPropertyDescriptor(mixin.prototype, member);
+ Object.defineProperty(classProto, member, desc);
+ }
+ }
+ }
+ return classReference;
+};
+
+classic.mix = function() {
+ var classProto, classReference, desc, member, mixin, mixins, _i, _j, _len;
+ mixins = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), classReference = arguments[_i++];
+ classProto = classReference.prototype;
+ classReference.__mixinCloners = [];
+ classReference.__applyClonersFor = function(instance, args) {
+ var cloner, _j, _len, _ref;
+ if (args == null) {
+ args = null;
+ }
+ _ref = classReference.__mixinCloners;
+ for (_j = 0, _len = _ref.length; _j < _len; _j++) {
+ cloner = _ref[_j];
+ cloner.apply(instance, args);
+ }
+ };
+ classReference.__mixinInitializers = [];
+ classReference.__initMixinsFor = function(instance, args) {
+ var initializer, _j, _len, _ref;
+ if (args == null) {
+ args = null;
+ }
+ _ref = classReference.__mixinInitializers;
+ for (_j = 0, _len = _ref.length; _j < _len; _j++) {
+ initializer = _ref[_j];
+ initializer.apply(instance, args);
+ }
+ };
+ classReference.__mixinQuitters = [];
+ classReference.__applyQuittersFor = function(instance, args) {
+ var quitter, _j, _len, _ref;
+ if (args == null) {
+ args = null;
+ }
+ _ref = classReference.__mixinQuitters;
+ for (_j = 0, _len = _ref.length; _j < _len; _j++) {
+ quitter = _ref[_j];
+ quitter.apply(instance, args);
+ }
+ };
+ for (_j = 0, _len = mixins.length; _j < _len; _j++) {
+ mixin = mixins[_j];
+ if (!(mixin.constructor instanceof Function)) {
+ throw Error("Mixin should be a function");
+ }
+ for (member in mixin.prototype) {
+ if (member.substr(0, 11) === '__initMixin') {
+ classReference.__mixinInitializers.push(mixin.prototype[member]);
+ continue;
+ } else if (member.substr(0, 11) === '__clonerFor') {
+ classReference.__mixinCloners.push(mixin.prototype[member]);
+ continue;
+ } else if (member.substr(0, 12) === '__quitterFor') {
+ classReference.__mixinQuitters.push(mixin.prototype[member]);
+ continue;
+ }
+ if (!Object.getOwnPropertyDescriptor(classProto, member)) {
+ desc = Object.getOwnPropertyDescriptor(mixin.prototype, member);
+ Object.defineProperty(classProto, member, desc);
+ }
+ }
+ }
+ return classReference;
+};
diff --git a/node_modules/utila/lib/object.js b/node_modules/utila/lib/object.js
new file mode 100644
index 00000000..47e2c168
--- /dev/null
+++ b/node_modules/utila/lib/object.js
@@ -0,0 +1,158 @@
+// Generated by CoffeeScript 1.6.3
+var object, _common,
+ __hasProp = {}.hasOwnProperty;
+
+_common = require('./_common');
+
+module.exports = object = {
+ isBareObject: _common.isBareObject.bind(_common),
+ /*
+ if object is an instance of a class
+ */
+
+ isInstance: function(what) {
+ return !this.isBareObject(what);
+ },
+ /*
+ Alias to _common.typeOf
+ */
+
+ typeOf: _common.typeOf.bind(_common),
+ /*
+ Alias to _common.clone
+ */
+
+ clone: _common.clone.bind(_common),
+ /*
+ Empties an object of its properties.
+ */
+
+ empty: function(o) {
+ var prop;
+ for (prop in o) {
+ if (o.hasOwnProperty(prop)) {
+ delete o[prop];
+ }
+ }
+ return o;
+ },
+ /*
+ Empties an object. Doesn't check for hasOwnProperty, so it's a tiny
+ bit faster. Use it for plain objects.
+ */
+
+ fastEmpty: function(o) {
+ var property;
+ for (property in o) {
+ delete o[property];
+ }
+ return o;
+ },
+ /*
+ Overrides values fomr `newValues` on `base`, as long as they
+ already exist in base.
+ */
+
+ overrideOnto: function(base, newValues) {
+ var key, newVal, oldVal;
+ if (!this.isBareObject(newValues) || !this.isBareObject(base)) {
+ return base;
+ }
+ for (key in base) {
+ oldVal = base[key];
+ newVal = newValues[key];
+ if (newVal === void 0) {
+ continue;
+ }
+ if (typeof newVal !== 'object' || this.isInstance(newVal)) {
+ base[key] = this.clone(newVal);
+ } else {
+ if (typeof oldVal !== 'object' || this.isInstance(oldVal)) {
+ base[key] = this.clone(newVal);
+ } else {
+ this.overrideOnto(oldVal, newVal);
+ }
+ }
+ }
+ return base;
+ },
+ /*
+ Takes a clone of 'base' and runs #overrideOnto on it
+ */
+
+ override: function(base, newValues) {
+ return this.overrideOnto(this.clone(base), newValues);
+ },
+ append: function(base, toAppend) {
+ return this.appendOnto(this.clone(base), toAppend);
+ },
+ appendOnto: function(base, toAppend) {
+ var key, newVal, oldVal;
+ if (!this.isBareObject(toAppend) || !this.isBareObject(base)) {
+ return base;
+ }
+ for (key in toAppend) {
+ if (!__hasProp.call(toAppend, key)) continue;
+ newVal = toAppend[key];
+ if (newVal === void 0) {
+ continue;
+ }
+ if (typeof newVal !== 'object' || this.isInstance(newVal)) {
+ base[key] = newVal;
+ } else {
+ oldVal = base[key];
+ if (typeof oldVal !== 'object' || this.isInstance(oldVal)) {
+ base[key] = this.clone(newVal);
+ } else {
+ this.appendOnto(oldVal, newVal);
+ }
+ }
+ }
+ return base;
+ },
+ groupProps: function(obj, groups) {
+ var def, defs, grouped, key, name, shouldAdd, val, _i, _len;
+ grouped = {};
+ for (name in groups) {
+ defs = groups[name];
+ grouped[name] = {};
+ }
+ grouped['rest'] = {};
+ top: //;
+ for (key in obj) {
+ val = obj[key];
+ shouldAdd = false;
+ for (name in groups) {
+ defs = groups[name];
+ if (!Array.isArray(defs)) {
+ defs = [defs];
+ }
+ for (_i = 0, _len = defs.length; _i < _len; _i++) {
+ def = defs[_i];
+ if (typeof def === 'string') {
+ if (key === def) {
+ shouldAdd = true;
+ }
+ } else if (def instanceof RegExp) {
+ if (def.test(key)) {
+ shouldAdd = true;
+ }
+ } else if (def instanceof Function) {
+ if (def(key)) {
+ shouldAdd = true;
+ }
+ } else {
+ throw Error('Group definitions must either\
+ be strings, regexes, or functions.');
+ }
+ if (shouldAdd) {
+ grouped[name][key] = val;
+ continue top;
+ }
+ }
+ }
+ grouped['rest'][key] = val;
+ }
+ return grouped;
+ }
+};
diff --git a/node_modules/utila/lib/string.js b/node_modules/utila/lib/string.js
new file mode 100644
index 00000000..e574c2cb
--- /dev/null
+++ b/node_modules/utila/lib/string.js
@@ -0,0 +1,14 @@
+// Generated by CoffeeScript 1.6.3
+module.exports = {
+ pad: function(n, width, z) {
+ if (z == null) {
+ z = '0';
+ }
+ n = n + '';
+ if (n.length >= width) {
+ return n;
+ } else {
+ return new Array(width - n.length + 1).join(z) + n;
+ }
+ }
+};
diff --git a/node_modules/utila/lib/utila.js b/node_modules/utila/lib/utila.js
new file mode 100644
index 00000000..21c550e0
--- /dev/null
+++ b/node_modules/utila/lib/utila.js
@@ -0,0 +1,10 @@
+// Generated by CoffeeScript 1.6.3
+var utila;
+
+module.exports = utila = {
+ array: require('./array'),
+ classic: require('./classic'),
+ object: require('./object'),
+ string: require('./string'),
+ Emitter: require('./Emitter')
+};