@zwa73/utils 1.0.192 → 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.
@@ -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
+ }
@@ -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, ivk: typeof UtilFunc.ivk;
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;
@@ -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.ivk = 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;
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, exports.ivk = UtilFunctions_1.UtilFunc.ivk;
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.js CHANGED
@@ -135,22 +135,16 @@ class Stream {
135
135
  async append() {
136
136
  if (this._operation.length == 0)
137
137
  return this;
138
- const pList = [];
139
138
  //均分处理
140
- this.divide(this._concurrent).forEach((subList) => {
141
- if (!subList)
142
- return;
143
- pList.push(new Promise(async (reslove) => {
144
- const result = [];
145
- for (let item of subList) {
146
- if (!item)
147
- continue;
148
- for (const operation of this._operation)
149
- item = await operation(item);
150
- result.push(item);
151
- }
152
- reslove(result);
153
- }));
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);
154
148
  });
155
149
  const rlist = await Promise.all(pList);
156
150
  //拼接结果 轮询均分
@@ -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的函数
@@ -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) ?? UtilFunc.ivk(() => {
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
@@ -11,3 +11,4 @@ export * from './UtilLogger';
11
11
  export * from './UtilFP';
12
12
  export * from './QuickFunction';
13
13
  export * from './UtilI18n';
14
+ export * from './LiteFunction';
package/dist/index.js CHANGED
@@ -27,3 +27,4 @@ __exportStar(require("./UtilLogger"), exports);
27
27
  __exportStar(require("./UtilFP"), exports);
28
28
  __exportStar(require("./QuickFunction"), exports);
29
29
  __exportStar(require("./UtilI18n"), exports);
30
+ __exportStar(require("./LiteFunction"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.192",
3
+ "version": "1.0.193",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
+ }
@@ -24,7 +24,6 @@ export const {
24
24
  eitherize,
25
25
  taskEitherize,
26
26
  memoize,
27
- ivk,
28
27
  } = UtilFunc;
29
28
 
30
29
  export const {
@@ -67,5 +66,4 @@ if(false){
67
66
  let matt = matchProc(null as any as Outcome<symbol,123>,{
68
67
 
69
68
  })
70
- }
71
-
69
+ }
package/src/UtilClass.ts CHANGED
@@ -137,23 +137,17 @@ export class Stream<T> implements Iterable<T>{
137
137
  async append(): Promise<Stream<T>> {
138
138
  if (this._operation.length == 0) return this;
139
139
 
140
- const pList: Promise<T[]>[] = [];
141
140
  //均分处理
142
- this.divide(this._concurrent).forEach((subList)=>{
143
- if (!subList) return;
144
- pList.push(
145
- new Promise(async (reslove) => {
141
+ const pList = this.divide(this._concurrent)
142
+ .map(async (subList)=>{
146
143
  const result:T[] = [];
147
144
  for (let item of subList) {
148
- if (!item) continue;
149
145
  for (const operation of this._operation)
150
146
  item = await operation(item);
151
147
  result.push(item);
152
148
  }
153
- reslove(result);
154
- })
155
- );
156
- })
149
+ return (result);
150
+ });
157
151
  const rlist = await Promise.all(pList);
158
152
 
159
153
  //拼接结果 轮询均分
@@ -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) ?? UtilFunc.ivk(()=>{
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
@@ -10,4 +10,5 @@ export * from './UtilFileTools';
10
10
  export * from './UtilLogger';
11
11
  export * from './UtilFP';
12
12
  export * from './QuickFunction';
13
- export * from './UtilI18n';
13
+ export * from './UtilI18n';
14
+ export * from './LiteFunction';
File without changes
@@ -1 +0,0 @@
1
- "use strict";
File without changes