-
Notifications
You must be signed in to change notification settings - Fork 0
/
polyfills.js
44 lines (37 loc) · 980 Bytes
/
polyfills.js
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
;(function () {
"use strict";
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
}
// extend underscore
_.mixin({
capitalize: function(string) {
return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase();
},
toTitleCase: function (str) {
var regex = /\w\S*/g;
return str.replace(regex, function(w) {
return w.charAt(0).toUpperCase() + w.substr(1).toLowerCase();
});
},
assert: function (exp, err) {
if (!exp) {
throw new Meteor.Error(err ? err : "oops, assert failed");
}
},
dynamicSort: function (property) {
var sortOrder = 1;
if(property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a,b) {
var result = (a[property] < b[property]) ?
-1 : (a[property] > b[property]) ? 1 : 0;
return result * sortOrder;
}
},
});
}());