@zwa73/utils 1.0.33 → 1.0.34

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.
@@ -67,7 +67,12 @@ interface SortCallback<T> {
67
67
  }
68
68
  export declare class SList<T> {
69
69
  private _arr;
70
- constructor(obj?: Array<T> | number);
70
+ /**建立0长度的SList */
71
+ constructor();
72
+ /**建立一个长度为 obj 的SList */
73
+ constructor(obj: number);
74
+ /**根据obj建立SList */
75
+ constructor(obj: Array<T>);
71
76
  /**返回数组长度
72
77
  * @returns {number} - 长度
73
78
  */
package/dist/UtilCom.js CHANGED
@@ -33,7 +33,7 @@ function sPost(type, json, options, timeLimit = -1) {
33
33
  throw funcName + " 接收反馈错误: resdata 为空";
34
34
  try {
35
35
  let obj = JSON.parse(resdata);
36
- UtilLogger_1.SLogger.http(funcName + " 接受信息:", (0, UtilInterfaces_1.stringifyJToken)(obj));
36
+ UtilLogger_1.SLogger.http(funcName + " 接受信息:", obj);
37
37
  resolve(obj);
38
38
  return;
39
39
  }
@@ -18,3 +18,7 @@ export interface IJData {
18
18
  * @returns 转换完成的字符串
19
19
  */
20
20
  export declare function stringifyJToken(token: JToken, space?: string | number | null | undefined): string;
21
+ /**转为可写的 */
22
+ export type Writeable<T> = {
23
+ -readonly [P in keyof T]: T[P];
24
+ };
@@ -111,14 +111,23 @@ class SLogger {
111
111
  log(level, ...messages) {
112
112
  level = level || "silly";
113
113
  let strMessages = [];
114
+ //上一条是字符串字符串
115
+ let preIsString = true;
114
116
  for (let message of messages) {
115
117
  let out;
116
- if (message == null)
117
- out = `<${typeof message}> ${typeof message}`;
118
- else if (typeof message !== "string")
118
+ //非string类型
119
+ if (typeof message !== "string") {
119
120
  out = `<${typeof message}> ${(0, util_1.inspect)(message)}`;
120
- else
121
+ preIsString = false;
122
+ }
123
+ else if (!preIsString) {
124
+ //如果上一条不是字符串则需要添加<string>类型标记
125
+ out = `<${typeof message}> ${(0, util_1.inspect)(message)}`;
126
+ preIsString = true;
127
+ }
128
+ else {
121
129
  out = message;
130
+ }
122
131
  strMessages.push(out);
123
132
  }
124
133
  let outMessage = strMessages.join("\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/UtilClass.ts CHANGED
@@ -80,6 +80,12 @@ interface SortCallback<T> {
80
80
 
81
81
  export class SList<T> {
82
82
  private _arr: Array<T>;
83
+ /**建立0长度的SList */
84
+ constructor();
85
+ /**建立一个长度为 obj 的SList */
86
+ constructor(obj:number);
87
+ /**根据obj建立SList */
88
+ constructor(obj:Array<T>);
83
89
  constructor(obj?: Array<T> | number) {
84
90
  if (typeof obj == "number") this._arr = new Array<T>(obj);
85
91
  else if (Array.isArray(obj)) this._arr = obj;
package/src/UtilCom.ts CHANGED
@@ -38,7 +38,7 @@ function sPost(type:"http"|"https",json:JObject,options:Object,timeLimit:number=
38
38
  throw funcName+" 接收反馈错误: resdata 为空";
39
39
  try{
40
40
  let obj = JSON.parse(resdata);
41
- SLogger.http(funcName+" 接受信息:",stringifyJToken(obj));
41
+ SLogger.http(funcName+" 接受信息:",obj);
42
42
  resolve(obj);
43
43
  return;
44
44
  }
@@ -24,3 +24,6 @@ export function stringifyJToken(token:JToken,space:string|number|null|undefined=
24
24
  return JSON.stringify(token,null,space);
25
25
  }
26
26
 
27
+ /**转为可写的 */
28
+ export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
29
+
package/src/UtilLogger.ts CHANGED
@@ -134,13 +134,21 @@ export class SLogger{
134
134
  log(level:LogLevel,...messages:Array<any>):SLogger{
135
135
  level = level||"silly";
136
136
  let strMessages:Array<string> = [];
137
+ //上一条是字符串字符串
138
+ let preIsString = true;
137
139
  for(let message of messages){
138
140
  let out:string;
139
- if(message == null)
140
- out = `<${typeof message}> ${typeof message}`;
141
- else if(typeof message!=="string")
141
+ //非string类型
142
+ if(typeof message!=="string"){
142
143
  out=`<${typeof message}> ${inspect(message)}`;
143
- else out = message;
144
+ preIsString=false;
145
+ }else if(!preIsString){
146
+ //如果上一条不是字符串则需要添加<string>类型标记
147
+ out = `<${typeof message}> ${inspect(message)}`;
148
+ preIsString=true;
149
+ }else{
150
+ out = message;
151
+ }
144
152
  strMessages.push(out);
145
153
  }
146
154
  let outMessage = strMessages.join("\n");
@@ -258,20 +266,15 @@ export class SLogger{
258
266
  }
259
267
  }
260
268
  concat(Days,':','dd',
261
- `${Days.toString()}`,
262
- );
269
+ `${Days.toString()}`);
263
270
  concat(hours,':','HH',
264
- `${hours.toString().padStart(2, '0')}`
265
- );
271
+ `${hours.toString().padStart(2, '0')}`);
266
272
  concat(minutes,':','mm',
267
- `${minutes.toString().padStart(2, '0')}`
268
- );
273
+ `${minutes.toString().padStart(2, '0')}`);
269
274
  concat(seconds,':','ss',
270
- `${seconds.toString().padStart(2, '0')}`
271
- );
275
+ `${seconds.toString().padStart(2, '0')}`);
272
276
  concat(milliseconds,'.','mmm',
273
- `${milliseconds.toString().padStart(3, '0')}`
274
- );
277
+ `${milliseconds.toString().padStart(3, '0')}`);
275
278
  //result = result.replace(/^(0(?![^0-9]))+/, '');
276
279
  result = result.replace(/^0+([0-9])/,"$1");
277
280
  out = `${result} (${format})`;