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/web/animation/index.js
CHANGED
|
@@ -1,109 +1,109 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* animation of OIPage v1.
|
|
2
|
+
* animation of OIPage v1.7.0-alpha.1
|
|
3
3
|
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
//当前正在运动的动画的tick函数堆栈
|
|
7
|
-
var $timers = [];
|
|
8
|
-
//唯一定时器的定时间隔
|
|
9
|
-
var $interval = 13;
|
|
10
|
-
//定时器ID
|
|
11
|
-
var $timerId;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 动画轮播
|
|
15
|
-
* @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
|
|
16
|
-
* @param {number} duration 动画时长,可选
|
|
17
|
-
* @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
|
|
18
|
-
*
|
|
19
|
-
* @returns {function} 返回一个函数,调用该函数,可以提前结束动画
|
|
20
|
-
*/
|
|
21
|
-
export function animation(doback, duration, callback) {
|
|
22
|
-
if (arguments.length < 2) duration = 400;
|
|
23
|
-
if (arguments.length < 3) callback = function () { };
|
|
24
|
-
|
|
25
|
-
var clock = {
|
|
26
|
-
//把tick函数推入堆栈
|
|
27
|
-
"timer": function (tick, duration, callback) {
|
|
28
|
-
if (!tick) {
|
|
29
|
-
throw new Error('Tick is required!');
|
|
30
|
-
}
|
|
31
|
-
var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
|
|
32
|
-
$timers.push({
|
|
33
|
-
"id": id,
|
|
34
|
-
"createTime": new Date(),
|
|
35
|
-
"tick": tick,
|
|
36
|
-
"duration": duration,
|
|
37
|
-
"callback": callback
|
|
38
|
-
});
|
|
39
|
-
clock.start();
|
|
40
|
-
return id;
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
//开启唯一的定时器timerId
|
|
44
|
-
"start": function () {
|
|
45
|
-
if (!$timerId) {
|
|
46
|
-
$timerId = setInterval(clock.tick, $interval);
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
//被定时器调用,遍历timers堆栈
|
|
51
|
-
"tick": function () {
|
|
52
|
-
var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
|
|
53
|
-
|
|
54
|
-
$timers = [];
|
|
55
|
-
$timers.length = 0;
|
|
56
|
-
|
|
57
|
-
for (flag = 0; flag < timers.length; flag++) {
|
|
58
|
-
//初始化数据
|
|
59
|
-
timer = timers[flag];
|
|
60
|
-
createTime = timer.createTime;
|
|
61
|
-
tick = timer.tick;
|
|
62
|
-
duration = timer.duration;
|
|
63
|
-
callback = timer.callback;
|
|
64
|
-
|
|
65
|
-
//执行
|
|
66
|
-
passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
|
|
67
|
-
passTime = passTime > 1 ? 1 : passTime;
|
|
68
|
-
tick(passTime);
|
|
69
|
-
if (passTime < 1 && timer.id) {
|
|
70
|
-
//动画没有结束再添加
|
|
71
|
-
$timers.push(timer);
|
|
72
|
-
} else {
|
|
73
|
-
callback(passTime);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if ($timers.length <= 0) {
|
|
77
|
-
clock.stop();
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
//停止定时器,重置timerId=null
|
|
82
|
-
"stop": function () {
|
|
83
|
-
if ($timerId) {
|
|
84
|
-
clearInterval($timerId);
|
|
85
|
-
$timerId = null;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
var id = clock.timer(function (deep) {
|
|
91
|
-
//其中deep为0-1,表示改变的程度
|
|
92
|
-
doback(deep);
|
|
93
|
-
}, duration, callback);
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
// 一个函数
|
|
97
|
-
// 用于在动画结束前结束动画
|
|
98
|
-
stop: function () {
|
|
99
|
-
var i;
|
|
100
|
-
for (i in $timers) {
|
|
101
|
-
if ($timers[i].id == id) {
|
|
102
|
-
$timers[i].id = void 0;
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
6
|
+
//当前正在运动的动画的tick函数堆栈
|
|
7
|
+
var $timers = [];
|
|
8
|
+
//唯一定时器的定时间隔
|
|
9
|
+
var $interval = 13;
|
|
10
|
+
//定时器ID
|
|
11
|
+
var $timerId;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 动画轮播
|
|
15
|
+
* @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
|
|
16
|
+
* @param {number} duration 动画时长,可选
|
|
17
|
+
* @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
|
|
18
|
+
*
|
|
19
|
+
* @returns {function} 返回一个函数,调用该函数,可以提前结束动画
|
|
20
|
+
*/
|
|
21
|
+
export function animation(doback, duration, callback) {
|
|
22
|
+
if (arguments.length < 2) duration = 400;
|
|
23
|
+
if (arguments.length < 3) callback = function () { };
|
|
24
|
+
|
|
25
|
+
var clock = {
|
|
26
|
+
//把tick函数推入堆栈
|
|
27
|
+
"timer": function (tick, duration, callback) {
|
|
28
|
+
if (!tick) {
|
|
29
|
+
throw new Error('Tick is required!');
|
|
30
|
+
}
|
|
31
|
+
var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
|
|
32
|
+
$timers.push({
|
|
33
|
+
"id": id,
|
|
34
|
+
"createTime": new Date(),
|
|
35
|
+
"tick": tick,
|
|
36
|
+
"duration": duration,
|
|
37
|
+
"callback": callback
|
|
38
|
+
});
|
|
39
|
+
clock.start();
|
|
40
|
+
return id;
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
//开启唯一的定时器timerId
|
|
44
|
+
"start": function () {
|
|
45
|
+
if (!$timerId) {
|
|
46
|
+
$timerId = setInterval(clock.tick, $interval);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
//被定时器调用,遍历timers堆栈
|
|
51
|
+
"tick": function () {
|
|
52
|
+
var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
|
|
53
|
+
|
|
54
|
+
$timers = [];
|
|
55
|
+
$timers.length = 0;
|
|
56
|
+
|
|
57
|
+
for (flag = 0; flag < timers.length; flag++) {
|
|
58
|
+
//初始化数据
|
|
59
|
+
timer = timers[flag];
|
|
60
|
+
createTime = timer.createTime;
|
|
61
|
+
tick = timer.tick;
|
|
62
|
+
duration = timer.duration;
|
|
63
|
+
callback = timer.callback;
|
|
64
|
+
|
|
65
|
+
//执行
|
|
66
|
+
passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
|
|
67
|
+
passTime = passTime > 1 ? 1 : passTime;
|
|
68
|
+
tick(passTime);
|
|
69
|
+
if (passTime < 1 && timer.id) {
|
|
70
|
+
//动画没有结束再添加
|
|
71
|
+
$timers.push(timer);
|
|
72
|
+
} else {
|
|
73
|
+
callback(passTime);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if ($timers.length <= 0) {
|
|
77
|
+
clock.stop();
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
//停止定时器,重置timerId=null
|
|
82
|
+
"stop": function () {
|
|
83
|
+
if ($timerId) {
|
|
84
|
+
clearInterval($timerId);
|
|
85
|
+
$timerId = null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
var id = clock.timer(function (deep) {
|
|
91
|
+
//其中deep为0-1,表示改变的程度
|
|
92
|
+
doback(deep);
|
|
93
|
+
}, duration, callback);
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
// 一个函数
|
|
97
|
+
// 用于在动画结束前结束动画
|
|
98
|
+
stop: function () {
|
|
99
|
+
var i;
|
|
100
|
+
for (i in $timers) {
|
|
101
|
+
if ($timers[i].id == id) {
|
|
102
|
+
$timers[i].id = void 0;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
109
|
}
|
package/web/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/web/format/index.js
CHANGED
|
@@ -1,112 +1,112 @@
|
|
|
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
|
-
export 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
|
-
export 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
|
+
export 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
|
+
export 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
|
};
|
package/web/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
|