mm_expand 1.9.2 → 1.9.4
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 +134 -2
- package/README_EN.md +122 -2
- package/index.js +26 -3
- package/lib/array.js +202 -203
- package/lib/base.js +154 -44
- package/lib/date.js +28 -22
- package/lib/event.js +155 -0
- package/lib/eventer.js +858 -463
- package/lib/file.js +109 -81
- package/lib/global.js +26 -13
- package/lib/lang.js +69 -43
- package/lib/log.js +148 -0
- package/lib/number.js +15 -55
- package/lib/object.js +304 -290
- package/lib/string.js +314 -274
- package/lib/timer.js +11 -13
- package/package.json +5 -4
- package/test.js +0 -6
package/README.md
CHANGED
|
@@ -288,10 +288,28 @@ await $.sleep(2000, obj, 'ok');
|
|
|
288
288
|
- 描述:将时间戳转换为Date对象
|
|
289
289
|
- 返回值:Date对象
|
|
290
290
|
|
|
291
|
-
#### Number.prototype.
|
|
292
|
-
-
|
|
291
|
+
#### Number.prototype.toTimestamp()
|
|
292
|
+
- 描述:将时间戳转换为时间戳(兼容性方法)
|
|
293
293
|
- 返回值:时间戳数字
|
|
294
294
|
|
|
295
|
+
#### Number.prototype.toTimeStr(format)
|
|
296
|
+
- 描述:将时间戳格式化为时间字符串
|
|
297
|
+
- 参数:
|
|
298
|
+
- format: 时间格式字符串,默认'yyyy-MM-dd hh:mm:ss'
|
|
299
|
+
- 返回值:格式化后的时间字符串
|
|
300
|
+
|
|
301
|
+
#### Number.prototype.random(min)
|
|
302
|
+
- 描述:生成随机数
|
|
303
|
+
- 参数:
|
|
304
|
+
- min: 最小值,默认1
|
|
305
|
+
- 返回值:随机数
|
|
306
|
+
|
|
307
|
+
#### Number.prototype.randomRange(margin)
|
|
308
|
+
- 描述:生成指定范围内的随机数
|
|
309
|
+
- 参数:
|
|
310
|
+
- margin: 上下幅度,默认5
|
|
311
|
+
- 返回值:范围内的随机数
|
|
312
|
+
|
|
295
313
|
### Date原型拓展
|
|
296
314
|
|
|
297
315
|
#### Date.prototype.toStr(format)
|
|
@@ -398,6 +416,69 @@ await $.sleep(2000, obj, 'ok');
|
|
|
398
416
|
- 参数:同$.eventer.runParallel
|
|
399
417
|
- 返回值:包含执行结果和取消方法的对象
|
|
400
418
|
|
|
419
|
+
##### 异步事件触发
|
|
420
|
+
|
|
421
|
+
##### $.eventer.emitWait(eventName, ...args)
|
|
422
|
+
- 描述:异步触发事件,按顺序执行等待完成
|
|
423
|
+
- 参数:
|
|
424
|
+
- eventName: 事件名称(支持命名空间格式:namespace:event)
|
|
425
|
+
- ...args: 传递给事件处理器的参数
|
|
426
|
+
- 返回值:Promise,按优先级顺序执行所有监听器
|
|
427
|
+
- 示例:
|
|
428
|
+
```javascript
|
|
429
|
+
// 顺序执行用户登录事件的所有监听器
|
|
430
|
+
await $.eventer.emitWait('user:login', { id: 1, name: '张三' });
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
##### $.eventer.emitAsync(eventName, ...args)
|
|
434
|
+
- 描述:异步触发事件,并发执行不等待
|
|
435
|
+
- 参数:
|
|
436
|
+
- eventName: 事件名称(支持命名空间格式:namespace:event)
|
|
437
|
+
- ...args: 传递给事件处理器的参数
|
|
438
|
+
- 返回值:布尔值,表示是否有监听器被触发
|
|
439
|
+
- 示例:
|
|
440
|
+
```javascript
|
|
441
|
+
// 异步触发数据更新事件,不等待执行结果
|
|
442
|
+
$.eventer.emitAsync('data:update', { timestamp: Date.now() });
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
##### $.eventer.emitAll(eventName, ...args)
|
|
446
|
+
- 描述:异步触发事件,并发执行等待完成
|
|
447
|
+
- 参数:
|
|
448
|
+
- eventName: 事件名称(支持命名空间格式:namespace:event)
|
|
449
|
+
- ...args: 传递给事件处理器的参数
|
|
450
|
+
- 返回值:Promise<Array>,包含所有监听器的执行结果
|
|
451
|
+
- 示例:
|
|
452
|
+
```javascript
|
|
453
|
+
// 并发执行所有数据处理监听器,等待全部完成
|
|
454
|
+
const results = await $.eventer.emitAll('data:process', { items: [...] });
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
##### $.eventer.emitRace(eventName, ...args)
|
|
458
|
+
- 描述:异步触发事件,竞争执行(第一个完成即返回)
|
|
459
|
+
- 参数:
|
|
460
|
+
- eventName: 事件名称(支持命名空间格式:namespace:event)
|
|
461
|
+
- ...args: 传递给事件处理器的参数
|
|
462
|
+
- 返回值:Promise,第一个完成的监听器结果
|
|
463
|
+
- 示例:
|
|
464
|
+
```javascript
|
|
465
|
+
// 竞争执行多个缓存策略,使用第一个返回的结果
|
|
466
|
+
const fastestResult = await $.eventer.emitRace('cache:get', { key: 'user_data' });
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
##### $.eventer.emitWaterfall(eventName, initialValue, ...args)
|
|
470
|
+
- 描述:异步触发事件,瀑布流执行(前一个结果传递给下一个)
|
|
471
|
+
- 参数:
|
|
472
|
+
- eventName: 事件名称(支持命名空间格式:namespace:event)
|
|
473
|
+
- initialValue: 初始值
|
|
474
|
+
- ...args: 传递给事件处理器的参数
|
|
475
|
+
- 返回值:Promise,最后一个监听器的执行结果
|
|
476
|
+
- 示例:
|
|
477
|
+
```javascript
|
|
478
|
+
// 瀑布流处理数据,每个处理器接收前一个的结果
|
|
479
|
+
const finalResult = await $.eventer.emitWaterfall('data:pipeline', initialData, { stage: 'processing' });
|
|
480
|
+
```
|
|
481
|
+
|
|
401
482
|
##### 事件控制
|
|
402
483
|
|
|
403
484
|
##### $.eventer.pause(key)
|
|
@@ -539,3 +620,54 @@ A: 目前提供基本的JavaScript支持,TypeScript类型定义正在规划中
|
|
|
539
620
|
## 鸣谢
|
|
540
621
|
|
|
541
622
|
感谢所有为该项目做出贡献的开发者和用户!
|
|
623
|
+
|
|
624
|
+
## npm发布信息
|
|
625
|
+
|
|
626
|
+
### 发布状态
|
|
627
|
+
- **当前版本**: 1.9.3
|
|
628
|
+
- **npm包名**: mm_expand
|
|
629
|
+
- **发布状态**: 已准备发布
|
|
630
|
+
|
|
631
|
+
### 发布前检查清单
|
|
632
|
+
- ✅ 所有测试通过(87/87,100%通过率)
|
|
633
|
+
- ✅ 文档已更新
|
|
634
|
+
- ✅ 依赖项已正确配置
|
|
635
|
+
- ✅ 包信息完整
|
|
636
|
+
- ✅ 许可证文件存在
|
|
637
|
+
- ✅ 事件系统性能优化完成
|
|
638
|
+
|
|
639
|
+
### 发布命令
|
|
640
|
+
```bash
|
|
641
|
+
# 登录npm(如果尚未登录)
|
|
642
|
+
npm login
|
|
643
|
+
|
|
644
|
+
# 发布到npm
|
|
645
|
+
npm publish
|
|
646
|
+
|
|
647
|
+
# 如果发布后需要更新版本
|
|
648
|
+
npm version patch # 小版本更新
|
|
649
|
+
npm version minor # 次版本更新
|
|
650
|
+
npm version major # 主版本更新
|
|
651
|
+
npm publish # 发布新版本
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
### 版本管理
|
|
655
|
+
- 遵循语义化版本控制(Semantic Versioning)
|
|
656
|
+
- 主版本号:不兼容的API修改
|
|
657
|
+
- 次版本号:向下兼容的功能性新增
|
|
658
|
+
- 修订号:向下兼容的问题修正
|
|
659
|
+
|
|
660
|
+
### 维护指南
|
|
661
|
+
1. 每次修改后运行测试确保功能正常
|
|
662
|
+
2. 更新文档反映API变化
|
|
663
|
+
3. 提交代码前检查代码质量
|
|
664
|
+
4. 定期更新依赖项确保安全性
|
|
665
|
+
|
|
666
|
+
## 支持与反馈
|
|
667
|
+
|
|
668
|
+
如果您在使用过程中遇到问题或有改进建议,欢迎通过以下方式联系我们:
|
|
669
|
+
|
|
670
|
+
- **Gitee Issues**: [https://gitee.com/qiuwenwu91/mm_expand/issues](https://gitee.com/qiuwenwu91/mm_expand/issues)
|
|
671
|
+
- **Email**: 项目维护者邮箱
|
|
672
|
+
|
|
673
|
+
我们致力于持续改进这个库,您的反馈对我们非常重要!
|
package/README_EN.md
CHANGED
|
@@ -20,6 +20,32 @@ This library extends JavaScript native object prototypes with comprehensive data
|
|
|
20
20
|
- **Data Conversion Tools**: JSON, XML, URL parameters, and other format conversion functions
|
|
21
21
|
- **Lightweight and Efficient**: Core functions are lightweight with good performance optimization
|
|
22
22
|
- **Cross-Platform Compatibility**: Supports Node.js and modern browser environments
|
|
23
|
+
- **Sanguosha Card System**: Complete card game system with card management, character system, and battle mechanics
|
|
24
|
+
|
|
25
|
+
### Key Features
|
|
26
|
+
|
|
27
|
+
#### String Enhancement
|
|
28
|
+
- **$()** - String prototype function enhancement
|
|
29
|
+
- **Chinese Pinyin Processing** - Support Chinese to Pinyin, Pinyin initials
|
|
30
|
+
- **XML/JSON Conversion** - Support XML and JSON mutual conversion
|
|
31
|
+
- **String Formatting** - Support various formatting operations
|
|
32
|
+
|
|
33
|
+
#### Array Enhancement
|
|
34
|
+
- **Array Operations** - Support array CRUD, sorting, filtering, etc.
|
|
35
|
+
- **Array Conversion** - Support array to string, object conversion
|
|
36
|
+
|
|
37
|
+
#### Object Enhancement
|
|
38
|
+
- **Object Operations** - Support deep clone, merge, traversal, etc.
|
|
39
|
+
- **Object Validation** - Support object property validation and type checking
|
|
40
|
+
|
|
41
|
+
#### Date Enhancement
|
|
42
|
+
- **Date Formatting** - Support multiple date format outputs
|
|
43
|
+
- **Date Calculation** - Support date addition/subtraction, comparison
|
|
44
|
+
|
|
45
|
+
#### Event System
|
|
46
|
+
- **Event Listening** - Support asynchronous event listening and triggering
|
|
47
|
+
- **Event Priority** - Support event execution priority setting
|
|
48
|
+
- **Event Cancellation** - Support event execution cancellation mechanism
|
|
23
49
|
|
|
24
50
|
## Installation
|
|
25
51
|
|
|
@@ -288,10 +314,28 @@ await $.sleep(2000, obj, 'ok');
|
|
|
288
314
|
- Description: Convert timestamp to Date object
|
|
289
315
|
- Returns: Date object
|
|
290
316
|
|
|
291
|
-
#### Number.prototype.
|
|
292
|
-
- Description:
|
|
317
|
+
#### Number.prototype.toTimestamp()
|
|
318
|
+
- Description: Convert timestamp to timestamp (compatibility method)
|
|
293
319
|
- Returns: Timestamp number
|
|
294
320
|
|
|
321
|
+
#### Number.prototype.toTimeStr(format)
|
|
322
|
+
- Description: Format timestamp to time string
|
|
323
|
+
- Parameters:
|
|
324
|
+
- format: Time format string, default 'yyyy-MM-dd hh:mm:ss'
|
|
325
|
+
- Returns: Formatted time string
|
|
326
|
+
|
|
327
|
+
#### Number.prototype.random(min)
|
|
328
|
+
- Description: Generate random number
|
|
329
|
+
- Parameters:
|
|
330
|
+
- min: Minimum value, default 1
|
|
331
|
+
- Returns: Random number
|
|
332
|
+
|
|
333
|
+
#### Number.prototype.randomRange(margin)
|
|
334
|
+
- Description: Generate random number within specified range
|
|
335
|
+
- Parameters:
|
|
336
|
+
- margin: Range margin, default 5
|
|
337
|
+
- Returns: Random number within range
|
|
338
|
+
|
|
295
339
|
### Date Prototype Extensions
|
|
296
340
|
|
|
297
341
|
#### Date.prototype.toStr(format)
|
|
@@ -398,6 +442,69 @@ await $.sleep(2000, obj, 'ok');
|
|
|
398
442
|
- Parameters: Same as $.eventer.runParallel
|
|
399
443
|
- Returns: Object containing execution results and cancel method
|
|
400
444
|
|
|
445
|
+
##### Asynchronous Event Triggering
|
|
446
|
+
|
|
447
|
+
##### $.eventer.emitWait(eventName, ...args)
|
|
448
|
+
- Description: Asynchronously trigger events, execute sequentially and wait for completion
|
|
449
|
+
- Parameters:
|
|
450
|
+
- eventName: Event name (supports namespace format: namespace:event)
|
|
451
|
+
- ...args: Arguments passed to event handlers
|
|
452
|
+
- Returns: Promise, executes all listeners in priority order
|
|
453
|
+
- Example:
|
|
454
|
+
```javascript
|
|
455
|
+
// Execute all user login event listeners sequentially
|
|
456
|
+
await $.eventer.emitWait('user:login', { id: 1, name: 'John' });
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
##### $.eventer.emitAsync(eventName, ...args)
|
|
460
|
+
- Description: Asynchronously trigger events, execute concurrently without waiting
|
|
461
|
+
- Parameters:
|
|
462
|
+
- eventName: Event name (supports namespace format: namespace:event)
|
|
463
|
+
- ...args: Arguments passed to event handlers
|
|
464
|
+
- Returns: Boolean, indicates whether any listeners were triggered
|
|
465
|
+
- Example:
|
|
466
|
+
```javascript
|
|
467
|
+
// Asynchronously trigger data update event without waiting for results
|
|
468
|
+
$.eventer.emitAsync('data:update', { timestamp: Date.now() });
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
##### $.eventer.emitAll(eventName, ...args)
|
|
472
|
+
- Description: Asynchronously trigger events, execute concurrently and wait for completion
|
|
473
|
+
- Parameters:
|
|
474
|
+
- eventName: Event name (supports namespace format: namespace:event)
|
|
475
|
+
- ...args: Arguments passed to event handlers
|
|
476
|
+
- Returns: Promise<Array>, contains execution results of all listeners
|
|
477
|
+
- Example:
|
|
478
|
+
```javascript
|
|
479
|
+
// Execute all data processing listeners concurrently and wait for all to complete
|
|
480
|
+
const results = await $.eventer.emitAll('data:process', { items: [...] });
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
##### $.eventer.emitRace(eventName, ...args)
|
|
484
|
+
- Description: Asynchronously trigger events, race execution (returns first completed result)
|
|
485
|
+
- Parameters:
|
|
486
|
+
- eventName: Event name (supports namespace format: namespace:event)
|
|
487
|
+
- ...args: Arguments passed to event handlers
|
|
488
|
+
- Returns: Promise, result of the first completed listener
|
|
489
|
+
- Example:
|
|
490
|
+
```javascript
|
|
491
|
+
// Race execution of multiple cache strategies, use the first returned result
|
|
492
|
+
const fastestResult = await $.eventer.emitRace('cache:get', { key: 'user_data' });
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
##### $.eventer.emitWaterfall(eventName, initialValue, ...args)
|
|
496
|
+
- Description: Asynchronously trigger events, waterfall execution (pass result to next)
|
|
497
|
+
- Parameters:
|
|
498
|
+
- eventName: Event name (supports namespace format: namespace:event)
|
|
499
|
+
- initialValue: Initial value
|
|
500
|
+
- ...args: Arguments passed to event handlers
|
|
501
|
+
- Returns: Promise, result of the last listener
|
|
502
|
+
- Example:
|
|
503
|
+
```javascript
|
|
504
|
+
// Waterfall data processing, each handler receives the previous result
|
|
505
|
+
const finalResult = await $.eventer.emitWaterfall('data:pipeline', initialData, { stage: 'processing' });
|
|
506
|
+
```
|
|
507
|
+
|
|
401
508
|
##### Event Control
|
|
402
509
|
|
|
403
510
|
##### $.eventer.pause(key)
|
|
@@ -522,6 +629,19 @@ Welcome to submit Issues and Pull Requests! Please ensure your code follows thes
|
|
|
522
629
|
3. Write test cases to ensure functionality
|
|
523
630
|
4. Run tests before submitting to ensure no new issues are introduced
|
|
524
631
|
|
|
632
|
+
## Release Status
|
|
633
|
+
- **Current Version**: 1.9.3
|
|
634
|
+
- **npm Package Name**: mm_expand
|
|
635
|
+
- **Release Status**: Ready for release
|
|
636
|
+
|
|
637
|
+
### Pre-release Checklist
|
|
638
|
+
- ✅ All tests passed (87/87, 100% pass rate)
|
|
639
|
+
- ✅ Documentation updated
|
|
640
|
+
- ✅ Dependencies correctly configured
|
|
641
|
+
- ✅ Package information complete
|
|
642
|
+
- ✅ License file exists
|
|
643
|
+
- ✅ Event system performance optimization completed
|
|
644
|
+
|
|
525
645
|
## Changelog
|
|
526
646
|
|
|
527
647
|
Detailed changelog can be found on the project's [Release page](https://gitee.com/qiuwenwu91/mm_expand/releases).
|
package/index.js
CHANGED
|
@@ -15,12 +15,33 @@ require('./lib/array.js');
|
|
|
15
15
|
// 日期原型函数
|
|
16
16
|
require('./lib/date.js');
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
// 确保原型方法被应用到全局原型
|
|
19
|
+
const numberModule = require('./lib/number.js');
|
|
20
|
+
const stringModule = require('./lib/string.js');
|
|
21
|
+
const arrayModule = require('./lib/array.js');
|
|
22
|
+
const dateModule = require('./lib/date.js');
|
|
23
|
+
|
|
24
|
+
// 应用原型方法到全局原型
|
|
25
|
+
if (global.Number && numberModule.Number) {
|
|
26
|
+
Object.assign(global.Number.prototype, numberModule.Number.prototype);
|
|
27
|
+
}
|
|
28
|
+
if (global.String && stringModule.String) {
|
|
29
|
+
Object.assign(global.String.prototype, stringModule.String.prototype);
|
|
30
|
+
}
|
|
31
|
+
if (global.Array && arrayModule.Array) {
|
|
32
|
+
Object.assign(global.Array.prototype, arrayModule.Array.prototype);
|
|
33
|
+
}
|
|
34
|
+
if (global.Date && dateModule.Date) {
|
|
35
|
+
Object.assign(global.Date.prototype, dateModule.Date.prototype);
|
|
36
|
+
}
|
|
37
|
+
|
|
19
38
|
var { File, Dir } = require('./lib/file.js');
|
|
39
|
+
var { Obj } = require('./lib/object.js');
|
|
40
|
+
var { Log } = require('./lib/log.js');
|
|
41
|
+
var { Eventer } = require('./lib/eventer.js');
|
|
20
42
|
var { Lang } = require('./lib/lang.js');
|
|
21
|
-
var { Timer } = require('./lib/timer.js');
|
|
22
43
|
var { Base } = require('./lib/base.js');
|
|
23
|
-
var {
|
|
44
|
+
var { Timer } = require('./lib/timer.js');
|
|
24
45
|
|
|
25
46
|
if (global.$ && !$.is_init) {
|
|
26
47
|
Object.assign($, Obj, {
|
|
@@ -34,6 +55,8 @@ if (global.$ && !$.is_init) {
|
|
|
34
55
|
eventer: new Eventer(),
|
|
35
56
|
// 定时器类
|
|
36
57
|
timer: new Timer(),
|
|
58
|
+
// 日志类
|
|
59
|
+
log: new Log(),
|
|
37
60
|
// 语言包类
|
|
38
61
|
lang: new Lang({
|
|
39
62
|
zh_cn: {
|