UNPKG

2.56 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.12.7
2(function() {
3 var getTimezoneSeparatorFromString, normalizeMillisecondsField, normalizeMillisecondsFieldInString, typeIsArray;
4
5 module.exports.removeNulls = function(things) {
6 return things.filter(function(x) {
7 return x != null;
8 });
9 };
10
11 module.exports.numerical_sort = function(things, direction) {
12 if (direction == null) {
13 direction = "asc";
14 }
15 return things.sort(function(a, b) {
16 if (direction === "asc") {
17 return a - b;
18 } else {
19 return b - a;
20 }
21 });
22 };
23
24 module.exports.isNull = function(value) {
25 return value === null;
26 };
27
28 module.exports.typeIsArray = typeIsArray = Array.isArray || function(value) {
29 return {}.toString.call(value) === '[object Array]';
30 };
31
32 module.exports.allTrue = function(things) {
33 if (typeIsArray(things)) {
34 return things.every(function(x) {
35 return x;
36 });
37 } else {
38 return things;
39 }
40 };
41
42 module.exports.anyTrue = function(things) {
43 if (typeIsArray(things)) {
44 return things.some(function(x) {
45 return x;
46 });
47 } else {
48 return things;
49 }
50 };
51
52 module.exports.jsDate = Date;
53
54 module.exports.normalizeMillisecondsFieldInString = normalizeMillisecondsFieldInString = function(string, msString) {
55 var beforeMs, msAndAfter, ref, timezoneField, timezoneSeparator;
56 msString = normalizeMillisecondsField(msString);
57 ref = string.split('.'), beforeMs = ref[0], msAndAfter = ref[1];
58 timezoneSeparator = getTimezoneSeparatorFromString(msAndAfter);
59 if (!!timezoneSeparator) {
60 timezoneField = msAndAfter != null ? msAndAfter.split(timezoneSeparator)[1] : void 0;
61 }
62 if (timezoneField == null) {
63 timezoneField = '';
64 }
65 return string = beforeMs + '.' + msString + timezoneSeparator + timezoneField;
66 };
67
68 module.exports.normalizeMillisecondsField = normalizeMillisecondsField = function(msString) {
69 return msString = (msString + "00").substring(0, 3);
70 };
71
72 module.exports.getTimezoneSeparatorFromString = getTimezoneSeparatorFromString = function(string) {
73 var ref, ref1, timezoneSeparator;
74 if ((string != null ? (ref = string.match(/-/)) != null ? ref.length : void 0 : void 0) === 1) {
75 return timezoneSeparator = '-';
76 } else if ((string != null ? (ref1 = string.match(/\+/)) != null ? ref1.length : void 0 : void 0) === 1) {
77 return timezoneSeparator = '+';
78 } else {
79 return timezoneSeparator = '';
80 }
81 };
82
83}).call(this);
84
85//# sourceMappingURL=util.js.map