}
);
- /**
- * Utility function that allows you to easily switch a string between two alternating values. The passed value
- * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
- * they are already different, the first value passed in is returned. Note that this method returns the new value
- * but does not change the current string.
- * <pre><code>
- // alternate sort directions
- sort = sort.toggle('ASC', 'DESC');
-
- // instead of conditional logic:
- sort = (sort == 'ASC' ? 'DESC' : 'ASC');
- </code></pre>
- * @param {String} value The value to compare to the current string
- * @param {String} other The new value to use if the string already equals the first value passed in
- * @return {String} The new value
- */
-
XObject.extend(String.prototype, {
-
+
+ /**
+ * Utility function that allows you to easily switch a string between two alternating values. The passed value
+ * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
+ * they are already different, the first value passed in is returned. Note that this method returns the new value
+ * but does not change the current string.
+ * <pre><code>
+ // alternate sort directions
+ sort = sort.toggle('ASC', 'DESC');
+
+ // instead of conditional logic:
+ sort = (sort == 'ASC' ? 'DESC' : 'ASC');
+ </code></pre>
+ * @param {String} value The value to compare to the current string
+ * @param {String} other The new value to use if the string already equals the first value passed in
+ * @return {String} The new value
+ */
+
toggle : function(value, other){
return this == value ? other : value;
},
-
+ /**
+ * trim a string from the beginning and end
+ * This is NOT whitespace strip, it is prefix/suffix stripping
+ *
+ * @param {String} string to strip.
+ */
trim : function (toTrim) {
var out = this.ltrim(toTrim);
out = out.rtrim(toTrim);
return out;
},
-
+ /**
+ * trim a string from the beginning
+ * This is NOT whitespace strip, it is prefix stripping
+ *
+ * @param {String} string to remove if it exists.
+ */
ltrim : function (toTrim) {
if (this.substr(0, toTrim.length) == toTrim) {
return this.slice(toTrim.length);
return this;
},
-
+ /**
+ * trim a string from the end
+ * This is NOT whitespace strip, it is suffix stripping
+ *
+ * @param {String} string to remove if it exists.
+ */
rtrim : function (toTrim) {
if (this.substr(this.length - toTrim.length) == toTrim) {
return this.slice(0, this.length - toTrim.length);