@zwa73/utils 1.0.191 → 1.0.193
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/LiteFunction.d.ts +9 -0
- package/dist/LiteFunction.js +20 -0
- package/dist/QuickFunction.d.ts +1 -1
- package/dist/QuickFunction.js +2 -2
- package/dist/UtilClass.d.ts +3 -1
- package/dist/UtilClass.js +15 -17
- package/dist/UtilFunctions.d.ts +0 -5
- package/dist/UtilFunctions.js +2 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/LiteFunction.ts +18 -0
- package/src/QuickFunction.ts +1 -3
- package/src/UtilClass.ts +10 -12
- package/src/UtilFunctions.ts +2 -11
- package/src/index.ts +2 -1
- package/dist/ServiceManager.d.ts +0 -0
- package/dist/ServiceManager.js +0 -1
- package/src/ServiceManager.ts +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**立即执行传入的函数
|
|
2
|
+
* @param fn - 需要立即执行的函数。
|
|
3
|
+
* @returns 返回 fn 函数的执行结果。
|
|
4
|
+
*/
|
|
5
|
+
export declare function ivk<T extends () => any>(fn: T): ReturnType<T>;
|
|
6
|
+
/**一个可供sort使用的从小到大排序的函数 */
|
|
7
|
+
export declare function s2l(a: number, b: number): number;
|
|
8
|
+
/**一个可供sort使用的从大到小排序的函数 */
|
|
9
|
+
export declare function l2s(a: number, b: number): number;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ivk = ivk;
|
|
4
|
+
exports.s2l = s2l;
|
|
5
|
+
exports.l2s = l2s;
|
|
6
|
+
/**立即执行传入的函数
|
|
7
|
+
* @param fn - 需要立即执行的函数。
|
|
8
|
+
* @returns 返回 fn 函数的执行结果。
|
|
9
|
+
*/
|
|
10
|
+
function ivk(fn) {
|
|
11
|
+
return fn();
|
|
12
|
+
}
|
|
13
|
+
/**一个可供sort使用的从小到大排序的函数 */
|
|
14
|
+
function s2l(a, b) {
|
|
15
|
+
return a - b;
|
|
16
|
+
}
|
|
17
|
+
/**一个可供sort使用的从大到小排序的函数 */
|
|
18
|
+
function l2s(a, b) {
|
|
19
|
+
return b - a;
|
|
20
|
+
}
|
package/dist/QuickFunction.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { UtilFT } from "./UtilFileTools";
|
|
2
2
|
import { UtilFunc } from "./UtilFunctions";
|
|
3
|
-
export declare const outcome: typeof UtilFunc.outcome, matchProc: typeof UtilFunc.matchProc, sucesProc: typeof UtilFunc.sucesProc, isFailed: typeof UtilFunc.isFailed, isSafeNumber: typeof UtilFunc.isSafeNumber, isSuccess: typeof UtilFunc.isSuccess, likeNone: typeof UtilFunc.likeNone, expect: typeof UtilFunc.expect, assertType: typeof UtilFunc.assertType, assertLiteral: typeof UtilFunc.assertLiteral, deepClone: typeof UtilFunc.deepClone, sleep: typeof UtilFunc.sleep, stringifyJToken: typeof UtilFunc.stringifyJToken, getTime: typeof UtilFunc.getTime, mapEntries: typeof UtilFunc.mapEntries, dedent: typeof UtilFunc.dedent, throwError: typeof UtilFunc.throwError, eitherize: typeof UtilFunc.eitherize, taskEitherize: typeof UtilFunc.taskEitherize, memoize: typeof UtilFunc.memoize
|
|
3
|
+
export declare const outcome: typeof UtilFunc.outcome, matchProc: typeof UtilFunc.matchProc, sucesProc: typeof UtilFunc.sucesProc, isFailed: typeof UtilFunc.isFailed, isSafeNumber: typeof UtilFunc.isSafeNumber, isSuccess: typeof UtilFunc.isSuccess, likeNone: typeof UtilFunc.likeNone, expect: typeof UtilFunc.expect, assertType: typeof UtilFunc.assertType, assertLiteral: typeof UtilFunc.assertLiteral, deepClone: typeof UtilFunc.deepClone, sleep: typeof UtilFunc.sleep, stringifyJToken: typeof UtilFunc.stringifyJToken, getTime: typeof UtilFunc.getTime, mapEntries: typeof UtilFunc.mapEntries, dedent: typeof UtilFunc.dedent, throwError: typeof UtilFunc.throwError, eitherize: typeof UtilFunc.eitherize, taskEitherize: typeof UtilFunc.taskEitherize, memoize: typeof UtilFunc.memoize;
|
|
4
4
|
export declare const stylizePath: typeof UtilFT.stylizePath, posixizePath: typeof UtilFT.posixizePath, win32izePath: typeof UtilFT.win32izePath, currosizePath: typeof UtilFT.currosizePath;
|
package/dist/QuickFunction.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.currosizePath = exports.win32izePath = exports.posixizePath = exports.stylizePath = exports.
|
|
3
|
+
exports.currosizePath = exports.win32izePath = exports.posixizePath = exports.stylizePath = exports.memoize = exports.taskEitherize = exports.eitherize = exports.throwError = exports.dedent = exports.mapEntries = exports.getTime = exports.stringifyJToken = exports.sleep = exports.deepClone = exports.assertLiteral = exports.assertType = exports.expect = exports.likeNone = exports.isSuccess = exports.isSafeNumber = exports.isFailed = exports.sucesProc = exports.matchProc = exports.outcome = void 0;
|
|
4
4
|
const UtilFileTools_1 = require("./UtilFileTools");
|
|
5
5
|
const UtilFunctions_1 = require("./UtilFunctions");
|
|
6
6
|
const UtilSymbol_1 = require("./UtilSymbol");
|
|
7
|
-
exports.outcome = UtilFunctions_1.UtilFunc.outcome, exports.matchProc = UtilFunctions_1.UtilFunc.matchProc, exports.sucesProc = UtilFunctions_1.UtilFunc.sucesProc, exports.isFailed = UtilFunctions_1.UtilFunc.isFailed, exports.isSafeNumber = UtilFunctions_1.UtilFunc.isSafeNumber, exports.isSuccess = UtilFunctions_1.UtilFunc.isSuccess, exports.likeNone = UtilFunctions_1.UtilFunc.likeNone, exports.expect = UtilFunctions_1.UtilFunc.expect, exports.assertType = UtilFunctions_1.UtilFunc.assertType, exports.assertLiteral = UtilFunctions_1.UtilFunc.assertLiteral, exports.deepClone = UtilFunctions_1.UtilFunc.deepClone, exports.sleep = UtilFunctions_1.UtilFunc.sleep, exports.stringifyJToken = UtilFunctions_1.UtilFunc.stringifyJToken, exports.getTime = UtilFunctions_1.UtilFunc.getTime, exports.mapEntries = UtilFunctions_1.UtilFunc.mapEntries, exports.dedent = UtilFunctions_1.UtilFunc.dedent, exports.throwError = UtilFunctions_1.UtilFunc.throwError, exports.eitherize = UtilFunctions_1.UtilFunc.eitherize, exports.taskEitherize = UtilFunctions_1.UtilFunc.taskEitherize, exports.memoize = UtilFunctions_1.UtilFunc.memoize
|
|
7
|
+
exports.outcome = UtilFunctions_1.UtilFunc.outcome, exports.matchProc = UtilFunctions_1.UtilFunc.matchProc, exports.sucesProc = UtilFunctions_1.UtilFunc.sucesProc, exports.isFailed = UtilFunctions_1.UtilFunc.isFailed, exports.isSafeNumber = UtilFunctions_1.UtilFunc.isSafeNumber, exports.isSuccess = UtilFunctions_1.UtilFunc.isSuccess, exports.likeNone = UtilFunctions_1.UtilFunc.likeNone, exports.expect = UtilFunctions_1.UtilFunc.expect, exports.assertType = UtilFunctions_1.UtilFunc.assertType, exports.assertLiteral = UtilFunctions_1.UtilFunc.assertLiteral, exports.deepClone = UtilFunctions_1.UtilFunc.deepClone, exports.sleep = UtilFunctions_1.UtilFunc.sleep, exports.stringifyJToken = UtilFunctions_1.UtilFunc.stringifyJToken, exports.getTime = UtilFunctions_1.UtilFunc.getTime, exports.mapEntries = UtilFunctions_1.UtilFunc.mapEntries, exports.dedent = UtilFunctions_1.UtilFunc.dedent, exports.throwError = UtilFunctions_1.UtilFunc.throwError, exports.eitherize = UtilFunctions_1.UtilFunc.eitherize, exports.taskEitherize = UtilFunctions_1.UtilFunc.taskEitherize, exports.memoize = UtilFunctions_1.UtilFunc.memoize;
|
|
8
8
|
exports.stylizePath = UtilFileTools_1.UtilFT.stylizePath, exports.posixizePath = UtilFileTools_1.UtilFT.posixizePath, exports.win32izePath = UtilFileTools_1.UtilFT.win32izePath, exports.currosizePath = UtilFileTools_1.UtilFT.currosizePath;
|
|
9
9
|
if (false) {
|
|
10
10
|
let aaser = (0, exports.assertLiteral)({ a: 1 });
|
package/dist/UtilClass.d.ts
CHANGED
|
@@ -28,7 +28,9 @@ export declare class Stream<T> implements Iterable<T> {
|
|
|
28
28
|
private _operation;
|
|
29
29
|
private constructor();
|
|
30
30
|
/**从arraylike创建流 */
|
|
31
|
-
static from<T>(
|
|
31
|
+
static from<T>(args: Parameters<typeof Array.from<T>>[0], concurrent?: number): Stream<T>;
|
|
32
|
+
/**从数组创建流 */
|
|
33
|
+
static of<T>(...args: T[]): Stream<T>;
|
|
32
34
|
/**设置并发数 */
|
|
33
35
|
concurrent(count: number): Stream<T>;
|
|
34
36
|
/**平分数组
|
package/dist/UtilClass.js
CHANGED
|
@@ -50,8 +50,12 @@ class Stream {
|
|
|
50
50
|
this._concurrent = concurrent;
|
|
51
51
|
}
|
|
52
52
|
/**从arraylike创建流 */
|
|
53
|
-
static from(
|
|
54
|
-
return new Stream(Array.from(
|
|
53
|
+
static from(args, concurrent = 1) {
|
|
54
|
+
return new Stream(Array.from(args), concurrent);
|
|
55
|
+
}
|
|
56
|
+
/**从数组创建流 */
|
|
57
|
+
static of(...args) {
|
|
58
|
+
return new Stream(args);
|
|
55
59
|
}
|
|
56
60
|
/**设置并发数 */
|
|
57
61
|
concurrent(count) {
|
|
@@ -131,22 +135,16 @@ class Stream {
|
|
|
131
135
|
async append() {
|
|
132
136
|
if (this._operation.length == 0)
|
|
133
137
|
return this;
|
|
134
|
-
const pList = [];
|
|
135
138
|
//均分处理
|
|
136
|
-
this.divide(this._concurrent)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
item = await operation(item);
|
|
146
|
-
result.push(item);
|
|
147
|
-
}
|
|
148
|
-
reslove(result);
|
|
149
|
-
}));
|
|
139
|
+
const pList = this.divide(this._concurrent)
|
|
140
|
+
.map(async (subList) => {
|
|
141
|
+
const result = [];
|
|
142
|
+
for (let item of subList) {
|
|
143
|
+
for (const operation of this._operation)
|
|
144
|
+
item = await operation(item);
|
|
145
|
+
result.push(item);
|
|
146
|
+
}
|
|
147
|
+
return (result);
|
|
150
148
|
});
|
|
151
149
|
const rlist = await Promise.all(pList);
|
|
152
150
|
//拼接结果 轮询均分
|
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -291,11 +291,6 @@ export declare class UtilFunc {
|
|
|
291
291
|
result: any;
|
|
292
292
|
timestamp: number;
|
|
293
293
|
}>>;
|
|
294
|
-
/**立即执行传入的函数
|
|
295
|
-
* @param fn - 需要立即执行的函数。
|
|
296
|
-
* @returns 返回 fn 函数的执行结果。
|
|
297
|
-
*/
|
|
298
|
-
static ivk<T extends () => any>(fn: T): ReturnType<T>;
|
|
299
294
|
/**创建一个带有缓存有效期的memoize函数
|
|
300
295
|
* 只在传入值均为JToken时有效
|
|
301
296
|
* @param fn - 需要被memoize的函数
|
package/dist/UtilFunctions.js
CHANGED
|
@@ -44,6 +44,7 @@ const UtilDecorators_1 = require("./UtilDecorators");
|
|
|
44
44
|
const path_1 = __importDefault(require("path"));
|
|
45
45
|
const UtilFileTools_1 = require("./UtilFileTools");
|
|
46
46
|
const util_1 = require("util");
|
|
47
|
+
const LiteFunction_1 = require("./LiteFunction");
|
|
47
48
|
const HashMethodList = ["md5", "sha1", "sha256", "sha512", "sha3", "blake2", "blake3"];
|
|
48
49
|
/**永不完成的Promise单例 */
|
|
49
50
|
const NeverResolvedPromise = new Promise(() => { });
|
|
@@ -697,13 +698,6 @@ class UtilFunc {
|
|
|
697
698
|
}
|
|
698
699
|
/**缓存池 */
|
|
699
700
|
static cachePool = new WeakMap();
|
|
700
|
-
/**立即执行传入的函数
|
|
701
|
-
* @param fn - 需要立即执行的函数。
|
|
702
|
-
* @returns 返回 fn 函数的执行结果。
|
|
703
|
-
*/
|
|
704
|
-
static ivk(fn) {
|
|
705
|
-
return fn();
|
|
706
|
-
}
|
|
707
701
|
/**创建一个带有缓存有效期的memoize函数
|
|
708
702
|
* 只在传入值均为JToken时有效
|
|
709
703
|
* @param fn - 需要被memoize的函数
|
|
@@ -711,7 +705,7 @@ class UtilFunc {
|
|
|
711
705
|
* @returns 返回一个新的函数,这个函数在调用时会尝试从缓存中获取结果,如果缓存不存在或已过期,就会调用原函数并缓存其结果。
|
|
712
706
|
*/
|
|
713
707
|
static memoize(fn, expiry = Infinity) {
|
|
714
|
-
const cache = UtilFunc.cachePool.get(fn) ??
|
|
708
|
+
const cache = UtilFunc.cachePool.get(fn) ?? (0, LiteFunction_1.ivk)(() => {
|
|
715
709
|
const c = new Map();
|
|
716
710
|
UtilFunc.cachePool.set(fn, c);
|
|
717
711
|
return c;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**立即执行传入的函数
|
|
5
|
+
* @param fn - 需要立即执行的函数。
|
|
6
|
+
* @returns 返回 fn 函数的执行结果。
|
|
7
|
+
*/
|
|
8
|
+
export function ivk<T extends ()=>any>(fn:T): ReturnType<T> {
|
|
9
|
+
return fn();
|
|
10
|
+
}
|
|
11
|
+
/**一个可供sort使用的从小到大排序的函数 */
|
|
12
|
+
export function s2l(a:number,b:number) {
|
|
13
|
+
return a-b;
|
|
14
|
+
}
|
|
15
|
+
/**一个可供sort使用的从大到小排序的函数 */
|
|
16
|
+
export function l2s(a:number,b:number) {
|
|
17
|
+
return b-a;
|
|
18
|
+
}
|
package/src/QuickFunction.ts
CHANGED
package/src/UtilClass.ts
CHANGED
|
@@ -53,8 +53,12 @@ export class Stream<T> implements Iterable<T>{
|
|
|
53
53
|
this._concurrent = concurrent;
|
|
54
54
|
}
|
|
55
55
|
/**从arraylike创建流 */
|
|
56
|
-
static from<T>(
|
|
57
|
-
return new Stream<T>(Array.from(
|
|
56
|
+
static from<T>(args:Parameters<typeof Array.from<T>>[0],concurrent:number=1){
|
|
57
|
+
return new Stream<T>(Array.from(args),concurrent);
|
|
58
|
+
}
|
|
59
|
+
/**从数组创建流 */
|
|
60
|
+
static of<T>(...args:T[]){
|
|
61
|
+
return new Stream<T>(args);
|
|
58
62
|
}
|
|
59
63
|
/**设置并发数 */
|
|
60
64
|
concurrent(count: number): Stream<T> {
|
|
@@ -133,23 +137,17 @@ export class Stream<T> implements Iterable<T>{
|
|
|
133
137
|
async append(): Promise<Stream<T>> {
|
|
134
138
|
if (this._operation.length == 0) return this;
|
|
135
139
|
|
|
136
|
-
const pList: Promise<T[]>[] = [];
|
|
137
140
|
//均分处理
|
|
138
|
-
this.divide(this._concurrent)
|
|
139
|
-
|
|
140
|
-
pList.push(
|
|
141
|
-
new Promise(async (reslove) => {
|
|
141
|
+
const pList = this.divide(this._concurrent)
|
|
142
|
+
.map(async (subList)=>{
|
|
142
143
|
const result:T[] = [];
|
|
143
144
|
for (let item of subList) {
|
|
144
|
-
if (!item) continue;
|
|
145
145
|
for (const operation of this._operation)
|
|
146
146
|
item = await operation(item);
|
|
147
147
|
result.push(item);
|
|
148
148
|
}
|
|
149
|
-
|
|
150
|
-
})
|
|
151
|
-
);
|
|
152
|
-
})
|
|
149
|
+
return (result);
|
|
150
|
+
});
|
|
153
151
|
const rlist = await Promise.all(pList);
|
|
154
152
|
|
|
155
153
|
//拼接结果 轮询均分
|
package/src/UtilFunctions.ts
CHANGED
|
@@ -8,6 +8,7 @@ import opath from 'path';
|
|
|
8
8
|
import { UtilFT } from "./UtilFileTools";
|
|
9
9
|
import {inspect} from 'util';
|
|
10
10
|
import type * as publicIp from 'public-ip';
|
|
11
|
+
import { ivk } from "./LiteFunction";
|
|
11
12
|
|
|
12
13
|
const HashMethodList = ["md5","sha1","sha256","sha512","sha3","blake2","blake3"] as const;
|
|
13
14
|
type HashMethod = typeof HashMethodList[number];
|
|
@@ -817,16 +818,6 @@ static async dynamicImport(moduleName:string):Promise<any> {
|
|
|
817
818
|
/**缓存池 */
|
|
818
819
|
static cachePool = new WeakMap<Function, Map<string, { result: any, timestamp: number }>>();
|
|
819
820
|
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
/**立即执行传入的函数
|
|
823
|
-
* @param fn - 需要立即执行的函数。
|
|
824
|
-
* @returns 返回 fn 函数的执行结果。
|
|
825
|
-
*/
|
|
826
|
-
static ivk<T extends ()=>any>(fn:T): ReturnType<T> {
|
|
827
|
-
return fn();
|
|
828
|
-
}
|
|
829
|
-
|
|
830
821
|
/**创建一个带有缓存有效期的memoize函数
|
|
831
822
|
* 只在传入值均为JToken时有效
|
|
832
823
|
* @param fn - 需要被memoize的函数
|
|
@@ -837,7 +828,7 @@ static memoize<T extends (...args:any[])=>any> (fn: T, expiry = Infinity):
|
|
|
837
828
|
T extends (...args:infer In)=>any
|
|
838
829
|
? AllExtends<In,JToken> extends true ? T : never
|
|
839
830
|
: never {
|
|
840
|
-
const cache = UtilFunc.cachePool.get(fn) ??
|
|
831
|
+
const cache = UtilFunc.cachePool.get(fn) ?? ivk(()=>{
|
|
841
832
|
const c = new Map();
|
|
842
833
|
UtilFunc.cachePool.set(fn, c);
|
|
843
834
|
return c;
|
package/src/index.ts
CHANGED
package/dist/ServiceManager.d.ts
DELETED
|
File without changes
|
package/dist/ServiceManager.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/src/ServiceManager.ts
DELETED
|
File without changes
|