utils-lib-js 1.0.2 → 1.0.3
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/common/index.d.ts +3 -0
- package/dist/common/index.js +3 -0
- package/dist/common/object.d.ts +3 -1
- package/dist/common/object.js +35 -2
- package/dist/common/request.d.ts +11 -0
- package/dist/common/request.js +26 -0
- package/dist/common/types.d.ts +11 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/object.d.ts +3 -1
- package/dist/esm/object.js +31 -0
- package/dist/esm/request.d.ts +11 -0
- package/dist/esm/request.js +18 -0
- package/dist/esm/types.d.ts +11 -0
- package/package.json +1 -1
- package/dist/common/fetch.d.ts +0 -0
- package/dist/common/fetch.js +0 -0
- package/dist/esm/fetch.d.ts +0 -0
- package/dist/esm/fetch.js +0 -0
package/dist/common/index.d.ts
CHANGED
package/dist/common/index.js
CHANGED
|
@@ -24,4 +24,7 @@ __exportStar(require("./function"), exports);
|
|
|
24
24
|
__exportStar(require("./element"), exports);
|
|
25
25
|
__exportStar(require("./static"), exports);
|
|
26
26
|
__exportStar(require("./types"), exports);
|
|
27
|
+
__exportStar(require("./request"), exports);
|
|
28
|
+
__exportStar(require("./event"), exports);
|
|
29
|
+
__exportStar(require("./storage"), exports);
|
|
27
30
|
__exportStar(require("event-message-center"), exports);
|
package/dist/common/object.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IGetValue, ISetValue, IMixIn, ICloneDeep, ICreateObjectVariable, IEnumInversion, IInherit, ICreateObject } from "./types";
|
|
1
|
+
import { IGetValue, ISetValue, IMixIn, ICloneDeep, ICreateObjectVariable, IEnumInversion, IInherit, ICreateObject, IGetInstance, IClassDecorator } from "./types";
|
|
2
2
|
export declare const getValue: IGetValue;
|
|
3
3
|
export declare const setValue: ISetValue;
|
|
4
4
|
export declare const mixIn: IMixIn;
|
|
@@ -8,3 +8,5 @@ export declare const cloneDeep: ICloneDeep;
|
|
|
8
8
|
export declare const createObjectVariable: ICreateObjectVariable;
|
|
9
9
|
export declare const createObject: ICreateObject;
|
|
10
10
|
export declare const inherit: IInherit;
|
|
11
|
+
export declare const getInstance: IGetInstance;
|
|
12
|
+
export declare const classDecorator: IClassDecorator;
|
package/dist/common/object.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
4
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
5
|
+
if (ar || !(i in from)) {
|
|
6
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
7
|
+
ar[i] = from[i];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
11
|
+
};
|
|
3
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.inherit = exports.createObject = exports.createObjectVariable = exports.cloneDeep = exports.isNotObject = exports.enumInversion = exports.mixIn = exports.setValue = exports.getValue = void 0;
|
|
13
|
+
exports.classDecorator = exports.getInstance = exports.inherit = exports.createObject = exports.createObjectVariable = exports.cloneDeep = exports.isNotObject = exports.enumInversion = exports.mixIn = exports.setValue = exports.getValue = void 0;
|
|
5
14
|
var base_1 = require("./base");
|
|
6
15
|
var getValue = function (object, key, defaultValue) {
|
|
7
16
|
if (defaultValue === void 0) {
|
|
@@ -131,4 +140,28 @@ var inherit = function (source, target) {
|
|
|
131
140
|
target.prototype.constructor = target;
|
|
132
141
|
return target;
|
|
133
142
|
};
|
|
134
|
-
exports.inherit = inherit;
|
|
143
|
+
exports.inherit = inherit;
|
|
144
|
+
var getInstance = function (classProto, overwrite) {
|
|
145
|
+
if (overwrite === void 0) {
|
|
146
|
+
overwrite = false;
|
|
147
|
+
}
|
|
148
|
+
var params = [];
|
|
149
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
150
|
+
params[_i - 2] = arguments[_i];
|
|
151
|
+
}
|
|
152
|
+
if (!classProto._instance || overwrite) {
|
|
153
|
+
classProto._instance = new (classProto.bind.apply(classProto, __spreadArray([void 0], params, false)))();
|
|
154
|
+
}
|
|
155
|
+
return classProto._instance;
|
|
156
|
+
};
|
|
157
|
+
exports.getInstance = getInstance;
|
|
158
|
+
var classDecorator = function (params) {
|
|
159
|
+
return function (target) {
|
|
160
|
+
for (var key in params) {
|
|
161
|
+
if (!!!Reflect.has(target.prototype, key)) {
|
|
162
|
+
target.prototype[key] = params[key];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
exports.classDecorator = classDecorator;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IRequest } from "./types";
|
|
2
|
+
export declare class Request implements IRequest {
|
|
3
|
+
origin: string;
|
|
4
|
+
constructor();
|
|
5
|
+
fixOrigin(origin: any): any;
|
|
6
|
+
envDesc(): "Window" | "Node";
|
|
7
|
+
}
|
|
8
|
+
export declare const GET: () => void;
|
|
9
|
+
export declare const POST: () => void;
|
|
10
|
+
export declare const PUT: () => void;
|
|
11
|
+
export declare const DELETE: () => void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.DELETE = exports.PUT = exports.POST = exports.GET = exports.Request = void 0;
|
|
5
|
+
var Request = function () {
|
|
6
|
+
function Request() {}
|
|
7
|
+
Request.prototype.fixOrigin = function (origin) {
|
|
8
|
+
return origin;
|
|
9
|
+
};
|
|
10
|
+
Request.prototype.envDesc = function () {
|
|
11
|
+
if (Window) {
|
|
12
|
+
return "Window";
|
|
13
|
+
}
|
|
14
|
+
return "Node";
|
|
15
|
+
};
|
|
16
|
+
return Request;
|
|
17
|
+
}();
|
|
18
|
+
exports.Request = Request;
|
|
19
|
+
var GET = function () {};
|
|
20
|
+
exports.GET = GET;
|
|
21
|
+
var POST = function () {};
|
|
22
|
+
exports.POST = POST;
|
|
23
|
+
var PUT = function () {};
|
|
24
|
+
exports.PUT = PUT;
|
|
25
|
+
var DELETE = function () {};
|
|
26
|
+
exports.DELETE = DELETE;
|
package/dist/common/types.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export interface IPromise extends IObject<any> {
|
|
|
7
7
|
resolve: () => unknown;
|
|
8
8
|
reject: () => unknown;
|
|
9
9
|
}
|
|
10
|
+
export declare type IInstance<T> = {
|
|
11
|
+
_instance: Function;
|
|
12
|
+
} & T;
|
|
10
13
|
export declare type IDemoteArray<T> = Array<IDemoteArray<T> | T>;
|
|
11
14
|
export declare type IRandomNum = (min: number, max: number, bool?: boolean) => number;
|
|
12
15
|
export declare type IUrlSplit = (url: string) => IObject<any>;
|
|
@@ -20,6 +23,8 @@ export declare type ICloneDeep = (target?: any) => any;
|
|
|
20
23
|
export declare type ICreateObjectVariable = (type: string, source?: any) => any;
|
|
21
24
|
export declare type ICreateObject = <T, U extends T>(source: T) => U;
|
|
22
25
|
export declare type IInherit = <T extends Function>(source: T, target?: Function) => Function;
|
|
26
|
+
export declare type IGetInstance = (classProto: IInstance<FunctionConstructor>, overwrite?: boolean, ...params: any[]) => Function;
|
|
27
|
+
export declare type IClassDecorator = (params: IObject<any>) => <TFunction extends Function>(target: TFunction) => void;
|
|
23
28
|
export declare type IThrottle = (fn: Function, time: number) => (...args: any[]) => void;
|
|
24
29
|
export declare type IDebounce = (fn: Function, time: number) => (...args: any[]) => void;
|
|
25
30
|
export declare type IDefer = () => IPromise;
|
|
@@ -39,4 +44,10 @@ export declare type IStopBubble = (e: Event) => void;
|
|
|
39
44
|
export declare type IStopDefault = (e: Event) => void;
|
|
40
45
|
export declare type IRemoveHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void;
|
|
41
46
|
export declare type IDispatchEvent = <T extends Document>(ele: T, data: any) => void;
|
|
47
|
+
export declare type IRequest = {
|
|
48
|
+
origin: string;
|
|
49
|
+
fixOrigin: <T = string>(origin: T) => T;
|
|
50
|
+
envDesc: () => "Window" | "Node";
|
|
51
|
+
};
|
|
52
|
+
export declare type IGet = (url: string, params: IObject<any>) => Promise<void>;
|
|
42
53
|
export {};
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/object.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IGetValue, ISetValue, IMixIn, ICloneDeep, ICreateObjectVariable, IEnumInversion, IInherit, ICreateObject } from "./types";
|
|
1
|
+
import { IGetValue, ISetValue, IMixIn, ICloneDeep, ICreateObjectVariable, IEnumInversion, IInherit, ICreateObject, IGetInstance, IClassDecorator } from "./types";
|
|
2
2
|
export declare const getValue: IGetValue;
|
|
3
3
|
export declare const setValue: ISetValue;
|
|
4
4
|
export declare const mixIn: IMixIn;
|
|
@@ -8,3 +8,5 @@ export declare const cloneDeep: ICloneDeep;
|
|
|
8
8
|
export declare const createObjectVariable: ICreateObjectVariable;
|
|
9
9
|
export declare const createObject: ICreateObject;
|
|
10
10
|
export declare const inherit: IInherit;
|
|
11
|
+
export declare const getInstance: IGetInstance;
|
|
12
|
+
export declare const classDecorator: IClassDecorator;
|
package/dist/esm/object.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
2
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
+
if (ar || !(i in from)) {
|
|
4
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
+
ar[i] = from[i];
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
+
};
|
|
1
10
|
import { getType } from "./base";
|
|
2
11
|
export var getValue = function (object, key, defaultValue) {
|
|
3
12
|
if (defaultValue === void 0) {
|
|
@@ -118,4 +127,26 @@ export var inherit = function (source, target) {
|
|
|
118
127
|
target.prototype.super = source;
|
|
119
128
|
target.prototype.constructor = target;
|
|
120
129
|
return target;
|
|
130
|
+
};
|
|
131
|
+
export var getInstance = function (classProto, overwrite) {
|
|
132
|
+
if (overwrite === void 0) {
|
|
133
|
+
overwrite = false;
|
|
134
|
+
}
|
|
135
|
+
var params = [];
|
|
136
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
137
|
+
params[_i - 2] = arguments[_i];
|
|
138
|
+
}
|
|
139
|
+
if (!classProto._instance || overwrite) {
|
|
140
|
+
classProto._instance = new (classProto.bind.apply(classProto, __spreadArray([void 0], params, false)))();
|
|
141
|
+
}
|
|
142
|
+
return classProto._instance;
|
|
143
|
+
};
|
|
144
|
+
export var classDecorator = function (params) {
|
|
145
|
+
return function (target) {
|
|
146
|
+
for (var key in params) {
|
|
147
|
+
if (!!!Reflect.has(target.prototype, key)) {
|
|
148
|
+
target.prototype[key] = params[key];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
121
152
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IRequest } from "./types";
|
|
2
|
+
export declare class Request implements IRequest {
|
|
3
|
+
origin: string;
|
|
4
|
+
constructor();
|
|
5
|
+
fixOrigin(origin: any): any;
|
|
6
|
+
envDesc(): "Window" | "Node";
|
|
7
|
+
}
|
|
8
|
+
export declare const GET: () => void;
|
|
9
|
+
export declare const POST: () => void;
|
|
10
|
+
export declare const PUT: () => void;
|
|
11
|
+
export declare const DELETE: () => void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var Request = function () {
|
|
2
|
+
function Request() {}
|
|
3
|
+
Request.prototype.fixOrigin = function (origin) {
|
|
4
|
+
return origin;
|
|
5
|
+
};
|
|
6
|
+
Request.prototype.envDesc = function () {
|
|
7
|
+
if (Window) {
|
|
8
|
+
return "Window";
|
|
9
|
+
}
|
|
10
|
+
return "Node";
|
|
11
|
+
};
|
|
12
|
+
return Request;
|
|
13
|
+
}();
|
|
14
|
+
export { Request };
|
|
15
|
+
export var GET = function () {};
|
|
16
|
+
export var POST = function () {};
|
|
17
|
+
export var PUT = function () {};
|
|
18
|
+
export var DELETE = function () {};
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export interface IPromise extends IObject<any> {
|
|
|
7
7
|
resolve: () => unknown;
|
|
8
8
|
reject: () => unknown;
|
|
9
9
|
}
|
|
10
|
+
export declare type IInstance<T> = {
|
|
11
|
+
_instance: Function;
|
|
12
|
+
} & T;
|
|
10
13
|
export declare type IDemoteArray<T> = Array<IDemoteArray<T> | T>;
|
|
11
14
|
export declare type IRandomNum = (min: number, max: number, bool?: boolean) => number;
|
|
12
15
|
export declare type IUrlSplit = (url: string) => IObject<any>;
|
|
@@ -20,6 +23,8 @@ export declare type ICloneDeep = (target?: any) => any;
|
|
|
20
23
|
export declare type ICreateObjectVariable = (type: string, source?: any) => any;
|
|
21
24
|
export declare type ICreateObject = <T, U extends T>(source: T) => U;
|
|
22
25
|
export declare type IInherit = <T extends Function>(source: T, target?: Function) => Function;
|
|
26
|
+
export declare type IGetInstance = (classProto: IInstance<FunctionConstructor>, overwrite?: boolean, ...params: any[]) => Function;
|
|
27
|
+
export declare type IClassDecorator = (params: IObject<any>) => <TFunction extends Function>(target: TFunction) => void;
|
|
23
28
|
export declare type IThrottle = (fn: Function, time: number) => (...args: any[]) => void;
|
|
24
29
|
export declare type IDebounce = (fn: Function, time: number) => (...args: any[]) => void;
|
|
25
30
|
export declare type IDefer = () => IPromise;
|
|
@@ -39,4 +44,10 @@ export declare type IStopBubble = (e: Event) => void;
|
|
|
39
44
|
export declare type IStopDefault = (e: Event) => void;
|
|
40
45
|
export declare type IRemoveHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void;
|
|
41
46
|
export declare type IDispatchEvent = <T extends Document>(ele: T, data: any) => void;
|
|
47
|
+
export declare type IRequest = {
|
|
48
|
+
origin: string;
|
|
49
|
+
fixOrigin: <T = string>(origin: T) => T;
|
|
50
|
+
envDesc: () => "Window" | "Node";
|
|
51
|
+
};
|
|
52
|
+
export declare type IGet = (url: string, params: IObject<any>) => Promise<void>;
|
|
42
53
|
export {};
|
package/package.json
CHANGED
package/dist/common/fetch.d.ts
DELETED
|
File without changes
|
package/dist/common/fetch.js
DELETED
|
File without changes
|
package/dist/esm/fetch.d.ts
DELETED
|
File without changes
|
package/dist/esm/fetch.js
DELETED
|
File without changes
|