Skip to content

Commit 925f627

Browse files
committed
jstring v0.1
jstring v0.1
0 parents  commit 925f627

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

jstring.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
String.prototype.contains = function(text){
2+
if(text == '') return true;
3+
else if(text == null) return false;
4+
else return this.indexOf(text) !== -1;
5+
}
6+
String.prototype.count = function(text){
7+
if(this.contains(text)){
8+
return this.split(text).length-1;
9+
}
10+
else
11+
return 0;
12+
}
13+
String.prototype.capitalize = function(){
14+
if(this == '') return str;
15+
else return this.charAt(0).toUpperCase() + this.slice(1);
16+
}
17+
String.prototype.clear = function(){
18+
return this.trim().replace(/\s+/g, ' ');
19+
}
20+
String.prototype.endsWith = function(text) {
21+
if(text == '') return true;
22+
else if(text == null) return false;
23+
else return this.indexOf(text, this.length - text.length) !== -1;
24+
}
25+
26+
String.prototype.insert = function(text,at) {
27+
if(at == null || at > this.length)
28+
at = this.length;
29+
else if(at < 0)
30+
at = 0;
31+
32+
return this.substring(0,at)+text+this.substring(at);
33+
}

0 commit comments

Comments
 (0)