@zwa73/utils 1.0.110 → 1.0.111
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 +6 -0
- package/dist/UtilClass.js +8 -0
- package/dist/UtilFfmpegTools.js +2 -2
- package/dist/UtilFileTools.js +2 -2
- package/dist/UtilFunctions.d.ts +5 -2
- package/dist/UtilFunctions.js +5 -3
- package/package.json +1 -1
- package/scripts/postinstall.js +1 -1
- package/src/UtilClass.ts +9 -0
- package/src/UtilFfmpegTools.ts +2 -2
- package/src/UtilFileTools.ts +2 -2
- package/src/UtilFunctions.ts +7 -3
package/dist/UtilClass.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LiteralCheck } from "./UtilInterfaces";
|
|
1
2
|
/**函数管道器 */
|
|
2
3
|
export declare class Piper<Arg, Result = Arg> {
|
|
3
4
|
/**管道函数列表 */
|
|
@@ -55,6 +56,11 @@ export declare class Stream<T> implements Iterable<T> {
|
|
|
55
56
|
* @returns 数组
|
|
56
57
|
*/
|
|
57
58
|
toArray(): Promise<Array<T>>;
|
|
59
|
+
/**应用加工 并排除某个字面量
|
|
60
|
+
* @param value - 排除的值
|
|
61
|
+
* @returns 自身
|
|
62
|
+
*/
|
|
63
|
+
exclude<E>(value: LiteralCheck<E>): Promise<Stream<Exclude<T, E>>>;
|
|
58
64
|
/**应用加工 并过滤
|
|
59
65
|
* @param func - 过滤函数
|
|
60
66
|
* @returns 自身
|
package/dist/UtilClass.js
CHANGED
|
@@ -155,6 +155,14 @@ class Stream {
|
|
|
155
155
|
await this.append();
|
|
156
156
|
return [...this];
|
|
157
157
|
}
|
|
158
|
+
/**应用加工 并排除某个字面量
|
|
159
|
+
* @param value - 排除的值
|
|
160
|
+
* @returns 自身
|
|
161
|
+
*/
|
|
162
|
+
async exclude(value) {
|
|
163
|
+
await this.append();
|
|
164
|
+
return new Stream(this._list.filter((v) => v !== value));
|
|
165
|
+
}
|
|
158
166
|
/**应用加工 并过滤
|
|
159
167
|
* @param func - 过滤函数
|
|
160
168
|
* @returns 自身
|
package/dist/UtilFfmpegTools.js
CHANGED
|
@@ -37,9 +37,9 @@ const UtilClass_1 = require("./UtilClass");
|
|
|
37
37
|
class SFfmpegTool {
|
|
38
38
|
/**静态构造函数 */
|
|
39
39
|
static init() {
|
|
40
|
-
|
|
40
|
+
const ffmpegPath = process.env.FFMPEG_PATH;
|
|
41
41
|
if (ffmpegPath != null) {
|
|
42
|
-
|
|
42
|
+
const exepath = path.join(ffmpegPath, "ffmpeg.exe");
|
|
43
43
|
SFfmpegTool.setFfmpegPath(exepath);
|
|
44
44
|
}
|
|
45
45
|
}
|
package/dist/UtilFileTools.js
CHANGED
|
@@ -239,8 +239,8 @@ var UtilFT;
|
|
|
239
239
|
*/
|
|
240
240
|
function fileSearchGlob(dir, globPattern, opt) {
|
|
241
241
|
const fixedPath = typeof globPattern === "string"
|
|
242
|
-
? path.join(dir,
|
|
243
|
-
: globPattern.map((p) => path.join(dir,
|
|
242
|
+
? path.join(dir, globPattern).replaceAll("\\", "/")
|
|
243
|
+
: globPattern.map((p) => path.join(dir, p).replaceAll("\\", "/"));
|
|
244
244
|
return (0, glob_1.globSync)(fixedPath, { ignore: opt?.ingore, absolute: true })
|
|
245
245
|
.map((filePath) => {
|
|
246
246
|
if (opt?.normalize === undefined)
|
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AnyFunc, ComposedClass, ComposedMixinable, ComposedRefMixinable, ExtractOutcome, IJData, JObject, JToken, Keyable, LiteralCheck, Matchable, MatchableFlag, Mixinable, Outcome, PromiseVerifyFn, RefMixinable, UnionToIntersection } from "./UtilInterfaces";
|
|
2
2
|
import { LogLevel } from "./UtilLogger";
|
|
3
3
|
import { FailedLike, None, StatusSymbol, Success, SuccessLike, Timeout } from "./UtilSymbol";
|
|
4
|
+
declare const HashMethodList: readonly ["md5", "sha1", "sha256", "sha512", "sha3", "blake2", "blake3"];
|
|
5
|
+
type HashMethod = typeof HashMethodList[number];
|
|
4
6
|
type SuccessOut<T> = Outcome<Success, T>;
|
|
5
7
|
type TimeoutOut<T> = Outcome<Timeout, Promise<T>>;
|
|
6
8
|
/**常用函数 */
|
|
@@ -30,10 +32,11 @@ export declare class UtilFunc {
|
|
|
30
32
|
*/
|
|
31
33
|
static genUUID(): string;
|
|
32
34
|
/**计算Hash
|
|
33
|
-
* @param str
|
|
35
|
+
* @param str - 待计算的字符串
|
|
36
|
+
* @param method - hash算法
|
|
34
37
|
* @returns hash
|
|
35
38
|
*/
|
|
36
|
-
static calcHash(str: string): string;
|
|
39
|
+
static calcHash(str: string, method?: HashMethod): string;
|
|
37
40
|
/**等待 timeMs 毫秒
|
|
38
41
|
* @async
|
|
39
42
|
* @param timeMs - 等待的毫秒数
|
package/dist/UtilFunctions.js
CHANGED
|
@@ -38,6 +38,7 @@ const cp = __importStar(require("child_process"));
|
|
|
38
38
|
const UtilLogger_1 = require("./UtilLogger");
|
|
39
39
|
const UtilSymbol_1 = require("./UtilSymbol");
|
|
40
40
|
const UtilDecorators_1 = require("./UtilDecorators");
|
|
41
|
+
const HashMethodList = ["md5", "sha1", "sha256", "sha512", "sha3", "blake2", "blake3"];
|
|
41
42
|
/**永不完成的Promise单例 */
|
|
42
43
|
const NeverResolvedPromise = new Promise(() => { });
|
|
43
44
|
/**常用函数 */
|
|
@@ -88,11 +89,12 @@ class UtilFunc {
|
|
|
88
89
|
return crypto.randomBytes(16).toString("hex");
|
|
89
90
|
}
|
|
90
91
|
/**计算Hash
|
|
91
|
-
* @param str
|
|
92
|
+
* @param str - 待计算的字符串
|
|
93
|
+
* @param method - hash算法
|
|
92
94
|
* @returns hash
|
|
93
95
|
*/
|
|
94
|
-
static calcHash(str) {
|
|
95
|
-
return crypto.createHash(
|
|
96
|
+
static calcHash(str, method = 'md5') {
|
|
97
|
+
return crypto.createHash(method).update(str).digest('hex');
|
|
96
98
|
}
|
|
97
99
|
static async sleep(timeMs, result) {
|
|
98
100
|
return new Promise(function (resolve, rejecte) {
|
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -45,7 +45,7 @@ function showUpgradeMessages(prevVersion, currentVersion) {
|
|
|
45
45
|
async function main(){
|
|
46
46
|
const packageTable = await UtilFT.loadJSONFile(PACKAGE_PATH);
|
|
47
47
|
const currentVersion = packageTable.version;
|
|
48
|
-
await UtilFT.ensurePathExists(
|
|
48
|
+
await UtilFT.ensurePathExists(VERSION_PATH);
|
|
49
49
|
const versionTable = Object.assign({},
|
|
50
50
|
await UtilFT.loadJSONFile(VERSION_PATH,{}),
|
|
51
51
|
{utils:{version:currentVersion}});
|
package/src/UtilClass.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { matchProc } from "./QuickFunction";
|
|
2
|
+
import { LiteralCheck } from "./UtilInterfaces";
|
|
2
3
|
|
|
3
4
|
/**函数管道器 */
|
|
4
5
|
export class Piper<Arg, Result = Arg> {
|
|
@@ -160,6 +161,14 @@ export class Stream<T> implements Iterable<T>{
|
|
|
160
161
|
await this.append();
|
|
161
162
|
return [...this];
|
|
162
163
|
}
|
|
164
|
+
/**应用加工 并排除某个字面量
|
|
165
|
+
* @param value - 排除的值
|
|
166
|
+
* @returns 自身
|
|
167
|
+
*/
|
|
168
|
+
async exclude<E>(value:LiteralCheck<E>): Promise<Stream<Exclude<T,E>>>{
|
|
169
|
+
await this.append();
|
|
170
|
+
return new Stream(this._list.filter((v)=>v!==value as any) as Exclude<T,E>[]);
|
|
171
|
+
}
|
|
163
172
|
/**应用加工 并过滤
|
|
164
173
|
* @param func - 过滤函数
|
|
165
174
|
* @returns 自身
|
package/src/UtilFfmpegTools.ts
CHANGED
|
@@ -15,9 +15,9 @@ export type IOMap = { [key: string]: string };
|
|
|
15
15
|
class SFfmpegTool {
|
|
16
16
|
/**静态构造函数 */
|
|
17
17
|
static init() {
|
|
18
|
-
|
|
18
|
+
const ffmpegPath = process.env.FFMPEG_PATH;
|
|
19
19
|
if(ffmpegPath!=null){
|
|
20
|
-
|
|
20
|
+
const exepath = path.join(ffmpegPath,"ffmpeg.exe");
|
|
21
21
|
SFfmpegTool.setFfmpegPath(exepath);
|
|
22
22
|
}
|
|
23
23
|
}
|
package/src/UtilFileTools.ts
CHANGED
|
@@ -274,8 +274,8 @@ export function fileSearchRegex(dir: string, traitRegex: string, opt?:FileSearch
|
|
|
274
274
|
*/
|
|
275
275
|
export function fileSearchGlob(dir: string, globPattern:string|string[],opt?:FileSearchGlobOpt){
|
|
276
276
|
const fixedPath = typeof globPattern === "string"
|
|
277
|
-
? path.join(dir,
|
|
278
|
-
: globPattern.map((p)=>path.join(dir,
|
|
277
|
+
? path.join(dir,globPattern).replaceAll("\\","/")
|
|
278
|
+
: globPattern.map((p)=>path.join(dir,p).replaceAll("\\","/"));
|
|
279
279
|
return globSync(fixedPath, { ignore: opt?.ingore, absolute: true })
|
|
280
280
|
.map((filePath) => {
|
|
281
281
|
if (opt?.normalize === undefined) return filePath;
|
package/src/UtilFunctions.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { LogLevel, SLogger } from "@src/UtilLogger";
|
|
|
5
5
|
import { Completed, Failed, FailedLike, None, StatusSymbol, Success, SuccessLike, Terminated, Timeout } from "./UtilSymbol";
|
|
6
6
|
import { Catch, DeferAsync, LogTimeAsync } from "./UtilDecorators";
|
|
7
7
|
|
|
8
|
+
const HashMethodList = ["md5","sha1","sha256","sha512","sha3","blake2","blake3"] as const;
|
|
9
|
+
type HashMethod = typeof HashMethodList[number];
|
|
8
10
|
|
|
9
11
|
type SuccessOut<T> = Outcome<Success,T>;
|
|
10
12
|
type TimeoutOut<T> = Outcome<Timeout,Promise<T>>;
|
|
@@ -71,12 +73,14 @@ static initObject<T extends JObject>
|
|
|
71
73
|
static genUUID() {
|
|
72
74
|
return crypto.randomBytes(16).toString("hex");
|
|
73
75
|
}
|
|
76
|
+
|
|
74
77
|
/**计算Hash
|
|
75
|
-
* @param str
|
|
78
|
+
* @param str - 待计算的字符串
|
|
79
|
+
* @param method - hash算法
|
|
76
80
|
* @returns hash
|
|
77
81
|
*/
|
|
78
|
-
static calcHash(str:string) {
|
|
79
|
-
return crypto.createHash(
|
|
82
|
+
static calcHash(str:string,method:HashMethod='md5') {
|
|
83
|
+
return crypto.createHash(method).update(str).digest('hex');
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
|