@makano/rew 1.1.81 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/lib/coffeescript/browser.js +144 -139
  2. package/lib/coffeescript/cake.js +132 -133
  3. package/lib/coffeescript/coffeescript.js +437 -381
  4. package/lib/coffeescript/command.js +806 -724
  5. package/lib/coffeescript/grammar.js +1908 -2474
  6. package/lib/coffeescript/helpers.js +509 -473
  7. package/lib/coffeescript/index.js +228 -215
  8. package/lib/coffeescript/lexer.js +2282 -1909
  9. package/lib/coffeescript/nodes.js +9782 -9202
  10. package/lib/coffeescript/optparse.js +255 -227
  11. package/lib/coffeescript/parser.js +20305 -1265
  12. package/lib/coffeescript/register.js +107 -87
  13. package/lib/coffeescript/repl.js +307 -284
  14. package/lib/coffeescript/rewriter.js +1389 -1079
  15. package/lib/coffeescript/scope.js +176 -172
  16. package/lib/coffeescript/sourcemap.js +242 -227
  17. package/lib/rew/cli/cli.js +312 -239
  18. package/lib/rew/cli/log.js +27 -27
  19. package/lib/rew/cli/run.js +8 -8
  20. package/lib/rew/cli/utils.js +368 -199
  21. package/lib/rew/const/config_path.js +2 -2
  22. package/lib/rew/const/default.js +38 -53
  23. package/lib/rew/const/files.js +11 -14
  24. package/lib/rew/const/opt.js +6 -6
  25. package/lib/rew/css/theme.css +1 -1
  26. package/lib/rew/functions/core.js +55 -55
  27. package/lib/rew/functions/curl.js +23 -0
  28. package/lib/rew/functions/emitter.js +52 -55
  29. package/lib/rew/functions/exec.js +25 -25
  30. package/lib/rew/functions/export.js +17 -17
  31. package/lib/rew/functions/fs.js +57 -59
  32. package/lib/rew/functions/future.js +29 -21
  33. package/lib/rew/functions/id.js +8 -9
  34. package/lib/rew/functions/import.js +106 -122
  35. package/lib/rew/functions/map.js +10 -10
  36. package/lib/rew/functions/match.js +35 -42
  37. package/lib/rew/functions/path.js +8 -8
  38. package/lib/rew/functions/require.js +32 -36
  39. package/lib/rew/functions/sleep.js +2 -2
  40. package/lib/rew/functions/stdout.js +18 -18
  41. package/lib/rew/functions/types.js +82 -106
  42. package/lib/rew/html/ui.html +12 -12
  43. package/lib/rew/html/ui.js +196 -201
  44. package/lib/rew/main.js +14 -14
  45. package/lib/rew/misc/bin.js +37 -0
  46. package/lib/rew/misc/findAppInfo.js +13 -13
  47. package/lib/rew/misc/findAppPath.js +15 -15
  48. package/lib/rew/misc/req.js +7 -0
  49. package/lib/rew/misc/seededid.js +8 -8
  50. package/lib/rew/models/enum.js +12 -12
  51. package/lib/rew/models/struct.js +30 -32
  52. package/lib/rew/modules/compiler.js +237 -209
  53. package/lib/rew/modules/fs.js +10 -10
  54. package/lib/rew/modules/runtime.js +17 -21
  55. package/lib/rew/modules/yaml.js +27 -30
  56. package/lib/rew/pkgs/conf.js +82 -92
  57. package/lib/rew/pkgs/data.js +10 -10
  58. package/lib/rew/pkgs/date.js +27 -27
  59. package/lib/rew/pkgs/env.js +5 -5
  60. package/lib/rew/pkgs/modules/data/bintree.js +51 -51
  61. package/lib/rew/pkgs/modules/data/doublylinked.js +84 -84
  62. package/lib/rew/pkgs/modules/data/linkedList.js +72 -72
  63. package/lib/rew/pkgs/modules/data/queue.js +18 -18
  64. package/lib/rew/pkgs/modules/data/stack.js +18 -18
  65. package/lib/rew/pkgs/modules/threads/worker.js +36 -36
  66. package/lib/rew/pkgs/modules/ui/classes.js +181 -184
  67. package/lib/rew/pkgs/pkgs.js +9 -9
  68. package/lib/rew/pkgs/rune.js +373 -410
  69. package/lib/rew/pkgs/threads.js +62 -66
  70. package/lib/rew/pkgs/ui.js +148 -160
  71. package/lib/rew/qrew/compile.js +12 -0
  72. package/package.json +4 -3
@@ -1,250 +1,245 @@
1
1
  try {
2
- window.execContext = $OPTIONS(json.execContext);
2
+ window.execContext = $OPTIONS(json.execContext);
3
3
  } catch (e) {
4
- window.execContext = {};
4
+ window.execContext = {};
5
5
  }
6
6
 
7
7
  try {
8
- window.exec = $OPTIONS(exec);
8
+ window.exec = $OPTIONS(exec);
9
9
  } catch (e) {
10
- window.exec = function () {};
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
- if (parent == "null") {
23
- document.body.appendChild(el);
24
- } else {
25
- findInDom(parent).appendChild(el);
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
- if (el.widgetOptions) {
31
- if (el.widgetOptions.style) {
32
- for (let i in options.style) {
33
- el.style.removeProperty(i, el.widgetOptions.style[i]);
34
- }
35
- }
36
- if (el.widgetOptions.attr) {
37
- for (let i in el.widgetOptions.attr) {
38
- el.removeAttribute(i);
39
- }
40
- }
41
- }
42
-
43
- el.widgetOptions = options;
44
- el.id = options.id;
45
- el.textContent = options.data.text;
46
-
47
- if (options.style) {
48
- for (let i in options.style) {
49
- el.style.setProperty(i, options.style[i]);
50
- }
51
- }
52
-
53
- if (options.attr) {
54
- for (let i in options.attr) {
55
- el.setAttribute(i, options.attr[i]);
56
- }
57
- }
58
-
59
- if (options.children.length) {
60
- options.children.forEach((option) => {
61
- option.parent = options.uuid;
62
- if (update) updateElement(findInDom(option.uuid), option);
63
- else createElement(option);
64
- });
65
- }
66
-
67
- if (options.parent) {
68
- addTo(el, options.parent);
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
- if (!el) return;
74
- initElement(el, options, true);
75
- return el;
71
+ if (!el) return;
72
+ initElement(el, options, true);
73
+ return el;
76
74
  };
77
75
 
78
76
  const events = [
79
- "click",
80
- "dblclick",
81
- "mousedown",
82
- "mouseup",
83
- "mouseover",
84
- "mouseout",
85
- "mousemove",
86
- "mouseenter",
87
- "mouseleave",
88
- "keydown",
89
- "keypress",
90
- "keyup",
91
- "change",
92
- "input",
93
- "submit",
94
- "focus",
95
- "blur",
96
- "copy",
97
- "cut",
98
- "paste",
99
- "scroll",
100
- "wheel",
101
- "resize",
102
- "contextmenu",
103
- "drag",
104
- "dragstart",
105
- "dragend",
106
- "dragenter",
107
- "dragleave",
108
- "dragover",
109
- "drop",
110
- "error",
111
- "load",
112
- "abort",
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
- events.forEach((event) => {
116
- el.addEventListener(event, (e) => {
117
- sendData({
118
- action: "hook:eventTrigger",
119
- data: {
120
- rid: "event_trigger",
121
- object: {
122
- uuid: el.widgetOptions.uuid,
123
- event,
124
- data: {
125
- mouse: { x: e.clientX, y: e.clientY },
126
- key: { code: e.keyCode, key: e.key },
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
- return function (e) {
137
- sendData({
138
- action: "hook:event_" + event,
139
- data: {
140
- rid: hookID,
141
- object: {
142
- uuid,
143
- event,
144
- data: {
145
- mouse: { x: e.clientX, y: e.clientY },
146
- key: { code: e.keyCode, key: e.key },
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
- const el = document.createElement(options.element);
156
- DOM.push(el);
157
- initElement(el, options);
158
- return el;
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
- try {
163
- return JSON.stringify(json, null, 4);
164
- } catch (e) {
165
- return json.toString();
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
- window.webkit.messageHandlers.external.postMessage(
171
- JSON.stringify(
172
- {
173
- action: "log",
174
- data: strings
175
- .map((r) =>
176
- typeof r == "object" ? stringifyJSON(r) : `${r.toString()}`,
177
- )
178
- // .map((i) => i.replace(/\"/g, '\\\\"').replace(/\n/g, "\\\\n"))
179
- .join("\n"),
180
- },
181
- null,
182
- 4,
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
- log("RESPONSE::" + stringifyJSON(data));
184
+ log('RESPONSE::' + stringifyJSON(data));
189
185
  };
190
186
 
191
187
  function process_data(data) {
192
- return JSON.parse(data);
188
+ return JSON.parse(data);
193
189
  }
194
190
 
195
191
  window.recieveMessage = (data) => {
196
- const edata = data;
197
- if (edata.action == "eventListen") {
198
- const el = findInDom(edata.data.uuid);
199
- if (el) {
200
- el.addEventListener(edata.data.event, eventHandlerFunction(edata.data));
201
- }
202
- } else if (edata.action == "createElement") {
203
- const options = edata.data;
204
- try {
205
- createElement(options);
206
- } catch (e) {
207
- log(e.toString());
208
- }
209
- } else if (edata.action == "addStyleSheet") {
210
- const style = document.createElement("style");
211
- style.textContent = edata.data;
212
- document.head.appendChild(style);
213
- } else if (edata.action == "updateElement") {
214
- const options = edata.data;
215
- try {
216
- updateElement(findInDom(options.uuid), options);
217
- } catch (e) {
218
- log(e.toString());
219
- }
220
- } else if (edata.action == "findElement") {
221
- const id = edata.data.id;
222
- const rid = edata.data.rid;
223
- try {
224
- sendData({
225
- action: "hook:findElement",
226
- data: { rid, object: findInDom(id)?.widgetOptions },
227
- });
228
- } catch (e) {
229
- log(e.toString());
230
- }
231
- } else if (edata.action == "message") {
232
- window.dispatchEvent(
233
- new CustomEvent("message", {
234
- detail: edata.data,
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("load", () => {
241
- window.exec({
242
- ...window.execContext,
243
- window,
244
- log,
245
- send: (data) => sendData({ action: "message", data }),
246
- onRecieve: (cb) =>
247
- window.addEventListener("message", (e) => cb(e.detail || {})),
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("./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");
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
- 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);
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("js-yaml");
2
- const { findAppPath } = require("./findAppPath");
3
- const path = require("path");
4
- const { readFileSync } = require("fs");
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
- 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;
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("path"); // Import the 'path' module
2
- const fs = require("fs"); // Import the 'path' module
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
- // 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
- }
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
- // If not found, move up a directory level
12
- const parentDir = path.dirname(currentDir);
11
+ // If not found, move up a directory level
12
+ const parentDir = path.dirname(currentDir);
13
13
 
14
- // Check if we reached the root directory
15
- if (parentDir === currentDir) {
16
- return null; // Not found
17
- }
14
+ // Check if we reached the root directory
15
+ if (parentDir === currentDir) {
16
+ return null; // Not found
17
+ }
18
18
 
19
- // Recursively call the function on the parent directory
20
- return module.exports.findAppPath(parentDir);
19
+ // Recursively call the function on the parent directory
20
+ return module.exports.findAppPath(parentDir);
21
21
  };
@@ -0,0 +1,7 @@
1
+ const axios = require("axios")
2
+
3
+
4
+ module.exports.req = async (url, options = {}) => {
5
+ return await axios
6
+ .get(url, { ...options });
7
+ }
@@ -1,13 +1,13 @@
1
1
  module.exports.seededID = function (seed) {
2
- const charCodes = seed.split("").map((char) => char.charCodeAt(0));
2
+ const charCodes = seed.split('').map((char) => char.charCodeAt(0));
3
3
 
4
- let result = "";
5
- let sum = 0;
4
+ let result = '';
5
+ let sum = 0;
6
6
 
7
- for (let i = 0; i < charCodes.length; i++) {
8
- sum += charCodes[i];
9
- result += String.fromCharCode(((charCodes[i] + sum) % 26) + 97);
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
- return result.slice(0, 12);
12
+ return result.slice(0, 12);
13
13
  };
@@ -1,14 +1,14 @@
1
1
  module.exports.cenum = function cenum(values) {
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;
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
  };