@makano/rew 1.1.81 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/coffeescript/browser.js +144 -139
- package/lib/coffeescript/cake.js +132 -133
- package/lib/coffeescript/coffeescript.js +437 -381
- package/lib/coffeescript/command.js +806 -724
- package/lib/coffeescript/grammar.js +1908 -2474
- package/lib/coffeescript/helpers.js +509 -473
- package/lib/coffeescript/index.js +228 -215
- package/lib/coffeescript/lexer.js +2282 -1909
- package/lib/coffeescript/nodes.js +9782 -9202
- package/lib/coffeescript/optparse.js +255 -227
- package/lib/coffeescript/parser.js +20305 -1265
- package/lib/coffeescript/register.js +107 -87
- package/lib/coffeescript/repl.js +307 -284
- package/lib/coffeescript/rewriter.js +1389 -1079
- package/lib/coffeescript/scope.js +176 -172
- package/lib/coffeescript/sourcemap.js +242 -227
- package/lib/rew/cli/cli.js +296 -239
- package/lib/rew/cli/log.js +27 -27
- package/lib/rew/cli/run.js +8 -8
- package/lib/rew/cli/utils.js +353 -199
- package/lib/rew/const/config_path.js +2 -2
- package/lib/rew/const/default.js +38 -53
- package/lib/rew/const/files.js +11 -14
- package/lib/rew/const/opt.js +6 -6
- package/lib/rew/css/theme.css +1 -1
- package/lib/rew/functions/core.js +55 -55
- package/lib/rew/functions/curl.js +23 -0
- package/lib/rew/functions/emitter.js +52 -55
- package/lib/rew/functions/exec.js +25 -25
- package/lib/rew/functions/export.js +17 -17
- package/lib/rew/functions/fs.js +57 -59
- package/lib/rew/functions/future.js +29 -21
- package/lib/rew/functions/id.js +8 -9
- package/lib/rew/functions/import.js +106 -122
- package/lib/rew/functions/map.js +10 -10
- package/lib/rew/functions/match.js +35 -42
- package/lib/rew/functions/path.js +8 -8
- package/lib/rew/functions/require.js +32 -36
- package/lib/rew/functions/sleep.js +2 -2
- package/lib/rew/functions/stdout.js +18 -18
- package/lib/rew/functions/types.js +82 -106
- package/lib/rew/html/ui.html +12 -12
- package/lib/rew/html/ui.js +196 -201
- package/lib/rew/main.js +14 -14
- package/lib/rew/misc/bin.js +37 -0
- package/lib/rew/misc/findAppInfo.js +13 -13
- package/lib/rew/misc/findAppPath.js +15 -15
- package/lib/rew/misc/req.js +7 -0
- package/lib/rew/misc/seededid.js +8 -8
- package/lib/rew/models/enum.js +12 -12
- package/lib/rew/models/struct.js +30 -32
- package/lib/rew/modules/compiler.js +237 -209
- package/lib/rew/modules/fs.js +10 -10
- package/lib/rew/modules/runtime.js +17 -21
- package/lib/rew/modules/yaml.js +27 -30
- package/lib/rew/pkgs/conf.js +82 -92
- package/lib/rew/pkgs/data.js +10 -10
- package/lib/rew/pkgs/date.js +27 -27
- package/lib/rew/pkgs/env.js +5 -5
- package/lib/rew/pkgs/modules/data/bintree.js +51 -51
- package/lib/rew/pkgs/modules/data/doublylinked.js +84 -84
- package/lib/rew/pkgs/modules/data/linkedList.js +72 -72
- package/lib/rew/pkgs/modules/data/queue.js +18 -18
- package/lib/rew/pkgs/modules/data/stack.js +18 -18
- package/lib/rew/pkgs/modules/threads/worker.js +36 -36
- package/lib/rew/pkgs/modules/ui/classes.js +181 -184
- package/lib/rew/pkgs/pkgs.js +9 -9
- package/lib/rew/pkgs/rune.js +373 -410
- package/lib/rew/pkgs/threads.js +62 -66
- package/lib/rew/pkgs/ui.js +148 -160
- package/lib/rew/qrew/compile.js +12 -0
- package/package.json +4 -3
package/lib/rew/html/ui.js
CHANGED
@@ -1,250 +1,245 @@
|
|
1
1
|
try {
|
2
|
-
|
2
|
+
window.execContext = $OPTIONS(json.execContext);
|
3
3
|
} catch (e) {
|
4
|
-
|
4
|
+
window.execContext = {};
|
5
5
|
}
|
6
6
|
|
7
7
|
try {
|
8
|
-
|
8
|
+
window.exec = $OPTIONS(exec);
|
9
9
|
} catch (e) {
|
10
|
-
|
10
|
+
window.exec = function () {};
|
11
11
|
}
|
12
12
|
|
13
13
|
const DOM = [];
|
14
14
|
|
15
|
-
const findInDom = (id) =>
|
16
|
-
DOM.find((el) => el.widgetOptions.uuid == id) ||
|
17
|
-
DOM.find((el) => el.id == id);
|
15
|
+
const findInDom = (id) => DOM.find((el) => el.widgetOptions.uuid == id) || DOM.find((el) => el.id == id);
|
18
16
|
|
19
17
|
const parseStyleValue = (val) => val;
|
20
18
|
|
21
19
|
const addTo = (el, parent) => {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
if (parent == 'null') {
|
21
|
+
document.body.appendChild(el);
|
22
|
+
} else {
|
23
|
+
findInDom(parent).appendChild(el);
|
24
|
+
}
|
27
25
|
};
|
28
26
|
|
29
27
|
const initElement = (el, options, update = false) => {
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
28
|
+
if (el.widgetOptions) {
|
29
|
+
if (el.widgetOptions.style) {
|
30
|
+
for (let i in options.style) {
|
31
|
+
el.style.removeProperty(i, el.widgetOptions.style[i]);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
if (el.widgetOptions.attr) {
|
35
|
+
for (let i in el.widgetOptions.attr) {
|
36
|
+
el.removeAttribute(i);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
el.widgetOptions = options;
|
42
|
+
el.id = options.id;
|
43
|
+
el.textContent = options.data.text;
|
44
|
+
|
45
|
+
if (options.style) {
|
46
|
+
for (let i in options.style) {
|
47
|
+
el.style.setProperty(i, options.style[i]);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
if (options.attr) {
|
52
|
+
for (let i in options.attr) {
|
53
|
+
el.setAttribute(i, options.attr[i]);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
if (options.children.length) {
|
58
|
+
options.children.forEach((option) => {
|
59
|
+
option.parent = options.uuid;
|
60
|
+
if (update) updateElement(findInDom(option.uuid), option);
|
61
|
+
else createElement(option);
|
62
|
+
});
|
63
|
+
}
|
64
|
+
|
65
|
+
if (options.parent) {
|
66
|
+
addTo(el, options.parent);
|
67
|
+
}
|
70
68
|
};
|
71
69
|
|
72
70
|
const updateElement = (el, options) => {
|
73
|
-
|
74
|
-
|
75
|
-
|
71
|
+
if (!el) return;
|
72
|
+
initElement(el, options, true);
|
73
|
+
return el;
|
76
74
|
};
|
77
75
|
|
78
76
|
const events = [
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
77
|
+
'click',
|
78
|
+
'dblclick',
|
79
|
+
'mousedown',
|
80
|
+
'mouseup',
|
81
|
+
'mouseover',
|
82
|
+
'mouseout',
|
83
|
+
'mousemove',
|
84
|
+
'mouseenter',
|
85
|
+
'mouseleave',
|
86
|
+
'keydown',
|
87
|
+
'keypress',
|
88
|
+
'keyup',
|
89
|
+
'change',
|
90
|
+
'input',
|
91
|
+
'submit',
|
92
|
+
'focus',
|
93
|
+
'blur',
|
94
|
+
'copy',
|
95
|
+
'cut',
|
96
|
+
'paste',
|
97
|
+
'scroll',
|
98
|
+
'wheel',
|
99
|
+
'resize',
|
100
|
+
'contextmenu',
|
101
|
+
'drag',
|
102
|
+
'dragstart',
|
103
|
+
'dragend',
|
104
|
+
'dragenter',
|
105
|
+
'dragleave',
|
106
|
+
'dragover',
|
107
|
+
'drop',
|
108
|
+
'error',
|
109
|
+
'load',
|
110
|
+
'abort',
|
113
111
|
];
|
114
112
|
const handleListeners = (el) => {
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
113
|
+
events.forEach((event) => {
|
114
|
+
el.addEventListener(event, (e) => {
|
115
|
+
sendData({
|
116
|
+
action: 'hook:eventTrigger',
|
117
|
+
data: {
|
118
|
+
rid: 'event_trigger',
|
119
|
+
object: {
|
120
|
+
uuid: el.widgetOptions.uuid,
|
121
|
+
event,
|
122
|
+
data: {
|
123
|
+
mouse: { x: e.clientX, y: e.clientY },
|
124
|
+
key: { code: e.keyCode, key: e.key },
|
125
|
+
},
|
126
|
+
},
|
127
|
+
},
|
128
|
+
});
|
129
|
+
});
|
130
|
+
});
|
133
131
|
};
|
134
132
|
|
135
133
|
function eventHandlerFunction({ uuid, hookID, event }) {
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
134
|
+
return function (e) {
|
135
|
+
sendData({
|
136
|
+
action: 'hook:event_' + event,
|
137
|
+
data: {
|
138
|
+
rid: hookID,
|
139
|
+
object: {
|
140
|
+
uuid,
|
141
|
+
event,
|
142
|
+
data: {
|
143
|
+
mouse: { x: e.clientX, y: e.clientY },
|
144
|
+
key: { code: e.keyCode, key: e.key },
|
145
|
+
},
|
146
|
+
},
|
147
|
+
},
|
148
|
+
});
|
149
|
+
};
|
152
150
|
}
|
153
151
|
|
154
152
|
const createElement = (options) => {
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
153
|
+
const el = document.createElement(options.element);
|
154
|
+
DOM.push(el);
|
155
|
+
initElement(el, options);
|
156
|
+
return el;
|
159
157
|
};
|
160
158
|
|
161
159
|
const stringifyJSON = (json) => {
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
160
|
+
try {
|
161
|
+
return JSON.stringify(json, null, 4);
|
162
|
+
} catch (e) {
|
163
|
+
return json.toString();
|
164
|
+
}
|
167
165
|
};
|
168
166
|
|
169
167
|
const log = (...strings) => {
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
),
|
184
|
-
);
|
168
|
+
window.webkit.messageHandlers.external.postMessage(
|
169
|
+
JSON.stringify(
|
170
|
+
{
|
171
|
+
action: 'log',
|
172
|
+
data: strings
|
173
|
+
.map((r) => (typeof r == 'object' ? stringifyJSON(r) : `${r.toString()}`))
|
174
|
+
// .map((i) => i.replace(/\"/g, '\\\\"').replace(/\n/g, "\\\\n"))
|
175
|
+
.join('\n'),
|
176
|
+
},
|
177
|
+
null,
|
178
|
+
4,
|
179
|
+
),
|
180
|
+
);
|
185
181
|
};
|
186
182
|
|
187
183
|
const sendData = (data) => {
|
188
|
-
|
184
|
+
log('RESPONSE::' + stringifyJSON(data));
|
189
185
|
};
|
190
186
|
|
191
187
|
function process_data(data) {
|
192
|
-
|
188
|
+
return JSON.parse(data);
|
193
189
|
}
|
194
190
|
|
195
191
|
window.recieveMessage = (data) => {
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
192
|
+
const edata = data;
|
193
|
+
if (edata.action == 'eventListen') {
|
194
|
+
const el = findInDom(edata.data.uuid);
|
195
|
+
if (el) {
|
196
|
+
el.addEventListener(edata.data.event, eventHandlerFunction(edata.data));
|
197
|
+
}
|
198
|
+
} else if (edata.action == 'createElement') {
|
199
|
+
const options = edata.data;
|
200
|
+
try {
|
201
|
+
createElement(options);
|
202
|
+
} catch (e) {
|
203
|
+
log(e.toString());
|
204
|
+
}
|
205
|
+
} else if (edata.action == 'addStyleSheet') {
|
206
|
+
const style = document.createElement('style');
|
207
|
+
style.textContent = edata.data;
|
208
|
+
document.head.appendChild(style);
|
209
|
+
} else if (edata.action == 'updateElement') {
|
210
|
+
const options = edata.data;
|
211
|
+
try {
|
212
|
+
updateElement(findInDom(options.uuid), options);
|
213
|
+
} catch (e) {
|
214
|
+
log(e.toString());
|
215
|
+
}
|
216
|
+
} else if (edata.action == 'findElement') {
|
217
|
+
const id = edata.data.id;
|
218
|
+
const rid = edata.data.rid;
|
219
|
+
try {
|
220
|
+
sendData({
|
221
|
+
action: 'hook:findElement',
|
222
|
+
data: { rid, object: findInDom(id)?.widgetOptions },
|
223
|
+
});
|
224
|
+
} catch (e) {
|
225
|
+
log(e.toString());
|
226
|
+
}
|
227
|
+
} else if (edata.action == 'message') {
|
228
|
+
window.dispatchEvent(
|
229
|
+
new CustomEvent('message', {
|
230
|
+
detail: edata.data,
|
231
|
+
}),
|
232
|
+
);
|
233
|
+
}
|
238
234
|
};
|
239
235
|
|
240
|
-
window.addEventListener(
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
log("SETUP::READY");
|
236
|
+
window.addEventListener('load', () => {
|
237
|
+
window.exec({
|
238
|
+
...window.execContext,
|
239
|
+
window,
|
240
|
+
log,
|
241
|
+
send: (data) => sendData({ action: 'message', data }),
|
242
|
+
onRecieve: (cb) => window.addEventListener('message', (e) => cb(e.detail || {})),
|
243
|
+
});
|
244
|
+
log('SETUP::READY');
|
250
245
|
});
|
package/lib/rew/main.js
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
const { compileFile } = require(
|
2
|
-
const { exec, runPath } = require(
|
3
|
-
const fs = require(
|
4
|
-
const { imp } = require(
|
5
|
-
const { FILES } = require(
|
1
|
+
const { compileFile } = require('./modules/compiler');
|
2
|
+
const { exec, runPath } = require('./modules/runtime');
|
3
|
+
const fs = require('fs');
|
4
|
+
const { imp } = require('./functions/import');
|
5
|
+
const { FILES } = require('./const/files');
|
6
6
|
|
7
7
|
module.exports.run = function (filepath, options = {}, custom_context = {}) {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
FILES.forEach((file) => {
|
9
|
+
if (fs.existsSync(file.path)) return;
|
10
|
+
if (file.content) {
|
11
|
+
fs.writeFileSync(file.path, file.content);
|
12
|
+
} else {
|
13
|
+
fs.mkdirSync(file.path, { recursive: true });
|
14
|
+
}
|
15
|
+
});
|
16
|
+
return runPath(filepath, options, custom_context);
|
17
17
|
};
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
const msgpack = require('tiny-msgpack');
|
4
|
+
const crypto = require('crypto');
|
5
|
+
|
6
|
+
const algorithm = 'aes-256-ctr';
|
7
|
+
|
8
|
+
const encrypt = (data, encryptionKey) => {
|
9
|
+
const iv = crypto.randomBytes(16);
|
10
|
+
const cipher = crypto.createCipheriv(algorithm, Buffer.from(encryptionKey, 'hex'), iv);
|
11
|
+
const encrypted = Buffer.concat([cipher.update(data), cipher.final()]);
|
12
|
+
return Buffer.concat([iv, encrypted]);
|
13
|
+
};
|
14
|
+
|
15
|
+
const decrypt = (data, encryptionKey) => {
|
16
|
+
const iv = data.slice(0, 16);
|
17
|
+
const encryptedData = data.slice(16);
|
18
|
+
const decipher = crypto.createDecipheriv(algorithm, Buffer.from(encryptionKey, 'hex'), iv);
|
19
|
+
const decrypted = Buffer.concat([decipher.update(encryptedData), decipher.final()]);
|
20
|
+
return decrypted;
|
21
|
+
};
|
22
|
+
|
23
|
+
module.exports.serializeData = (data, encryptionKey) => {
|
24
|
+
return encrypt(msgpack.encode(data), encryptionKey);
|
25
|
+
};
|
26
|
+
|
27
|
+
module.exports.deserializeData = (buffer, encryptionKey) => {
|
28
|
+
return msgpack.decode(decrypt(buffer, encryptionKey));
|
29
|
+
};
|
30
|
+
|
31
|
+
module.exports.gen_key = (secret) => {
|
32
|
+
if (secret) {
|
33
|
+
return crypto.createHash('sha256').update(secret).digest('hex');
|
34
|
+
} else {
|
35
|
+
return crypto.randomBytes(32).toString('hex');
|
36
|
+
}
|
37
|
+
}
|
@@ -1,16 +1,16 @@
|
|
1
|
-
const jsYaml = require(
|
2
|
-
const { findAppPath } = require(
|
3
|
-
const path = require(
|
4
|
-
const { readFileSync } = require(
|
1
|
+
const jsYaml = require('js-yaml');
|
2
|
+
const { findAppPath } = require('./findAppPath');
|
3
|
+
const path = require('path');
|
4
|
+
const { readFileSync } = require('fs');
|
5
5
|
|
6
6
|
module.exports.findAppInfo = function (filepath) {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
const appPath = findAppPath(path.dirname(filepath));
|
8
|
+
if (appPath) {
|
9
|
+
const config = jsYaml.load(readFileSync(path.join(appPath, 'app.yaml')));
|
10
|
+
return {
|
11
|
+
path: appPath,
|
12
|
+
config,
|
13
|
+
};
|
14
|
+
}
|
15
|
+
return null;
|
16
16
|
};
|
@@ -1,21 +1,21 @@
|
|
1
|
-
const path = require(
|
2
|
-
const fs = require(
|
1
|
+
const path = require('path'); // Import the 'path' module
|
2
|
+
const fs = require('fs'); // Import the 'path' module
|
3
3
|
|
4
4
|
module.exports.findAppPath = (currentDir = __dirname) => {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
// Check if app.yaml exists in the current directory
|
6
|
+
const appYamlPath = path.join(currentDir, 'app.yaml');
|
7
|
+
if (fs.existsSync(appYamlPath)) {
|
8
|
+
return currentDir;
|
9
|
+
}
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
// If not found, move up a directory level
|
12
|
+
const parentDir = path.dirname(currentDir);
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
// Check if we reached the root directory
|
15
|
+
if (parentDir === currentDir) {
|
16
|
+
return null; // Not found
|
17
|
+
}
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
// Recursively call the function on the parent directory
|
20
|
+
return module.exports.findAppPath(parentDir);
|
21
21
|
};
|
package/lib/rew/misc/seededid.js
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module.exports.seededID = function (seed) {
|
2
|
-
|
2
|
+
const charCodes = seed.split('').map((char) => char.charCodeAt(0));
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
let result = '';
|
5
|
+
let sum = 0;
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
for (let i = 0; i < charCodes.length; i++) {
|
8
|
+
sum += charCodes[i];
|
9
|
+
result += String.fromCharCode(((charCodes[i] + sum) % 26) + 97);
|
10
|
+
}
|
11
11
|
|
12
|
-
|
12
|
+
return result.slice(0, 12);
|
13
13
|
};
|
package/lib/rew/models/enum.js
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module.exports.cenum = function cenum(values) {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
2
|
+
var enumObj, i, len, value;
|
3
|
+
// Create an object to hold the enum values
|
4
|
+
enumObj = {};
|
5
|
+
for (i = 0, len = values.length; i < len; i++) {
|
6
|
+
value = values[i];
|
7
|
+
enumObj[value] = value;
|
8
|
+
}
|
9
|
+
// Add a method to check if a value is a valid enum value
|
10
|
+
enumObj.isValid = function (val) {
|
11
|
+
return indexOf.call(enumObj, val) >= 0;
|
12
|
+
};
|
13
|
+
return enumObj;
|
14
14
|
};
|