mm_expand 1.9.9 → 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.
Files changed (52) hide show
  1. package/README.md +39 -2
  2. package/README_EN.md +74 -6
  3. package/index.js +55 -54
  4. package/lib/array.js +818 -587
  5. package/lib/base.js +581 -303
  6. package/lib/date.js +54 -53
  7. package/lib/event.js +97 -93
  8. package/lib/eventer.js +1988 -1416
  9. package/lib/file.js +447 -389
  10. package/lib/global.js +270 -132
  11. package/lib/lang.js +382 -345
  12. package/lib/logger.js +111 -95
  13. package/lib/number.js +29 -29
  14. package/lib/object.js +1289 -624
  15. package/lib/string.js +429 -368
  16. package/lib/timer.js +265 -104
  17. package/lib/validator.js +1277 -1151
  18. package/package.json +30 -5
  19. package/.gitattributes +0 -5
  20. package/script.js +0 -1
  21. package/test/array_test.js +0 -167
  22. package/test/base_test.js +0 -87
  23. package/test/chain_validation_test.js +0 -223
  24. package/test/comprehensive_test.js +0 -185
  25. package/test/date_test.js +0 -124
  26. package/test/debug_test.js +0 -110
  27. package/test/detailed_test.js +0 -154
  28. package/test/doEasy_test.js +0 -192
  29. package/test/event_test.js +0 -112
  30. package/test/eventer_async_test.js +0 -173
  31. package/test/eventer_test.js +0 -395
  32. package/test/file_test.js +0 -104
  33. package/test/game_damage_system.js +0 -533
  34. package/test/global_test.js +0 -115
  35. package/test/index.js +0 -61
  36. package/test/lang_test.js +0 -118
  37. package/test/log_test.js +0 -103
  38. package/test/number_test.js +0 -140
  39. package/test/object_test.js +0 -106
  40. package/test/optimized_performance_test.js +0 -192
  41. package/test/performance_test.js +0 -211
  42. package/test/sanguosha_card_system.js +0 -491
  43. package/test/sanguosha_complete_system.js +0 -912
  44. package/test/sanguosha_event_model.js +0 -500
  45. package/test/sanguosha_optimization.js +0 -432
  46. package/test/simple_sanguosha_test.js +0 -88
  47. package/test/simple_test.js +0 -88
  48. package/test/string_test.js +0 -141
  49. package/test/test.txt +0 -1
  50. package/test/timer_test.js +0 -103
  51. package/test/validator_test.js +0 -1693
  52. package/test.js +0 -618
package/README.md CHANGED
@@ -11,6 +11,24 @@ mm_expand 是一个功能丰富的 JavaScript 工具库,为原生类型(Stri
11
11
 
12
12
  这个库通过扩展 JavaScript 原生对象的原型链,提供了丰富的数据操作方法,使开发者能够用更简洁的代码处理常见的数据操作任务。同时,它还包含了强大的事件系统、文件操作工具和对象处理功能,适用于各种 JavaScript 应用场景。
13
13
 
14
+ ### 最新功能更新(v1.9.9)
15
+
16
+ #### ECS架构支持
17
+ - **组件操作增强**:新增 `add`、`set`、`del`、`get` 方法,专门为游戏ECS(Entity Component System)架构设计
18
+ - **路径支持**:支持点分隔符和数组路径访问嵌套属性
19
+ - **覆盖控制**:所有方法支持 `overwrite` 参数,控制是否修改原对象
20
+ - **默认值补全**:`get` 方法支持对象默认值补全,确保组件属性完整性
21
+
22
+ #### 对象操作增强
23
+ - **Object.prototype扩展**:为所有对象添加原型方法,包括 `keys`、`getInfo`、`add`、`del`、`set`、`get` 等
24
+ - **类型安全**:所有方法都包含严格的参数校验和错误处理
25
+ - **深度操作**:支持深层嵌套对象的操作和遍历
26
+
27
+ #### 代码质量提升
28
+ - **ESLint合规**:所有代码符合ESLint规范,确保代码质量
29
+ - **函数优化**:重构长函数,降低复杂度,提高可维护性
30
+ - **测试覆盖**:完整的测试套件,确保功能稳定性
31
+
14
32
  ## 特点
15
33
 
16
34
  - **原生类型扩展**:为 String、Array、Number、Date 等原生类型提供丰富的原型方法
@@ -94,6 +112,25 @@ $.eventer.runParallel('data:process', { items: [...] });
94
112
  // 暂停和恢复事件
95
113
  $.eventer.pause('user:*'); // 暂停所有用户相关事件
96
114
  $.eventer.resume('user:*'); // 恢复所有用户相关事件
115
+
116
+ // ECS架构组件操作示例
117
+ const entity = { position: { x: 0, y: 0 }, health: 100 };
118
+
119
+ // 添加组件属性
120
+ entity.add({ velocity: { x: 1, y: 0 } });
121
+
122
+ // 设置组件值(类型转换)
123
+ entity.set({ health: '150' }); // 自动转换为数字类型
124
+
125
+ // 删除组件属性
126
+ entity.del('velocity.x');
127
+
128
+ // 获取组件(支持默认值补全)
129
+ const position = entity.get('position', { x: 0, y: 0, z: 0 });
130
+ // 返回 { x: 0, y: 0, z: 0 },补全了缺失的z属性
131
+
132
+ // 使用路径访问嵌套属性
133
+ const x = entity.get('position.x'); // 返回 0
97
134
  ```
98
135
 
99
136
  ## 模块导出
@@ -635,7 +672,7 @@ const finalResult = await $.eventer.emitWaterfall('data:pipeline', initialData,
635
672
 
636
673
  ### 代码执行
637
674
 
638
- #### $.run_code(code, cm, em, qm, rm)
675
+ #### $.runCode(code, cm, em, qm, rm)
639
676
  - 描述:执行动态代码
640
677
  - 参数:
641
678
  - code: 要执行的代码字符串
@@ -733,7 +770,7 @@ A: 目前提供基本的JavaScript支持,TypeScript类型定义正在规划中
733
770
  ## npm发布信息
734
771
 
735
772
  ### 发布状态
736
- - **当前版本**: 1.9.6
773
+ - **当前版本**: 1.9.9
737
774
  - **npm包名**: mm_expand
738
775
  - **发布状态**: 已准备发布
739
776
 
package/README_EN.md CHANGED
@@ -11,6 +11,24 @@ A comprehensive JavaScript utility library that extends native prototypes (Strin
11
11
 
12
12
  This library extends JavaScript native object prototypes with comprehensive data operation methods, enabling developers to handle common data manipulation tasks with more concise code. It also includes a powerful event system, file operation tools, and object processing functions, making it suitable for various JavaScript application scenarios.
13
13
 
14
+ ### Latest Features Update (v1.9.9)
15
+
16
+ #### ECS Architecture Support
17
+ - **Enhanced Component Operations**: New `add`, `set`, `del`, `get` methods specifically designed for game ECS (Entity Component System) architecture
18
+ - **Path Support**: Support for dot-separated and array paths to access nested properties
19
+ - **Overwrite Control**: All methods support `overwrite` parameter to control whether to modify the original object
20
+ - **Default Value Completion**: `get` method supports object default value completion to ensure component property integrity
21
+
22
+ #### Enhanced Object Operations
23
+ - **Object.prototype Extensions**: Added prototype methods for all objects including `keys`, `getInfo`, `add`, `del`, `set`, `get`, etc.
24
+ - **Type Safety**: All methods include strict parameter validation and error handling
25
+ - **Deep Operations**: Support for deep nested object operations and traversal
26
+
27
+ #### Code Quality Improvements
28
+ - **ESLint Compliance**: All code conforms to ESLint standards ensuring code quality
29
+ - **Function Optimization**: Refactored long functions to reduce complexity and improve maintainability
30
+ - **Test Coverage**: Complete test suite ensuring functional stability
31
+
14
32
  ## Features
15
33
 
16
34
  - **Native Type Extension**: Rich prototype methods for native types like String, Array, Number, Date, etc.
@@ -120,6 +138,25 @@ $.eventer.runParallel('data:process', { items: [...] });
120
138
  // Pause and resume events
121
139
  $.eventer.pause('user:*'); // Pause all user-related events
122
140
  $.eventer.resume('user:*'); // Resume all user-related events
141
+
142
+ // ECS Architecture Component Operations Example
143
+ const entity = { position: { x: 0, y: 0 }, health: 100 };
144
+
145
+ // Add component properties
146
+ entity.add({ velocity: { x: 1, y: 0 } });
147
+
148
+ // Set component values (type conversion)
149
+ entity.set({ health: '150' }); // Automatically converts to number type
150
+
151
+ // Delete component properties
152
+ entity.del('velocity.x');
153
+
154
+ // Get component (supports default value completion)
155
+ const position = entity.get('position', { x: 0, y: 0, z: 0 });
156
+ // Returns { x: 0, y: 0, z: 0 }, completing the missing z property
157
+
158
+ // Use path to access nested properties
159
+ const x = entity.get('position.x'); // Returns 0
123
160
  ```
124
161
 
125
162
  ## Module Exports
@@ -661,7 +698,7 @@ const finalResult = await $.eventer.emitWaterfall('data:pipeline', initialData,
661
698
 
662
699
  ### Code Execution
663
700
 
664
- #### $.run_code(code, cm, em, qm, rm)
701
+ #### $.runCode(code, cm, em, qm, rm)
665
702
  - Description: Execute dynamic code
666
703
  - Parameters:
667
704
  - code: Code string to execute
@@ -738,18 +775,49 @@ Welcome to submit Issues and Pull Requests! Please ensure your code follows thes
738
775
  3. Write test cases to ensure functionality
739
776
  4. Run tests before submitting to ensure no new issues are introduced
740
777
 
741
- ## Release Status
742
- - **Current Version**: 1.9.6
778
+ ## npm Publishing Information
779
+
780
+ ### Release Status
781
+ - **Current Version**: 1.9.9
743
782
  - **npm Package Name**: mm_expand
744
- - **Release Status**: Ready for release
783
+ - **Release Status**: Ready for publishing
745
784
 
746
785
  ### Pre-release Checklist
747
786
  - ✅ All tests passed (87/87, 100% pass rate)
748
- - ✅ Documentation updated
787
+ - ✅ Documentation updated with latest features
749
788
  - ✅ Dependencies correctly configured
750
789
  - ✅ Package information complete
751
790
  - ✅ License file exists
752
- - ✅ Event system performance optimization completed
791
+ - ✅ ESLint compliance verified
792
+ - ✅ ECS architecture support implemented
793
+ - ✅ Object.prototype extensions completed
794
+
795
+ ### Publishing Commands
796
+ ```bash
797
+ # Login to npm (if not already logged in)
798
+ npm login
799
+
800
+ # Publish to npm
801
+ npm publish
802
+
803
+ # If you need to update version after publishing
804
+ npm version patch # Patch version update
805
+ npm version minor # Minor version update
806
+ npm version major # Major version update
807
+ npm publish # Publish new version
808
+ ```
809
+
810
+ ### Version Management
811
+ - Follows Semantic Versioning (SemVer)
812
+ - Major version: Incompatible API changes
813
+ - Minor version: Backward-compatible functionality additions
814
+ - Patch version: Backward-compatible bug fixes
815
+
816
+ ### Maintenance Guidelines
817
+ 1. Run tests after each modification to ensure functionality
818
+ 2. Update documentation to reflect API changes
819
+ 3. Check code quality before committing code
820
+ 4. Regularly update dependencies to ensure security
753
821
 
754
822
  ## Changelog
755
823
 
package/index.js CHANGED
@@ -24,61 +24,62 @@ var { Base } = require('./lib/base.js');
24
24
  var { Timer } = require('./lib/timer.js');
25
25
  var { Validator, validator } = require('./lib/validator.js');
26
26
 
27
-
27
+ // 初始化$对象
28
28
  if (global.$ && !$.is_init) {
29
- Object.assign($, require('./lib/object.js'), {
30
- // 验证器类
31
- validator,
32
- // 事件驱动类
33
- eventer,
34
- // 日志类
35
- logger: new Logger(),
36
- // 文件类
37
- file: new File(),
38
- // 目录类
39
- dir: new Dir(),
40
- // 定时器类
41
- timer: new Timer(),
42
- // 语言包类
43
- lang: new Lang({
44
- zh_cn: {
45
- name: "超级美眉"
46
- },
47
- en: {
48
- name: "MM"
49
- }
50
- }),
51
- // 基础类
52
- Base,
53
- // 事件类
54
- Event
55
- });
56
- $.is_init = true;
29
+ Object.assign($, require('./lib/object.js'), {
30
+ // 验证器类
31
+ validator,
32
+ // 事件驱动类
33
+ eventer,
34
+ // 日志类
35
+ log: new Logger(),
36
+ // 文件类
37
+ file: new File(),
38
+ // 目录类
39
+ dir: new Dir(),
40
+ // 定时器类
41
+ timer: new Timer(),
42
+ // 语言包类
43
+ lang: new Lang({
44
+ zh_cn: {
45
+ name: '超级美眉'
46
+ },
47
+ en: {
48
+ name: 'MM'
49
+ }
50
+ }),
51
+ // 基础类
52
+ Base,
53
+ // 事件类
54
+ Event
55
+ });
56
+
57
+ $.is_init = true;
57
58
  }
58
59
 
59
60
  module.exports = {
60
- // 全局对象
61
- $: global.$,
62
- // 验证器类
63
- Validator,
64
- // 事件类
65
- Event,
66
- // 事件驱动类
67
- Eventer,
68
- // 定时器类
69
- Timer,
70
- // 日志类
71
- Logger,
72
- // 语言包类
73
- Lang,
74
- // 基础类
75
- Base,
76
- // 文件类
77
- File,
78
- // 目录类
79
- Dir,
80
- // 验证器实例
81
- validator,
82
- // 事件驱动实例
83
- eventer
84
- }
61
+ // 全局对象
62
+ $: global.$,
63
+ // 验证器类
64
+ Validator,
65
+ // 事件类
66
+ Event,
67
+ // 事件驱动类
68
+ Eventer,
69
+ // 定时器类
70
+ Timer,
71
+ // 日志类
72
+ Logger,
73
+ // 语言包类
74
+ Lang,
75
+ // 基础类
76
+ Base,
77
+ // 文件类
78
+ File,
79
+ // 目录类
80
+ Dir,
81
+ // 验证器实例
82
+ validator,
83
+ // 事件驱动实例
84
+ eventer
85
+ };