@zhongguo168a/yxeditor-common 0.0.99 → 0.0.100

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/dist/index.d.ts CHANGED
@@ -900,6 +900,13 @@ declare class List<T = any> {
900
900
  * @param target
901
901
  */
902
902
  random(count: number, enableRepeat?: boolean, target?: List<T>): List<T>;
903
+ /**
904
+ * 随机获取【count】个项,并返回【target】对象
905
+ * @param count
906
+ * @param enableRepeat 允许重复
907
+ * @param target
908
+ */
909
+ randomOne(): T;
903
910
  protected callPush(value: any): void;
904
911
  protected callRemove(value: any): void;
905
912
  protected _data: any[];
package/dist/index.esm.js CHANGED
@@ -3430,6 +3430,10 @@ class List {
3430
3430
  if (!target) {
3431
3431
  target = new List();
3432
3432
  }
3433
+ let data = this._data;
3434
+ if (data.length <= 0) {
3435
+ return target;
3436
+ }
3433
3437
  const copyItems = [...this._data]; // 创建副本以避免修改原数组
3434
3438
  for (let i = 0; i < count && copyItems.length > 0; i++) {
3435
3439
  const randomIndex = Math.floor(Math.random() * copyItems.length);
@@ -3440,6 +3444,20 @@ class List {
3440
3444
  }
3441
3445
  return target;
3442
3446
  }
3447
+ /**
3448
+ * 随机获取【count】个项,并返回【target】对象
3449
+ * @param count
3450
+ * @param enableRepeat 允许重复
3451
+ * @param target
3452
+ */
3453
+ randomOne() {
3454
+ let data = this._data;
3455
+ if (data.length <= 0) {
3456
+ return null;
3457
+ }
3458
+ const randomIndex = Math.floor(Math.random() * data.length);
3459
+ return data[randomIndex];
3460
+ }
3443
3461
  callPush(value) {
3444
3462
  if (this._onSet !== null) {
3445
3463
  this._onSet.call(this._onSetCaller, value);