oipage 1.6.0 → 1.7.0-alpha.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.
- package/.github/FUNDING.yml +11 -11
- package/AUTHORS.txt +6 -6
- package/CHANGELOG +144 -137
- package/LICENSE +20 -20
- package/README.md +95 -95
- package/bin/WebSocket/decodeWsFrame.js +43 -43
- package/bin/WebSocket/encodeWsFrame.js +28 -28
- package/bin/WebSocket/headersToJSON.js +26 -26
- package/bin/WebSocket/index.js +80 -80
- package/bin/data/mineTypes.json +104 -104
- package/bin/disk.js +42 -42
- package/bin/help.js +43 -43
- package/bin/intercept.js +15 -15
- package/bin/network.js +21 -21
- package/bin/run +115 -115
- package/bin/serve.d.ts +55 -55
- package/bin/serve.js +158 -158
- package/bin/template/404.html +186 -186
- package/bin/tools/deleteEmptyFolder.js +23 -23
- package/bin/tools/format.js +75 -75
- package/bin/tools/network.js +42 -42
- package/bin/tools/resolve404.js +83 -83
- package/bin/tools/resolveImport.js +88 -88
- package/bin/website-htmls/components/ui-select-file/index.html +7 -7
- package/bin/website-htmls/components/ui-select-file/index.js +37 -37
- package/bin/website-htmls/components/ui-select-file/index.scss +44 -44
- package/bin/website-htmls/dialogs/imageSize/index.html +54 -54
- package/bin/website-htmls/dialogs/imageSize/index.js +53 -53
- package/bin/website-htmls/dialogs/imageSize/index.scss +138 -138
- package/bin/website-htmls/dialogs/index.js +52 -52
- package/bin/website-htmls/images/addFile.svg +1 -1
- package/bin/website-htmls/images/img-to-pdf.svg +1 -1
- package/bin/website-htmls/index.html +17 -17
- package/bin/website-htmls/main.js +13 -13
- package/bin/website-htmls/pages/App/index.html +6 -6
- package/bin/website-htmls/pages/App/index.js +22 -22
- package/bin/website-htmls/pages/App/index.scss +43 -43
- package/bin/website-htmls/pages/appStore/index.html +24 -24
- package/bin/website-htmls/pages/appStore/index.js +19 -19
- package/bin/website-htmls/pages/appStore/index.scss +41 -41
- package/bin/website-htmls/pages/chart/index.html +8 -8
- package/bin/website-htmls/pages/chart/index.js +72 -72
- package/bin/website-htmls/pages/chart/index.scss +72 -72
- package/bin/website-htmls/pages/image-editor/index.html +27 -27
- package/bin/website-htmls/pages/image-editor/index.js +106 -106
- package/bin/website-htmls/pages/image-editor/index.scss +45 -45
- package/bin/website-htmls/pages/img-to-pdf/index.html +3 -3
- package/bin/website-htmls/pages/img-to-pdf/index.js +44 -44
- package/bin/website-htmls/pages/img-to-pdf/index.scss +4 -4
- package/bin/website-htmls/router.config.js +19 -19
- package/bin/website-htmls/styles/normalize.css +94 -94
- package/bin/website-plugins/intercept/chart.js +33 -33
- package/bin/website-plugins/intercept/head.js +8 -8
- package/bin/website-plugins/intercept/index.js +8 -8
- package/bin/website-plugins/intercept/oipage-vislite-intercept.js +33 -33
- package/bin/website-plugins/intercept/oipage-zipaper-intercept.js +39 -39
- package/bin/website-plugins/loader/index.js +11 -11
- package/bin/website-plugins/loader/oipage-html-loader.js +7 -7
- package/bin/website-plugins/loader/oipage-scss-loader.js +149 -149
- package/nodejs/animation/index.d.ts +19 -19
- package/nodejs/animation/index.js +104 -104
- package/nodejs/cmdlog/index.d.ts +20 -20
- package/nodejs/cmdlog/index.js +75 -75
- package/nodejs/disk/index.d.ts +47 -47
- package/nodejs/disk/index.js +165 -165
- package/nodejs/format/index.d.ts +29 -29
- package/nodejs/format/index.js +107 -107
- package/nodejs/json/index.d.ts +9 -9
- package/nodejs/json/index.js +206 -206
- package/nodejs/logform/index.d.ts +18 -18
- package/nodejs/logform/index.js +94 -94
- package/nodejs/reader/index.d.ts +32 -32
- package/nodejs/reader/index.js +20 -20
- package/nodejs/remote/index.d.ts +32 -0
- package/nodejs/remote/index.js +71 -0
- package/nodejs/throttle/index.d.ts +30 -30
- package/nodejs/throttle/index.js +50 -50
- package/package.json +43 -43
- package/web/XMLHttpRequest/index.d.ts +17 -17
- package/web/XMLHttpRequest/index.js +60 -60
- package/web/animation/index.d.ts +19 -19
- package/web/animation/index.js +104 -104
- package/web/format/index.d.ts +29 -29
- package/web/format/index.js +107 -107
- package/web/json/index.d.ts +9 -9
- package/web/json/index.js +206 -206
- package/web/onReady/index.d.ts +7 -7
- package/web/onReady/index.js +8 -8
- package/web/performChunk/index.d.ts +4 -4
- package/web/performChunk/index.js +19 -19
- package/web/reader/index.d.ts +32 -32
- package/web/reader/index.js +20 -20
- package/web/style/index.d.ts +21 -21
- package/web/style/index.js +19 -19
- package/web/throttle/index.d.ts +30 -30
- package/web/throttle/index.js +50 -50
package/nodejs/disk/index.js
CHANGED
|
@@ -1,172 +1,172 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* disk of OIPage v1.
|
|
2
|
+
* disk of OIPage v1.7.0-alpha.1
|
|
3
3
|
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const { join } = require("path");
|
|
7
|
-
const { existsSync, readdirSync, lstatSync, unlinkSync, rmdirSync, mkdirSync, copyFileSync, symlinkSync } = require("fs");
|
|
8
|
-
const { execSync } = require("child_process");
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 删除文件或文件夹
|
|
12
|
-
* @param {string} diskPath
|
|
13
|
-
*/
|
|
14
|
-
function deleteDisk(diskPath) {
|
|
15
|
-
// 如果文件夹不存在,直接返回即可
|
|
16
|
-
if (!existsSync(diskPath)) return;
|
|
17
|
-
|
|
18
|
-
// 如果是文件,直接删除即可
|
|
19
|
-
if (!lstatSync(diskPath).isDirectory()) {
|
|
20
|
-
unlinkSync(diskPath);
|
|
21
|
-
} else {
|
|
22
|
-
|
|
23
|
-
// 读取子文件
|
|
24
|
-
const subFiles = readdirSync(diskPath);
|
|
25
|
-
|
|
26
|
-
subFiles.forEach(function (item) {
|
|
27
|
-
|
|
28
|
-
// 调用这个方法,删除子文件或文件夹
|
|
29
|
-
const curPath = join(diskPath, "./" + item);
|
|
30
|
-
deleteDisk(curPath);
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// 等子文件或文件夹删除完毕以后,删除本文件夹
|
|
35
|
-
rmdirSync(diskPath);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 复制文件或文件夹
|
|
41
|
-
* @param {string} sourcePath
|
|
42
|
-
* @param {string} targetPath
|
|
43
|
-
* @param {boolean} isForce 可选,是否强制执行
|
|
44
|
-
*/
|
|
45
|
-
function copyDisk(sourcePath, targetPath, isForce) {
|
|
46
|
-
|
|
47
|
-
// 如果源文件不存在
|
|
48
|
-
if (!existsSync(sourcePath)) {
|
|
49
|
-
console.log("\x1b[0m\x1b[31m" + sourcePath + "\x1b[0m");
|
|
50
|
-
throw new Error("OIPage: The source path does not exist.");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// 如果目标文件已经存在
|
|
54
|
-
if (existsSync(targetPath)) {
|
|
55
|
-
if (isForce) {
|
|
56
|
-
deleteDisk(targetPath);
|
|
57
|
-
} else {
|
|
58
|
-
console.log("\x1b[0m\x1b[31m" + targetPath + "\x1b[0m");
|
|
59
|
-
throw new Error("OIPage: The target path already exists.");
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
(function copyDiskFun(sourcePath, targetPath) {
|
|
64
|
-
// 如果是文件,直接复制即可
|
|
65
|
-
if (!lstatSync(sourcePath).isDirectory()) {
|
|
66
|
-
copyFileSync(sourcePath, targetPath);
|
|
67
|
-
} else {
|
|
68
|
-
|
|
69
|
-
// 读取子文件
|
|
70
|
-
const subFiles = readdirSync(sourcePath);
|
|
71
|
-
|
|
72
|
-
// 如果文件夹不存在,创建
|
|
73
|
-
if (!existsSync(targetPath)) {
|
|
74
|
-
mkdirSync(targetPath, { recursive: true });
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// 复制子文件或文件夹
|
|
78
|
-
subFiles.forEach(function (item) {
|
|
79
|
-
copyDiskFun(join(sourcePath, "./" + item), join(targetPath, "./" + item));
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
})(sourcePath, targetPath);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 移动文件或文件夹
|
|
88
|
-
* @param {string} sourcePath
|
|
89
|
-
* @param {string} targetPath
|
|
90
|
-
* @param {boolean} isForce 可选,是否强制执行
|
|
91
|
-
*/
|
|
92
|
-
function moveDisk(sourcePath, targetPath, isForce) {
|
|
93
|
-
|
|
94
|
-
// 如果源文件不存在
|
|
95
|
-
if (!existsSync(sourcePath)) {
|
|
96
|
-
console.log("\x1b[0m\x1b[31m" + sourcePath + "\x1b[0m");
|
|
97
|
-
throw new Error("OIPage: The source path does not exist.");
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// 如果目标文件已经存在
|
|
101
|
-
if (existsSync(targetPath)) {
|
|
102
|
-
if (isForce) {
|
|
103
|
-
deleteDisk(targetPath);
|
|
104
|
-
} else {
|
|
105
|
-
console.log("\x1b[0m\x1b[31m" + targetPath + "\x1b[0m");
|
|
106
|
-
throw new Error("OIPage: The target path already exists.");
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// 如果是文件,直接剪切即可
|
|
111
|
-
if (!lstatSync(sourcePath).isDirectory()) {
|
|
112
|
-
copyFileSync(sourcePath, targetPath);
|
|
113
|
-
unlinkSync(sourcePath);
|
|
114
|
-
} else {
|
|
115
|
-
|
|
116
|
-
// 读取子文件
|
|
117
|
-
const subFiles = readdirSync(sourcePath);
|
|
118
|
-
|
|
119
|
-
// 如果文件夹不存在,创建
|
|
120
|
-
if (!existsSync(targetPath)) {
|
|
121
|
-
mkdirSync(targetPath, { recursive: true });
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// 移动子文件或文件夹
|
|
125
|
-
subFiles.forEach(function (file) {
|
|
126
|
-
moveDisk(join(sourcePath, "./" + file), join(targetPath, "./" + file));
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// 移动完子文件或文件夹以后(移动完毕也意味着子文件或文件夹被删除了)
|
|
130
|
-
rmdirSync(sourcePath);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* 遍历当前文件或文件夹中所有文件
|
|
136
|
-
* @param {string} sourcePath
|
|
137
|
-
* @param {function} callback
|
|
138
|
-
*/
|
|
139
|
-
function listDisk(sourcePath, callback) {
|
|
140
|
-
// 文件夹
|
|
141
|
-
if (lstatSync(sourcePath).isDirectory()) {
|
|
142
|
-
|
|
143
|
-
// 读取子文件
|
|
144
|
-
const subFiles = readdirSync(sourcePath);
|
|
145
|
-
subFiles.forEach(function (file) {
|
|
146
|
-
listDisk(join(sourcePath, "./" + file), callback);
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// 文件
|
|
151
|
-
else {
|
|
152
|
-
let folder = join(sourcePath, "../");
|
|
153
|
-
|
|
154
|
-
callback({
|
|
155
|
-
"name": sourcePath.replace(folder, ""),
|
|
156
|
-
"path": sourcePath,
|
|
157
|
-
"folder": folder
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* 软链接文件或文件夹
|
|
164
|
-
* @param {*} sourcePath
|
|
165
|
-
* @param {*} targetPath
|
|
166
|
-
*/
|
|
167
|
-
function linkDisk(sourcePath, targetPath) {
|
|
168
|
-
const type = lstatSync(sourcePath).isDirectory() ? 'junction' : 'file';
|
|
169
|
-
symlinkSync(sourcePath, targetPath, type);
|
|
6
|
+
const { join } = require("path");
|
|
7
|
+
const { existsSync, readdirSync, lstatSync, unlinkSync, rmdirSync, mkdirSync, copyFileSync, symlinkSync } = require("fs");
|
|
8
|
+
const { execSync } = require("child_process");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 删除文件或文件夹
|
|
12
|
+
* @param {string} diskPath
|
|
13
|
+
*/
|
|
14
|
+
function deleteDisk(diskPath) {
|
|
15
|
+
// 如果文件夹不存在,直接返回即可
|
|
16
|
+
if (!existsSync(diskPath)) return;
|
|
17
|
+
|
|
18
|
+
// 如果是文件,直接删除即可
|
|
19
|
+
if (!lstatSync(diskPath).isDirectory()) {
|
|
20
|
+
unlinkSync(diskPath);
|
|
21
|
+
} else {
|
|
22
|
+
|
|
23
|
+
// 读取子文件
|
|
24
|
+
const subFiles = readdirSync(diskPath);
|
|
25
|
+
|
|
26
|
+
subFiles.forEach(function (item) {
|
|
27
|
+
|
|
28
|
+
// 调用这个方法,删除子文件或文件夹
|
|
29
|
+
const curPath = join(diskPath, "./" + item);
|
|
30
|
+
deleteDisk(curPath);
|
|
31
|
+
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// 等子文件或文件夹删除完毕以后,删除本文件夹
|
|
35
|
+
rmdirSync(diskPath);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 复制文件或文件夹
|
|
41
|
+
* @param {string} sourcePath
|
|
42
|
+
* @param {string} targetPath
|
|
43
|
+
* @param {boolean} isForce 可选,是否强制执行
|
|
44
|
+
*/
|
|
45
|
+
function copyDisk(sourcePath, targetPath, isForce) {
|
|
46
|
+
|
|
47
|
+
// 如果源文件不存在
|
|
48
|
+
if (!existsSync(sourcePath)) {
|
|
49
|
+
console.log("\x1b[0m\x1b[31m" + sourcePath + "\x1b[0m");
|
|
50
|
+
throw new Error("OIPage: The source path does not exist.");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 如果目标文件已经存在
|
|
54
|
+
if (existsSync(targetPath)) {
|
|
55
|
+
if (isForce) {
|
|
56
|
+
deleteDisk(targetPath);
|
|
57
|
+
} else {
|
|
58
|
+
console.log("\x1b[0m\x1b[31m" + targetPath + "\x1b[0m");
|
|
59
|
+
throw new Error("OIPage: The target path already exists.");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
(function copyDiskFun(sourcePath, targetPath) {
|
|
64
|
+
// 如果是文件,直接复制即可
|
|
65
|
+
if (!lstatSync(sourcePath).isDirectory()) {
|
|
66
|
+
copyFileSync(sourcePath, targetPath);
|
|
67
|
+
} else {
|
|
68
|
+
|
|
69
|
+
// 读取子文件
|
|
70
|
+
const subFiles = readdirSync(sourcePath);
|
|
71
|
+
|
|
72
|
+
// 如果文件夹不存在,创建
|
|
73
|
+
if (!existsSync(targetPath)) {
|
|
74
|
+
mkdirSync(targetPath, { recursive: true });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 复制子文件或文件夹
|
|
78
|
+
subFiles.forEach(function (item) {
|
|
79
|
+
copyDiskFun(join(sourcePath, "./" + item), join(targetPath, "./" + item));
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
})(sourcePath, targetPath);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 移动文件或文件夹
|
|
88
|
+
* @param {string} sourcePath
|
|
89
|
+
* @param {string} targetPath
|
|
90
|
+
* @param {boolean} isForce 可选,是否强制执行
|
|
91
|
+
*/
|
|
92
|
+
function moveDisk(sourcePath, targetPath, isForce) {
|
|
93
|
+
|
|
94
|
+
// 如果源文件不存在
|
|
95
|
+
if (!existsSync(sourcePath)) {
|
|
96
|
+
console.log("\x1b[0m\x1b[31m" + sourcePath + "\x1b[0m");
|
|
97
|
+
throw new Error("OIPage: The source path does not exist.");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 如果目标文件已经存在
|
|
101
|
+
if (existsSync(targetPath)) {
|
|
102
|
+
if (isForce) {
|
|
103
|
+
deleteDisk(targetPath);
|
|
104
|
+
} else {
|
|
105
|
+
console.log("\x1b[0m\x1b[31m" + targetPath + "\x1b[0m");
|
|
106
|
+
throw new Error("OIPage: The target path already exists.");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 如果是文件,直接剪切即可
|
|
111
|
+
if (!lstatSync(sourcePath).isDirectory()) {
|
|
112
|
+
copyFileSync(sourcePath, targetPath);
|
|
113
|
+
unlinkSync(sourcePath);
|
|
114
|
+
} else {
|
|
115
|
+
|
|
116
|
+
// 读取子文件
|
|
117
|
+
const subFiles = readdirSync(sourcePath);
|
|
118
|
+
|
|
119
|
+
// 如果文件夹不存在,创建
|
|
120
|
+
if (!existsSync(targetPath)) {
|
|
121
|
+
mkdirSync(targetPath, { recursive: true });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 移动子文件或文件夹
|
|
125
|
+
subFiles.forEach(function (file) {
|
|
126
|
+
moveDisk(join(sourcePath, "./" + file), join(targetPath, "./" + file));
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// 移动完子文件或文件夹以后(移动完毕也意味着子文件或文件夹被删除了)
|
|
130
|
+
rmdirSync(sourcePath);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 遍历当前文件或文件夹中所有文件
|
|
136
|
+
* @param {string} sourcePath
|
|
137
|
+
* @param {function} callback
|
|
138
|
+
*/
|
|
139
|
+
function listDisk(sourcePath, callback) {
|
|
140
|
+
// 文件夹
|
|
141
|
+
if (lstatSync(sourcePath).isDirectory()) {
|
|
142
|
+
|
|
143
|
+
// 读取子文件
|
|
144
|
+
const subFiles = readdirSync(sourcePath);
|
|
145
|
+
subFiles.forEach(function (file) {
|
|
146
|
+
listDisk(join(sourcePath, "./" + file), callback);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 文件
|
|
151
|
+
else {
|
|
152
|
+
let folder = join(sourcePath, "../");
|
|
153
|
+
|
|
154
|
+
callback({
|
|
155
|
+
"name": sourcePath.replace(folder, ""),
|
|
156
|
+
"path": sourcePath,
|
|
157
|
+
"folder": folder
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 软链接文件或文件夹
|
|
164
|
+
* @param {*} sourcePath
|
|
165
|
+
* @param {*} targetPath
|
|
166
|
+
*/
|
|
167
|
+
function linkDisk(sourcePath, targetPath) {
|
|
168
|
+
const type = lstatSync(sourcePath).isDirectory() ? 'junction' : 'file';
|
|
169
|
+
symlinkSync(sourcePath, targetPath, type);
|
|
170
170
|
}
|
|
171
171
|
exports.deleteDisk = deleteDisk;
|
|
172
172
|
exports.copyDisk = copyDisk;
|
package/nodejs/format/index.d.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 数字格式化
|
|
3
|
-
*/
|
|
4
|
-
export interface numberFormatType {
|
|
5
|
-
(input: number | string): string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export let numberFormat: numberFormatType
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 日期格式化
|
|
12
|
-
*/
|
|
13
|
-
export interface dateFormatType {
|
|
14
|
-
(input?: string | Date, option?: {
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 输入格式
|
|
18
|
-
*/
|
|
19
|
-
inputFormat?: string
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 输出格式
|
|
23
|
-
*/
|
|
24
|
-
format?: string
|
|
25
|
-
}): string
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export let dateFormat: dateFormatType
|
|
29
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 数字格式化
|
|
3
|
+
*/
|
|
4
|
+
export interface numberFormatType {
|
|
5
|
+
(input: number | string): string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export let numberFormat: numberFormatType
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 日期格式化
|
|
12
|
+
*/
|
|
13
|
+
export interface dateFormatType {
|
|
14
|
+
(input?: string | Date, option?: {
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 输入格式
|
|
18
|
+
*/
|
|
19
|
+
inputFormat?: string
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 输出格式
|
|
23
|
+
*/
|
|
24
|
+
format?: string
|
|
25
|
+
}): string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export let dateFormat: dateFormatType
|
|
29
|
+
|
package/nodejs/format/index.js
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* format of OIPage v1.
|
|
2
|
+
* format of OIPage v1.7.0-alpha.1
|
|
3
3
|
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
function numberFormat(input) {
|
|
7
|
-
if (!input && input !== 0) {
|
|
8
|
-
return '';
|
|
9
|
-
} else {
|
|
10
|
-
input = input + "";
|
|
11
|
-
|
|
12
|
-
var decimalValue, integerValue;
|
|
13
|
-
|
|
14
|
-
var dotIndex = input.indexOf('.');
|
|
15
|
-
if (dotIndex == -1) {
|
|
16
|
-
decimalValue = ".00";
|
|
17
|
-
integerValue = input;
|
|
18
|
-
} else {
|
|
19
|
-
var temp = input.split(".");
|
|
20
|
-
decimalValue = "." + (temp[1] + "0").substring(0, 2);
|
|
21
|
-
integerValue = temp[0];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
var integerArray = []
|
|
25
|
-
for (var index = integerValue.length; index > 0; index -= 3) {
|
|
26
|
-
integerArray.unshift(integerValue.substring(index > 2 ? index - 3 : 0, index));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return integerArray.join(",").replace(/^\-,/, "-") + decimalValue;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function dateFormat(input, option) {
|
|
34
|
-
option = option || {};
|
|
35
|
-
var dateObj;
|
|
36
|
-
|
|
37
|
-
// 如果无值,就用当前日期
|
|
38
|
-
if (!input) {
|
|
39
|
-
dateObj = new Date();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// 日期对象
|
|
43
|
-
else if (typeof input == 'object' && input.constructor === Date) {
|
|
44
|
-
dateObj = input;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// 否则就尝试创建日期对象
|
|
48
|
-
else if (!option.inputFormat) {
|
|
49
|
-
dateObj = new Date(input);
|
|
50
|
-
if (dateObj + "" == "Invalid Date") {
|
|
51
|
-
console.error("非法的日期格式:" + input, dateObj);
|
|
52
|
-
return "";
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// 年、月、日、时、分、秒
|
|
57
|
-
var single = {
|
|
58
|
-
yyyy: 0, MM: 0, dd: 0, HH: 0, mm: 0, ss: 0
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// 如果获取了日期实例
|
|
62
|
-
if (dateObj) {
|
|
63
|
-
|
|
64
|
-
single.yyyy = dateObj.getFullYear();
|
|
65
|
-
single.MM = dateObj.getMonth() + 1;
|
|
66
|
-
single.dd = dateObj.getDate();
|
|
67
|
-
|
|
68
|
-
single.HH = dateObj.getHours();
|
|
69
|
-
single.mm = dateObj.getMinutes();
|
|
70
|
-
single.ss = dateObj.getSeconds();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// 否则只能借助 inputFormat 来解析
|
|
74
|
-
else {
|
|
75
|
-
var inputFormat = option.inputFormat + "", valIndex = 0;
|
|
76
|
-
for (var index = 0; index < inputFormat.length; index++) {
|
|
77
|
-
|
|
78
|
-
// 年
|
|
79
|
-
if (inputFormat.substring(index, index + 4) == "yyyy") {
|
|
80
|
-
single.yyyy = +input.substring(valIndex, valIndex + 4);
|
|
81
|
-
|
|
82
|
-
valIndex += 4;
|
|
83
|
-
index += 3;
|
|
84
|
-
} else {
|
|
85
|
-
var curFlag = inputFormat.substring(index, index + 2);
|
|
86
|
-
if (["MM", "dd", "HH", "mm", "ss"].indexOf(curFlag) > -1) {
|
|
87
|
-
var valContent = input[valIndex];
|
|
88
|
-
if (/\d/.test(input[valIndex + 1])) {
|
|
89
|
-
valContent += input[valIndex + 1];
|
|
90
|
-
valIndex += 2;
|
|
91
|
-
} else {
|
|
92
|
-
valIndex += 1;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
(single)[curFlag] = +valContent;
|
|
96
|
-
index += 1;
|
|
97
|
-
} else {
|
|
98
|
-
valIndex += 1;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (single.MM < 10) single.MM = "0" + single.MM;
|
|
105
|
-
if (single.dd < 10) single.dd = "0" + single.dd;
|
|
106
|
-
if (single.HH < 10) single.HH = "0" + single.HH;
|
|
107
|
-
if (single.mm < 10) single.mm = "0" + single.mm;
|
|
108
|
-
if (single.ss < 10) single.ss = "0" + single.ss;
|
|
109
|
-
|
|
110
|
-
var format = option.format || "yyyy/MM/dd";
|
|
111
|
-
return format.replace("yyyy", single.yyyy).replace("MM", single.MM).replace("dd", single.dd).replace("HH", single.HH).replace("mm", single.mm).replace("ss", single.ss);
|
|
6
|
+
function numberFormat(input) {
|
|
7
|
+
if (!input && input !== 0) {
|
|
8
|
+
return '';
|
|
9
|
+
} else {
|
|
10
|
+
input = input + "";
|
|
11
|
+
|
|
12
|
+
var decimalValue, integerValue;
|
|
13
|
+
|
|
14
|
+
var dotIndex = input.indexOf('.');
|
|
15
|
+
if (dotIndex == -1) {
|
|
16
|
+
decimalValue = ".00";
|
|
17
|
+
integerValue = input;
|
|
18
|
+
} else {
|
|
19
|
+
var temp = input.split(".");
|
|
20
|
+
decimalValue = "." + (temp[1] + "0").substring(0, 2);
|
|
21
|
+
integerValue = temp[0];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var integerArray = []
|
|
25
|
+
for (var index = integerValue.length; index > 0; index -= 3) {
|
|
26
|
+
integerArray.unshift(integerValue.substring(index > 2 ? index - 3 : 0, index));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return integerArray.join(",").replace(/^\-,/, "-") + decimalValue;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function dateFormat(input, option) {
|
|
34
|
+
option = option || {};
|
|
35
|
+
var dateObj;
|
|
36
|
+
|
|
37
|
+
// 如果无值,就用当前日期
|
|
38
|
+
if (!input) {
|
|
39
|
+
dateObj = new Date();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 日期对象
|
|
43
|
+
else if (typeof input == 'object' && input.constructor === Date) {
|
|
44
|
+
dateObj = input;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 否则就尝试创建日期对象
|
|
48
|
+
else if (!option.inputFormat) {
|
|
49
|
+
dateObj = new Date(input);
|
|
50
|
+
if (dateObj + "" == "Invalid Date") {
|
|
51
|
+
console.error("非法的日期格式:" + input, dateObj);
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 年、月、日、时、分、秒
|
|
57
|
+
var single = {
|
|
58
|
+
yyyy: 0, MM: 0, dd: 0, HH: 0, mm: 0, ss: 0
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// 如果获取了日期实例
|
|
62
|
+
if (dateObj) {
|
|
63
|
+
|
|
64
|
+
single.yyyy = dateObj.getFullYear();
|
|
65
|
+
single.MM = dateObj.getMonth() + 1;
|
|
66
|
+
single.dd = dateObj.getDate();
|
|
67
|
+
|
|
68
|
+
single.HH = dateObj.getHours();
|
|
69
|
+
single.mm = dateObj.getMinutes();
|
|
70
|
+
single.ss = dateObj.getSeconds();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 否则只能借助 inputFormat 来解析
|
|
74
|
+
else {
|
|
75
|
+
var inputFormat = option.inputFormat + "", valIndex = 0;
|
|
76
|
+
for (var index = 0; index < inputFormat.length; index++) {
|
|
77
|
+
|
|
78
|
+
// 年
|
|
79
|
+
if (inputFormat.substring(index, index + 4) == "yyyy") {
|
|
80
|
+
single.yyyy = +input.substring(valIndex, valIndex + 4);
|
|
81
|
+
|
|
82
|
+
valIndex += 4;
|
|
83
|
+
index += 3;
|
|
84
|
+
} else {
|
|
85
|
+
var curFlag = inputFormat.substring(index, index + 2);
|
|
86
|
+
if (["MM", "dd", "HH", "mm", "ss"].indexOf(curFlag) > -1) {
|
|
87
|
+
var valContent = input[valIndex];
|
|
88
|
+
if (/\d/.test(input[valIndex + 1])) {
|
|
89
|
+
valContent += input[valIndex + 1];
|
|
90
|
+
valIndex += 2;
|
|
91
|
+
} else {
|
|
92
|
+
valIndex += 1;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
(single)[curFlag] = +valContent;
|
|
96
|
+
index += 1;
|
|
97
|
+
} else {
|
|
98
|
+
valIndex += 1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (single.MM < 10) single.MM = "0" + single.MM;
|
|
105
|
+
if (single.dd < 10) single.dd = "0" + single.dd;
|
|
106
|
+
if (single.HH < 10) single.HH = "0" + single.HH;
|
|
107
|
+
if (single.mm < 10) single.mm = "0" + single.mm;
|
|
108
|
+
if (single.ss < 10) single.ss = "0" + single.ss;
|
|
109
|
+
|
|
110
|
+
var format = option.format || "yyyy/MM/dd";
|
|
111
|
+
return format.replace("yyyy", single.yyyy).replace("MM", single.MM).replace("dd", single.dd).replace("HH", single.HH).replace("mm", single.mm).replace("ss", single.ss);
|
|
112
112
|
};
|
|
113
113
|
exports.dateFormat = dateFormat;
|
|
114
114
|
exports.numberFormat = numberFormat;
|
package/nodejs/json/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 把一段字符串变成json返回
|
|
3
|
-
* @param express 非严格json字符串
|
|
4
|
-
* @returns 返回一个JSON对象
|
|
5
|
-
*/
|
|
6
|
-
export interface strToJsonType {
|
|
7
|
-
(express:string): object
|
|
8
|
-
}
|
|
9
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 把一段字符串变成json返回
|
|
3
|
+
* @param express 非严格json字符串
|
|
4
|
+
* @returns 返回一个JSON对象
|
|
5
|
+
*/
|
|
6
|
+
export interface strToJsonType {
|
|
7
|
+
(express:string): object
|
|
8
|
+
}
|
|
9
|
+
|
|
10
10
|
export let strToJson: strToJsonType
|