ts-commons
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -91,3 +91,7 @@ export declare class StringUtils { | ||
static subString(str: string, start: number, end?: number): string; | ||
static startWith(str: string, prefix: string): boolean; | ||
static startWithIgnoreCase(str: string, prefix: string): boolean; | ||
static endWith(str: string, suffix: string): boolean; | ||
static endWithIgnoreCase(str: string, suffix: string): boolean; | ||
static isWhitespace(ch: string): boolean; | ||
} |
@@ -251,2 +251,32 @@ "use strict"; | ||
}; | ||
StringUtils.startWith = function (str, prefix) { | ||
if (!object_utils_1.ObjectUtils.isString(str) || !object_utils_1.ObjectUtils.isString(prefix)) { | ||
return false; | ||
} | ||
// return str.indexOf(prefix) === 0; | ||
// according to https://leonax.net/p/5806/use-string-startswith-and-endswith-in-javascript/ | ||
return str.slice(0, prefix.length) === prefix; | ||
}; | ||
StringUtils.startWithIgnoreCase = function (str, prefix) { | ||
if (!object_utils_1.ObjectUtils.isString(str) || !object_utils_1.ObjectUtils.isString(prefix)) { | ||
return false; | ||
} | ||
var useStr = str.toLocaleLowerCase(); | ||
var usePrefix = prefix.toLocaleLowerCase(); | ||
return useStr.slice(0, usePrefix.length) === usePrefix; | ||
}; | ||
StringUtils.endWith = function (str, suffix) { | ||
if (!object_utils_1.ObjectUtils.isString(str) || !object_utils_1.ObjectUtils.isString(suffix)) { | ||
return false; | ||
} | ||
return str.indexOf(suffix, str.length - suffix.length) !== -1; | ||
}; | ||
StringUtils.endWithIgnoreCase = function (str, suffix) { | ||
if (!object_utils_1.ObjectUtils.isString(str) || !object_utils_1.ObjectUtils.isString(suffix)) { | ||
return false; | ||
} | ||
var useStr = str.toLocaleLowerCase(); | ||
var useSuffix = suffix.toLocaleLowerCase(); | ||
return useStr.indexOf(useSuffix, useStr.length - useSuffix.length) !== -1; | ||
}; | ||
StringUtils.isWhitespace = function (ch) { | ||
@@ -253,0 +283,0 @@ return " \f\n\r\t\v\u00A0\u2028\u2029".indexOf(ch) > -1; |
{ | ||
"name": "ts-commons", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "common methods for typescript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
54123
704