@zwa73/utils 1.0.94 → 1.0.97

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,23 @@ 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 values - 插入模板字符串中的值。
179
+ * @returns 返回处理后的字符串,每行开始的空格数已被最小化。
180
+ *
181
+ * @example
182
+ * const name = 'World';
183
+ * const str = dedent`
184
+ * Hello,
185
+ * ${name}!
186
+ * `;
187
+ * console.log(str);
188
+ * // 输出:
189
+ * // Hello,
190
+ * // World!
191
+ */
192
+ static dedent(strings: TemplateStringsArray, ...values: any[]): string;
175
193
  }
176
194
  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 values - 插入模板字符串中的值。
501
+ * @returns 返回处理后的字符串,每行开始的空格数已被最小化。
502
+ *
503
+ * @example
504
+ * const name = 'World';
505
+ * const str = dedent`
506
+ * Hello,
507
+ * ${name}!
508
+ * `;
509
+ * console.log(str);
510
+ * // 输出:
511
+ * // Hello,
512
+ * // World!
513
+ */
514
+ static dedent(strings, ...values) {
515
+ const str = strings.reduce((result, string, i) => result + string + (values[i] || ''), '');
516
+ const lines = str.split('\n');
517
+ const minIndent = Math.min(...lines.filter(line => line.trim() !== '').map(line => line.search(/\S/)));
518
+ return lines.map(line => line.slice(minIndent)).join('\n');
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.94",
3
+ "version": "1.0.97",
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,31 @@ 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 values - 插入模板字符串中的值。
566
+ * @returns 返回处理后的字符串,每行开始的空格数已被最小化。
567
+ *
568
+ * @example
569
+ * const name = 'World';
570
+ * const str = dedent`
571
+ * Hello,
572
+ * ${name}!
573
+ * `;
574
+ * console.log(str);
575
+ * // 输出:
576
+ * // Hello,
577
+ * // World!
578
+ */
579
+ static dedent(strings: TemplateStringsArray, ...values: any[]): string {
580
+ const str = strings.reduce((result, string, i) => result + string + (values[i] || ''), '');
581
+ const lines = str.split('\n');
582
+ const minIndent = Math.min(
583
+ ...lines.filter(line => line.trim() !== '').map(line => line.search(/\S/))
584
+ );
585
+ return lines.map(line => line.slice(minIndent)).join('\n');
586
+ }
587
+
562
588
 
563
589
  }