forked from nezroy/EVEoj
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.js
More file actions
59 lines (50 loc) · 1.38 KB
/
Copy pathUtils.js
File metadata and controls
59 lines (50 loc) · 1.38 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
/* global jQuery: false */
var Promise = require("./Promise");
exports.isBrowser = typeof(window) !== "undefined";
var F = function() {};
exports.create = (typeof Object.create === "function") ?
Object.create :
function(o) {
// object create polyfill (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
if (arguments.length > 1) throw Error("Second argument not supported");
if (o === null) throw Error("Cannot set a null [[Prototype]]");
if (typeof(o) !== "object") throw TypeError("Argument must be an object");
F.prototype = o;
return new F();
};
exports.FormatNum = function(val, fixed) {
var stringy = [],
base = String(Math.floor(val)),
k = -1,
i = 0,
decimals;
fixed = fixed || 0;
for (i = base.length - 1; i >= 0; i--) {
if (k % 3 === 0) {
k = 1;
stringy.push(",");
} else if (k == -1) {
k = 1;
} else {
k++;
}
stringy.push(base.charAt(i));
}
base = "";
for (i = stringy.length - 1; i >= 0; i--) {
base = base.concat(stringy[i]);
}
if (fixed > 0) {
decimals = val.toFixed(fixed);
base += decimals.substring(decimals.length - fixed - 1);
}
return base;
};
var ajaxP = function(url, settings, cb) {
jQuery.ajax(url, settings).done(function(data, status, jqxhr) {
cb(null, data);
}).fail(function(jqxhr, status, error) {
cb(error, null);
});
};
exports.ajaxP = Promise.promisify(ajaxP);