@zwa73/utils 1.0.288 → 1.0.290

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.
@@ -57,6 +57,6 @@ declare class _UtilFunc {
57
57
  */
58
58
  static resolveDataStore<T>(source: ParseableDataStore<T>): DataStore<T>;
59
59
  }
60
- export declare const UtilFunc: import("@zwa73/modular-mixer").ComposedClass<typeof _UtilFunc, typeof JsFunc, "__jsUtils", "prototype" | "preset" | "assignOption" | "genUUID" | "getTime" | "initField" | "initObject" | "afterward" | "sleep" | "getNeverResolvedPromise" | "retryPromise" | "timelimitPromise" | "mapEntries" | "eachField" | "stringifyJToken" | "sortJToken" | "assertType" | "assertLiteral" | "deepClone" | "isSafeNumber" | "dedent" | "throwError" | "getStack" | "getFuncLoc" | "cachePool" | "memoize" | "asyncize" | "lazyFunction" | "splitToChunk" | "mergeFromChunk" | "structEqual" | "concurrent" | "dynamicImport" | "createInjectable" | "createAsyncProxy" | "checkSharpSchema" | "unwarpReadonly" | "outcome" | "extractOutcome" | "success" | "failed" | "match" | "isStatus" | "eitherize" | "parseSrtTime" | "formatSrtTime" | "parseSrt" | "createSrt" | "ivk" | "range" | "s2l" | "l2s">;
60
+ export declare const UtilFunc: import("@zwa73/modular-mixer").ComposedClass<typeof _UtilFunc, typeof JsFunc, "__jsUtils", "prototype" | "preset" | "assignOption" | "genUUID" | "getTime" | "initField" | "initObject" | "afterward" | "sleep" | "getNeverResolvedPromise" | "retryPromise" | "timelimitPromise" | "mapEntries" | "eachField" | "stringifyJToken" | "sortJToken" | "assertType" | "assertLiteral" | "deepClone" | "isSafeNumber" | "dedent" | "throwError" | "getStack" | "getFuncLoc" | "cachePool" | "memoize" | "asyncize" | "lazyFunction" | "iocify" | "splitToChunk" | "mergeFromChunk" | "structEqual" | "concurrent" | "dynamicImport" | "createInjectable" | "createAsyncProxy" | "checkSharpSchema" | "unwarpReadonly" | "outcome" | "extractOutcome" | "success" | "failed" | "match" | "isStatus" | "eitherize" | "parseSrtTime" | "formatSrtTime" | "parseSrt" | "createSrt" | "ivk" | "range" | "s2l" | "l2s">;
61
61
  export type UtilFunc = typeof UtilFunc;
62
62
  export {};
@@ -76,15 +76,15 @@ class _UtilFunc {
76
76
  * @param opt.cwd - 执行目录
77
77
  * @param opt.env - 额外环境变量
78
78
  */
79
- static async exec(command, opt) {
79
+ static async exec(command, opt = {}) {
80
80
  return new Promise(async (resolve, reject) => {
81
81
  // 创建一个新的环境变量对象,并将项目的 node_modules/.bin 目录添加到 PATH 环境变量中
82
- const env = Object.assign(Object.create(process.env), opt?.env ?? {});
83
- const penv = opt?.nodeModules
82
+ const env = Object.assign(Object.create(process.env), opt.env ?? {});
83
+ const penv = opt.nodeModules
84
84
  ? opt.nodeModules == 'None' ? ''
85
85
  : path_1.default.join(UtilFileTools_1.UtilFT.currosizePath(opt.nodeModules), '.bin')
86
86
  : UtilFileTools_1.UtilFT.currosizePath(await exports.UtilFunc.memoize(UtilFileTools_1.UtilFT.findNodeModulesDir)(process.cwd(), '.bin') ?? '');
87
- if (opt?.nodeModules != "None" && (_UtilFunc.checkEnv && (penv == "" || !await UtilFileTools_1.UtilFT.pathExists(penv)))) {
87
+ if (opt.nodeModules != "None" && (_UtilFunc.checkEnv && (penv == "" || !await UtilFileTools_1.UtilFT.pathExists(penv)))) {
88
88
  UtilLogger_1.SLogger.warn(`UtilFunc.exec 错误, 没有检测到 node_modules/.bin 环境 penv:${penv}`);
89
89
  _UtilFunc.checkEnv = false;
90
90
  }
@@ -93,28 +93,28 @@ class _UtilFunc {
93
93
  _UtilFunc.originalExecTitle = _UtilFunc.originalExecTitle == UtilSymbol_1.None
94
94
  ? process.title
95
95
  : _UtilFunc.originalExecTitle;
96
- const cwd = opt?.cwd ?? process.cwd();
96
+ const cwd = opt.cwd ?? process.cwd();
97
97
  const child = cp.spawn(command, { shell: true, env, cwd });
98
98
  let stdout = '';
99
99
  let stderr = '';
100
100
  child.stdout.on('data', (data) => {
101
101
  stdout += data;
102
- if (opt?.outlvl) {
102
+ if (opt.outlvl != undefined && opt.outlvl != 'none') {
103
103
  const text = data.toString().replace(/\r?\n$/, '');
104
104
  if (typeof opt.outlvl === "function")
105
105
  opt.outlvl(text);
106
106
  else
107
- UtilLogger_1.SLogger.log(opt?.outlvl, text);
107
+ UtilLogger_1.SLogger.log(opt.outlvl, text);
108
108
  }
109
109
  });
110
110
  child.stderr.on('data', (data) => {
111
111
  stderr += data;
112
- if (opt?.errlvl) {
112
+ if (opt.errlvl != undefined && opt.errlvl != 'none') {
113
113
  const text = data.toString().replace(/\r?\n$/, '');
114
114
  if (typeof opt.errlvl === "function")
115
115
  opt.errlvl(text);
116
116
  else
117
- UtilLogger_1.SLogger.log(opt?.errlvl, text);
117
+ UtilLogger_1.SLogger.log(opt.errlvl, text);
118
118
  }
119
119
  });
120
120
  child.on('error', reject);
package/dist/UtilHttp.js CHANGED
@@ -178,7 +178,7 @@ class UtilHttp {
178
178
  }
179
179
  try {
180
180
  const obj = JSON.parse(data.trim());
181
- UtilLogger_1.SLogger.log(opt.logLevel, `accept json 接受信息 data:`, UtilFunctions_1.UtilFunc.stringifyJToken(obj, { compress: true, space: 2 }), `result:`, UtilFunctions_1.UtilFunc.stringifyJToken(rest, { compress: true, space: 2 }));
181
+ UtilLogger_1.SLogger.log(opt.logLevel ?? 'none', `accept json 接受信息 data:`, UtilFunctions_1.UtilFunc.stringifyJToken(obj, { compress: true, space: 2 }), `result:`, UtilFunctions_1.UtilFunc.stringifyJToken(rest, { compress: true, space: 2 }));
182
182
  return { ...rest, data: obj };
183
183
  }
184
184
  catch (err) {
@@ -1,2 +1,2 @@
1
- export type { JToken, JValue, JArray, JObject, IJData, AnyFunc, Keyable, DeepReadonly, DeepWritable, PartialOption, ProperSubset, ProperSubsetCheck, IncludeCheck, UnionCheck, Literal, LiteralCheck, AllExtends, AssignObject, Writeable, Requireify, Inverted, FixedLengthTuple, Increment, RangeTuple, AnyString, UnionToIntersection, ExclusiveRecord, ExclusiveJObject, PromiseStatus, StatusVerifyFn, Await, FuncPropNames, ExtendThen, RequiredOnly, WithPrefix, Outcome, Either, Matchable, MatchableFlag, ExtractOutcome, ExtractMatchable, NeedInit, PRecord, MPromise, SPromise, SMPromise, NotPromise, AnyRecord, MReturnType, CmtTuple, Flasy, SrtSegment, ILogger, LogLevel, Asyncize, SharpSchema, ExpandSharpSchema, Preset, PresetOption, PresetFinal } from "@zwa73/js-utils";
1
+ export type { JToken, JValue, JArray, JObject, IJData, AnyFunc, Keyable, DeepReadonly, DeepWritable, PartialOption, ProperSubset, ProperSubsetCheck, IncludeCheck, UnionCheck, Literal, LiteralCheck, AllExtends, AssignObject, Writeable, Requireify, Inverted, FixedLengthTuple, Increment, RangeTuple, AnyString, UnionToIntersection, ExclusiveRecord, ExclusiveJObject, PromiseStatus, StatusVerifyFn, Await, FuncPropNames, ExtendThen, RequiredOnly, WithPrefix, Outcome, Either, Matchable, MatchableFlag, ExtractOutcome, ExtractMatchable, NeedInit, PRecord, MPromise, SPromise, SMPromise, NotPromise, AnyRecord, ReturnTypeOrNever, CmtTuple, Flasy, SrtSegment, ILogger, LogLevel, Asyncize, SharpSchema, ExpandSharpSchema, Preset, PresetOption, PresetFinal, NotFunc, MFunc, MReturnType, IoCDepTable, IoCDepCtorRtn, IoCDepCtor, StaticClass } from "@zwa73/js-utils";
2
2
  export type { StringifyOpt, PromiseRetries, PromiseRetryResult } from "@zwa73/js-utils";
@@ -85,10 +85,10 @@ export declare class SLogger {
85
85
  time(flag: string): HRTimeLog;
86
86
  /**根据之前记录的时间戳计算经过的时间 并输出log
87
87
  * @param flag - 记录的命名
88
- * @param level - log等级 === null时不产生log
88
+ * @param level - log等级
89
89
  * @returns 格式化的时间字符串
90
90
  */
91
- timeEnd(flag: string, level?: LogLevel | null): string | undefined;
91
+ timeEnd(flag: string, level?: LogLevel): string | undefined;
92
92
  /**名称为default的slogger实例 */
93
93
  private static get defaultInstance();
94
94
  /**让名称为default的logger 产生一条对应等级的log 返回自身
@@ -133,6 +133,8 @@ class SLogger {
133
133
  * @returns 自身
134
134
  */
135
135
  log(level, ...messages) {
136
+ if (level == 'none')
137
+ return this;
136
138
  level ??= "silly";
137
139
  const strMessages = [];
138
140
  //上一条是字符串字符串
@@ -228,7 +230,7 @@ class SLogger {
228
230
  }
229
231
  /**根据之前记录的时间戳计算经过的时间 并输出log
230
232
  * @param flag - 记录的命名
231
- * @param level - log等级 === null时不产生log
233
+ * @param level - log等级
232
234
  * @returns 格式化的时间字符串
233
235
  */
234
236
  timeEnd(flag, level = "info") {
@@ -284,7 +286,7 @@ class SLogger {
284
286
  else {
285
287
  out = `${totalMilliseconds.toFixed(3)}ms`;
286
288
  }
287
- if (level !== null)
289
+ if (level !== 'none')
288
290
  this.log(level, `${flag}: ${out}`);
289
291
  delete SLogger.timeTable[flag];
290
292
  return out;
@@ -302,6 +304,8 @@ class SLogger {
302
304
  * @returns 自身
303
305
  */
304
306
  static log(level, ...messages) {
307
+ if (level == null)
308
+ return this.defaultInstance;
305
309
  level = level ?? "silly";
306
310
  this.defaultInstance.log(level, ...messages);
307
311
  return this.defaultInstance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.288",
3
+ "version": "1.0.290",
4
4
  "description": "my utils",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {