@zwa73/utils 1.0.201 → 1.0.202

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/dist/UtilCom.js CHANGED
@@ -9,7 +9,6 @@ const https_1 = __importDefault(require("https"));
9
9
  const UtilLogger_1 = require("./UtilLogger");
10
10
  const UtilFunctions_1 = require("./UtilFunctions");
11
11
  const querystring_1 = __importDefault(require("querystring"));
12
- const UtilSymbol_1 = require("./UtilSymbol");
13
12
  const http_proxy_agent_1 = __importDefault(require("http-proxy-agent"));
14
13
  const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
15
14
  const AcceptTypeList = ["json", "string"];
@@ -136,8 +135,10 @@ class UtilCom {
136
135
  init: '',
137
136
  reduce: (acc, curr) => acc + curr,
138
137
  parse: (result) => {
139
- if (result == undefined)
138
+ if (result == undefined) {
139
+ UtilLogger_1.SLogger.warn(`json accept 接收反馈错误: 响应结果无效`);
140
140
  return undefined;
141
+ }
141
142
  const { data, ...rest } = result;
142
143
  if (data.trim() == "") {
143
144
  UtilLogger_1.SLogger.warn(`json accept 接收反馈错误: 原始字符串为空`, UtilFunctions_1.UtilFunc.stringifyJToken(result, { compress: true, space: 2 }));
@@ -339,14 +340,10 @@ exports.UtilCom = UtilCom;
339
340
  if (false)
340
341
  ((async () => {
341
342
  const t = await UtilCom.https().postJson()
342
- .retry({
343
- option: {
344
- hostname: 'httpbin.org',
345
- path: '/post',
346
- timeout: 10000
347
- },
348
- verify: () => UtilSymbol_1.Success,
349
- retries: {}
343
+ .once({
344
+ hostname: 'httpbin.org',
345
+ path: '/post',
346
+ timeout: 10000
350
347
  }, { test: 1 });
351
348
  console.log(t);
352
349
  })());
@@ -387,8 +387,10 @@ class UtilFunc {
387
387
  return `${ec}${str}${ec}`;
388
388
  return value;
389
389
  };
390
- return JSON.stringify(token, compressReplacer, space)
391
- .replace(new RegExp(`"${ec}(.*?)${ec}"`, 'g'), (match, p1) => p1.replace(/\\([\\"])/g, '$1'));
390
+ const result = JSON.stringify(token, compressReplacer, space);
391
+ if (typeof result != 'string')
392
+ return result;
393
+ return result.replace(new RegExp(`"${ec}(.*?)${ec}"`, 'g'), (match, p1) => p1.replace(/\\([\\"])/g, '$1'));
392
394
  }
393
395
  /**验证一个变量的类型是否为 T
394
396
  * @template T - 验证类型
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.201",
3
+ "version": "1.0.202",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/UtilCom.ts CHANGED
@@ -206,7 +206,10 @@ A extends AcceptProc<any,any>,
206
206
  init:'',
207
207
  reduce:(acc,curr)=>acc+curr,
208
208
  parse:(result)=>{
209
- if(result==undefined) return undefined;
209
+ if(result==undefined){
210
+ SLogger.warn(`json accept 接收反馈错误: 响应结果无效`);
211
+ return undefined;
212
+ }
210
213
  const {data,...rest} = result;
211
214
 
212
215
  if(data.trim()==""){
@@ -444,14 +447,10 @@ A extends AcceptProc<any,any>,
444
447
 
445
448
  if(false)((async ()=>{
446
449
  const t = await UtilCom.https().postJson()
447
- .retry({
448
- option:{
449
- hostname:'httpbin.org',
450
- path:'/post',
451
- timeout:10000
452
- },
453
- verify:()=>Success,
454
- retries:{}
450
+ .once({
451
+ hostname:'httpbin.org',
452
+ path:'/post',
453
+ timeout:10000
455
454
  },{test:1});
456
455
  console.log(t);
457
456
  })())
@@ -461,8 +461,9 @@ static stringifyJToken(token:JToken|IJData,opt?:StringifyOpt){
461
461
  return value;
462
462
  }
463
463
 
464
- return JSON.stringify(token,compressReplacer,space)
465
- .replace(new RegExp(`"${ec}(.*?)${ec}"`,'g'), (match, p1) =>
464
+ const result = JSON.stringify(token,compressReplacer,space);
465
+ if(typeof result!='string') return result;
466
+ return result.replace(new RegExp(`"${ec}(.*?)${ec}"`,'g'), (match, p1) =>
466
467
  p1.replace(/\\([\\"])/g, '$1'));
467
468
  }
468
469