mm_https 1.6.4 → 1.6.6

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/README.md CHANGED
@@ -13,7 +13,9 @@ npm install mm_https
13
13
  ### 初始化
14
14
 
15
15
  ```javascript
16
- const Http = require('mm_https');
16
+ const {
17
+ Http
18
+ } = require('mm_https');
17
19
 
18
20
  // 基本初始化
19
21
  const http = new Http();
@@ -40,6 +42,10 @@ const httpWithConfig = new Http({
40
42
  ### GET请求
41
43
 
42
44
  ```javascript
45
+ const {
46
+ Http
47
+ } = new Http();
48
+
43
49
  const http = new Http();
44
50
 
45
51
  // 基本GET请求
@@ -67,6 +73,10 @@ async function getWithCookie() {
67
73
  ### POST请求
68
74
 
69
75
  ```javascript
76
+ const {
77
+ Http
78
+ } = new Http();
79
+
70
80
  const http = new Http();
71
81
 
72
82
  // JSON格式POST请求
@@ -101,6 +111,10 @@ async function postWithHeadersAndCookie() {
101
111
  ### 文件下载
102
112
 
103
113
  ```javascript
114
+ const {
115
+ Http
116
+ } = new Http();
117
+
104
118
  const http = new Http();
105
119
 
106
120
  // 基本文件下载
@@ -134,11 +148,21 @@ async function downloadWithHeaders() {
134
148
  ### Cookie管理
135
149
 
136
150
  ```javascript
151
+ const {
152
+ Http
153
+ } = new Http();
154
+
137
155
  const http = new Http();
138
156
 
139
157
  // 设置Cookie
140
158
  http.setCookie('session=abc123; user=john');
141
159
 
160
+ // 或者通过对象设置多个Cookie
161
+ http.setCookie({
162
+ 'session': 'abc123',
163
+ 'user': 'john'
164
+ });
165
+
142
166
  // 获取当前所有Cookie
143
167
  const cookieString = http.getCookie();
144
168
  $.log.debug('当前Cookie:', cookieString);
@@ -0,0 +1,68 @@
1
+ const jsdoc = require('eslint-plugin-jsdoc');
2
+
3
+ module.exports = [
4
+ {
5
+ files: ['lib/**/*.js'],
6
+ languageOptions: {
7
+ ecmaVersion: 2020,
8
+ sourceType: 'script'
9
+ },
10
+ plugins: {
11
+ jsdoc: jsdoc
12
+ },
13
+ rules: {
14
+ // JSDoc相关规则 - 设置为error级别强制要求
15
+ 'jsdoc/require-jsdoc': ['error', {
16
+ require: {
17
+ FunctionDeclaration: true,
18
+ MethodDefinition: true,
19
+ ClassDeclaration: true,
20
+ ArrowFunctionExpression: true
21
+ }
22
+ }],
23
+ 'jsdoc/check-param-names': 'off',
24
+ 'jsdoc/check-tag-names': 'off',
25
+ 'jsdoc/check-types': 'off',
26
+ 'jsdoc/require-param': 'off',
27
+ 'jsdoc/require-param-description': 'off',
28
+ 'jsdoc/require-returns': 'off',
29
+ 'jsdoc/require-returns-description': 'off',
30
+
31
+ // 基础语法规则
32
+ 'no-unused-vars': ['error', { args: 'none', vars: 'all' }],
33
+ 'no-console': 'warn',
34
+
35
+ // 代码风格规则
36
+ 'indent': ['error', 2],
37
+ 'quotes': ['error', 'single'],
38
+ 'semi': ['error', 'always'],
39
+ 'comma-dangle': ['error', 'never'],
40
+ 'no-trailing-spaces': 'error',
41
+ 'eol-last': 'error',
42
+ 'max-len': ['error', { code: 100 }],
43
+ 'max-lines-per-function': ['error', { max: 40 }],
44
+ 'complexity': ['error', 12],
45
+ 'max-depth': ['error', 4],
46
+ 'max-params': ['error', 4],
47
+
48
+ // 命名规则
49
+ 'id-length': ['error', {
50
+ min: 1,
51
+ max: 20,
52
+ properties: 'always'
53
+ }]
54
+ }
55
+ },
56
+ {
57
+ files: ['test/**/*.js'],
58
+ languageOptions: {
59
+ ecmaVersion: 2020,
60
+ sourceType: 'script'
61
+ },
62
+ rules: {
63
+ // 测试文件中允许使用console
64
+ 'no-console': 'off',
65
+ 'no-unused-vars': 'off'
66
+ }
67
+ }
68
+ ];
package/index.js CHANGED
@@ -56,9 +56,21 @@ class Http {
56
56
  var headers = this.changeHeaders(config.headers);
57
57
  Object.assign(this._headers, headers);
58
58
  }
59
+
60
+ this._logger = $.log || console;
59
61
  }
60
62
  }
61
63
 
64
+ /**
65
+ * 日志记录
66
+ * @param {string} level - 日志级别
67
+ * @param {string} message - 日志消息
68
+ * @param {...*} args - 日志参数
69
+ */
70
+ Http.prototype.log = function (level, message, ...args) {
71
+ this._logger[level](`[${this.constructor.name}] ${message}`, ...args);
72
+ }
73
+
62
74
  /**
63
75
  * 设置Cookie
64
76
  * @param {Object|String} cookies - Cookie字符串
@@ -351,7 +363,7 @@ Http.prototype.request = function (options) {
351
363
  });
352
364
 
353
365
  req.on("error", function (err) {
354
- $.log.debug("错误", err);
366
+ self.log("debug", "错误", err);
355
367
  resolve({
356
368
  status: 0,
357
369
  message: err.message
@@ -437,7 +449,7 @@ Http.prototype.download = async function (url, filename, auto, headers, cookie)
437
449
  filePath = null;
438
450
  }
439
451
  } else {
440
- $.log.debug('保存文件名(filename)不能为!');
452
+ this.log("debug", '保存文件名(filename)不能为!');
441
453
  }
442
454
  }
443
455
  return filePath;
@@ -450,11 +462,9 @@ Http.prototype.clear = function () {
450
462
  this._cookies = {};
451
463
  };
452
464
 
453
- if (global.$) {
454
- $.Http = Http;
455
- }
456
-
457
465
  /**
458
466
  * 导出构造函数
459
467
  */
460
- module.exports = Http;
468
+ module.exports = {
469
+ Http
470
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_https",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "description": "超级美眉HTTP请求模块 - 支持自动Cookie管理、代理设置、文件下载等功能",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "https-proxy-agent": "^7.0.6",
37
- "iconv-lite": "^0.7.0",
38
- "mm_expand": "^1.9.7"
37
+ "iconv-lite": "^0.7.1",
38
+ "mm_expand": "^2.0.0"
39
39
  }
40
40
  }
package/test.js CHANGED
@@ -3,8 +3,9 @@
3
3
  * 用于npm发布前的功能验证
4
4
  */
5
5
 
6
- const Http = require('./index.js');
7
- const fs = require('fs');
6
+ const {
7
+ Http
8
+ } = require('./index.js');
8
9
 
9
10
  /**
10
11
  * 基础HTTP请求测试
@@ -97,7 +98,8 @@ async function testErrorHandling() {
97
98
  // 设置较短的超时时间,避免长时间等待
98
99
  const timeoutHttp = new Http();
99
100
  // 使用不存在的域名进行测试
100
- await timeoutHttp.get('http://nonexistent-domain-12345.test');
101
+ const res = await timeoutHttp.get('http://nonexistent-domain-12345.test');
102
+ console.log('GET响应状态码:', res.status, '响应消息:', res.message, '响应内容:', res.body);
101
103
  console.log('⚠️ 不存在的域名测试 - 请求可能被重定向或超时');
102
104
  } catch (err) {
103
105
  console.log('不存在的域名处理正确:', err.message);
@@ -1,99 +0,0 @@
1
- # mm_https模块 npm发布检查清单
2
-
3
- ## ✅ 已完成的项目
4
-
5
- ### 1. 代码重构和规范
6
- - [x] 类名和方法名使用小驼峰命名法
7
- - [x] 私有成员使用下划线前缀
8
- - [x] 变量名使用小写蛇形命名法
9
- - [x] 完整的JSDoc注释
10
- - [x] 符合ES6类和原型方法范式
11
-
12
- ### 2. 测试文件优化
13
- - [x] 创建适合npm发布的测试文件
14
- - [x] 包含基础功能测试
15
- - [x] 包含高级功能测试
16
- - [x] 包含错误处理测试
17
- - [x] 所有测试通过
18
-
19
- ### 3. 配置文件优化
20
- - [x] 更新package.json描述和关键词
21
- - [x] 添加Node.js版本要求
22
- - [x] 优化依赖管理
23
-
24
- ### 4. 功能验证
25
- - [x] 语法检查通过
26
- - [x] 依赖关系正常
27
- - [x] 模块功能完整
28
-
29
- ## 📋 npm发布前检查
30
-
31
- ### 版本管理
32
- - [ ] 确认当前版本号:1.6.4
33
- - [ ] 是否需要更新版本号
34
- - [ ] 更新CHANGELOG.md(如有)
35
-
36
- ### 文档检查
37
- - [ ] README.md内容完整且准确
38
- - [ ] 示例代码正确
39
- - [ ] 安装说明清晰
40
-
41
- ### 发布准备
42
- - [ ] 登录npm账号:`npm login`
43
- - [ ] 检查包名可用性:`npm search mm_https`
44
- - [ ] 执行发布命令:`npm publish`
45
-
46
- ## 🚀 发布命令
47
-
48
- ```bash
49
- # 登录npm(如果未登录)
50
- npm login
51
-
52
- # 检查包名是否可用
53
- npm search mm_https
54
-
55
- # 发布到npm
56
- npm publish
57
-
58
- # 或者发布为公开包(如果需要)
59
- npm publish --access public
60
- ```
61
-
62
- ## 📦 安装使用
63
-
64
- 发布后,用户可以通过以下方式安装:
65
-
66
- ```bash
67
- npm install mm_https
68
- ```
69
-
70
- 使用示例:
71
- ```javascript
72
- const { Http } = require('mm_https');
73
-
74
- async function example() {
75
- const http = new Http();
76
- const res = await http.get('https://httpbin.org/get');
77
- console.log(res.body);
78
- }
79
- ```
80
-
81
- ## 🔧 开发命令
82
-
83
- ```bash
84
- # 运行测试
85
- npm test
86
-
87
- # 开发模式
88
- npm run dev
89
-
90
- # 安装依赖
91
- npm install
92
- ```
93
-
94
- ## 📞 支持信息
95
-
96
- - 作者:邱文武
97
- - 许可证:ISC
98
- - 问题反馈:https://gitee.com/qiuwenwu91/mm_https/issues
99
- - 主页:https://gitee.com/qiuwenwu91/mm_https#readme