Using underscore / underscore.string for stringStarts / stringEnds.
This commit is contained in:
Родитель
b51da50245
Коммит
ec1b6a3e12
|
@ -13,6 +13,9 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var _ = require('underscore');
|
||||||
|
_.mixin(require('underscore.string'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encodes an URI.
|
* Encodes an URI.
|
||||||
*
|
*
|
||||||
|
@ -87,15 +90,7 @@ exports.stringFormat = function (text) {
|
||||||
* @return {Bool} True if the string starts with the prefix; false otherwise.
|
* @return {Bool} True if the string starts with the prefix; false otherwise.
|
||||||
*/
|
*/
|
||||||
exports.stringStartsWith = function (text, prefix) {
|
exports.stringStartsWith = function (text, prefix) {
|
||||||
if (!text) {
|
return _.startsWith(text, prefix);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!prefix) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return text.indexOf(prefix) === 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,15 +101,7 @@ exports.stringStartsWith = function (text, prefix) {
|
||||||
* @return {Bool} True if the string ends with the suffix; false otherwise.
|
* @return {Bool} True if the string ends with the suffix; false otherwise.
|
||||||
*/
|
*/
|
||||||
exports.stringEndsWith = function (text, suffix) {
|
exports.stringEndsWith = function (text, suffix) {
|
||||||
if (!text) {
|
return _.endsWith(text, suffix);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!suffix) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return text.lastIndexOf(suffix) === (text.length - suffix.length);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,7 +15,9 @@
|
||||||
"log": ">= 1.2.0",
|
"log": ">= 1.2.0",
|
||||||
"xmlbuilder": ">= 0.3.1",
|
"xmlbuilder": ">= 0.3.1",
|
||||||
"mime": ">= 1.2.4",
|
"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": {
|
"devDependencies": {
|
||||||
"nodeunit": ">= 0.6.4"
|
"nodeunit": ">= 0.6.4"
|
||||||
|
|
Загрузка…
Ссылка в новой задаче