Permalink
Browse files

Removed syntax differences, most of them

  • Loading branch information...
larzconwell committed Sep 25, 2012
1 parent 2e5bec8 commit b1d69c57fc9e6bbba191da2bbb27a85172af8ecf
Showing with 153 additions and 151 deletions.
  1. +5 −5 lib/array.js
  2. +4 −4 lib/date.js
  3. +1 −1 lib/event_buffer.js
  4. +3 −3 lib/file.js
  5. +1 −1 lib/i18n.js
  6. +9 −9 lib/object.js
  7. +29 −27 lib/string.js
  8. +2 −2 lib/xml.js
  9. +1 −1 test/event_buffer.js
  10. +22 −22 test/inflection.js
  11. +6 −6 test/object.js
  12. +50 −50 test/string.js
  13. +12 −12 test/uri.js
  14. +8 −8 test/xml.js
View
@@ -31,9 +31,9 @@ var array = new (function () {
@description Creates a string containing the array elements in a readable format
@param {Array} array The array to humanize
*/
- this.humanize = function(array) {
+ this.humanize = function (array) {
// If array only has one item then just return it
- if(array.length <= 1) {
+ if (array.length <= 1) {
return String(array);
}
@@ -53,10 +53,10 @@ var array = new (function () {
@param {Any} item The item to look for
@param {Array} array The array to check
*/
- this.included = function(item, array) {
+ this.included = function (item, array) {
var result = array.indexOf(item);
- if(result === -1) {
+ if (result === -1) {
return false;
} else {
return array;
@@ -72,7 +72,7 @@ var array = new (function () {
@param {Array} array The array to check
@param {Any} item The item to look for
*/
- this.include = function(array, item) {
+ this.include = function (array, item) {
var res = -1;
if (typeof array.indexOf == 'function') {
res = array.indexOf(item);
View
@@ -254,7 +254,7 @@ date = new (function () {
// If year ends in 00 subtract one, because it's still the century before the one
// it divides to
- if(year.substring(year.length - 2) === '00') {
+ if (year.substring(year.length - 2) === '00') {
ret--;
}
@@ -269,7 +269,7 @@ date = new (function () {
@description Calculate the day number in the year a particular date is on
@param {Date} dt The date to use
*/
- this.calcDays = function(dt) {
+ this.calcDays = function (dt) {
var first = new Date(dt.getFullYear(), 0, 1);
var diff = 0;
var ret = 0;
@@ -386,8 +386,8 @@ date = new (function () {
*/
this.add = function (dt, interv, incr) {
if (typeof dt == 'number') { dt = new Date(dt); }
- function fixOvershoot(){
- if (sum.getDate() < dt.getDate()){
+ function fixOvershoot() {
+ if (sum.getDate() < dt.getDate()) {
sum.setDate(0);
}
}
View
@@ -25,7 +25,7 @@ Example:
, dest = new EventEmitter()
, buff = new EventBuffer(source)
, data = '';
- dest.on('data', function(d) { data += d; });
+ dest.on('data', function (d) { data += d; });
source.writeable = true;
source.readable = true;
source.emit('data', 'abcdef');
View
@@ -47,7 +47,7 @@ var fileUtils = new (function () {
, _watch;
// Recursively copy files and directories
- _copyFile = function(fromPath, toPath, opts) {
+ _copyFile = function (fromPath, toPath, opts) {
var from = path.normalize(fromPath)
, to = path.normalize(toPath)
, options = opts || {}
@@ -405,7 +405,7 @@ var fileUtils = new (function () {
@param {String} p The path to search for
@param {Function} callback The function to call once the path is found
*/
- this.searchParentPath = function(p, callback) {
+ this.searchParentPath = function (p, callback) {
if (!p) {
// Return if no path is given
return;
@@ -468,7 +468,7 @@ var fileUtils = new (function () {
@param {String} module The module to require
@param {String} message An option message to throw if the module doesn't exist
*/
- this.requireLocal = function(module, message) {
+ this.requireLocal = function (module, message) {
// Try to require in the application directory
try {
dep = require(path.join(process.cwd(), 'node_modules', module));
View
@@ -28,7 +28,7 @@ i18n = new (function () {
, defaultLocaleStrings = _strings[_defaultLocale] || {}
, str = currentLocaleStrings[key]
|| defaultLocaleStrings[key] || "[[" + key + "]]";
- for (p in opts){
+ for (p in opts) {
str = str.replace(new RegExp('\\{' + p + '\\}', 'g'), opts[p]);
}
return str;
View
@@ -33,21 +33,21 @@ var object = new (function () {
@param {Object} object Object to merge into
@param {Object} otherObject Object to read from
*/
- this.merge = function(object, otherObject) {
+ this.merge = function (object, otherObject) {
object = object || {};
otherObject = otherObject || {};
var i, key, value;
- for(i in otherObject) {
+ for (i in otherObject) {
key = i, value = otherObject[key];
try {
// If value is an object
- if(typeof value === 'object' && !(value instanceof Array)) {
+ if (typeof value === 'object' && !(value instanceof Array)) {
// Update value of object to the one from otherObject
object[key] = merge(object[key], value);
} else object[key] = value;
- } catch(err) {
+ } catch (err) {
// Object isn't set so set it
object[key] = value;
}
@@ -64,7 +64,7 @@ var object = new (function () {
@param {Object} object Object to read from
@param {Object} defaultObject Object to merge into
*/
- this.reverseMerge = function(object, defaultObject) {
+ this.reverseMerge = function (object, defaultObject) {
// Same as `merge` except `defaultObject` is the object being changed
// - this is useful if we want to easily deal with default object values
return this.merge(defaultObject, object);
@@ -78,9 +78,9 @@ var object = new (function () {
@description isEmpty checks if an Object is empty
@param {Object} object Object to check if empty
*/
- this.isEmpty = function(object) {
+ this.isEmpty = function (object) {
// Returns true if a object is empty false if not
- for(var i in object) { return false; }
+ for (var i in object) { return false; }
return true;
};
@@ -92,11 +92,11 @@ var object = new (function () {
@description Converts an object to an array of objects each including the original key/value
@param {Object} object Object to convert
*/
- this.toArray = function(object) {
+ this.toArray = function (object) {
// Converts an object into an array of objects with the original key, values
array = [];
- for(var i in object) {
+ for (var i in object) {
array.push({ key: i, value: object[i] });
}
View
@@ -45,8 +45,8 @@ string = new (function () {
// Builds the escape/unescape methods using a
// map of characters
- _buildEscape = function(direction) {
- return function(str) {
+ _buildEscape = function (direction) {
+ return function (str) {
var string = str;
// If string is NaN, null or undefined then provide an empty default
@@ -58,7 +58,7 @@ string = new (function () {
string = string.toString();
var from, to, p;
- for(p in _CHARS) {
+ for (p in _CHARS) {
from = direction == 'to' ? p : _CHARS[p];
to = direction == 'to' ? _CHARS[p] : p;
@@ -72,12 +72,12 @@ string = new (function () {
// Builds a method that tests for any escapable
// characters, useful for avoiding double-scaping if
// you're not sure if a string has already been escaped
- _buildEscapeTest = function(direction) {
- return function(string) {
+ _buildEscapeTest = function (direction) {
+ return function (string) {
var pat = ''
, p;
- for(p in _CHARS) {
+ for (p in _CHARS) {
pat += direction == 'to' ? p : _CHARS[p];
pat += '|';
}
@@ -111,7 +111,7 @@ string = new (function () {
used to build regexes dynamically
@param {String} string The string of chars to escape
*/
- this.escapeRegExpChars = (function() {
+ this.escapeRegExpChars = (function () {
var specials = [ '^', '$', '/', '.', '*', '+', '?', '|', '(', ')',
'[', ']', '{', '}', '\\' ];
sRE = new RegExp('(\\' + specials.join('|\\') + ')', 'g');
@@ -130,7 +130,7 @@ string = new (function () {
@description Converts a string to an array
@param {String} string The string to convert
*/
- this.toArray = function(string) {
+ this.toArray = function (string) {
var str = string || ''
, arr = []
, i = -1;
@@ -151,7 +151,7 @@ string = new (function () {
@description Reverses a string
@param {String} string The string to reverse
*/
- this.reverse = function(string) {
+ this.reverse = function (string) {
var str = string || '';
str = String(str);
return this.toArray(str).reverse().join('');
@@ -167,7 +167,7 @@ string = new (function () {
@param {String} string The string to trim
@param {String} char The character to trim
*/
- this.ltrim = function(string, char) {
+ this.ltrim = function (string, char) {
var str = string || ''
, pat = char ? new RegExp('^' + char + '+') : _LTR;
str = String(str);
@@ -252,7 +252,7 @@ string = new (function () {
@param {String} char The character to pad with
@param {Number} width the width to pad to
*/
- this.lpad = function(string, char, width) {
+ this.lpad = function (string, char, width) {
var str = string || ''
, width;
str = String(str);
@@ -261,7 +261,7 @@ string = new (function () {
width = parseInt(width, 10) || str.length;
char = char || ' ';
- while(str.length < width) {
+ while (str.length < width) {
str = char + str;
}
return str;
@@ -278,7 +278,7 @@ string = new (function () {
@param {String} char The character to pad with
@param {Number} width the width to pad to
*/
- this.rpad = function(string, char, width) {
+ this.rpad = function (string, char, width) {
var str = string || ''
, width;
str = String(str);
@@ -287,7 +287,7 @@ string = new (function () {
width = parseInt(width, 10) || str.length;
char = char || ' ';
- while(str.length < width) {
+ while (str.length < width) {
str += char;
}
return str;
@@ -304,7 +304,7 @@ string = new (function () {
@param {String} char The character to pad with
@param {Number} width the width to pad to
*/
- this.pad = function(string, char, width) {
+ this.pad = function (string, char, width) {
var str = string || ''
, width;
str = String(str);
@@ -313,7 +313,7 @@ string = new (function () {
width = parseInt(width, 10) || str.length;
char = char || ' ';
- while(str.length < width) {
+ while (str.length < width) {
str = char + str + char;
}
return str;
@@ -336,7 +336,7 @@ string = new (function () {
@param {String/RegExp} [options.seperator] Break the truncated test at the nearest `seperator`
@param {Function} callback Callback is called only if a truncation is done
*/
- this.truncate = function(string, options, callback) {
+ this.truncate = function (string, options, callback) {
var str = string || ''
, stringLen
, opts
@@ -434,7 +434,7 @@ string = new (function () {
truncation will loop through all text inside HTML tags
@param {Function} callback Callback is called only if a truncation is done
*/
- this.truncateHTML = function(string, options, callback) {
+ this.truncateHTML = function (string, options, callback) {
var str = string || ''
, returnString = ''
, opts = options;
@@ -462,7 +462,7 @@ string = new (function () {
, i;
// Gather the HTML tags and content into the array
- while(result) {
+ while (result) {
firstPos = result.index;
lastPos = pat.lastIndex;
@@ -479,14 +479,16 @@ string = new (function () {
// Re-run the pattern on the new string
result = pat.exec(str);
}
- if (str !== '') arr.push(str);
+ if (str !== '') {
+ arr.push(str);
+ }
// Loop through array items appending the tags to the string,
// - and truncating the text then appending it to content
i = -1;
- while(++i < arr.length) {
+ while (++i < arr.length) {
item = arr[i];
- switch(true) {
+ switch (true) {
// Closing tag
case item.indexOf('</') == 0:
returnString += item;
@@ -521,7 +523,7 @@ string = new (function () {
into line break HTML tags
@param {String} string The string to convert
*/
- this.nl2br = function(string) {
+ this.nl2br = function (string) {
var str = string || '';
str = String(str);
@@ -658,7 +660,7 @@ string = new (function () {
@param {String} string The string to dasherize
@param {String} replace='-' The character to replace with
*/
- this.dasherize = function(string, replace) {
+ this.dasherize = function (string, replace) {
var repl = replace || '-'
return this.snakeize(string, repl);
};
@@ -747,7 +749,7 @@ string = new (function () {
// From Math.uuid.js, https://github.com/broofa/node-uuid
// Robert Kieffer (robert@broofa.com), MIT license
- this.uuid = function(length, radix) {
+ this.uuid = function (length, radix) {
var chars = _UUID_CHARS
, uuid = []
, r
@@ -758,7 +760,7 @@ string = new (function () {
if (length) {
// Compact form
i = -1;
- while(++i < length) {
+ while (++i < length) {
uuid[i] = chars[0 | Math.random()*radix];
}
} else {
@@ -771,7 +773,7 @@ string = new (function () {
// Fill in random data. At i==19 set the high bits of clock sequence as
// per rfc4122, sec. 4.1.5
i = -1;
- while(++i < 36) {
+ while (++i < 36) {
if (!uuid[i]) {
r = 0 | Math.random()*16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
Oops, something went wrong.

0 comments on commit b1d69c5

Please sign in to comment.