forked from endel/js2php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
59 lines (48 loc) · 1.21 KB
/
utils.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
module.exports = {
//
// classize:
//
// Example
// input: 'some.module.name'
// output: '\Some\Module\Name'
//
classize: function (string) {
var modules = string.split(".");
if (modules.length == 1) {
return string.charAt(0).toUpperCase() + string.slice(1);
} else {
var m = [];
for (var i=0; i<modules.length; i++) {
m.push(this.classize(modules[i]));
}
return m.join("\\");
}
},
clone: function(obj) {
var parent = null, response = null;
// prevent circular loop when cloning the obj.
if (obj.parent) {
parent = obj.parent;
delete obj.parent;
}
response = JSON.parse(JSON.stringify(obj));
// keep original parent
if (parent) { obj.parent = parent; }
return response;
},
isString: function(node) {
return node.type == "Literal" && node.raw.match(/^['|"]/);
},
isRegExp: function(node) {
var value = node.raw;
if (value.match(/^['"].+['"]$/)) {
value = value.substr(1, node.raw.length-2);
}
var isRegExp = value.match(/^\/[^\/]+\/[gimy]?$/);
if (isRegExp) {
node.raw.value = "'" + value + "'";
node.dataType = 'RegExp';
}
return isRegExp;
}
}