-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
66 lines (63 loc) · 1.68 KB
/
utils.js
File metadata and controls
66 lines (63 loc) · 1.68 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
Utils.js
Standard utilities.
*/
/**
* Determines whether variable a is:
* 1)set (if b is not used or is null)
* 2)the type specified by b (i.e., ISSET(null, 'undefined')==true)
*/
window['ISSET']=function(a,b) {
if(typeof b === 'undefined') {
return typeof a !== 'undefined';
} else {
return typeof a === b;
}
throw(new Error("How did I get here?"));
};
//std string functions
/**
* Determines whether the string starts with the substring needle.
*/
String.prototype.startsWith = function(needle) {
return this.indexOf(needle) == 0;
};
/**
* Determines whether the string contains the substring needle.
*/
String.prototype.contains = function(needle) {
return this.indexOf(needle) >= 0;
};
/**
* Capotalizes the first letter of the string.
*/
String.prototype.capitalizeFirstLetter = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
};
/**
* Adds newLn as a new line
*/
String.prototype.pushLn = function(newLn) {
return this + newLn + "\n";
};
window.FileDownloader = function(data, MIME) {
var self = Object.create(null);
self.data = encodeURIComponent(data);
self.mime = MIME;
self.download = function(filename) {
//creds and thanks to http://paxcel.net/blog/savedownload-file-using-html5-javascript-the-download-attribute-2/
var uri = 'data:' + self.mime + ';charset=utf-8,' + self.data;
//For IE
if (navigator.appName == "Microsoft Internet Explorer") {
myFrame.document.open("text/html", "replace");
myFrame.document.write(uuu);
myFrame.document.close();
myFrame.focus()
myFrame.document.execCommand('SaveAs', true, filename);
} else {
//Other browsers
$('#btnExport').attr({'href': uri, 'target': '_blank' });
}
};
return self;
};