@zwa73/utils 1.0.62 → 1.0.64
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/UtilFunctions.d.ts +2 -2
- package/dist/UtilFunctions.js +6 -4
- package/dist/UtilInterfaces.d.ts +1 -1
- package/dist/UtilInterfaces.js +3 -3
- package/dist/test/composeTest.js +1 -1
- package/package.json +1 -1
- package/src/UtilFunctions.ts +4 -2
- package/src/UtilInterfaces.ts +1 -1
- package/src/test/composeTest.ts +2 -2
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComposedClassMult, ComposedClassPart, JToken, PromiseProcFn, PromiseVerifyFn } from "./UtilInterfaces";
|
|
1
|
+
import { ComposedClassMult, ComposedClassPart, FuncPropNames, JToken, PromiseProcFn, PromiseVerifyFn } from "./UtilInterfaces";
|
|
2
2
|
/**常用函数 */
|
|
3
3
|
export declare namespace UtilFunc {
|
|
4
4
|
/**获取当前时间戳
|
|
@@ -64,7 +64,7 @@ export declare namespace UtilFunc {
|
|
|
64
64
|
* @param fields - 需要混入的字段
|
|
65
65
|
* @returns 混合完成的类
|
|
66
66
|
*/
|
|
67
|
-
function composeClassPart<Base extends object, Mixin extends object, Field extends
|
|
67
|
+
function composeClassPart<Base extends object, Mixin extends object, Field extends FuncPropNames<Mixin>>(base: Base, mixin: Mixin, ...fields: Field[]): ComposedClassPart<Base, Mixin, Field>;
|
|
68
68
|
/**类组合
|
|
69
69
|
* 将mixinList每个成员的字段混入base
|
|
70
70
|
* @param base - 基础类
|
package/dist/UtilFunctions.js
CHANGED
|
@@ -207,14 +207,16 @@ var UtilFunc;
|
|
|
207
207
|
function composeClassPart(base, mixin, ...fields) {
|
|
208
208
|
const compObj = base;
|
|
209
209
|
for (const fd of fields) {
|
|
210
|
+
/**
|
|
210
211
|
Object.defineProperty(compObj, fd, {
|
|
211
|
-
get: ()
|
|
212
|
-
set: (value)
|
|
213
|
-
enumerable:
|
|
212
|
+
get: ()=>mixin[fd],
|
|
213
|
+
set: (value)=>{mixin[fd] = value},
|
|
214
|
+
enumerable:true ,
|
|
214
215
|
//writable: true ,
|
|
215
216
|
configurable: true
|
|
216
217
|
});
|
|
217
|
-
|
|
218
|
+
*/
|
|
219
|
+
compObj[fd] = mixin[fd].bind(mixin);
|
|
218
220
|
}
|
|
219
221
|
return compObj;
|
|
220
222
|
}
|
package/dist/UtilInterfaces.d.ts
CHANGED
|
@@ -99,5 +99,5 @@ export type MethodsThisAs<Methods, T> = {
|
|
|
99
99
|
* @template T - 目标this类型
|
|
100
100
|
* @param prototype - 类的原型
|
|
101
101
|
*/
|
|
102
|
-
export declare function
|
|
102
|
+
export declare function assertThisAs<Self, T>(prototype: MethodsThisAs<Self, T>): void;
|
|
103
103
|
export {};
|
package/dist/UtilInterfaces.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.assertThisAs = exports.stringifyJToken = void 0;
|
|
4
4
|
/**将JToken转换为字符串
|
|
5
5
|
* @param token - 待转换的Token
|
|
6
6
|
* @param space - 插入的空格 数字为空格数量 默认为制表符\t
|
|
@@ -19,5 +19,5 @@ exports.stringifyJToken = stringifyJToken;
|
|
|
19
19
|
* @template T - 目标this类型
|
|
20
20
|
* @param prototype - 类的原型
|
|
21
21
|
*/
|
|
22
|
-
function
|
|
23
|
-
exports.
|
|
22
|
+
function assertThisAs(prototype) { }
|
|
23
|
+
exports.assertThisAs = assertThisAs;
|
package/dist/test/composeTest.js
CHANGED
package/package.json
CHANGED
package/src/UtilFunctions.ts
CHANGED
|
@@ -221,10 +221,11 @@ export async function repeatPromise<T>(procFn:PromiseProcFn<T>,verifyFn?:Promise
|
|
|
221
221
|
* @returns 混合完成的类
|
|
222
222
|
*/
|
|
223
223
|
export function composeClassPart
|
|
224
|
-
<Base extends object,Mixin extends object,Field extends
|
|
224
|
+
<Base extends object,Mixin extends object,Field extends FuncPropNames<Mixin>>
|
|
225
225
|
(base:Base,mixin:Mixin,...fields:Field[]):ComposedClassPart<Base,Mixin,Field>{
|
|
226
226
|
const compObj = base as any;
|
|
227
227
|
for(const fd of fields){
|
|
228
|
+
/**
|
|
228
229
|
Object.defineProperty(compObj, fd, {
|
|
229
230
|
get: ()=>mixin[fd],
|
|
230
231
|
set: (value)=>{mixin[fd] = value},
|
|
@@ -232,7 +233,8 @@ export function composeClassPart
|
|
|
232
233
|
//writable: true ,
|
|
233
234
|
configurable: true
|
|
234
235
|
});
|
|
235
|
-
|
|
236
|
+
*/
|
|
237
|
+
(compObj as any)[fd] = (mixin[fd] as any).bind(mixin);
|
|
236
238
|
}
|
|
237
239
|
return compObj;
|
|
238
240
|
}
|
package/src/UtilInterfaces.ts
CHANGED
|
@@ -155,4 +155,4 @@ export type MethodsThisAs<Methods, T> = {
|
|
|
155
155
|
* @template T - 目标this类型
|
|
156
156
|
* @param prototype - 类的原型
|
|
157
157
|
*/
|
|
158
|
-
export function
|
|
158
|
+
export function assertThisAs<Self,T>(prototype: MethodsThisAs<Self, T>) {}
|
package/src/test/composeTest.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UtilFP, UtilFunc,
|
|
1
|
+
import { UtilFP, UtilFunc, assertThisAs } from ".."
|
|
2
2
|
|
|
3
3
|
class A {
|
|
4
4
|
private num = 1;
|
|
@@ -39,7 +39,7 @@ function composeC(obj:_C){
|
|
|
39
39
|
}
|
|
40
40
|
export type C = ReturnType<typeof composeC>;
|
|
41
41
|
export const C = _C;
|
|
42
|
-
|
|
42
|
+
assertThisAs<_C,C>(C.prototype);
|
|
43
43
|
|
|
44
44
|
const insc:C=C.create();//?
|
|
45
45
|
insc.getC().testFunc()//?
|