@zwa73/utils 1.0.93 → 1.0.96

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.
@@ -1,2 +1,2 @@
1
1
  import { UtilFunc } from "./UtilFunctions";
2
- export declare const outcome: typeof UtilFunc.outcome, matchProc: typeof UtilFunc.matchProc, sucesProc: typeof UtilFunc.sucesProc, isFailed: typeof UtilFunc.isFailed, isSafeNumber: typeof UtilFunc.isSafeNumber, isSuccess: typeof UtilFunc.isSuccess, likeNone: typeof UtilFunc.likeNone, expect: typeof UtilFunc.expect, assertType: typeof UtilFunc.assertType, assertLiteral: typeof UtilFunc.assertLiteral, deepClone: typeof UtilFunc.deepClone, sleep: typeof UtilFunc.sleep, stringifyJToken: typeof UtilFunc.stringifyJToken, getTime: typeof UtilFunc.getTime, mapEntries: typeof UtilFunc.mapEntries, composeMixinable: typeof UtilFunc.composeMixinable;
2
+ export declare const outcome: typeof UtilFunc.outcome, matchProc: typeof UtilFunc.matchProc, sucesProc: typeof UtilFunc.sucesProc, isFailed: typeof UtilFunc.isFailed, isSafeNumber: typeof UtilFunc.isSafeNumber, isSuccess: typeof UtilFunc.isSuccess, likeNone: typeof UtilFunc.likeNone, expect: typeof UtilFunc.expect, assertType: typeof UtilFunc.assertType, assertLiteral: typeof UtilFunc.assertLiteral, deepClone: typeof UtilFunc.deepClone, sleep: typeof UtilFunc.sleep, stringifyJToken: typeof UtilFunc.stringifyJToken, getTime: typeof UtilFunc.getTime, mapEntries: typeof UtilFunc.mapEntries, composeMixinable: typeof UtilFunc.composeMixinable, dedent: typeof UtilFunc.dedent;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.composeMixinable = exports.mapEntries = exports.getTime = exports.stringifyJToken = exports.sleep = exports.deepClone = exports.assertLiteral = exports.assertType = exports.expect = exports.likeNone = exports.isSuccess = exports.isSafeNumber = exports.isFailed = exports.sucesProc = exports.matchProc = exports.outcome = void 0;
3
+ exports.dedent = exports.composeMixinable = exports.mapEntries = exports.getTime = exports.stringifyJToken = exports.sleep = exports.deepClone = exports.assertLiteral = exports.assertType = exports.expect = exports.likeNone = exports.isSuccess = exports.isSafeNumber = exports.isFailed = exports.sucesProc = exports.matchProc = exports.outcome = void 0;
4
4
  const UtilFunctions_1 = require("./UtilFunctions");
5
5
  const UtilSymbol_1 = require("./UtilSymbol");
6
- exports.outcome = UtilFunctions_1.UtilFunc.outcome, exports.matchProc = UtilFunctions_1.UtilFunc.matchProc, exports.sucesProc = UtilFunctions_1.UtilFunc.sucesProc, exports.isFailed = UtilFunctions_1.UtilFunc.isFailed, exports.isSafeNumber = UtilFunctions_1.UtilFunc.isSafeNumber, exports.isSuccess = UtilFunctions_1.UtilFunc.isSuccess, exports.likeNone = UtilFunctions_1.UtilFunc.likeNone, exports.expect = UtilFunctions_1.UtilFunc.expect, exports.assertType = UtilFunctions_1.UtilFunc.assertType, exports.assertLiteral = UtilFunctions_1.UtilFunc.assertLiteral, exports.deepClone = UtilFunctions_1.UtilFunc.deepClone, exports.sleep = UtilFunctions_1.UtilFunc.sleep, exports.stringifyJToken = UtilFunctions_1.UtilFunc.stringifyJToken, exports.getTime = UtilFunctions_1.UtilFunc.getTime, exports.mapEntries = UtilFunctions_1.UtilFunc.mapEntries, exports.composeMixinable = UtilFunctions_1.UtilFunc.composeMixinable;
6
+ exports.outcome = UtilFunctions_1.UtilFunc.outcome, exports.matchProc = UtilFunctions_1.UtilFunc.matchProc, exports.sucesProc = UtilFunctions_1.UtilFunc.sucesProc, exports.isFailed = UtilFunctions_1.UtilFunc.isFailed, exports.isSafeNumber = UtilFunctions_1.UtilFunc.isSafeNumber, exports.isSuccess = UtilFunctions_1.UtilFunc.isSuccess, exports.likeNone = UtilFunctions_1.UtilFunc.likeNone, exports.expect = UtilFunctions_1.UtilFunc.expect, exports.assertType = UtilFunctions_1.UtilFunc.assertType, exports.assertLiteral = UtilFunctions_1.UtilFunc.assertLiteral, exports.deepClone = UtilFunctions_1.UtilFunc.deepClone, exports.sleep = UtilFunctions_1.UtilFunc.sleep, exports.stringifyJToken = UtilFunctions_1.UtilFunc.stringifyJToken, exports.getTime = UtilFunctions_1.UtilFunc.getTime, exports.mapEntries = UtilFunctions_1.UtilFunc.mapEntries, exports.composeMixinable = UtilFunctions_1.UtilFunc.composeMixinable, exports.dedent = UtilFunctions_1.UtilFunc.dedent;
7
7
  if (false) {
8
8
  let aaser = (0, exports.assertLiteral)({ a: 1 });
9
9
  let a = null;
@@ -172,5 +172,22 @@ export declare class UtilFunc {
172
172
  static bindTo<K extends Keyable, V, B extends {} = {}>(key: LiteralCheck<K>, value: V, base?: B): keyof B extends K ? "Base中已有对应键" & Error : {
173
173
  [P in K | keyof B]: P extends K ? V : P extends keyof B ? B[P] : never;
174
174
  };
175
+ /**移除多行字符串中每行开始的最小空格数。
176
+ *
177
+ * @param strings - 需要处理的多行字符串模板。
178
+ * @param trim - 是否移除字符串开始和结束的空格。
179
+ * @returns - 返回处理后的字符串,每行开始的空格数已被最小化。
180
+ *
181
+ * @example
182
+ * const str = dedent`
183
+ * Hello,
184
+ * World!
185
+ * `;
186
+ * console.log(str);
187
+ * // 输出:
188
+ * // Hello,
189
+ * // World!
190
+ */
191
+ static dedent(strings: TemplateStringsArray, trim?: boolean): string;
175
192
  }
176
193
  export {};
@@ -494,6 +494,29 @@ class UtilFunc {
494
494
  out[key] = value;
495
495
  return out;
496
496
  }
497
+ /**移除多行字符串中每行开始的最小空格数。
498
+ *
499
+ * @param strings - 需要处理的多行字符串模板。
500
+ * @param trim - 是否移除字符串开始和结束的空格。
501
+ * @returns - 返回处理后的字符串,每行开始的空格数已被最小化。
502
+ *
503
+ * @example
504
+ * const str = dedent`
505
+ * Hello,
506
+ * World!
507
+ * `;
508
+ * console.log(str);
509
+ * // 输出:
510
+ * // Hello,
511
+ * // World!
512
+ */
513
+ static dedent(strings, trim = true) {
514
+ const str = strings.join('');
515
+ const lines = str.split('\n');
516
+ const minIndent = Math.min(...lines.filter(line => line.trim() !== '').map(line => line.search(/\S/)));
517
+ const result = lines.map(line => line.slice(minIndent)).join('\n');
518
+ return trim ? result.trim() : result;
519
+ }
497
520
  }
498
521
  exports.UtilFunc = UtilFunc;
499
522
  __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.93",
3
+ "version": "1.0.96",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -18,7 +18,8 @@ export const {
18
18
  stringifyJToken,
19
19
  getTime,
20
20
  mapEntries,
21
- composeMixinable
21
+ composeMixinable,
22
+ dedent,
22
23
  } = UtilFunc;
23
24
 
24
25
  if(false){
@@ -559,5 +559,30 @@ static bindTo<K extends Keyable, V, B extends {} = {}>
559
559
  out[key]=value;
560
560
  return out;
561
561
  }
562
+ /**移除多行字符串中每行开始的最小空格数。
563
+ *
564
+ * @param strings - 需要处理的多行字符串模板。
565
+ * @param trim - 是否移除字符串开始和结束的空格。
566
+ * @returns - 返回处理后的字符串,每行开始的空格数已被最小化。
567
+ *
568
+ * @example
569
+ * const str = dedent`
570
+ * Hello,
571
+ * World!
572
+ * `;
573
+ * console.log(str);
574
+ * // 输出:
575
+ * // Hello,
576
+ * // World!
577
+ */
578
+ static dedent(strings: TemplateStringsArray, trim = true): string {
579
+ const str = strings.join('');
580
+ const lines = str.split('\n');
581
+ const minIndent = Math.min(
582
+ ...lines.filter(line => line.trim() !== '').map(line => line.search(/\S/))
583
+ );
584
+ const result = lines.map(line => line.slice(minIndent)).join('\n');
585
+ return trim ? result.trim() : result;
586
+ }
562
587
 
563
588
  }