﻿Nitto = new Object();

Nitto.Utils = {
    /**
    * Trim a string. If str param is not a string, the whole object will be returned.
    * @param str string to trim
    * @param lr left, right flag. true: trim = leftTrim, false: trim = rightTrim, other: both.
    */
    trim: (function() {
        var chars = ' \n\r\t\v\f\u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
        var ws = {};
        for (var i = 0; i < chars.length; i++) {
            ws[chars.charAt(i)] = true;
        }

        return function(str, lr) {
            var s = -1, e = str.length;
            while (lr !== true && ws[str.charAt(--e)]);
            while (lr !== false && s++ !== e && ws[str.charAt(s)]);
            return str.substring(s, e + 1);
        };
    })()
}

/**
 * Shortcuts - Debugging only. Use with care.
 */
$e = alert;