@makano/rew 1.1.73 → 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 +288 -186
- package/lib/rew/cli/log.js +31 -32
- package/lib/rew/cli/run.js +10 -12
- package/lib/rew/cli/utils.js +344 -176
- package/lib/rew/const/config_path.js +4 -0
- package/lib/rew/const/default.js +38 -35
- package/lib/rew/const/files.js +9 -9
- package/lib/rew/const/opt.js +8 -8
- package/lib/rew/css/theme.css +2 -2
- package/lib/rew/functions/core.js +55 -57
- package/lib/rew/functions/curl.js +23 -0
- package/lib/rew/functions/emitter.js +52 -55
- package/lib/rew/functions/exec.js +25 -21
- package/lib/rew/functions/export.js +18 -20
- package/lib/rew/functions/fs.js +55 -54
- package/lib/rew/functions/future.js +29 -21
- package/lib/rew/functions/id.js +8 -9
- package/lib/rew/functions/import.js +107 -93
- package/lib/rew/functions/map.js +13 -16
- package/lib/rew/functions/match.js +35 -26
- package/lib/rew/functions/path.js +8 -8
- package/lib/rew/functions/require.js +32 -33
- package/lib/rew/functions/sleep.js +2 -2
- package/lib/rew/functions/stdout.js +20 -20
- package/lib/rew/functions/types.js +96 -95
- package/lib/rew/html/ui.html +12 -13
- package/lib/rew/html/ui.js +205 -168
- package/lib/rew/main.js +14 -14
- package/lib/rew/misc/bin.js +37 -0
- package/lib/rew/misc/findAppInfo.js +16 -0
- package/lib/rew/misc/findAppPath.js +21 -0
- package/lib/rew/misc/req.js +7 -0
- package/lib/rew/misc/seededid.js +13 -0
- package/lib/rew/models/enum.js +12 -12
- package/lib/rew/models/struct.js +30 -32
- package/lib/rew/modules/compiler.js +237 -177
- package/lib/rew/modules/context.js +35 -22
- 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 -75
- package/lib/rew/pkgs/data.js +12 -7
- package/lib/rew/pkgs/date.js +27 -28
- package/lib/rew/pkgs/env.js +6 -8
- package/lib/rew/pkgs/modules/data/bintree.js +52 -52
- package/lib/rew/pkgs/modules/data/doublylinked.js +85 -85
- package/lib/rew/pkgs/modules/data/linkedList.js +73 -73
- package/lib/rew/pkgs/modules/data/queue.js +19 -20
- package/lib/rew/pkgs/modules/data/stack.js +19 -19
- package/lib/rew/pkgs/modules/threads/worker.js +36 -26
- package/lib/rew/pkgs/modules/ui/classes.js +182 -178
- package/lib/rew/pkgs/pkgs.js +9 -10
- package/lib/rew/pkgs/rune.js +400 -0
- package/lib/rew/pkgs/threads.js +57 -53
- package/lib/rew/pkgs/ui.js +148 -136
- package/lib/rew/qrew/compile.js +12 -0
- package/package.json +11 -4
@@ -1,39 +1,40 @@
|
|
1
1
|
const defaultContext = require("../const/default");
|
2
2
|
const { execOptions } = require("../const/opt");
|
3
|
-
const emitter = require("../functions/emitter");
|
4
3
|
const { exportsFunction, pubFunction } = require("../functions/export");
|
5
4
|
const { imp } = require("../functions/import");
|
6
5
|
const { customRequire } = require("../functions/require");
|
7
|
-
const fsLib = require(
|
8
|
-
const pathLib = require(
|
9
|
-
const execLib = require(
|
6
|
+
const fsLib = require("../functions/fs");
|
7
|
+
const pathLib = require("../functions/path");
|
8
|
+
const execLib = require("../functions/exec");
|
9
|
+
const { findAppInfo } = require("../misc/findAppInfo");
|
10
10
|
|
11
11
|
let mainFile = "";
|
12
|
-
const isMainFile = filepath => filepath == mainFile;
|
12
|
+
const isMainFile = (filepath) => filepath == mainFile;
|
13
13
|
module.exports.prepareContext = function (
|
14
14
|
custom_context,
|
15
15
|
options,
|
16
16
|
filepath = "",
|
17
17
|
runPath = () => {},
|
18
18
|
) {
|
19
|
-
if(mainFile == "") mainFile = filepath;
|
19
|
+
if (mainFile == "") mainFile = filepath;
|
20
20
|
let context = {
|
21
21
|
module: {
|
22
22
|
exports: null,
|
23
23
|
filepath,
|
24
24
|
main: isMainFile(filepath),
|
25
|
-
imports: []
|
25
|
+
imports: [],
|
26
26
|
},
|
27
27
|
imports: {
|
28
28
|
meta: {},
|
29
|
-
assert: options.import ?? {}
|
29
|
+
assert: options.import ?? {},
|
30
30
|
},
|
31
|
+
app: findAppInfo(filepath),
|
31
32
|
...fsLib(filepath),
|
32
33
|
};
|
33
34
|
if (options.useContext) {
|
34
35
|
context = {
|
35
36
|
...custom_context,
|
36
|
-
...context
|
37
|
+
...context,
|
37
38
|
};
|
38
39
|
} else {
|
39
40
|
context = {
|
@@ -43,9 +44,15 @@ module.exports.prepareContext = function (
|
|
43
44
|
...execLib(filepath),
|
44
45
|
require: (package) => {
|
45
46
|
try {
|
46
|
-
return execOptions.nativeRequire || package.startsWith(
|
47
|
+
return execOptions.nativeRequire || package.startsWith("node:")
|
48
|
+
? require(
|
49
|
+
package.startsWith("node:")
|
50
|
+
? package.split("node:")[1]
|
51
|
+
: package,
|
52
|
+
)
|
53
|
+
: customRequire(package, filepath);
|
47
54
|
} catch (e) {
|
48
|
-
throw new Error("Module "+package+" not found");
|
55
|
+
throw new Error("Module " + package + " not found");
|
49
56
|
}
|
50
57
|
},
|
51
58
|
...custom_context,
|
@@ -57,34 +64,40 @@ module.exports.prepareContext = function (
|
|
57
64
|
target: {
|
58
65
|
on: (event, listener) => process.on(event, listener),
|
59
66
|
off: (event, listener) => process.off(event, listener),
|
60
|
-
emit: (event, code) => process.emit(event, code)
|
67
|
+
emit: (event, code) => process.emit(event, code),
|
61
68
|
},
|
62
69
|
env: process.env,
|
63
70
|
cwd: () => process.cwd(),
|
64
|
-
arch: process.arch
|
71
|
+
arch: process.arch,
|
65
72
|
};
|
66
|
-
|
73
|
+
|
67
74
|
context.global = context;
|
68
75
|
context.imports.assert = options.import ?? {};
|
69
76
|
context.imp = imp(runPath, context);
|
70
77
|
context.inc = (package, asserts) => {
|
71
|
-
try{
|
72
|
-
if(package.startsWith(
|
78
|
+
try {
|
79
|
+
if (package.startsWith("node:") || package.startsWith("pkg:"))
|
80
|
+
throw new Error("");
|
73
81
|
return context.imp(package, asserts);
|
74
|
-
} catch(e) {
|
75
|
-
return context.require(
|
82
|
+
} catch (e) {
|
83
|
+
return context.require(
|
84
|
+
package.startsWith("pkg:") ? package.split("pkg:")[1] : package,
|
85
|
+
);
|
76
86
|
}
|
77
87
|
};
|
78
88
|
context.pub = pubFunction(context);
|
79
89
|
context.exports = exportsFunction(context);
|
80
90
|
|
81
|
-
if
|
91
|
+
if (
|
92
|
+
context.module.main ||
|
93
|
+
(options.fromMain == true && options.as == "main")
|
94
|
+
) {
|
82
95
|
context.opt = {
|
83
|
-
set: (key, value) => execOptions[key] = value,
|
96
|
+
set: (key, value) => (execOptions[key] = value),
|
84
97
|
get: (key) => execOptions[key],
|
85
98
|
push: (key, value) => execOptions[key]?.push(value),
|
86
|
-
pop: (key) => execOptions[key]?.pop()
|
99
|
+
pop: (key) => execOptions[key]?.pop(),
|
87
100
|
};
|
88
|
-
} else delete context.opt
|
101
|
+
} else delete context.opt;
|
89
102
|
return context;
|
90
103
|
};
|
package/lib/rew/modules/fs.js
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
const { struct } = require(
|
2
|
-
const fs = require(
|
1
|
+
const { struct } = require('../models/struct');
|
2
|
+
const fs = require('fs');
|
3
3
|
|
4
4
|
const file = (module.exports.file = struct({
|
5
|
-
|
6
|
-
|
5
|
+
path: '',
|
6
|
+
content: '',
|
7
7
|
}));
|
8
8
|
|
9
9
|
const readFile = (module.exports.readFile = function readFile(file) {
|
10
|
-
|
10
|
+
return (file.content = fs.readFileSync(file.path, { encoding: 'utf-8' }));
|
11
11
|
});
|
12
12
|
|
13
13
|
module.exports.getFile = function (filepath) {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
const f = file({
|
15
|
+
path: filepath,
|
16
|
+
});
|
17
|
+
readFile(f);
|
18
|
+
return f;
|
19
19
|
};
|
@@ -1,28 +1,24 @@
|
|
1
|
-
const vm = require(
|
2
|
-
const { compileFile } = require(
|
3
|
-
const { prepareContext } = require(
|
1
|
+
const vm = require('vm');
|
2
|
+
const { compileFile } = require('./compiler');
|
3
|
+
const { prepareContext } = require('./context');
|
4
4
|
|
5
5
|
const exec = (module.exports.exec = function (code, context) {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
return vm.runInNewContext(code, vm.createContext(context), {
|
7
|
+
filename: context.module.filepath,
|
8
|
+
lineOffset: 0,
|
9
|
+
displayErrors: true,
|
10
|
+
});
|
11
11
|
});
|
12
12
|
|
13
|
-
module.exports.runPath = function runPath(
|
14
|
-
|
15
|
-
|
16
|
-
custom_context = {},
|
17
|
-
) {
|
18
|
-
const { compiled_code, file } = compileFile(filepath, options);
|
19
|
-
const context = prepareContext(custom_context, options, file.path, runPath);
|
13
|
+
module.exports.runPath = function runPath(filepath, options = {}, custom_context = {}) {
|
14
|
+
const { compiled_code, file } = compileFile(filepath, options);
|
15
|
+
const context = prepareContext(custom_context, options, file.path, runPath);
|
20
16
|
|
21
|
-
|
22
|
-
|
17
|
+
context.module.compiled = compiled_code;
|
18
|
+
context.process.exit = (int) => process.exit(int);
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
return {
|
21
|
+
context,
|
22
|
+
returns: exec(compiled_code, context),
|
23
|
+
};
|
28
24
|
};
|
package/lib/rew/modules/yaml.js
CHANGED
@@ -1,36 +1,33 @@
|
|
1
|
-
const yaml = require(
|
2
|
-
const path = require(
|
3
|
-
const { getFile } = require(
|
1
|
+
const yaml = require('js-yaml');
|
2
|
+
const path = require('path');
|
3
|
+
const { getFile } = require('./fs');
|
4
4
|
|
5
5
|
function yamlFile(file) {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
6
|
+
const schema = new yaml.Schema([
|
7
|
+
new yaml.Type('!import', {
|
8
|
+
kind: 'scalar',
|
9
|
+
construct: (p) => importYaml(path.resolve(path.dirname(file.path), p)),
|
10
|
+
}),
|
11
|
+
new yaml.Type('!int', {
|
12
|
+
kind: 'scalar',
|
13
|
+
construct: (data) => parseInt(data),
|
14
|
+
}),
|
15
|
+
new yaml.Type('!float', {
|
16
|
+
kind: 'scalar',
|
17
|
+
construct: (data) => parseFloat(data),
|
18
|
+
}),
|
19
|
+
new yaml.Type('!bool', {
|
20
|
+
kind: 'scalar',
|
21
|
+
construct: (data) => (data == 'true' ? true : false),
|
22
|
+
}),
|
23
|
+
]);
|
24
24
|
|
25
|
-
|
25
|
+
return yaml.load(file.content, { schema });
|
26
26
|
}
|
27
27
|
|
28
|
-
const importYaml = (module.exports.importYaml = function importYaml(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
file = getFile(filepath);
|
34
|
-
}
|
35
|
-
return yamlFile(file);
|
28
|
+
const importYaml = (module.exports.importYaml = function importYaml(filepath, file) {
|
29
|
+
if (!file) {
|
30
|
+
file = getFile(filepath);
|
31
|
+
}
|
32
|
+
return yamlFile(file);
|
36
33
|
});
|
package/lib/rew/pkgs/conf.js
CHANGED
@@ -1,92 +1,99 @@
|
|
1
1
|
const fs = require('fs');
|
2
2
|
const jsYaml = require('js-yaml');
|
3
3
|
const path = require('path');
|
4
|
-
|
5
|
-
const
|
4
|
+
const { CONFIG_PATH } = require('../const/config_path');
|
5
|
+
const { seededID } = require('../misc/seededid');
|
6
6
|
|
7
7
|
const createPackageRoot = (packageName) => {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
8
|
+
const rootPath = path.join(CONFIG_PATH, packageName);
|
9
|
+
fs.mkdirSync(rootPath, { recursive: true });
|
10
|
+
return rootPath;
|
11
|
+
};
|
12
12
|
|
13
13
|
module.exports = (context) => ({
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
CONFIG_PATH,
|
15
|
+
_onImport() {
|
16
|
+
if (context.app) {
|
17
|
+
return this.create(context.app.config.package);
|
18
|
+
} else {
|
19
|
+
return this.create(seededID(path.basename(context.module.filepath).replace(/[-_/\.]/g, '')));
|
20
|
+
}
|
21
|
+
},
|
22
|
+
create: (packageName) => {
|
23
|
+
const rootPath = createPackageRoot(packageName);
|
24
|
+
|
25
|
+
const conf = {};
|
17
26
|
|
18
|
-
|
27
|
+
const dumpYaml = (val) => {
|
28
|
+
if (JSON.stringify(val) == '{}') return '';
|
29
|
+
else return jsYaml.dump(val);
|
30
|
+
};
|
19
31
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
32
|
+
const setData = (optionCenter, key, value) => {
|
33
|
+
conf[optionCenter.name][key] = value;
|
34
|
+
fs.writeFileSync(optionCenter.root, dumpYaml(conf[optionCenter.name]));
|
35
|
+
return true;
|
36
|
+
};
|
24
37
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
38
|
+
const removeData = (optionCenter, key) => {
|
39
|
+
delete conf[optionCenter.name][key];
|
40
|
+
fs.writeFileSync(optionCenter.root, dumpYaml(conf[optionCenter.name]));
|
41
|
+
return true;
|
42
|
+
};
|
30
43
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
return true;
|
35
|
-
}
|
44
|
+
const getData = (optionCenter, key) => {
|
45
|
+
return conf[optionCenter.name][key];
|
46
|
+
};
|
36
47
|
|
37
|
-
|
38
|
-
|
39
|
-
|
48
|
+
const staticFile = (name, defaultValue = '') => {
|
49
|
+
const fileRoot = path.join(rootPath, name);
|
50
|
+
const exists = fs.existsSync(fileRoot);
|
51
|
+
return {
|
52
|
+
create(value) {
|
53
|
+
if (!fs.existsSync(path.dirname(fileRoot))) fs.mkdirSync(path.dirname(fileRoot), { recursive: true });
|
54
|
+
fs.writeFileSync(fileRoot, value || defaultValue);
|
55
|
+
},
|
56
|
+
fileRoot,
|
57
|
+
exists,
|
58
|
+
};
|
59
|
+
};
|
40
60
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
exists
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
const createOptionCenter = (name, defaults = {}) => {
|
55
|
-
const optionRoot = path.join(rootPath, name+'.yaml');
|
56
|
-
if(!fs.existsSync(path.dirname(optionRoot))) fs.mkdirSync(path.dirname(optionRoot), { recursive: true });
|
57
|
-
if(!fs.existsSync(optionRoot)) {
|
58
|
-
conf[name] = defaults;
|
59
|
-
fs.writeFileSync(optionRoot, dumpYaml(defaults));
|
60
|
-
} else {
|
61
|
-
conf[name] = jsYaml.load(fs.readFileSync(optionRoot, { encoding: 'utf-8' }));
|
62
|
-
}
|
61
|
+
const createOptionCenter = (name, defaults = {}) => {
|
62
|
+
const optionRoot = path.join(rootPath, name + '.yaml');
|
63
|
+
if (!fs.existsSync(path.dirname(optionRoot))) fs.mkdirSync(path.dirname(optionRoot), { recursive: true });
|
64
|
+
if (!fs.existsSync(optionRoot)) {
|
65
|
+
conf[name] = defaults;
|
66
|
+
fs.writeFileSync(optionRoot, dumpYaml(defaults));
|
67
|
+
} else {
|
68
|
+
conf[name] = jsYaml.load(fs.readFileSync(optionRoot, { encoding: 'utf-8' }));
|
69
|
+
}
|
63
70
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
71
|
+
const optionCenter = {
|
72
|
+
root: optionRoot,
|
73
|
+
name,
|
74
|
+
package: packageName,
|
75
|
+
};
|
69
76
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
return {
|
78
|
+
get: (key, defaultValue) => getData(optionCenter, key) || defaultValue,
|
79
|
+
set: (key, value) => setData(optionCenter, key, value),
|
80
|
+
remove: (key) => removeData(optionCenter, key),
|
81
|
+
reset: () => fs.writeFileSync(optionCenter.root, dumpYaml(defaults)) && (conf[name] = defaults),
|
82
|
+
getAll: (str = false) => (str ? dumpYaml(conf[name]) : conf[name]),
|
83
|
+
...optionCenter,
|
84
|
+
};
|
85
|
+
};
|
79
86
|
|
80
|
-
|
87
|
+
const defaultCenter = createOptionCenter('_default', { default: true });
|
81
88
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
});
|
89
|
+
return {
|
90
|
+
optionCenter: createOptionCenter,
|
91
|
+
staticFile: staticFile,
|
92
|
+
set: (key, value) => defaultCenter.set(key, value),
|
93
|
+
get: (key, defaultValue) => defaultCenter.get(key, defaultValue),
|
94
|
+
remove: (key) => defaultCenter.remove(key),
|
95
|
+
root: rootPath,
|
96
|
+
package: packageName,
|
97
|
+
};
|
98
|
+
},
|
99
|
+
});
|
package/lib/rew/pkgs/data.js
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
-
const { BinaryTree } = require(
|
2
|
-
const { DoublyLinkedList } = require(
|
3
|
-
const { LinkedList } = require(
|
4
|
-
const { Queue } = require(
|
5
|
-
const { Stack } = require(
|
1
|
+
const { BinaryTree } = require('./modules/data/bintree');
|
2
|
+
const { DoublyLinkedList } = require('./modules/data/doublylinked');
|
3
|
+
const { LinkedList } = require('./modules/data/linkedList');
|
4
|
+
const { Queue } = require('./modules/data/queue');
|
5
|
+
const { Stack } = require('./modules/data/stack');
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
module.exports = (context) => ({
|
8
|
+
Stack,
|
9
|
+
Queue,
|
10
|
+
BinaryTree,
|
11
|
+
DoublyLinkedList,
|
12
|
+
LinkedList,
|
13
|
+
});
|
package/lib/rew/pkgs/date.js
CHANGED
@@ -8,10 +8,10 @@
|
|
8
8
|
* @return {string} - The formatted date string.
|
9
9
|
*/
|
10
10
|
function formatDate(date) {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
const year = date.getFullYear();
|
12
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
13
|
+
const day = String(date.getDate()).padStart(2, '0');
|
14
|
+
return `${year}-${month}-${day}`;
|
15
15
|
}
|
16
16
|
|
17
17
|
/**
|
@@ -20,10 +20,10 @@ function formatDate(date) {
|
|
20
20
|
* @return {string} - The formatted time string.
|
21
21
|
*/
|
22
22
|
function formatTime(date) {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
const hours = String(date.getHours()).padStart(2, '0');
|
24
|
+
const minutes = String(date.getMinutes()).padStart(2, '0');
|
25
|
+
const seconds = String(date.getSeconds()).padStart(2, '0');
|
26
|
+
return `${hours}:${minutes}:${seconds}`;
|
27
27
|
}
|
28
28
|
|
29
29
|
// Parsing Functions
|
@@ -34,8 +34,8 @@ function formatTime(date) {
|
|
34
34
|
* @return {Date} - The parsed date object.
|
35
35
|
*/
|
36
36
|
function parseDate(dateString) {
|
37
|
-
|
38
|
-
|
37
|
+
const [year, month, day] = dateString.split('-').map(Number);
|
38
|
+
return new Date(year, month - 1, day);
|
39
39
|
}
|
40
40
|
|
41
41
|
/**
|
@@ -44,10 +44,10 @@ function parseDate(dateString) {
|
|
44
44
|
* @return {Date} - The parsed date object.
|
45
45
|
*/
|
46
46
|
function parseTime(timeString) {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
const [hours, minutes, seconds] = timeString.split(':').map(Number);
|
48
|
+
const date = new Date();
|
49
|
+
date.setHours(hours, minutes, seconds, 0);
|
50
|
+
return date;
|
51
51
|
}
|
52
52
|
|
53
53
|
// Arithmetic Functions
|
@@ -59,9 +59,9 @@ function parseTime(timeString) {
|
|
59
59
|
* @return {Date} - The new date object.
|
60
60
|
*/
|
61
61
|
function addDays(date, days) {
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
const result = new Date(date);
|
63
|
+
result.setDate(result.getDate() + days);
|
64
|
+
return result;
|
65
65
|
}
|
66
66
|
|
67
67
|
/**
|
@@ -71,7 +71,7 @@ function addDays(date, days) {
|
|
71
71
|
* @return {Date} - The new date object.
|
72
72
|
*/
|
73
73
|
function subtractDays(date, days) {
|
74
|
-
|
74
|
+
return addDays(date, -days);
|
75
75
|
}
|
76
76
|
|
77
77
|
/**
|
@@ -81,18 +81,17 @@ function subtractDays(date, days) {
|
|
81
81
|
* @return {number} - The difference in days.
|
82
82
|
*/
|
83
83
|
function differenceInDays(date1, date2) {
|
84
|
-
|
85
|
-
|
84
|
+
const diffTime = date2 - date1;
|
85
|
+
return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
86
86
|
}
|
87
87
|
|
88
|
-
|
89
88
|
// Exporting the functions as a CommonJS module
|
90
89
|
module.exports = () => ({
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
90
|
+
formatDate,
|
91
|
+
formatTime,
|
92
|
+
parseDate,
|
93
|
+
parseTime,
|
94
|
+
addDays,
|
95
|
+
subtractDays,
|
96
|
+
differenceInDays,
|
98
97
|
});
|
package/lib/rew/pkgs/env.js
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module.exports = (context) => ({
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
})
|
2
|
+
has: (key) => key in process.env,
|
3
|
+
get: (key) => process.env[key],
|
4
|
+
set: (key, value) => (process.env[key] = value),
|
5
|
+
rm: (key) => delete process.env[key],
|
6
|
+
is: (key, value) => process.env[key] == value,
|
7
|
+
});
|