@zwa73/utils 1.0.0 → 1.0.2
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/UtilClass.d.ts +324 -0
- package/dist/UtilClass.js +582 -0
- package/dist/UtilCodecs.d.ts +3 -3
- package/dist/UtilCodecs.js +0 -2
- package/dist/UtilFunctions.d.ts +1 -8
- package/dist/UtilFunctions.js +1 -62
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +2 -7
- package/release.bat +2 -0
- package/req_test/cjsRmjs.bat +2 -0
- package/req_test/cjsRmjs.cjs +3 -0
- package/req_test/mjsRcjs.bat +2 -0
- package/req_test/mjsRcjs.mjs +3 -0
- package/req_test/req.cjs +7 -0
- package/req_test/req.mjs +3 -0
- package/src/UtilClass.ts +646 -0
- package/src/UtilCodecs.ts +0 -2
- package/src/UtilFunctions.ts +0 -64
- package/src/index.ts +2 -1
- package/test.bat +2 -0
- package/test.js +6 -0
package/src/UtilCodecs.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import * as he from 'html-entities';
|
|
2
|
-
//const encoder = require('gpt-3-encoder');
|
|
3
|
-
//const tiktoken = require('@dqbd/tiktoken');
|
|
4
2
|
import * as tiktoken from '@dqbd/tiktoken';
|
|
5
3
|
const encoderTurbo = tiktoken.get_encoding("cl100k_base");
|
|
6
4
|
const encoderDavinci = tiktoken.get_encoding("p50k_base");
|
package/src/UtilFunctions.ts
CHANGED
|
@@ -34,32 +34,6 @@ export function loadJSONFile(filePath:string):JObject{
|
|
|
34
34
|
str = "{}";
|
|
35
35
|
return JSON.parse(str);
|
|
36
36
|
}
|
|
37
|
-
/**写入JSON文件
|
|
38
|
-
* void (string,Object)
|
|
39
|
-
* @param {string} filePath - 文件路径
|
|
40
|
-
* @param {JObject} obj - 所要写入的JObject
|
|
41
|
-
* @returns {void}
|
|
42
|
-
*/
|
|
43
|
-
export function writeJSONFile_o(filePath:string,obj:JObject){
|
|
44
|
-
let str = JSON.stringify(obj,null,"\t");
|
|
45
|
-
if(filePath.indexOf(".json")==-1)
|
|
46
|
-
filePath += ".json";
|
|
47
|
-
// 判断文件路径是否存在
|
|
48
|
-
if (!fs.existsSync(filePath)) {
|
|
49
|
-
// 如果路径不存在,创建文件夹
|
|
50
|
-
try {
|
|
51
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
52
|
-
}catch(e){}
|
|
53
|
-
}
|
|
54
|
-
fs.writeFile(filePath,str,function(err:any){
|
|
55
|
-
if(err==null)
|
|
56
|
-
console.log(filePath+"writeJSONFile 成功");
|
|
57
|
-
else{
|
|
58
|
-
console.log(filePath+"writeJSONFile 错误");
|
|
59
|
-
console.log(err);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
37
|
/**写入JSON文件
|
|
64
38
|
* void (string,Object)
|
|
65
39
|
* @async
|
|
@@ -137,41 +111,3 @@ export function sleep(timeMs:number):Promise<boolean>{
|
|
|
137
111
|
});
|
|
138
112
|
}
|
|
139
113
|
|
|
140
|
-
type struct = number|string;
|
|
141
|
-
|
|
142
|
-
class SEntry<K extends struct,V>{
|
|
143
|
-
_key:K;
|
|
144
|
-
_value:V|null;
|
|
145
|
-
constructor(key:K,value:V|null){
|
|
146
|
-
this._key = key;
|
|
147
|
-
this._value = value;
|
|
148
|
-
}
|
|
149
|
-
getKey(){
|
|
150
|
-
return this._key;
|
|
151
|
-
}
|
|
152
|
-
getValue(){
|
|
153
|
-
return this._value;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
class SHashMap<K extends struct,V>{
|
|
157
|
-
obj:Record<K,V|null> = {} as Record<K,V>;
|
|
158
|
-
constructor(){}
|
|
159
|
-
get(key:K){
|
|
160
|
-
return this.obj[key];
|
|
161
|
-
}
|
|
162
|
-
put(key:K, value:V){
|
|
163
|
-
this.obj[key] = value;
|
|
164
|
-
}
|
|
165
|
-
has(key:K):boolean{
|
|
166
|
-
return key in this.obj;
|
|
167
|
-
}
|
|
168
|
-
entrys(){
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
class SKVC{
|
|
174
|
-
stringMap:SHashMap<string,string> = new SHashMap();
|
|
175
|
-
|
|
176
|
-
constructor(){}
|
|
177
|
-
}
|
package/src/index.ts
CHANGED
package/test.bat
ADDED