oipage 2.0.0-alpha.0 → 2.0.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.
package/CHANGELOG CHANGED
@@ -1,189 +1,16 @@
1
- v1.0.0:
2
- date:2025-02-13
3
- changes:
4
- - 原v0.x的功能将独立一个分支继续维护:https://github.com/oi-contrib/OIPage/blob/v0.x/CHANGELOG
5
- (v0.x保持对零碎方法这种形式的支持和维护,此版本开始将作为一个框架或一个系统的工具箱以提供更高效的使用方式,这是一次彻底的非兼容改造)
6
- - 初始化版本(v1.x)
7
- 1、API功能(浏览器)
8
- * animation 动画
9
- * getStyle 获取节点样式
10
- * setStyle 设置节点样式
11
- * onReady 加载完毕执行
12
- * throttle 节流函数
13
- 2、API功能(Node.js)
14
- * animation 动画
15
- * deeplog 进度打印
16
- * linglog 单行打印
17
- * throttle 节流函数
18
- 3、命令(oipage-cli)
19
- * serve 开发服务器
20
- v1.1.0:
21
- date:2025-02-18
22
- changes:
23
- - 修复bug
24
- 1、通过路径类型判断以修复开发服务器无法设置绝对路径问题
25
- - 优化改造
26
- 1、使用流读取以使开发服务器支持大文件下载
27
- (同时添加下载进度可查)
28
- - 新增功能
29
- 1、API功能(Node.js)
30
- * disk 磁盘相关操作
31
- (包括:deleteDisk、copyDisk)
32
- * logform 表单输入
33
- 2、命令(oipage-cli)
34
- * dist 磁盘操作
35
- * run 运行多命令
36
- v1.2.0:
37
- date:2025-02-25
38
- changes:
39
- - 优化改造
40
- 1、优化npm包目录结构等
41
- - 新增功能
42
- 1、开发服务器
43
- * 添加配置文件
44
- (oipage-cli serve --config ./oipage.config.js)
45
- * 新增对node_modules包引入支持
46
- v1.2.1:
47
- date:2025-03-06
48
- changes:
49
- - 修复bug
50
- 1、开发服务器
51
- * 修复路径不存在时未正确同步修改浏览器地址问题
52
- v1.3.0:(已废弃,请用1.3.1代替)
53
- date:2025-05-18
54
- changes:
55
- - 修复bug
56
- 1、开发服务器
57
- * 修复服务器根路径判断错误导致node_modules包查找错误问题
58
- 2、修复animation动画types类型定义错误问题
59
- - 新增功能
60
- 1、API功能(浏览器)
61
- * reader 文本分析读取器
62
- * performChunk 空闲执行分片函数
63
- * strToJson JSON字符串解析
64
- 2、API功能(Node.js)
65
- * reader 文本分析读取器
66
- * strToJson JSON字符串解析
67
- 3、开发服务器
68
- * 新增 devServer.intercept 请求拦截
69
- * 新增对 if-modified-since和last-modified 之304协商缓存的支持
70
- v1.3.1:
71
- date:2025-05-23
72
- changes:
73
- - 修复bug
74
- 1、开发服务器
75
- * 由于是否入口判断导致import语句未正确解析
76
- * 修复 Last-Modified 格式不规范导致的运行报错
77
- v1.4.0:
78
- date:2025-09-02
79
- changes:
80
- - 修复bug
81
- 1、修复logform运行报错
82
- - 新增功能
83
- 1、API功能(浏览器)
84
- * dateFormat 日期格式化
85
- * numberFormat 数字格式化
86
- * XHRIntercept XHR拦截
87
- 2、API功能(Node.js)
88
- * dateFormat 日期格式化
89
- * numberFormat 数字格式化
90
- 3、开发服务器
91
- * 新增 serve.d.ts 以支持作为API在TypeScript中环境
92
- (仅对内使用,未正式对外暴露API相关文档)
93
- * 添加304是否启用开关
94
- * 应用市场(website内置网站)
95
- v1.4.1:
96
- date:2025-09-02
97
- changes:
98
- - 修复bug
99
- 1、修复开发服务器大文件丢失文件大小问题
100
- v1.5.0:
101
- date:2025-11-13
102
- changes:
103
- - 修复bug
104
- 1、修复404网站在手机浏览器显示高问题
105
- 2、服务器响应类型由 Content-type 改为 Content-Type
106
- 3、修复dateFormat第二个参数无法缺省报错
107
- 4、修复numberFormat不支持负数问题
108
- - 优化改造
109
- 1、优化run命令日志打印
110
- - 新增功能
111
- 1、开发服务器 / 应用市场
112
- * 群聊天
113
- * 图片编辑器
114
- * 图片转PDF
115
- 2、API功能(Node.js)
116
- * disk 磁盘相关操作
117
- (包括:moveDisk、listDisk)
118
- v1.6.0:
119
- (此版本已废弃,请用v1.6.1+代替)
120
- date:2025-12-14
121
- changes:
122
- - 修复bug
123
- 1、修复logform在run下无法正常使用问题
124
- (关联issue: https://github.com/oi-contrib/OIPage/issues/4 )
125
- 2、修复服务器错误修改XHR等请求数据问题
126
- - 优化改造
127
- 1、命令行帮助打印更可读
128
- - 新增功能
129
- 1、命令(oipage-cli)
130
- * disk
131
- --link 创建磁盘链接
132
- --delempty 删除空文件夹
133
- * network 网络相关
134
- * run 支持动态参数
135
- (关联issue: https://github.com/oi-contrib/OIPage/issues/5 )
136
- 2、API功能(Node.js)
137
- * disk 磁盘相关操作
138
- (包括:linkDisk)
139
- v1.6.1:
140
- date:2025-12-29
141
- changes:
142
- - 修复bug
143
- 1、修复run命令在Windows中运行错误
144
- (关联issue: https://github.com/oi-contrib/OIPage/issues/8 )
145
- v1.7.0:
146
- date:2026-01-06
147
- changes:
148
- - 优化改造
149
- 1、types定义模块,方便使用时代码提示
150
- 2、使用requestAnimationFrame改造animation
151
- - 修复bug
152
- 1、修复特殊情况下 “应用市场” 依赖查找错误问题
153
- 2、修复开发服务器错误缓存问题
154
- 3、修改types错误定义(intercept)
155
- - 新增功能
156
- 1、开发服务器
157
- * 转发功能 proxy
158
- v1.8.0:
159
- date:2026-02-01
1
+ v2.0.0:
2
+ date:2026-03-29
160
3
  changes:
4
+ - 基于更长远的考虑,原命令行功能将作为一个独立的项目进行维护: https://github.com/oi-contrib/oipage-cli
5
+ ( 原v1.x的功能将独立一个分支: https://github.com/oi-contrib/OIPage/blob/v1.x/CHANGELOG 保持对原命令行功能的支持和维护 )
161
6
  - 优化改造
162
- 1、animation兼容对支付宝小程序等支持
7
+ 1、开始放弃部分旧语法,直接使用ES6+的语法
163
8
  - 新增功能
164
- 1、开发服务器
165
- * 自动打开浏览器 open
166
- * 支持自定义404页面
167
- v1.8.1:
168
- date:2026-02-03
169
- changes:
170
- - 修复bug
171
- 1、开发服务器删除多余的打印语句
172
- v1.8.2:
173
- date:2026-02-07
174
- changes:
175
- - 修复bug
176
- 1、修复oipage-cli disk --delempty 命令错误
177
- v1.9.0:
178
- date:2026-03-04
179
- changes:
180
- - 优化改造
181
- 1、调整打包若干细节
182
- 2、针对应用市场优化UI设计
183
- 3、优化oipage-cli disk --delempty 命令路径不存在时提示
184
- v2.0.0:
185
- date:
186
- changes:
187
- - 基于更长远的考虑,原命令行功能将独立一个分支继续维护: https://github.com/oi-contrib/oipage-cli
188
- (原v1.x的功能将独立一个分支:https://github.com/oi-contrib/OIPage/blob/v1.x/CHANGELOG 保持对原命令行功能的支持和维护)
189
-
9
+ 1、option 配置项操作
10
+ * initOption
11
+ * mergeOption
12
+ 2、disk 磁盘相关操作 => 仅支持nodejs端
13
+ * readPlain
14
+ * writePlain
15
+ * readJSON
16
+ * writeJSON
package/README.md CHANGED
@@ -41,22 +41,24 @@ npm install oipage --save
41
41
 
42
42
  我们提供了若干前端开发基础API,现在就可以在项目中使用了。
43
43
 
44
+ > 基于更长远的考虑,原命令行功能将作为一个独立的项目进行维护: https://github.com/oi-contrib/oipage-cli
45
+
44
46
  比如:
45
47
 
46
48
  ### nodejs端
47
49
 
48
- - 命令行打印单行打印
49
- - 终端表单输入
50
- - 常用的磁盘操作
50
+ - [cmdlog 命令行单行打印、进度条显示等](https://oi-contrib.github.io/OIPage/index.html#/api/nodejs/cmdlog)
51
+ - [logform 实现在命令行中录入表单](https://oi-contrib.github.io/OIPage/index.html#/api/nodejs/logform)
52
+ - [disk 复制、删除、移动等磁盘操作](https://oi-contrib.github.io/OIPage/index.html#/api/nodejs/disk)
51
53
  - 等...
52
54
 
53
55
  ### 浏览器
54
56
 
55
- - 空闲执行分片函数
56
- - XHR请求埋点
57
+ - [performChunk 空闲执行分片函数](https://oi-contrib.github.io/OIPage/index.html#/api/web/performChunk)
58
+ - [XMLHttpRequest 请求埋点](https://oi-contrib.github.io/OIPage/index.html#/api/web/XMLHttpRequest)
57
59
  - 等...
58
60
 
59
- 已有功能或更多功能我们将根据实际情况逐步完善和维护,当然,你可以通过 [issue](https://github.com/oi-contrib/OIPage/issues) 给我们留言,告诉我们你的改进意见。
61
+ 你可以通过 [issue](https://github.com/oi-contrib/OIPage/issues) 给我们留言,告诉我们你的任何意见或报告BUG给我们。
60
62
 
61
63
  ## 版权
62
64
 
@@ -0,0 +1,17 @@
1
+ /**
2
+ * 获取一个值的类型字符串[object type]
3
+ */
4
+ export interface getTypeType {
5
+ (value: any): string
6
+ }
7
+
8
+ export let getType: getTypeType
9
+
10
+ /**
11
+ * 判断一个值是不是一个朴素的'对象'
12
+ */
13
+ export interface isPlainObjectType {
14
+ (value: any): boolean
15
+ }
16
+
17
+ export let isPlainObject: isPlainObjectType
@@ -0,0 +1,28 @@
1
+
2
+ const toString = Object.prototype.toString;
3
+
4
+ function getType(value) {
5
+ if (value == null) {
6
+ return value === undefined ? '[object Undefined]' : '[object Null]';
7
+ }
8
+ return toString.call(value);
9
+ }
10
+
11
+ function isPlainObject(value) {
12
+ if (value === null || typeof value !== 'object' || getType(value) != '[object Object]') {
13
+ return false;
14
+ }
15
+
16
+ // 如果原型为null
17
+ if (Object.getPrototypeOf(value) === null) {
18
+ return true;
19
+ }
20
+
21
+ let proto = value
22
+ while (Object.getPrototypeOf(proto) !== null) {
23
+ proto = Object.getPrototypeOf(proto);
24
+ }
25
+ return Object.getPrototypeOf(value) === proto;
26
+ }
27
+ exports.getType = getType;
28
+ exports.isPlainObject = isPlainObject;
@@ -1,10 +1,10 @@
1
1
 
2
2
  //当前正在运动的动画的tick函数堆栈
3
- var $timers = [];
3
+ let $timers = [];
4
4
  //唯一定时器的定时间隔
5
- var $interval = 13;
5
+ let $interval = 13;
6
6
  //定时器ID
7
- var $timerId;
7
+ let $timerId;
8
8
 
9
9
  /**
10
10
  * 动画轮播
@@ -18,13 +18,13 @@ function animation(doback, duration, callback) {
18
18
  if (arguments.length < 2) duration = 400;
19
19
  if (arguments.length < 3) callback = function () { };
20
20
 
21
- var clock = {
21
+ let clock = {
22
22
  //把tick函数推入堆栈
23
23
  "timer": function (tick, duration, callback) {
24
24
  if (!tick) {
25
25
  throw new Error('Tick is required!');
26
26
  }
27
- var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
27
+ let id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
28
28
  $timers.push({
29
29
  "id": id,
30
30
  "createTime": new Date(),
@@ -56,7 +56,7 @@ function animation(doback, duration, callback) {
56
56
 
57
57
  //被定时器调用,遍历timers堆栈
58
58
  "tick": function () {
59
- var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
59
+ let createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
60
60
 
61
61
  $timers = [];
62
62
  $timers.length = 0;
@@ -99,7 +99,7 @@ function animation(doback, duration, callback) {
99
99
  }
100
100
  };
101
101
 
102
- var id = clock.timer(function (deep) {
102
+ let id = clock.timer(function (deep) {
103
103
  //其中deep为0-1,表示改变的程度
104
104
  doback(deep);
105
105
  }, duration, callback);
@@ -108,7 +108,7 @@ function animation(doback, duration, callback) {
108
108
  // 一个函数
109
109
  // 用于在动画结束前结束动画
110
110
  stop: function () {
111
- var i;
111
+ let i;
112
112
  for (i in $timers) {
113
113
  if ($timers[i].id == id) {
114
114
  $timers[i].id = void 0;
@@ -45,4 +45,40 @@ export interface linkDiskType {
45
45
  (sourcePath: string, targetPath: string): void
46
46
  }
47
47
 
48
- export let linkDisk: linkDiskType
48
+ export let linkDisk: linkDiskType
49
+
50
+ /**
51
+ * 读取文件内容
52
+ */
53
+ export interface readPlainType {
54
+ (filePath: string): string
55
+ }
56
+
57
+ export let readPlain: readPlainType
58
+
59
+ /**
60
+ * 写入内容到文件
61
+ */
62
+ export interface writePlainTypes {
63
+ (filePath: string, content: string): void
64
+ }
65
+
66
+ export let writePlain: writePlainTypes
67
+
68
+ /**
69
+ * 读取JSON文件内容
70
+ */
71
+ export interface readJSONType {
72
+ (filePath: string): string
73
+ }
74
+
75
+ export let readJSON: readJSONType
76
+
77
+ /**
78
+ * 写入JSON内容到文件
79
+ */
80
+ export interface writeJSONTypes {
81
+ (filePath: string, content: string): void
82
+ }
83
+
84
+ export let writeJSON: writeJSONTypes
@@ -1,6 +1,6 @@
1
1
 
2
2
  const { join } = require("path");
3
- const { existsSync, readdirSync, lstatSync, unlinkSync, rmdirSync, mkdirSync, copyFileSync, symlinkSync } = require("fs");
3
+ const { existsSync, readdirSync, readFileSync, writeFileSync, lstatSync, unlinkSync, rmdirSync, mkdirSync, copyFileSync, symlinkSync } = require("fs");
4
4
 
5
5
  /**
6
6
  * 删除文件或文件夹
@@ -164,9 +164,47 @@ function linkDisk(sourcePath, targetPath) {
164
164
  symlinkSync(sourcePath, targetPath, type);
165
165
  }
166
166
 
167
-
167
+ function readPlain(filePath) {
168
+ if (existsSync(filePath)) {
169
+ return readFileSync(filePath, {
170
+ encoding: "utf8"
171
+ });
172
+ } else {
173
+ return "";
174
+ }
175
+ }
176
+
177
+ function writePlain(filePath, content) {
178
+ if (!existsSync(filePath)) {
179
+ const folder = join(filePath, "../");
180
+ if (!existsSync(folder)) {
181
+ mkdirSync(folder, { recursive: true });
182
+ }
183
+ }
184
+
185
+ writeFileSync(filePath, content, {
186
+ encoding: "utf8"
187
+ });
188
+ }
189
+
190
+ function readJSON(filePath) {
191
+ const content = readPlain(filePath);
192
+ try {
193
+ return JSON.parse(content);
194
+ } catch (e) {
195
+ return {};
196
+ }
197
+ }
198
+
199
+ function writeJSON(filePath, json) {
200
+ writePlain(filePath, JSON.stringify(json, null, 4));
201
+ }
168
202
  exports.deleteDisk = deleteDisk;
169
203
  exports.copyDisk = copyDisk;
170
204
  exports.moveDisk = moveDisk;
171
205
  exports.listDisk = listDisk;
172
206
  exports.linkDisk = linkDisk;
207
+ exports.readPlain = readPlain;
208
+ exports.writePlain = writePlain;
209
+ exports.readJSON = readJSON;
210
+ exports.writeJSON = writeJSON;
@@ -5,20 +5,20 @@ function numberFormat(input) {
5
5
  } else {
6
6
  input = input + "";
7
7
 
8
- var decimalValue, integerValue;
8
+ let decimalValue, integerValue;
9
9
 
10
- var dotIndex = input.indexOf('.');
10
+ let dotIndex = input.indexOf('.');
11
11
  if (dotIndex == -1) {
12
12
  decimalValue = ".00";
13
13
  integerValue = input;
14
14
  } else {
15
- var temp = input.split(".");
15
+ let temp = input.split(".");
16
16
  decimalValue = "." + (temp[1] + "0").substring(0, 2);
17
17
  integerValue = temp[0];
18
18
  }
19
19
 
20
- var integerArray = []
21
- for (var index = integerValue.length; index > 0; index -= 3) {
20
+ let integerArray = []
21
+ for (let index = integerValue.length; index > 0; index -= 3) {
22
22
  integerArray.unshift(integerValue.substring(index > 2 ? index - 3 : 0, index));
23
23
  }
24
24
 
@@ -28,7 +28,7 @@ function numberFormat(input) {
28
28
 
29
29
  function dateFormat(input, option) {
30
30
  option = option || {};
31
- var dateObj;
31
+ let dateObj;
32
32
 
33
33
  // 如果无值,就用当前日期
34
34
  if (!input) {
@@ -50,7 +50,7 @@ function dateFormat(input, option) {
50
50
  }
51
51
 
52
52
  // 年、月、日、时、分、秒
53
- var single = {
53
+ let single = {
54
54
  yyyy: 0, MM: 0, dd: 0, HH: 0, mm: 0, ss: 0
55
55
  };
56
56
 
@@ -68,8 +68,8 @@ function dateFormat(input, option) {
68
68
 
69
69
  // 否则只能借助 inputFormat 来解析
70
70
  else {
71
- var inputFormat = option.inputFormat + "", valIndex = 0;
72
- for (var index = 0; index < inputFormat.length; index++) {
71
+ let inputFormat = option.inputFormat + "", valIndex = 0;
72
+ for (let index = 0; index < inputFormat.length; index++) {
73
73
 
74
74
  // 年
75
75
  if (inputFormat.substring(index, index + 4) == "yyyy") {
@@ -78,9 +78,9 @@ function dateFormat(input, option) {
78
78
  valIndex += 4;
79
79
  index += 3;
80
80
  } else {
81
- var curFlag = inputFormat.substring(index, index + 2);
81
+ let curFlag = inputFormat.substring(index, index + 2);
82
82
  if (["MM", "dd", "HH", "mm", "ss"].indexOf(curFlag) > -1) {
83
- var valContent = input[valIndex];
83
+ let valContent = input[valIndex];
84
84
  if (/\d/.test(input[valIndex + 1])) {
85
85
  valContent += input[valIndex + 1];
86
86
  valIndex += 2;
@@ -103,7 +103,7 @@ function dateFormat(input, option) {
103
103
  if (single.mm < 10) single.mm = "0" + single.mm;
104
104
  if (single.ss < 10) single.ss = "0" + single.ss;
105
105
 
106
- var format = option.format || "yyyy/MM/dd";
106
+ let format = option.format || "yyyy/MM/dd";
107
107
  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);
108
108
  };
109
109
  exports.dateFormat = dateFormat;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * 初始化配置
3
+ */
4
+ export interface initOptionType {
5
+ (setOption: any, defaultOption: any): any
6
+ }
7
+
8
+ export let initOption: initOptionType
9
+
10
+ /**
11
+ * 合并配置
12
+ */
13
+ export interface mergeOptionType {
14
+ (oldOption: any, newOption: any): void
15
+ }
16
+
17
+ export let mergeOption: mergeOptionType
@@ -0,0 +1,29 @@
1
+ const {isPlainObject} = require("../__types/index.js");
2
+ function initOption(setOption, defaultOption) {
3
+ for (const key in setOption) {
4
+ defaultOption[key] = setOption[key];
5
+ }
6
+
7
+ return defaultOption;
8
+ }
9
+
10
+ function mergeOption(oldOption, newOption) {
11
+ (function doit(oldOption, newOption) {
12
+
13
+ for (const key in newOption) {
14
+ const value = newOption[key];
15
+
16
+ if (isPlainObject(value)) {
17
+ if (!oldOption[key]) oldOption[key] = {};
18
+
19
+ doit(oldOption[key], newOption[key]);
20
+ } else {
21
+ oldOption[key] = value;
22
+ }
23
+
24
+ }
25
+
26
+ })(oldOption, newOption);
27
+ }
28
+ exports.initOption = initOption;
29
+ exports.mergeOption = mergeOption;
@@ -2,7 +2,7 @@
2
2
  function throttle(callback, _option) {
3
3
 
4
4
  // 缺省值
5
- var option = {
5
+ let option = {
6
6
  time: 200,
7
7
  keep: false,
8
8
  opportunity: "end"
@@ -10,12 +10,12 @@ function throttle(callback, _option) {
10
10
 
11
11
  // 校对
12
12
  if (_option) {
13
- for (var key in _option) {
13
+ for (let key in _option) {
14
14
  option[key] = _option[key];
15
15
  }
16
16
  }
17
17
 
18
- var hadInterval = false, hadClick = false, oneClick = false, arg;
18
+ let hadInterval = false, hadClick = false, oneClick = false, arg;
19
19
  return function () {
20
20
  const _this = this;
21
21
  arg = arguments;
@@ -27,7 +27,7 @@ function throttle(callback, _option) {
27
27
  }
28
28
  hadInterval = true;
29
29
 
30
- var interval = setInterval(() => {
30
+ let interval = setInterval(() => {
31
31
  if (hadClick) {
32
32
  if (!option.keep) {
33
33
  callback.apply(_this, arg);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oipage",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0",
4
4
  "description": "主要是提供前端开发中常用的API接口,支持nodejs和浏览器端使用",
5
5
  "sideEffects": false,
6
6
  "typings": "./types/index.d.ts",
@@ -30,5 +30,8 @@
30
30
  "bugs": {
31
31
  "url": "https://github.com/oi-contrib/OIPage/issues"
32
32
  },
33
- "homepage": "https://oi-contrib.github.io/OIPage"
34
- }
33
+ "homepage": "https://oi-contrib.github.io/OIPage",
34
+ "devDependencies": {
35
+ "@oipage/testjs": "^0.1.0"
36
+ }
37
+ }
package/types/index.d.ts CHANGED
@@ -11,6 +11,8 @@ import "../nodejs/json/index";
11
11
  declare module "oipage/nodejs/json/index.js" {}
12
12
  import "../nodejs/logform/index";
13
13
  declare module "oipage/nodejs/logform/index.js" {}
14
+ import "../nodejs/option/index";
15
+ declare module "oipage/nodejs/option/index.js" {}
14
16
  import "../nodejs/reader/index";
15
17
  declare module "oipage/nodejs/reader/index.js" {}
16
18
  import "../nodejs/throttle/index";
@@ -23,6 +25,8 @@ import "../web/json/index";
23
25
  declare module "oipage/web/json/index.js" {}
24
26
  import "../web/onReady/index";
25
27
  declare module "oipage/web/onReady/index.js" {}
28
+ import "../web/option/index";
29
+ declare module "oipage/web/option/index.js" {}
26
30
  import "../web/performChunk/index";
27
31
  declare module "oipage/web/performChunk/index.js" {}
28
32
  import "../web/reader/index";
@@ -2,7 +2,7 @@
2
2
  export function XHRIntercept(callbackFactory) {
3
3
 
4
4
  // 原生的请求方法
5
- var { open, send } = window.XMLHttpRequest.prototype;
5
+ let { open, send } = window.XMLHttpRequest.prototype;
6
6
 
7
7
  window.XMLHttpRequest.prototype.open = function (method, url) {
8
8
  this.callback = callbackFactory();
@@ -0,0 +1,17 @@
1
+ /**
2
+ * 获取一个值的类型字符串[object type]
3
+ */
4
+ export interface getTypeType {
5
+ (value: any): string
6
+ }
7
+
8
+ export let getType: getTypeType
9
+
10
+ /**
11
+ * 判断一个值是不是一个朴素的'对象'
12
+ */
13
+ export interface isPlainObjectType {
14
+ (value: any): boolean
15
+ }
16
+
17
+ export let isPlainObject: isPlainObjectType
@@ -0,0 +1,26 @@
1
+
2
+ const toString = Object.prototype.toString;
3
+
4
+ export function getType(value) {
5
+ if (value == null) {
6
+ return value === undefined ? '[object Undefined]' : '[object Null]';
7
+ }
8
+ return toString.call(value);
9
+ }
10
+
11
+ export function isPlainObject(value) {
12
+ if (value === null || typeof value !== 'object' || getType(value) != '[object Object]') {
13
+ return false;
14
+ }
15
+
16
+ // 如果原型为null
17
+ if (Object.getPrototypeOf(value) === null) {
18
+ return true;
19
+ }
20
+
21
+ let proto = value
22
+ while (Object.getPrototypeOf(proto) !== null) {
23
+ proto = Object.getPrototypeOf(proto);
24
+ }
25
+ return Object.getPrototypeOf(value) === proto;
26
+ }
@@ -1,10 +1,10 @@
1
1
 
2
2
  //当前正在运动的动画的tick函数堆栈
3
- var $timers = [];
3
+ let $timers = [];
4
4
  //唯一定时器的定时间隔
5
- var $interval = 13;
5
+ let $interval = 13;
6
6
  //定时器ID
7
- var $timerId;
7
+ let $timerId;
8
8
 
9
9
  /**
10
10
  * 动画轮播
@@ -18,13 +18,13 @@ export function animation(doback, duration, callback) {
18
18
  if (arguments.length < 2) duration = 400;
19
19
  if (arguments.length < 3) callback = function () { };
20
20
 
21
- var clock = {
21
+ let clock = {
22
22
  //把tick函数推入堆栈
23
23
  "timer": function (tick, duration, callback) {
24
24
  if (!tick) {
25
25
  throw new Error('Tick is required!');
26
26
  }
27
- var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
27
+ let id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
28
28
  $timers.push({
29
29
  "id": id,
30
30
  "createTime": new Date(),
@@ -56,7 +56,7 @@ export function animation(doback, duration, callback) {
56
56
 
57
57
  //被定时器调用,遍历timers堆栈
58
58
  "tick": function () {
59
- var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
59
+ let createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
60
60
 
61
61
  $timers = [];
62
62
  $timers.length = 0;
@@ -99,7 +99,7 @@ export function animation(doback, duration, callback) {
99
99
  }
100
100
  };
101
101
 
102
- var id = clock.timer(function (deep) {
102
+ let id = clock.timer(function (deep) {
103
103
  //其中deep为0-1,表示改变的程度
104
104
  doback(deep);
105
105
  }, duration, callback);
@@ -108,7 +108,7 @@ export function animation(doback, duration, callback) {
108
108
  // 一个函数
109
109
  // 用于在动画结束前结束动画
110
110
  stop: function () {
111
- var i;
111
+ let i;
112
112
  for (i in $timers) {
113
113
  if ($timers[i].id == id) {
114
114
  $timers[i].id = void 0;
@@ -5,20 +5,20 @@ export function numberFormat(input) {
5
5
  } else {
6
6
  input = input + "";
7
7
 
8
- var decimalValue, integerValue;
8
+ let decimalValue, integerValue;
9
9
 
10
- var dotIndex = input.indexOf('.');
10
+ let dotIndex = input.indexOf('.');
11
11
  if (dotIndex == -1) {
12
12
  decimalValue = ".00";
13
13
  integerValue = input;
14
14
  } else {
15
- var temp = input.split(".");
15
+ let temp = input.split(".");
16
16
  decimalValue = "." + (temp[1] + "0").substring(0, 2);
17
17
  integerValue = temp[0];
18
18
  }
19
19
 
20
- var integerArray = []
21
- for (var index = integerValue.length; index > 0; index -= 3) {
20
+ let integerArray = []
21
+ for (let index = integerValue.length; index > 0; index -= 3) {
22
22
  integerArray.unshift(integerValue.substring(index > 2 ? index - 3 : 0, index));
23
23
  }
24
24
 
@@ -28,7 +28,7 @@ export function numberFormat(input) {
28
28
 
29
29
  export function dateFormat(input, option) {
30
30
  option = option || {};
31
- var dateObj;
31
+ let dateObj;
32
32
 
33
33
  // 如果无值,就用当前日期
34
34
  if (!input) {
@@ -50,7 +50,7 @@ export function dateFormat(input, option) {
50
50
  }
51
51
 
52
52
  // 年、月、日、时、分、秒
53
- var single = {
53
+ let single = {
54
54
  yyyy: 0, MM: 0, dd: 0, HH: 0, mm: 0, ss: 0
55
55
  };
56
56
 
@@ -68,8 +68,8 @@ export function dateFormat(input, option) {
68
68
 
69
69
  // 否则只能借助 inputFormat 来解析
70
70
  else {
71
- var inputFormat = option.inputFormat + "", valIndex = 0;
72
- for (var index = 0; index < inputFormat.length; index++) {
71
+ let inputFormat = option.inputFormat + "", valIndex = 0;
72
+ for (let index = 0; index < inputFormat.length; index++) {
73
73
 
74
74
  // 年
75
75
  if (inputFormat.substring(index, index + 4) == "yyyy") {
@@ -78,9 +78,9 @@ export function dateFormat(input, option) {
78
78
  valIndex += 4;
79
79
  index += 3;
80
80
  } else {
81
- var curFlag = inputFormat.substring(index, index + 2);
81
+ let curFlag = inputFormat.substring(index, index + 2);
82
82
  if (["MM", "dd", "HH", "mm", "ss"].indexOf(curFlag) > -1) {
83
- var valContent = input[valIndex];
83
+ let valContent = input[valIndex];
84
84
  if (/\d/.test(input[valIndex + 1])) {
85
85
  valContent += input[valIndex + 1];
86
86
  valIndex += 2;
@@ -103,6 +103,6 @@ export function dateFormat(input, option) {
103
103
  if (single.mm < 10) single.mm = "0" + single.mm;
104
104
  if (single.ss < 10) single.ss = "0" + single.ss;
105
105
 
106
- var format = option.format || "yyyy/MM/dd";
106
+ let format = option.format || "yyyy/MM/dd";
107
107
  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);
108
108
  };
@@ -1,6 +1,6 @@
1
1
 
2
2
  export function onReady(callback) {
3
- var readyState = document.readyState;
3
+ let readyState = document.readyState;
4
4
  if (readyState === 'interactive' || readyState === 'complete') {
5
5
  callback();
6
6
  } else {
@@ -0,0 +1,17 @@
1
+ /**
2
+ * 初始化配置
3
+ */
4
+ export interface initOptionType {
5
+ (setOption: any, defaultOption: any): any
6
+ }
7
+
8
+ export let initOption: initOptionType
9
+
10
+ /**
11
+ * 合并配置
12
+ */
13
+ export interface mergeOptionType {
14
+ (oldOption: any, newOption: any): void
15
+ }
16
+
17
+ export let mergeOption: mergeOptionType
@@ -0,0 +1,27 @@
1
+ import {isPlainObject} from "../__types/index.js";
2
+ export function initOption(setOption, defaultOption) {
3
+ for (const key in setOption) {
4
+ defaultOption[key] = setOption[key];
5
+ }
6
+
7
+ return defaultOption;
8
+ }
9
+
10
+ export function mergeOption(oldOption, newOption) {
11
+ (function doit(oldOption, newOption) {
12
+
13
+ for (const key in newOption) {
14
+ const value = newOption[key];
15
+
16
+ if (isPlainObject(value)) {
17
+ if (!oldOption[key]) oldOption[key] = {};
18
+
19
+ doit(oldOption[key], newOption[key]);
20
+ } else {
21
+ oldOption[key] = value;
22
+ }
23
+
24
+ }
25
+
26
+ })(oldOption, newOption);
27
+ }
@@ -1,6 +1,6 @@
1
1
 
2
2
  export function setStyle(el, styles) {
3
- for (var key in styles) {
3
+ for (let key in styles) {
4
4
  el.style[key] = styles[key];
5
5
  }
6
6
  }
@@ -8,7 +8,7 @@ export function setStyle(el, styles) {
8
8
  export function getStyle(el, name) {
9
9
 
10
10
  // 获取结点的全部样式
11
- var allStyle = document.defaultView && document.defaultView.getComputedStyle ?
11
+ let allStyle = document.defaultView && document.defaultView.getComputedStyle ?
12
12
  document.defaultView.getComputedStyle(el, null) :
13
13
  el.currentStyle;
14
14
 
@@ -2,7 +2,7 @@
2
2
  export function throttle(callback, _option) {
3
3
 
4
4
  // 缺省值
5
- var option = {
5
+ let option = {
6
6
  time: 200,
7
7
  keep: false,
8
8
  opportunity: "end"
@@ -10,12 +10,12 @@ export function throttle(callback, _option) {
10
10
 
11
11
  // 校对
12
12
  if (_option) {
13
- for (var key in _option) {
13
+ for (let key in _option) {
14
14
  option[key] = _option[key];
15
15
  }
16
16
  }
17
17
 
18
- var hadInterval = false, hadClick = false, oneClick = false, arg;
18
+ let hadInterval = false, hadClick = false, oneClick = false, arg;
19
19
  return function () {
20
20
  const _this = this;
21
21
  arg = arguments;
@@ -27,7 +27,7 @@ export function throttle(callback, _option) {
27
27
  }
28
28
  hadInterval = true;
29
29
 
30
- var interval = setInterval(() => {
30
+ let interval = setInterval(() => {
31
31
  if (hadClick) {
32
32
  if (!option.keep) {
33
33
  callback.apply(_this, arg);