oipage 1.3.0-alpha.2 → 1.3.0

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.
@@ -1,89 +1,76 @@
1
- /**
2
- * 把字节转换成更可读的内容
3
- * @param {*} value
4
- * @returns
5
- */
6
- exports.formatByte = function (value) {
7
- if (value < 1024) return value + "Byte";
8
-
9
- let kb = value / 1024;
10
- if (kb < 1024) return kb.toFixed(1) + "KB";
11
-
12
- let mb = kb / 1024;
13
- if (mb < 1024) return mb.toFixed(1) + "MB";
14
-
15
- let gb = mb / 1024;
16
- return gb.toFixed(1) + "GB";
17
- };
18
-
19
- /**
20
- * 把时间变成更可读的格式
21
- * @param {*} value
22
- * @returns
23
- */
24
- exports.formatTime = function (value) {
25
- let year = value.getFullYear();
26
- let month = value.getMonth() + 1;
27
- let day = value.getDate();
28
-
29
- let hour = value.getHours();
30
- let minutes = value.getMinutes();
31
-
32
- let today = new Date();
33
- if (year == today.getFullYear() && month == today.getMonth() + 1 && day == today.getDate()) {
34
- return "今天 " + hour + ":" + minutes;
35
- } else {
36
- return year + "年" + month + "月" + day + "日 " + hour + ":" + minutes;
37
- }
38
- };
39
-
40
- /**
41
- * 命令行参数解析
42
- * @param {*} argvs
43
- * @param {*} shorts
44
- * @param {*} isArray 是否按序号记录
45
- * @returns
46
- */
47
- exports.formatArgv = function (argvs, shorts, isArray) {
48
- let result = {}, keyName = "args", value = [];
49
- if (isArray) result["value"] = [];
50
-
51
- let pushValue = function () {
52
- if (isArray && keyName !== "args") {
53
- result["value"].push({
54
- name: keyName,
55
- value
56
- });
57
- } else {
58
- result[keyName] = value;
59
- }
60
- };
61
-
62
- for (let index = 3; index < argvs.length; index++) {
63
- let argv = argvs[index];
64
-
65
- if (/^\-/.test(argv)) {
66
- pushValue();
67
- keyName = shorts[argv] || argv;
68
- value = [];
69
- } else {
70
- value.push(argv);
71
- }
72
- }
73
- pushValue();
74
-
75
- return result;
76
- };
77
-
78
- /**
79
- * 请求头解析
80
- * @param {*} rawHeaders
81
- * @returns
82
- */
83
- exports.formatRawHeaders = function (rawHeaders) {
84
- let headers = {};
85
- for (let i = 0; i < rawHeaders.length - 1; i += 2) {
86
- headers[rawHeaders[i]] = rawHeaders[i + 1];
87
- }
88
- return headers;
1
+ /**
2
+ * 把字节转换成更可读的内容
3
+ * @param {*} value
4
+ * @returns
5
+ */
6
+ exports.formatByte = function (value) {
7
+ if (value < 1024) return value + "Byte";
8
+
9
+ let kb = value / 1024;
10
+ if (kb < 1024) return kb.toFixed(1) + "KB";
11
+
12
+ let mb = kb / 1024;
13
+ if (mb < 1024) return mb.toFixed(1) + "MB";
14
+
15
+ let gb = mb / 1024;
16
+ return gb.toFixed(1) + "GB";
17
+ };
18
+
19
+ /**
20
+ * 把时间变成更可读的格式
21
+ * @param {*} value
22
+ * @returns
23
+ */
24
+ exports.formatTime = function (value) {
25
+ let year = value.getFullYear();
26
+ let month = value.getMonth() + 1;
27
+ let day = value.getDate();
28
+
29
+ let hour = value.getHours();
30
+ let minutes = value.getMinutes();
31
+
32
+ let today = new Date();
33
+ if (year == today.getFullYear() && month == today.getMonth() + 1 && day == today.getDate()) {
34
+ return "今天 " + hour + ":" + minutes;
35
+ } else {
36
+ return year + "年" + month + "月" + day + "日 " + hour + ":" + minutes;
37
+ }
38
+ };
39
+
40
+ /**
41
+ * 命令行参数解析
42
+ * @param {*} argvs
43
+ * @param {*} shorts
44
+ * @param {*} isArray 是否按序号记录
45
+ * @returns
46
+ */
47
+ exports.formatArgv = function (argvs, shorts, isArray) {
48
+ let result = {}, keyName = "args", value = [];
49
+ if (isArray) result["value"] = [];
50
+
51
+ let pushValue = function () {
52
+ if (isArray && keyName !== "args") {
53
+ result["value"].push({
54
+ name: keyName,
55
+ value
56
+ });
57
+ } else {
58
+ result[keyName] = value;
59
+ }
60
+ };
61
+
62
+ for (let index = 3; index < argvs.length; index++) {
63
+ let argv = argvs[index];
64
+
65
+ if (/^\-/.test(argv)) {
66
+ pushValue();
67
+ keyName = shorts[argv] || argv;
68
+ value = [];
69
+ } else {
70
+ value.push(argv);
71
+ }
72
+ }
73
+ pushValue();
74
+
75
+ return result;
89
76
  };
@@ -1,89 +1,89 @@
1
- const { readFileSync, existsSync, lstatSync } = require("fs");
2
- const { join } = require("path");
3
- const { testIntercept } = require("../intercept.js");
4
-
5
- module.exports = function (basePath, filePath, entry, intercept, isDownload) {
6
- basePath = join(basePath, "./");
7
-
8
- let source = readFileSync(filePath);
9
- let resolveImport = content => content;
10
-
11
- let __resolveImport = function (content) {
12
- return content.replace(/import [^'"]* from (['"])([^'"]*)['"]/sg, function (_importCode, _, _importUrl) {
13
- if (/^[./]/.test(_importUrl)) {
14
- return _importCode;
15
- } else {
16
- return _importCode.replace(_importUrl, _importUrl.replace(/([^/])+/s, function (npmName) {
17
-
18
- if (testIntercept(npmName, intercept)) {
19
- return "/@modules/" + npmName;
20
- } else {
21
-
22
- let node_modulesRootPath = join(filePath, "../");
23
- let prePath = "";
24
- while (true) {
25
- let npmBundlePath = join(node_modulesRootPath, "./node_modules/", npmName);
26
-
27
- // 如果存在
28
- if (existsSync(npmBundlePath) && lstatSync(npmBundlePath).isDirectory()) {
29
- let npmNameValue = npmName;
30
-
31
- // 对于类似 import VISLite from "vislite"
32
- // 需要把包名解析成具体的文件
33
- if (!/\//.test(_importUrl)) {
34
- let bundlePackage = require(join(npmBundlePath, "./package.json"));
35
- npmNameValue = npmName + "/" + bundlePackage.main;
36
- }
37
-
38
- return (prePath ? prePath : "./") + "node_modules/" + npmNameValue;
39
- }
40
-
41
- if (node_modulesRootPath === basePath) {
42
-
43
- // 如果命令行根目录是一个项目
44
- let packagePath = join(basePath, "./package.json");
45
- if (existsSync(packagePath) && !lstatSync(packagePath).isDirectory()) {
46
- let bundlePackage = require(packagePath);
47
- if (!/\//.test(_importUrl)) {
48
- return "/" + bundlePackage.main;
49
- } else {
50
- return "/"
51
- }
52
- }
53
-
54
- return npmName;
55
- } else {
56
- node_modulesRootPath = join(node_modulesRootPath, "../");
57
- prePath = "../" + prePath;
58
- }
59
- }
60
-
61
- }
62
- }));
63
- }
64
- });
65
- };
66
-
67
- // 如果是下载
68
- if (isDownload) {
69
- // todo
70
- }
71
-
72
- // 如果不是直接访问的
73
- else if (!entry) {
74
- source += "";
75
- resolveImport = (content, notResolve) => notResolve ? content : __resolveImport(content);
76
- }
77
-
78
- // 如果是.html或.htm结尾
79
- else if (/\.html{0,1}$/.test(filePath)) {
80
- source = (source + "").replace(/<script type="module">(.*)<\/script>/sg, function (_, _matchCode) {
81
- return `<script type="module">${__resolveImport(_matchCode)}</script>`;
82
- });
83
- }
84
-
85
- return {
86
- source,
87
- resolveImport
88
- };
1
+ const { readFileSync, existsSync, lstatSync } = require("fs");
2
+ const { join } = require("path");
3
+ const { testIntercept } = require("../intercept.js");
4
+
5
+ module.exports = function (basePath, filePath, entry, intercept, isDownload) {
6
+ basePath = join(basePath, "./");
7
+
8
+ let source = readFileSync(filePath);
9
+ let resolveImport = content => content;
10
+
11
+ let __resolveImport = function (content) {
12
+ return content.replace(/import [^'"]* from (['"])([^'"]*)['"]/sg, function (_importCode, _, _importUrl) {
13
+ if (/^[./]/.test(_importUrl)) {
14
+ return _importCode;
15
+ } else {
16
+ return _importCode.replace(_importUrl, _importUrl.replace(/([^/])+/s, function (npmName) {
17
+
18
+ if (testIntercept(npmName, intercept)) {
19
+ return "/@modules/" + npmName;
20
+ } else {
21
+
22
+ let node_modulesRootPath = join(filePath, "../");
23
+ let prePath = "";
24
+ while (true) {
25
+ let npmBundlePath = join(node_modulesRootPath, "./node_modules/", npmName);
26
+
27
+ // 如果存在
28
+ if (existsSync(npmBundlePath) && lstatSync(npmBundlePath).isDirectory()) {
29
+ let npmNameValue = npmName;
30
+
31
+ // 对于类似 import VISLite from "vislite"
32
+ // 需要把包名解析成具体的文件
33
+ if (!/\//.test(_importUrl)) {
34
+ let bundlePackage = require(join(npmBundlePath, "./package.json"));
35
+ npmNameValue = npmName + "/" + bundlePackage.main;
36
+ }
37
+
38
+ return (prePath ? prePath : "./") + "node_modules/" + npmNameValue;
39
+ }
40
+
41
+ if (node_modulesRootPath === basePath) {
42
+
43
+ // 如果命令行根目录是一个项目
44
+ let packagePath = join(basePath, "./package.json");
45
+ if (existsSync(packagePath) && !lstatSync(packagePath).isDirectory()) {
46
+ let bundlePackage = require(packagePath);
47
+ if (!/\//.test(_importUrl)) {
48
+ return "/" + bundlePackage.main;
49
+ } else {
50
+ return "/"
51
+ }
52
+ }
53
+
54
+ return npmName;
55
+ } else {
56
+ node_modulesRootPath = join(node_modulesRootPath, "../");
57
+ prePath = "../" + prePath;
58
+ }
59
+ }
60
+
61
+ }
62
+ }));
63
+ }
64
+ });
65
+ };
66
+
67
+ // 如果是下载
68
+ if (isDownload) {
69
+ // todo
70
+ }
71
+
72
+ // 如果不是直接访问的
73
+ else if (!entry) {
74
+ source += "";
75
+ resolveImport = (content, notResolve) => notResolve ? content : __resolveImport(content);
76
+ }
77
+
78
+ // 如果是.html或.htm结尾
79
+ else if (/\.html{0,1}$/.test(filePath)) {
80
+ source = (source + "").replace(/<script type="module">(.*)<\/script>/sg, function (_, _matchCode) {
81
+ return `<script type="module">${__resolveImport(_matchCode)}</script>`;
82
+ });
83
+ }
84
+
85
+ return {
86
+ source,
87
+ resolveImport
88
+ };
89
89
  };
@@ -1,12 +1,20 @@
1
+ interface animationResult {
2
+
3
+ /**
4
+ * 一个函数,调用该函数,可以提前结束动画
5
+ */
6
+ stop(): void
7
+ }
8
+
1
9
  interface animationFun {
2
10
  (deep: number): void
3
11
  }
4
12
 
5
13
  /**
6
- * 轮询动画,返回一个函数,调用该函数,可以提前结束动画
14
+ * 轮询动画
7
15
  */
8
16
  export interface animationType {
9
- (doback: animationFun, duration?: number, callback?: animationFun): Function
17
+ (doback: animationFun, duration?: number, callback?: animationFun): animationResult
10
18
  }
11
19
 
12
20
  export let animation: animationType
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.3.0-alpha.2
2
+ * animation of OIPage v1.3.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * cmdlog of OIPage v1.3.0-alpha.2
2
+ * cmdlog of OIPage v1.3.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * disk of OIPage v1.3.0-alpha.2
2
+ * disk of OIPage v1.3.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 把一段字符串变成json返回
3
+ * @param express 非严格json字符串
4
+ * @returns 返回一个JSON对象
5
+ */
6
+ export interface strToJsonType {
7
+ (express:string): object
8
+ }
9
+
10
+ export let strToJson: strToJsonType
@@ -0,0 +1,212 @@
1
+ /*!
2
+ * json of OIPage v1.3.0
3
+ * git+https://github.com/oi-contrib/OIPage.git
4
+ */
5
+ const {reader} = require("../reader/index.js");
6
+ let calcValue = function (word) {
7
+ if (word.type != 'string' && word.type != 'object') {
8
+
9
+ // 数字
10
+ if (/[+-]{0,1}\d{1,}\.{0,1}\d{0,}/.test(word.value)) {
11
+ return +word.value;
12
+ }
13
+
14
+ // undefined
15
+ else if (word.value == 'undefined') {
16
+ return undefined;
17
+ }
18
+
19
+ // null
20
+ else if (word.value == 'null') {
21
+ return null;
22
+ }
23
+
24
+ // false
25
+ else if (word.value == 'false') {
26
+ return false;
27
+ }
28
+
29
+ // true
30
+ else if (word.value == 'true') {
31
+ return true;
32
+ }
33
+
34
+ }
35
+
36
+ return word.value;
37
+ };
38
+
39
+ let toValue = function (wordArray) {
40
+ let value;
41
+
42
+ // 是json
43
+ if (wordArray[0].value == '{') {
44
+ value = {};
45
+ for (let i = 3; i < wordArray.length; i += 4) {
46
+ value[wordArray[i - 2].value] = calcValue(wordArray[i]);
47
+ }
48
+ }
49
+
50
+ // 数组
51
+ else {
52
+ value = [];
53
+ for (let i = 2; i < wordArray.length; i += 2) {
54
+ value.push(calcValue(wordArray[i - 1]));
55
+ }
56
+ }
57
+
58
+ return {
59
+ type: "object",
60
+ value: value
61
+ };
62
+ };
63
+
64
+ let analyseWord = function (express) {
65
+ // 剔除开头和结尾的空白
66
+ express = express.trim();
67
+
68
+ // 获取字符串分析对象
69
+ let readerHandler = reader(express);
70
+
71
+ let wordArray = [];
72
+ let tempWord = "";
73
+ readerHandler.readNext();
74
+
75
+ // 定义一个追加普通串的方法
76
+ let pushNormal = function () {
77
+ tempWord = tempWord.trim();
78
+ if (tempWord != '') {
79
+ wordArray.push({
80
+ type: /\d%/.test(tempWord) ? "string" : "normal",
81
+ value: tempWord
82
+ });
83
+ }
84
+ tempWord = "";
85
+ };
86
+
87
+ while (true) {
88
+
89
+ if (readerHandler.index >= express.length) break;
90
+
91
+ // 单行注释
92
+ if (readerHandler.getNextN(2) == '//') {
93
+ while (!/\n/.test(readerHandler.readNext()) && readerHandler.index < express.length);
94
+ }
95
+
96
+ // 多行注释
97
+ else if (readerHandler.getNextN(2) == '/*') {
98
+ while (readerHandler.getNextN(2) != '*/') {
99
+ if (readerHandler.index >= express.length) {
100
+ throw new Error("Multiline comment not closed correctly : " + express + "\nstep='analyseWord-searchEndComment'");
101
+ }
102
+ readerHandler.readNext();
103
+ }
104
+ readerHandler.readNext();
105
+ readerHandler.readNext();
106
+ }
107
+
108
+ // 如果是边界符号
109
+ else if (['{', '}', ',', '[', ']', ':'].indexOf(readerHandler.value) > -1) {
110
+ pushNormal();
111
+
112
+ wordArray.push({
113
+ type: "insign",
114
+ value: readerHandler.value
115
+ });
116
+ readerHandler.readNext();
117
+ }
118
+
119
+ // 如果遇到字符串,应该是一个独立的单词
120
+ else if (['"', "'"].indexOf(readerHandler.value) > -1) {
121
+
122
+ let tempStrWord = "";
123
+ while (['"', "'"].indexOf(readerHandler.readNext()) < 0) {
124
+ if (readerHandler.index >= express.length) {
125
+ throw new Error("The string is not closed correctly : " + express + "\nstep='analyseWord-searchString',currentStrWord=" + tempStrWord);
126
+ }
127
+ tempStrWord += readerHandler.value;
128
+ }
129
+ readerHandler.readNext();
130
+ wordArray.push({
131
+ type: "string",
132
+ value: tempStrWord
133
+ });
134
+
135
+ } else {
136
+ tempWord += readerHandler.value;
137
+ readerHandler.readNext();
138
+ }
139
+
140
+ }
141
+
142
+ return wordArray;
143
+ };
144
+
145
+ function strToJson(express) {
146
+ if (typeof express === "string") {
147
+
148
+ // 先分析出来单词
149
+ let wordArray = analyseWord(express);
150
+
151
+ /**
152
+ * 思路:
153
+ * 从后往前找,找到第一个需要归结的,直接归结,
154
+ * 归结完毕以后,继续,直到找到开头,说明归结完毕,
155
+ * 这样设计的好处是:
156
+ * 从后往前找,一定是叶子,这就消除了递归。
157
+ */
158
+ let i = wordArray.length - 1, j;
159
+
160
+ // 只要单词数组归结完毕
161
+ while (wordArray.length > 1) {
162
+
163
+ // 从后往前找第一个需要归结的子对象
164
+ while (i >= 0 && (wordArray[i].type != 'insign' || ['{', '['].indexOf(wordArray[i].value) < 0)) {
165
+ i = i - 1;
166
+ }
167
+
168
+ if (i < 0) {
169
+ // 如果到开头都没有遇到,缺少开始符号
170
+ throw new Error("Illegal express : " + express + "\nstep='toOne-searchBeginIndex',wordArray=" + wordArray);
171
+ }
172
+
173
+ // 然后合并
174
+ j = i + 1;
175
+ let subWordArray = [wordArray[i]];
176
+ while (j < wordArray.length && (wordArray[j].type != 'insign' || wordArray[j].value != {
177
+ "{": "}",
178
+ "[": "]"
179
+ }[wordArray[i].value])) {
180
+ subWordArray.push(wordArray[j]);
181
+ j = j + 1;
182
+ }
183
+
184
+ if (j >= wordArray.length) {
185
+ // 如果到结尾都没有需要应该闭合的符号,缺少闭合符号
186
+ throw new Error("Illegal express : " + express + "\nstep='toOne-searchEndIndex',wordArray=" + wordArray);
187
+ } else {
188
+
189
+ // 结尾追加进去
190
+ subWordArray.push(wordArray[j]);
191
+
192
+ // 归结
193
+ wordArray[i] = toValue(subWordArray);
194
+
195
+ // 调整
196
+ wordArray.splice(i + 1, j - i);
197
+ }
198
+
199
+
200
+ }
201
+
202
+ // 返回计算结果
203
+ return wordArray[0].value;
204
+
205
+ } else {
206
+
207
+ throw new Error('The data passed is not a string.');
208
+
209
+ }
210
+
211
+ }
212
+ exports.strToJson = strToJson;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * logform of OIPage v1.3.0-alpha.2
2
+ * logform of OIPage v1.3.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
  const {linelog} = require("../cmdlog/index.js");
@@ -1,26 +1,26 @@
1
1
  /*!
2
- * reader of OIPage v1.3.0-alpha.2
2
+ * reader of OIPage v1.3.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
6
- function reader(plain) {
7
-
8
- let handler = {
9
- index: -1,
10
- value: null
11
- };
12
-
13
- // 读取下一个字符
14
- handler.readNext = function () {
15
- handler.value = handler.index++ < plain.length - 1 ? plain[handler.index] : null;
16
- return handler.value;
17
- };
18
-
19
- // 获取往后num个值
20
- handler.getNextN = function (num) {
21
- return express.substring(handler.index, num + handler.index > plain.length ? plain.length : num + handler.index);
22
- };
23
-
24
- return handler;
6
+ function reader(plain) {
7
+
8
+ let handler = {
9
+ index: -1,
10
+ value: null
11
+ };
12
+
13
+ // 读取下一个字符
14
+ handler.readNext = function () {
15
+ handler.value = handler.index++ < plain.length - 1 ? plain[handler.index] : null;
16
+ return handler.value;
17
+ };
18
+
19
+ // 获取往后num个值
20
+ handler.getNextN = function (num) {
21
+ return plain.substring(handler.index, num + handler.index > plain.length ? plain.length : num + handler.index);
22
+ };
23
+
24
+ return handler;
25
25
  }
26
26
  exports.reader = reader;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * throttle of OIPage v1.3.0-alpha.2
2
+ * throttle of OIPage v1.3.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5