Using underscore / underscore.string for stringStarts / stringEnds.
This commit is contained in:
Родитель
b51da50245
Коммит
ec1b6a3e12
|
@ -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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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"
|
||||
|
|
Загрузка…
Ссылка в новой задаче