diff options
Diffstat (limited to 'cordova/node_modules/pegjs/lib/utils')
| -rw-r--r-- | cordova/node_modules/pegjs/lib/utils/arrays.js | 108 | ||||
| -rw-r--r-- | cordova/node_modules/pegjs/lib/utils/classes.js | 12 | ||||
| -rw-r--r-- | cordova/node_modules/pegjs/lib/utils/objects.js | 54 |
3 files changed, 174 insertions, 0 deletions
diff --git a/cordova/node_modules/pegjs/lib/utils/arrays.js b/cordova/node_modules/pegjs/lib/utils/arrays.js new file mode 100644 index 0000000..93a833c --- /dev/null +++ b/cordova/node_modules/pegjs/lib/utils/arrays.js @@ -0,0 +1,108 @@ +"use strict"; + +/* Array utilities. */ +var arrays = { + range: function(start, stop) { + var length = stop - start, + result = new Array(length), + i, j; + + for (i = 0, j = start; i < length; i++, j++) { + result[i] = j; + } + + return result; + }, + + find: function(array, valueOrPredicate) { + var length = array.length, i; + + if (typeof valueOrPredicate === "function") { + for (i = 0; i < length; i++) { + if (valueOrPredicate(array[i])) { + return array[i]; + } + } + } else { + for (i = 0; i < length; i++) { + if (array[i] === valueOrPredicate) { + return array[i]; + } + } + } + }, + + indexOf: function(array, valueOrPredicate) { + var length = array.length, i; + + if (typeof valueOrPredicate === "function") { + for (i = 0; i < length; i++) { + if (valueOrPredicate(array[i])) { + return i; + } + } + } else { + for (i = 0; i < length; i++) { + if (array[i] === valueOrPredicate) { + return i; + } + } + } + + return -1; + }, + + contains: function(array, valueOrPredicate) { + return arrays.indexOf(array, valueOrPredicate) !== -1; + }, + + each: function(array, iterator) { + var length = array.length, i; + + for (i = 0; i < length; i++) { + iterator(array[i], i); + } + }, + + map: function(array, iterator) { + var length = array.length, + result = new Array(length), + i; + + for (i = 0; i < length; i++) { + result[i] = iterator(array[i], i); + } + + return result; + }, + + pluck: function(array, key) { + return arrays.map(array, function (e) { return e[key]; }); + }, + + every: function(array, predicate) { + var length = array.length, i; + + for (i = 0; i < length; i++) { + if (!predicate(array[i])) { + return false; + } + } + + return true; + }, + + some: function(array, predicate) { + var length = array.length, i; + + for (i = 0; i < length; i++) { + if (predicate(array[i])) { + return true; + } + } + + return false; + } +}; + +module.exports = arrays; diff --git a/cordova/node_modules/pegjs/lib/utils/classes.js b/cordova/node_modules/pegjs/lib/utils/classes.js new file mode 100644 index 0000000..1ad305e --- /dev/null +++ b/cordova/node_modules/pegjs/lib/utils/classes.js @@ -0,0 +1,12 @@ +"use strict"; + +/* Class utilities */ +var classes = { + subclass: function(child, parent) { + function ctor() { this.constructor = child; } + ctor.prototype = parent.prototype; + child.prototype = new ctor(); + } +}; + +module.exports = classes; diff --git a/cordova/node_modules/pegjs/lib/utils/objects.js b/cordova/node_modules/pegjs/lib/utils/objects.js new file mode 100644 index 0000000..09587c1 --- /dev/null +++ b/cordova/node_modules/pegjs/lib/utils/objects.js @@ -0,0 +1,54 @@ +"use strict"; + +/* Object utilities. */ +var objects = { + keys: function(object) { + var result = [], key; + + for (key in object) { + if (object.hasOwnProperty(key)) { + result.push(key); + } + } + + return result; + }, + + values: function(object) { + var result = [], key; + + for (key in object) { + if (object.hasOwnProperty(key)) { + result.push(object[key]); + } + } + + return result; + }, + + clone: function(object) { + var result = {}, key; + + for (key in object) { + if (object.hasOwnProperty(key)) { + result[key] = object[key]; + } + } + + return result; + }, + + defaults: function(object, defaults) { + var key; + + for (key in defaults) { + if (defaults.hasOwnProperty(key)) { + if (!(key in object)) { + object[key] = defaults[key]; + } + } + } + } +}; + +module.exports = objects; |
