xshell 1.2.43 → 1.2.44

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.2.43",
3
+ "version": "1.2.44",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -170,7 +170,9 @@ declare global {
170
170
  last: T;
171
171
  indent(this: string[], width?: number, c?: string): string[];
172
172
  /** 对数组中所有元素求和 (+), 返回结果,可传入 mapper 计算出某个值,用作求和 */
173
- sum<TReturn = T>(this: T[], mapper?: keyof T | Mapper<T>): TReturn;
173
+ sum<TKey extends keyof T>(this: T[], zero: T[TKey], mapper: TKey): T[TKey];
174
+ sum<TMapper extends Mapper<T>>(this: T[], zero: ReturnType<TMapper>, mapper: TMapper): ReturnType<TMapper>;
175
+ sum<TReturn = T>(this: T[], zero: TReturn, mapper?: keyof T | Mapper<T>): TReturn;
174
176
  /** 查找数组中最大的元素,可传入 mapper 计算出某个值,用作大小比较 */
175
177
  max(this: T[], mapper?: keyof T | Mapper<T>): T;
176
178
  /** 查找数组中最小的元素,可传入 mapper 计算出某个值,用作大小比较 */
@@ -501,17 +501,17 @@ Object.defineProperties(Array.prototype, {
501
501
  const indent = character.repeat(width);
502
502
  return this.map(line => indent + line);
503
503
  },
504
- sum(mapper) {
504
+ sum(zero, mapper) {
505
505
  if (!this.length)
506
506
  return undefined;
507
507
  // 快捷路径
508
508
  const first = this[0];
509
509
  if ((typeof first === 'number' || typeof first === 'bigint') && !mapper)
510
- return this.reduce((acc, x) => acc + x, first);
510
+ return this.reduce((acc, x) => acc + x, zero);
511
511
  if (is_key_type(mapper))
512
512
  mapper = build_mapper(mapper);
513
513
  mapper ??= ident;
514
- return this.reduce((acc, x) => acc + mapper(x), mapper(first));
514
+ return this.reduce((acc, x) => acc + mapper(x), zero);
515
515
  },
516
516
  max(mapper = ident) {
517
517
  if (!this.length)
package/prototype.d.ts CHANGED
@@ -195,7 +195,9 @@ declare global {
195
195
  indent(this: string[], width?: number, c?: string): string[];
196
196
  indent2to4(this: string[]): string[];
197
197
  /** 对数组中所有元素求和 (+), 返回结果,可传入 mapper 计算出某个值,用作求和 */
198
- sum<TReturn = T>(this: T[], mapper?: keyof T | Mapper<T>): TReturn;
198
+ sum<TKey extends keyof T>(this: T[], zero: T[TKey], mapper: TKey): T[TKey];
199
+ sum<TMapper extends Mapper<T>>(this: T[], zero: ReturnType<TMapper>, mapper: TMapper): ReturnType<TMapper>;
200
+ sum<TReturn = T>(this: T[], zero: TReturn, mapper?: keyof T | Mapper<T>): TReturn;
199
201
  /** 查找数组中最大的元素,可传入 mapper 计算出某个值,用作大小比较 */
200
202
  max(this: T[], mapper?: keyof T | Mapper<T>): T;
201
203
  /** 查找数组中最小的元素,可传入 mapper 计算出某个值,用作大小比较 */
package/prototype.js CHANGED
@@ -574,17 +574,17 @@ if (!globalThis.my_prototype_defined) {
574
574
  return this.split_indents()
575
575
  .map(line => ' '.repeat(line.indent * 2) + line.text);
576
576
  },
577
- sum(mapper) {
577
+ sum(zero, mapper) {
578
578
  if (!this.length)
579
579
  return undefined;
580
580
  // 快捷路径
581
581
  const first = this[0];
582
582
  if ((typeof first === 'number' || typeof first === 'bigint') && !mapper)
583
- return this.reduce((acc, x) => acc + x, first);
583
+ return this.reduce((acc, x) => acc + x, zero);
584
584
  if (is_key_type(mapper))
585
585
  mapper = build_mapper(mapper);
586
586
  mapper ??= ident;
587
- return this.reduce((acc, x) => acc + mapper(x), mapper(first));
587
+ return this.reduce((acc, x) => acc + mapper(x), zero);
588
588
  },
589
589
  max(mapper = ident) {
590
590
  if (!this.length)