mm_expand 1.9.5 → 1.9.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
@@ -82,6 +82,70 @@ $.eventer.pause('user:*'); // 暂停所有用户相关事件
82
82
  $.eventer.resume('user:*'); // 恢复所有用户相关事件
83
83
  ```
84
84
 
85
+ ## 模块导出
86
+
87
+ 本库提供多种导出方式,支持按需导入和使用:
88
+
89
+ ### 全局对象方式(推荐)
90
+ ```javascript
91
+ const $ = require('mm_expand');
92
+ // 使用全局对象调用所有功能
93
+ $.copy({ a: 1 }); // 对象深拷贝
94
+ $.eventer.on('event', handler); // 事件监听
95
+ ```
96
+
97
+ ### 按需导入方式
98
+ ```javascript
99
+ // 导入核心类
100
+ const { Event, Eventer, Lang, Base, File, Dir } = require('mm_expand');
101
+
102
+ // 导入对象操作函数
103
+ const { as, push, clear, toJson, copy, get, set } = require('mm_expand/lib/object.js');
104
+
105
+ // 导入数组构造函数
106
+ const { Array } = require('mm_expand/lib/array.js');
107
+
108
+ // 导入其他功能模块
109
+ const { Log } = require('mm_expand/lib/log.js');
110
+ const { Timer } = require('mm_expand/lib/timer.js');
111
+ ```
112
+
113
+ ### 主要导出模块
114
+
115
+ #### 核心类(index.js导出)
116
+ - **Event**: 事件类,用于创建和管理事件实例
117
+ - **Eventer**: 事件驱动类,提供完整的事件系统功能
118
+ - **Lang**: 语言包类,支持多语言国际化
119
+ - **Base**: 基础类,提供类创建和继承功能
120
+ - **File**: 文件操作类,提供文件读写功能
121
+ - **Dir**: 目录操作类,提供目录管理功能
122
+
123
+ #### 对象操作函数(object.js导出)
124
+ - **as**: 判断对象是否相似
125
+ - **push**: 合并对象属性
126
+ - **clear**: 清空对象值
127
+ - **toJson**: 对象转JSON字符串
128
+ - **toXml**: 对象转XML字符串
129
+ - **toUrl**: 对象转URL参数字符串
130
+ - **saveJson**: 对象保存为JSON文件
131
+ - **saveXml**: 对象保存为XML文件
132
+ - **copy**: 深度拷贝对象
133
+ - **keys**: 获取对象属性名
134
+ - **getInfo**: 获取对象详细信息
135
+ - **add**: 添加对象属性
136
+ - **del**: 删除对象属性
137
+ - **set**: 修改对象属性
138
+ - **get**: 查询对象属性
139
+ - **prop**: 遍历读写对象属性
140
+ - **arrToObj**: 数组转对象
141
+
142
+ #### 数组构造函数(array.js导出)
143
+ - **Array**: 增强的数组构造函数,包含所有数组原型扩展方法
144
+
145
+ #### 其他功能模块
146
+ - **Log**: 日志类,提供日志记录功能
147
+ - **Timer**: 定时器类,提供定时任务功能
148
+
85
149
  ## API文档
86
150
 
87
151
  ### 全局工具函数
@@ -624,7 +688,7 @@ A: 目前提供基本的JavaScript支持,TypeScript类型定义正在规划中
624
688
  ## npm发布信息
625
689
 
626
690
  ### 发布状态
627
- - **当前版本**: 1.9.3
691
+ - **当前版本**: 1.9.6
628
692
  - **npm包名**: mm_expand
629
693
  - **发布状态**: 已准备发布
630
694
 
package/README_EN.md CHANGED
@@ -108,6 +108,70 @@ $.eventer.pause('user:*'); // Pause all user-related events
108
108
  $.eventer.resume('user:*'); // Resume all user-related events
109
109
  ```
110
110
 
111
+ ## Module Exports
112
+
113
+ This library provides multiple export methods supporting on-demand import and usage:
114
+
115
+ ### Global Object Method (Recommended)
116
+ ```javascript
117
+ const $ = require('mm_expand');
118
+ // Use global object to access all functionality
119
+ $.copy({ a: 1 }); // Object deep copy
120
+ $.eventer.on('event', handler); // Event listening
121
+ ```
122
+
123
+ ### On-demand Import Method
124
+ ```javascript
125
+ // Import core classes
126
+ const { Event, Eventer, Lang, Base, File, Dir } = require('mm_expand');
127
+
128
+ // Import object operation functions
129
+ const { as, push, clear, toJson, copy, get, set } = require('mm_expand/lib/object.js');
130
+
131
+ // Import array constructor
132
+ const { Array } = require('mm_expand/lib/array.js');
133
+
134
+ // Import other functional modules
135
+ const { Log } = require('mm_expand/lib/log.js');
136
+ const { Timer } = require('mm_expand/lib/timer.js');
137
+ ```
138
+
139
+ ### Main Export Modules
140
+
141
+ #### Core Classes (index.js exports)
142
+ - **Event**: Event class for creating and managing event instances
143
+ - **Eventer**: Event-driven class providing complete event system functionality
144
+ - **Lang**: Language pack class supporting multilingual internationalization
145
+ - **Base**: Base class providing class creation and inheritance functionality
146
+ - **File**: File operation class providing file read/write functionality
147
+ - **Dir**: Directory operation class providing directory management functionality
148
+
149
+ #### Object Operation Functions (object.js exports)
150
+ - **as**: Determine if objects are similar
151
+ - **push**: Merge object properties
152
+ - **clear**: Clear object values
153
+ - **toJson**: Convert object to JSON string
154
+ - **toXml**: Convert object to XML string
155
+ - **toUrl**: Convert object to URL parameter string
156
+ - **saveJson**: Save object as JSON file
157
+ - **saveXml**: Save object as XML file
158
+ - **copy**: Deep copy object
159
+ - **keys**: Get object property names
160
+ - **getInfo**: Get object detailed information
161
+ - **add**: Add object properties
162
+ - **del**: Delete object properties
163
+ - **set**: Modify object properties
164
+ - **get**: Query object properties
165
+ - **prop**: Traverse and read/write object properties
166
+ - **arrToObj**: Convert array to object
167
+
168
+ #### Array Constructor (array.js exports)
169
+ - **Array**: Enhanced array constructor containing all array prototype extension methods
170
+
171
+ #### Other Functional Modules
172
+ - **Log**: Log class providing logging functionality
173
+ - **Timer**: Timer class providing scheduled task functionality
174
+
111
175
  ## API Documentation
112
176
 
113
177
  ### Global Utility Functions
@@ -630,7 +694,7 @@ Welcome to submit Issues and Pull Requests! Please ensure your code follows thes
630
694
  4. Run tests before submitting to ensure no new issues are introduced
631
695
 
632
696
  ## Release Status
633
- - **Current Version**: 1.9.3
697
+ - **Current Version**: 1.9.6
634
698
  - **npm Package Name**: mm_expand
635
699
  - **Release Status**: Ready for release
636
700
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_expand",
3
- "version": "1.9.5",
3
+ "version": "1.9.6",
4
4
  "description": "这是超级美眉原型函数拓展模块,更有利于对string、array、object的操作,避免出错,简化业务逻辑。",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,167 +0,0 @@
1
- /**
2
- * @description array.js 测试文件
3
- */
4
-
5
- // 导入array.js模块,它会自动扩展Array.prototype
6
- require('../lib/array.js');
7
-
8
- /**
9
- * @description 运行 array.js 测试
10
- * @returns {Object} 测试结果
11
- */
12
- async function run() {
13
- let total = 0;
14
- let passed = 0;
15
- let failed = 0;
16
-
17
- console.log('开始测试 array.js...');
18
-
19
- // 测试 Array.prototype.toTree
20
- total++;
21
- try {
22
- const arr = [
23
- { id: 1, name: '节点1', father_id: 0 },
24
- { id: 2, name: '节点2', father_id: 1 },
25
- { id: 3, name: '节点3', father_id: 1 }
26
- ];
27
- const result = arr.toTree('id', 0);
28
- if (result.length === 1 && result[0].sub.length === 2) {
29
- console.log('✅ Array.prototype.toTree: 通过');
30
- passed++;
31
- } else {
32
- console.log('❌ Array.prototype.toTree: 失败');
33
- failed++;
34
- }
35
- } catch (error) {
36
- console.log('❌ Array.prototype.toTree: 异常 -', error.message);
37
- failed++;
38
- }
39
-
40
- // 测试 Array.prototype.toList
41
- total++;
42
- try {
43
- const arr = [
44
- { id: 1, name: '节点1', sub: [
45
- { id: 2, name: '节点2' },
46
- { id: 3, name: '节点3' }
47
- ]}
48
- ];
49
- const result = arr.toList();
50
- if (result.length === 3) {
51
- console.log('✅ Array.prototype.toList: 通过');
52
- passed++;
53
- } else {
54
- console.log('❌ Array.prototype.toList: 失败');
55
- failed++;
56
- }
57
- } catch (error) {
58
- console.log('❌ Array.prototype.toList: 异常 -', error.message);
59
- failed++;
60
- }
61
-
62
- // 测试 Array.prototype.copy
63
- total++;
64
- try {
65
- const arr = [1, 2, 3];
66
- const result = arr.copy();
67
- if (result.length === 3 && result !== arr) {
68
- console.log('✅ Array.prototype.copy: 通过');
69
- passed++;
70
- } else {
71
- console.log('❌ Array.prototype.copy: 失败');
72
- failed++;
73
- }
74
- } catch (error) {
75
- console.log('❌ Array.prototype.copy: 异常 -', error.message);
76
- failed++;
77
- }
78
-
79
- // 测试 Array.prototype.toStr
80
- total++;
81
- try {
82
- const arr = [1, 2, 3];
83
- const result = arr.toStr(',');
84
- if (result === '1,2,3') {
85
- console.log('✅ Array.prototype.toStr: 通过');
86
- passed++;
87
- } else {
88
- console.log('❌ Array.prototype.toStr: 失败');
89
- failed++;
90
- }
91
- } catch (error) {
92
- console.log('❌ Array.prototype.toStr: 异常 -', error.message);
93
- failed++;
94
- }
95
-
96
- // 测试 Array.prototype.clear
97
- total++;
98
- try {
99
- const arr = [1, 2, 3];
100
- const result = arr.clear();
101
- if (result.length === 0 && arr.length === 0) {
102
- console.log('✅ Array.prototype.clear: 通过');
103
- passed++;
104
- } else {
105
- console.log('❌ Array.prototype.clear: 失败');
106
- failed++;
107
- }
108
- } catch (error) {
109
- console.log('❌ Array.prototype.clear: 异常 -', error.message);
110
- failed++;
111
- }
112
-
113
- // 测试 Array.prototype.has
114
- total++;
115
- try {
116
- const arr = [{ id: 1, name: 'test1' }, { id: 2, name: 'test2' }];
117
- const result1 = arr.has({ id: 1 });
118
- const result2 = arr.has({ id: 3 });
119
- if (result1 === true && result2 === false) {
120
- console.log('✅ Array.prototype.has: 通过');
121
- passed++;
122
- } else {
123
- console.log('❌ Array.prototype.has: 失败');
124
- failed++;
125
- }
126
- } catch (error) {
127
- console.log('❌ Array.prototype.has: 异常 -', error.message);
128
- failed++;
129
- }
130
-
131
- // 测试 Array.prototype.toObj
132
- total++;
133
- try {
134
- const arr = [{ id: 1, name: 'test1' }, { id: 2, name: 'test2' }];
135
- const result = arr.toObj('id');
136
- if (result[1].name === 'test1' && result[2].name === 'test2') {
137
- console.log('✅ Array.prototype.toObj: 通过');
138
- passed++;
139
- } else {
140
- console.log('❌ Array.prototype.toObj: 失败');
141
- failed++;
142
- }
143
- } catch (error) {
144
- console.log('❌ Array.prototype.toObj: 异常 -', error.message);
145
- failed++;
146
- }
147
-
148
- console.log(`array.js 测试完成: 通过 ${passed}/${total} 个测试`);
149
-
150
- return {
151
- total,
152
- passed,
153
- failed
154
- };
155
- }
156
-
157
- module.exports = {
158
- run
159
- };
160
-
161
- // 如果直接运行此文件,则执行测试
162
- if (require.main === module) {
163
- run().then(result => {
164
- console.log('测试结果:', result);
165
- process.exit(result.failed > 0 ? 1 : 0);
166
- }).catch(console.error);
167
- }
package/test/base_test.js DELETED
@@ -1,87 +0,0 @@
1
- /**
2
- * @description base.js 测试文件
3
- */
4
-
5
- const { Base } = require('../lib/base.js');
6
-
7
- /**
8
- * @description 运行 base.js 测试
9
- * @returns {Object} 测试结果
10
- */
11
- async function run() {
12
- let total = 0;
13
- let passed = 0;
14
- let failed = 0;
15
-
16
- console.log('开始测试 base.js...');
17
-
18
- // 测试 Base 类构造函数
19
- total++;
20
- try {
21
- const base = new Base({ name: 'test', version: '1.0.0' });
22
- if (base.config.name === 'test' && base.config.version === '1.0.0') {
23
- console.log('✅ Base 构造函数: 通过');
24
- passed++;
25
- } else {
26
- console.log('❌ Base 构造函数: 失败');
27
- failed++;
28
- }
29
- } catch (error) {
30
- console.log('❌ Base 构造函数: 异常 -', error.message);
31
- failed++;
32
- }
33
-
34
- // 测试 setConfig 方法
35
- total++;
36
- try {
37
- const base = new Base({ name: 'test' });
38
- base.setConfig({ version: '2.0.0', status: 'active' });
39
- if (base.config.version === '2.0.0' && base.config.status === 'active') {
40
- console.log('✅ Base.prototype.setConfig: 通过');
41
- passed++;
42
- } else {
43
- console.log('❌ Base.prototype.setConfig: 失败');
44
- failed++;
45
- }
46
- } catch (error) {
47
- console.log('❌ Base.prototype.setConfig: 异常 -', error.message);
48
- failed++;
49
- }
50
-
51
- // 测试 init 方法
52
- total++;
53
- try {
54
- const base = new Base({ name: 'test' });
55
- const result = await base.init('arg1', 'arg2');
56
- if (result === base) {
57
- console.log('✅ Base.prototype.init: 通过');
58
- passed++;
59
- } else {
60
- console.log('❌ Base.prototype.init: 失败');
61
- failed++;
62
- }
63
- } catch (error) {
64
- console.log('❌ Base.prototype.init: 异常 -', error.message);
65
- failed++;
66
- }
67
-
68
- console.log(`base.js 测试完成: 通过 ${passed}/${total} 个测试`);
69
-
70
- return {
71
- total,
72
- passed,
73
- failed
74
- };
75
- }
76
-
77
- module.exports = {
78
- run
79
- };
80
-
81
- // 如果直接运行此文件,则执行测试
82
- if (require.main === module) {
83
- run().then(result => {
84
- console.log('测试结果:', result);
85
- process.exit(result.failed > 0 ? 1 : 0);
86
- }).catch(console.error);
87
- }
@@ -1,185 +0,0 @@
1
- const { Card, Player, SanguoshaCompleteSystem } = require('./sanguosha_complete_system.js');
2
-
3
- /**
4
- * @description 全面测试三国杀系统
5
- */
6
- async function comprehensive_test() {
7
- console.log('=== 全面的三国杀系统测试 ===\n');
8
-
9
- // 创建玩家
10
- const liubei = new Player({
11
- id: 'p1',
12
- name: '刘备',
13
- hp: 4,
14
- max_hp: 4,
15
- hand_cards: [],
16
- position: 1
17
- });
18
-
19
- const caocao = new Player({
20
- id: 'p2',
21
- name: '曹操',
22
- hp: 4,
23
- max_hp: 4,
24
- hand_cards: [],
25
- position: 3
26
- });
27
-
28
- // 创建卡牌
29
- const attack_card = new Card({
30
- id: 'c1',
31
- name: '杀',
32
- type: 'attack',
33
- effect: 'damage',
34
- value: 1,
35
- range: 2
36
- });
37
-
38
- const heal_card = new Card({
39
- id: 'c2',
40
- name: '桃',
41
- type: 'basic',
42
- effect: 'heal',
43
- value: 1,
44
- range: 0
45
- });
46
-
47
- const draw_card = new Card({
48
- id: 'c3',
49
- name: '无中生有',
50
- type: 'magic',
51
- effect: 'draw',
52
- value: 2,
53
- range: 0
54
- });
55
-
56
- // 给玩家发牌
57
- liubei.addHandCard(attack_card);
58
- liubei.addHandCard(heal_card);
59
- liubei.addHandCard(draw_card);
60
-
61
- console.log('初始状态:');
62
- console.log('刘备手牌数量:', liubei.getHandCardCount());
63
- console.log('曹操手牌数量:', caocao.getHandCardCount());
64
- console.log('刘备血量:', liubei.config.hp);
65
- console.log('曹操血量:', caocao.config.hp);
66
-
67
- // 创建系统实例
68
- const system = new SanguoshaCompleteSystem({
69
- players: [liubei, caocao],
70
- cache_enabled: true,
71
- performance_monitoring: true
72
- });
73
-
74
- // 测试1: 普通攻击
75
- console.log('\n1. 普通攻击测试:');
76
- console.log('攻击前 - 曹操血量:', caocao.config.hp);
77
-
78
- try {
79
- const result1 = await system.useCard({
80
- card: attack_card,
81
- user: liubei,
82
- target: caocao
83
- });
84
-
85
- console.log('攻击后 - 曹操血量:', caocao.config.hp);
86
- console.log('使用结果:', result1);
87
- console.log('刘备手牌数量:', liubei.getHandCardCount());
88
- } catch (error) {
89
- console.error('攻击失败:', error.message);
90
- }
91
-
92
- // 测试2: 有效治疗测试(先让曹操受伤,然后刘备对自己治疗)
93
- console.log('\n2. 有效治疗测试:');
94
-
95
- // 先让曹操受伤
96
- caocao.config.hp = 2;
97
- console.log('曹操受伤后血量:', caocao.config.hp);
98
- console.log('治疗前 - 刘备血量:', liubei.config.hp);
99
-
100
- try {
101
- const result2 = await system.useCard({
102
- card: heal_card,
103
- user: liubei,
104
- target: liubei
105
- });
106
-
107
- console.log('治疗后 - 刘备血量:', liubei.config.hp);
108
- console.log('使用结果:', result2);
109
- console.log('刘备手牌数量:', liubei.getHandCardCount());
110
- } catch (error) {
111
- console.error('治疗失败:', error.message);
112
- }
113
-
114
- // 测试3: 抽牌效果测试
115
- console.log('\n3. 抽牌效果测试:');
116
- console.log('使用前 - 刘备手牌数量:', liubei.getHandCardCount());
117
-
118
- try {
119
- const result3 = await system.useCard({
120
- card: draw_card,
121
- user: liubei,
122
- target: liubei
123
- });
124
-
125
- console.log('使用后 - 刘备手牌数量:', liubei.getHandCardCount());
126
- console.log('使用结果:', result3);
127
- } catch (error) {
128
- console.error('抽牌失败:', error.message);
129
- }
130
-
131
- // 测试4: 距离测试
132
- console.log('\n4. 距离测试:');
133
- const distance = await system.calculateDistance(liubei, caocao);
134
- console.log('刘备到曹操的距离:', distance);
135
-
136
- // 测试5: 性能统计
137
- console.log('\n5. 性能统计:');
138
- const stats = system.getPerformanceStats();
139
- console.log('统计信息:', stats);
140
-
141
- console.log('\n=== 全面测试完成 ===');
142
- }
143
-
144
- /**
145
- * @description 运行全面测试
146
- * @returns {Object} 测试结果
147
- */
148
- async function run() {
149
- let total = 0;
150
- let passed = 0;
151
- let failed = 0;
152
-
153
- console.log('开始测试 comprehensive_test.js...');
154
-
155
- try {
156
- await comprehensive_test();
157
- console.log('✅ 全面测试: 通过');
158
- passed++;
159
- } catch (error) {
160
- console.log('❌ 全面测试: 失败 -', error.message);
161
- failed++;
162
- }
163
-
164
- total++;
165
-
166
- console.log(`comprehensive_test.js 测试完成: 通过 ${passed}/${total} 个测试`);
167
-
168
- return {
169
- total,
170
- passed,
171
- failed
172
- };
173
- }
174
-
175
- module.exports = {
176
- run
177
- };
178
-
179
- // 如果直接运行此文件,则执行测试
180
- if (require.main === module) {
181
- run().then(result => {
182
- console.log('测试结果:', result);
183
- process.exit(result.failed > 0 ? 1 : 0);
184
- }).catch(console.error);
185
- }