1 | const { isWin, isMac } = require("./const");
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | exports.getParams = function(arr) {
|
9 | const reg = /=|--/i;
|
10 | const result = arr
|
11 | .filter((_, i) => i > 1)
|
12 | .reduce((acc, cur) => {
|
13 | if (!reg.test(cur)) {
|
14 | cur = `${cur}=true`;
|
15 | }
|
16 | cur = cur.replace(/--([^\s]+)/, "$1=true");
|
17 | const [key, value] = cur.split("=");
|
18 | acc[key] = value;
|
19 | return acc;
|
20 | }, {});
|
21 | return result;
|
22 | };
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | exports.extend = function(source, target) {
|
28 | if (!target) return source;
|
29 | for (var key in source) {
|
30 | if (target[key] !== undefined) {
|
31 | source[key] = target[key];
|
32 | }
|
33 | }
|
34 | return source;
|
35 | };
|
36 |
|
37 | exports.toArray = function(source) {
|
38 | if (Array.isArray(source)) {
|
39 | return source;
|
40 | }
|
41 | if (!source) {
|
42 | return [];
|
43 | }
|
44 | return [source];
|
45 | };
|
46 |
|
47 | exports.getPageOption = function(config, key) {
|
48 | const option = Object.assign({}, config.pages, config.keys);
|
49 | return option[key] || {};
|
50 | };
|
51 |
|
52 | exports.upath = url => {
|
53 | if (isWin) {
|
54 | return url.replace(/\\+/g, "\\\\");
|
55 | } else {
|
56 | return url.replace(/\\+/g, "/");
|
57 | }
|
58 | };
|