From ec1b6a3e1224926df8e40eccaae8de371732e377 Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Wed, 22 Feb 2012 18:28:17 -0800 Subject: [PATCH] Using underscore / underscore.string for stringStarts / stringEnds. --- lib/util/util.js | 23 +++++------------------ package.json | 4 +++- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/lib/util/util.js b/lib/util/util.js index cabe962d5..3f301f047 100644 --- a/lib/util/util.js +++ b/lib/util/util.js @@ -13,6 +13,9 @@ * limitations under the License. */ +var _ = require('underscore'); +_.mixin(require('underscore.string')); + /** * Encodes an URI. * @@ -87,15 +90,7 @@ exports.stringFormat = function (text) { * @return {Bool} True if the string starts with the prefix; false otherwise. */ exports.stringStartsWith = function (text, prefix) { - if (!text) { - return false; - } - - if (!prefix) { - return true; - } - - return text.indexOf(prefix) === 0; + return _.startsWith(text, prefix); }; /** @@ -106,15 +101,7 @@ exports.stringStartsWith = function (text, prefix) { * @return {Bool} True if the string ends with the suffix; false otherwise. */ exports.stringEndsWith = function (text, suffix) { - if (!text) { - return false; - } - - if (!suffix) { - return true; - } - - return text.lastIndexOf(suffix) === (text.length - suffix.length); + return _.endsWith(text, suffix); }; /** diff --git a/package.json b/package.json index 6c0bfe3a0..d99b54963 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ "log": ">= 1.2.0", "xmlbuilder": ">= 0.3.1", "mime": ">= 1.2.4", - "dateformat": "1.0.2-1.2.3" + "dateformat": "1.0.2-1.2.3", + "underscore": ">= 1.3.1", + "underscore.string": ">= 2.0.0" }, "devDependencies": { "nodeunit": ">= 0.6.4"