forked from olton/metroui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.js
More file actions
36 lines (28 loc) · 1.01 KB
/
string.js
File metadata and controls
36 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* global Datetime, datetime */
(function() {
'use strict';
String.prototype.toArray = function(delimiter, type, format, locale){
var str = this;
var a;
type = type || "string";
delimiter = delimiter || ",";
format = format === undefined || format === null ? false : format;
a = (""+str).split(delimiter);
return a.map(function(s){
var result;
switch (type) {
case "int":
case "integer": result = isNaN(s) ? s.trim() : parseInt(s); break;
case "number":
case "float": result = isNaN(s) ? s : parseFloat(s); break;
case "date": result = !format ? datetime(s) : Datetime.from(s, format, locale || 'en-US'); break;
default: result = s.trim();
}
return result;
});
};
String.prototype.capitalize = function(){
var str = this;
return str.substr(0, 1).toUpperCase() + str.substr(1)
}
}());