forked from skulpt/skulpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
61 lines (52 loc) · 1.47 KB
/
util.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Global Sk object
var Sk = {}; // jshint ignore:line
Sk.build = {
githash: GITHASH,
date: BUILDDATE
};
/**
* Global object no matter where we're running
*/
Sk.global =
typeof global !== "undefined" ? global : // jshint ignore:line
typeof self !== "undefined" ? self : // jshint ignore:line
typeof window !== "undefined" ? window : // jshint ignore:line
{};
/**
* Export "object" to global namespace as "name".
*
* @param {string} name name to export the object to
* @param {*} object object to export
*/
Sk.exportSymbol = function (name, object) {
var parts = name.split(".");
var curobj = Sk.global;
var part, idx;
for (idx = 0; idx < (parts.length - 1); idx++) {
part = parts[idx];
if (curobj.hasOwnProperty(part)) {
curobj = curobj[part];
} else {
curobj = curobj[part] = {};
}
}
if (typeof object !== "undefined") {
part = parts[idx];
curobj[part] = object;
}
};
Sk.isArrayLike = function (object) {
if ((object instanceof Array) || (object && object.length && (typeof object.length == "number"))) {
return true;
}
return false;
};
Sk.js_beautify = function (x) {
return x;
};
Sk.exportSymbol("Sk", Sk);
Sk.exportSymbol("Sk.global", Sk.global);
Sk.exportSymbol("Sk.build", Sk.build);
Sk.exportSymbol("Sk.exportSymbol", Sk.exportSymbol);
Sk.exportSymbol("Sk.isArrayLike", Sk.isArrayLike);
Sk.exportSymbol("Sk.js_beautify", Sk.js_beautify);