utils-lib-js 1.0.3 → 1.0.4
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/array.d.ts +1 -1
- package/dist/common/array.js +2 -2
- package/dist/common/base.d.ts +1 -2
- package/dist/common/base.js +2 -2
- package/dist/common/element.d.ts +1 -1
- package/dist/common/event.d.ts +1 -1
- package/dist/common/function.d.ts +1 -1
- package/dist/common/index.d.ts +10 -11
- package/dist/common/index.js +10 -11
- package/dist/common/object.d.ts +1 -1
- package/dist/common/object.js +2 -2
- package/dist/common/request.d.ts +6 -2
- package/dist/common/request.js +42 -3
- package/dist/common/types.d.ts +4 -3
- package/dist/esm/array.d.ts +1 -1
- package/dist/esm/array.js +1 -1
- package/dist/esm/base.d.ts +1 -2
- package/dist/esm/base.js +1 -1
- package/dist/esm/element.d.ts +1 -1
- package/dist/esm/event.d.ts +1 -1
- package/dist/esm/function.d.ts +1 -1
- package/dist/esm/index.d.ts +10 -11
- package/dist/esm/index.js +10 -11
- package/dist/esm/object.d.ts +1 -1
- package/dist/esm/object.js +1 -1
- package/dist/esm/request.d.ts +6 -2
- package/dist/esm/request.js +40 -2
- package/dist/esm/types.d.ts +4 -3
- package/index.html +15 -0
- package/package.json +2 -1
- package/tsconfig.es.json +3 -7
package/dist/common/array.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./
|
|
1
|
+
import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./index.js";
|
|
2
2
|
export declare const arrayRandom: IArrayRandom<any[]>;
|
|
3
3
|
export declare const arrayUniq: IArrayUniq<any[]>;
|
|
4
4
|
export declare const arrayDemote: IArrayDemote<IDemoteArray<any>>;
|
package/dist/common/array.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.arrayDemote = exports.arrayUniq = exports.arrayRandom = void 0;
|
|
5
|
-
var
|
|
5
|
+
var index_js_1 = require("./index.js");
|
|
6
6
|
var arrayRandom = function (arr) {
|
|
7
7
|
return arr.sort(function () {
|
|
8
8
|
return Math.random() - 0.5;
|
|
@@ -18,7 +18,7 @@ var arrayDemote = function (arr, result) {
|
|
|
18
18
|
result = [];
|
|
19
19
|
}
|
|
20
20
|
arr.forEach(function (i) {
|
|
21
|
-
return (0,
|
|
21
|
+
return (0, index_js_1.getType)(i) === "array" ? (0, exports.arrayDemote)(i, result) : result.push(i);
|
|
22
22
|
});
|
|
23
23
|
return result;
|
|
24
24
|
};
|
package/dist/common/base.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { IRandomNum, IUrlSplit, IUrlJoin, IGetType } from "./
|
|
2
|
-
import { types } from "./static";
|
|
1
|
+
import { IRandomNum, IUrlSplit, IUrlJoin, IGetType, types } from "./index.js";
|
|
3
2
|
export declare const randomNum: IRandomNum;
|
|
4
3
|
export declare const urlSplit: IUrlSplit;
|
|
5
4
|
export declare const urlJoin: IUrlJoin;
|
package/dist/common/base.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.getType = exports.urlJoin = exports.urlSplit = exports.randomNum = void 0;
|
|
5
|
-
var
|
|
5
|
+
var index_js_1 = require("./index.js");
|
|
6
6
|
var randomNum = function (min, max, bool) {
|
|
7
7
|
if (bool === void 0) {
|
|
8
8
|
bool = false;
|
|
@@ -36,7 +36,7 @@ var getType = function (data) {
|
|
|
36
36
|
return "null";
|
|
37
37
|
} else if (type === "object") {
|
|
38
38
|
var key = Object.prototype.toString.call(data);
|
|
39
|
-
return
|
|
39
|
+
return index_js_1.types[key];
|
|
40
40
|
}
|
|
41
41
|
return type;
|
|
42
42
|
};
|
package/dist/common/element.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ICreateElement } from "./
|
|
1
|
+
import { ICreateElement } from "./index.js";
|
|
2
2
|
export declare const createElement: ICreateElement;
|
package/dist/common/event.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IAddHandler, IStopBubble, IStopDefault, IRemoveHandler, IDispatchEvent } from "./
|
|
1
|
+
import { IAddHandler, IStopBubble, IStopDefault, IRemoveHandler, IDispatchEvent } from "./index.js";
|
|
2
2
|
export declare const addHandler: IAddHandler;
|
|
3
3
|
export declare const stopBubble: IStopBubble;
|
|
4
4
|
export declare const stopDefault: IStopDefault;
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
export * from "./object";
|
|
2
|
-
export * from "./base";
|
|
3
|
-
export * from "./array";
|
|
4
|
-
export * from "./function";
|
|
5
|
-
export * from "./element";
|
|
6
|
-
export * from "./static";
|
|
7
|
-
export * from "./types";
|
|
8
|
-
export * from "./request";
|
|
9
|
-
export * from "./event";
|
|
10
|
-
export * from "./storage";
|
|
11
|
-
export * from "event-message-center";
|
|
1
|
+
export * from "./object.js";
|
|
2
|
+
export * from "./base.js";
|
|
3
|
+
export * from "./array.js";
|
|
4
|
+
export * from "./function.js";
|
|
5
|
+
export * from "./element.js";
|
|
6
|
+
export * from "./static.js";
|
|
7
|
+
export * from "./types.js";
|
|
8
|
+
export * from "./request.js";
|
|
9
|
+
export * from "./event.js";
|
|
10
|
+
export * from "./storage.js";
|
package/dist/common/index.js
CHANGED
|
@@ -17,14 +17,13 @@ var __exportStar = this && this.__exportStar || function (m, exports) {
|
|
|
17
17
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
__exportStar(require("./object"), exports);
|
|
21
|
-
__exportStar(require("./base"), exports);
|
|
22
|
-
__exportStar(require("./array"), exports);
|
|
23
|
-
__exportStar(require("./function"), exports);
|
|
24
|
-
__exportStar(require("./element"), exports);
|
|
25
|
-
__exportStar(require("./static"), exports);
|
|
26
|
-
__exportStar(require("./types"), exports);
|
|
27
|
-
__exportStar(require("./request"), exports);
|
|
28
|
-
__exportStar(require("./event"), exports);
|
|
29
|
-
__exportStar(require("./storage"), exports);
|
|
30
|
-
__exportStar(require("event-message-center"), exports);
|
|
20
|
+
__exportStar(require("./object.js"), exports);
|
|
21
|
+
__exportStar(require("./base.js"), exports);
|
|
22
|
+
__exportStar(require("./array.js"), exports);
|
|
23
|
+
__exportStar(require("./function.js"), exports);
|
|
24
|
+
__exportStar(require("./element.js"), exports);
|
|
25
|
+
__exportStar(require("./static.js"), exports);
|
|
26
|
+
__exportStar(require("./types.js"), exports);
|
|
27
|
+
__exportStar(require("./request.js"), exports);
|
|
28
|
+
__exportStar(require("./event.js"), exports);
|
|
29
|
+
__exportStar(require("./storage.js"), exports);
|
package/dist/common/object.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IGetValue, ISetValue, IMixIn, ICloneDeep, ICreateObjectVariable, IEnumInversion, IInherit, ICreateObject, IGetInstance, IClassDecorator } from "./
|
|
1
|
+
import { IGetValue, ISetValue, IMixIn, ICloneDeep, ICreateObjectVariable, IEnumInversion, IInherit, ICreateObject, IGetInstance, IClassDecorator } from "./index.js";
|
|
2
2
|
export declare const getValue: IGetValue;
|
|
3
3
|
export declare const setValue: ISetValue;
|
|
4
4
|
export declare const mixIn: IMixIn;
|
package/dist/common/object.js
CHANGED
|
@@ -11,7 +11,7 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
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;
|
|
14
|
-
var
|
|
14
|
+
var index_js_1 = require("./index.js");
|
|
15
15
|
var getValue = function (object, key, defaultValue) {
|
|
16
16
|
if (defaultValue === void 0) {
|
|
17
17
|
defaultValue = '';
|
|
@@ -81,7 +81,7 @@ var isNotObject = function (source, type) {
|
|
|
81
81
|
};
|
|
82
82
|
exports.isNotObject = isNotObject;
|
|
83
83
|
var cloneDeep = function (target) {
|
|
84
|
-
var __type = (0,
|
|
84
|
+
var __type = (0, index_js_1.getType)(target);
|
|
85
85
|
if ((0, exports.isNotObject)(target, __type)) return target;
|
|
86
86
|
var __init = (0, exports.createObjectVariable)(__type, target);
|
|
87
87
|
if (__type === "map") {
|
package/dist/common/request.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { IRequest } from "./
|
|
1
|
+
import { IRequest } from "./index.js";
|
|
2
2
|
export declare class Request implements IRequest {
|
|
3
3
|
origin: string;
|
|
4
4
|
constructor();
|
|
5
|
-
fixOrigin(origin: any):
|
|
5
|
+
fixOrigin(origin: any): this;
|
|
6
6
|
envDesc(): "Window" | "Node";
|
|
7
|
+
ajax(url: any, opts: any): void;
|
|
8
|
+
fetch(): Promise<Response>;
|
|
9
|
+
http(): void;
|
|
7
10
|
}
|
|
8
11
|
export declare const GET: () => void;
|
|
9
12
|
export declare const POST: () => void;
|
|
10
13
|
export declare const PUT: () => void;
|
|
11
14
|
export declare const DELETE: () => void;
|
|
15
|
+
export declare const OPTION: () => void;
|
package/dist/common/request.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.DELETE = exports.PUT = exports.POST = exports.GET = exports.Request = void 0;
|
|
4
|
+
exports.OPTION = exports.DELETE = exports.PUT = exports.POST = exports.GET = exports.Request = void 0;
|
|
5
|
+
var index_js_1 = require("./index.js");
|
|
5
6
|
var Request = function () {
|
|
6
7
|
function Request() {}
|
|
7
8
|
Request.prototype.fixOrigin = function (origin) {
|
|
8
|
-
|
|
9
|
+
this.origin = origin;
|
|
10
|
+
return this;
|
|
9
11
|
};
|
|
10
12
|
Request.prototype.envDesc = function () {
|
|
11
13
|
if (Window) {
|
|
@@ -13,6 +15,41 @@ var Request = function () {
|
|
|
13
15
|
}
|
|
14
16
|
return "Node";
|
|
15
17
|
};
|
|
18
|
+
Request.prototype.ajax = function (url, opts) {
|
|
19
|
+
var _a = (0, index_js_1.defer)(),
|
|
20
|
+
promise = _a.promise,
|
|
21
|
+
resolve = _a.resolve,
|
|
22
|
+
reject = _a.reject;
|
|
23
|
+
var _b = opts.method,
|
|
24
|
+
method = _b === void 0 ? "GET" : _b,
|
|
25
|
+
_c = opts.params,
|
|
26
|
+
params = _c === void 0 ? {} : _c,
|
|
27
|
+
_d = opts.body,
|
|
28
|
+
body = _d === void 0 ? {} : _d,
|
|
29
|
+
_e = opts.async,
|
|
30
|
+
async = _e === void 0 ? true : _e,
|
|
31
|
+
_f = opts.timeout,
|
|
32
|
+
timeout = _f === void 0 ? 30 * 1000 : _f;
|
|
33
|
+
var xhr = new XMLHttpRequest();
|
|
34
|
+
switch (method) {
|
|
35
|
+
case 'GET':
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
xhr.addEventListener('load', function () {
|
|
41
|
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
|
42
|
+
try {} catch (error) {}
|
|
43
|
+
} else {}
|
|
44
|
+
});
|
|
45
|
+
xhr.open(method, url, async);
|
|
46
|
+
xhr.send(body);
|
|
47
|
+
xhr.timeout = async && timeout;
|
|
48
|
+
};
|
|
49
|
+
Request.prototype.fetch = function () {
|
|
50
|
+
return fetch("");
|
|
51
|
+
};
|
|
52
|
+
Request.prototype.http = function () {};
|
|
16
53
|
return Request;
|
|
17
54
|
}();
|
|
18
55
|
exports.Request = Request;
|
|
@@ -23,4 +60,6 @@ exports.POST = POST;
|
|
|
23
60
|
var PUT = function () {};
|
|
24
61
|
exports.PUT = PUT;
|
|
25
62
|
var DELETE = function () {};
|
|
26
|
-
exports.DELETE = DELETE;
|
|
63
|
+
exports.DELETE = DELETE;
|
|
64
|
+
var OPTION = function () {};
|
|
65
|
+
exports.OPTION = OPTION;
|
package/dist/common/types.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export interface IObject<T> {
|
|
|
4
4
|
}
|
|
5
5
|
export interface IPromise extends IObject<any> {
|
|
6
6
|
promise: Promise<void>;
|
|
7
|
-
resolve: () => unknown;
|
|
8
|
-
reject: () => unknown;
|
|
7
|
+
resolve: (res: any) => unknown;
|
|
8
|
+
reject: (err: any) => unknown;
|
|
9
9
|
}
|
|
10
10
|
export declare type IInstance<T> = {
|
|
11
11
|
_instance: Function;
|
|
@@ -46,8 +46,9 @@ export declare type IRemoveHandler = <T extends Document>(ele: T, type: string,
|
|
|
46
46
|
export declare type IDispatchEvent = <T extends Document>(ele: T, data: any) => void;
|
|
47
47
|
export declare type IRequest = {
|
|
48
48
|
origin: string;
|
|
49
|
-
fixOrigin: <T = string>(origin: T) =>
|
|
49
|
+
fixOrigin: <T = string>(origin: T) => IRequest;
|
|
50
50
|
envDesc: () => "Window" | "Node";
|
|
51
|
+
fetch: () => Promise<Response>;
|
|
51
52
|
};
|
|
52
53
|
export declare type IGet = (url: string, params: IObject<any>) => Promise<void>;
|
|
53
54
|
export {};
|
package/dist/esm/array.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./
|
|
1
|
+
import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./index.js";
|
|
2
2
|
export declare const arrayRandom: IArrayRandom<any[]>;
|
|
3
3
|
export declare const arrayUniq: IArrayUniq<any[]>;
|
|
4
4
|
export declare const arrayDemote: IArrayDemote<IDemoteArray<any>>;
|
package/dist/esm/array.js
CHANGED
package/dist/esm/base.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { IRandomNum, IUrlSplit, IUrlJoin, IGetType } from "./
|
|
2
|
-
import { types } from "./static";
|
|
1
|
+
import { IRandomNum, IUrlSplit, IUrlJoin, IGetType, types } from "./index.js";
|
|
3
2
|
export declare const randomNum: IRandomNum;
|
|
4
3
|
export declare const urlSplit: IUrlSplit;
|
|
5
4
|
export declare const urlJoin: IUrlJoin;
|
package/dist/esm/base.js
CHANGED
package/dist/esm/element.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ICreateElement } from "./
|
|
1
|
+
import { ICreateElement } from "./index.js";
|
|
2
2
|
export declare const createElement: ICreateElement;
|
package/dist/esm/event.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IAddHandler, IStopBubble, IStopDefault, IRemoveHandler, IDispatchEvent } from "./
|
|
1
|
+
import { IAddHandler, IStopBubble, IStopDefault, IRemoveHandler, IDispatchEvent } from "./index.js";
|
|
2
2
|
export declare const addHandler: IAddHandler;
|
|
3
3
|
export declare const stopBubble: IStopBubble;
|
|
4
4
|
export declare const stopDefault: IStopDefault;
|
package/dist/esm/function.d.ts
CHANGED
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
export * from "./object";
|
|
2
|
-
export * from "./base";
|
|
3
|
-
export * from "./array";
|
|
4
|
-
export * from "./function";
|
|
5
|
-
export * from "./element";
|
|
6
|
-
export * from "./static";
|
|
7
|
-
export * from "./types";
|
|
8
|
-
export * from "./request";
|
|
9
|
-
export * from "./event";
|
|
10
|
-
export * from "./storage";
|
|
11
|
-
export * from "event-message-center";
|
|
1
|
+
export * from "./object.js";
|
|
2
|
+
export * from "./base.js";
|
|
3
|
+
export * from "./array.js";
|
|
4
|
+
export * from "./function.js";
|
|
5
|
+
export * from "./element.js";
|
|
6
|
+
export * from "./static.js";
|
|
7
|
+
export * from "./types.js";
|
|
8
|
+
export * from "./request.js";
|
|
9
|
+
export * from "./event.js";
|
|
10
|
+
export * from "./storage.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
export * from "./object";
|
|
2
|
-
export * from "./base";
|
|
3
|
-
export * from "./array";
|
|
4
|
-
export * from "./function";
|
|
5
|
-
export * from "./element";
|
|
6
|
-
export * from "./static";
|
|
7
|
-
export * from "./types";
|
|
8
|
-
export * from "./request";
|
|
9
|
-
export * from "./event";
|
|
10
|
-
export * from "./storage";
|
|
11
|
-
export * from "event-message-center";
|
|
1
|
+
export * from "./object.js";
|
|
2
|
+
export * from "./base.js";
|
|
3
|
+
export * from "./array.js";
|
|
4
|
+
export * from "./function.js";
|
|
5
|
+
export * from "./element.js";
|
|
6
|
+
export * from "./static.js";
|
|
7
|
+
export * from "./types.js";
|
|
8
|
+
export * from "./request.js";
|
|
9
|
+
export * from "./event.js";
|
|
10
|
+
export * from "./storage.js";
|
package/dist/esm/object.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IGetValue, ISetValue, IMixIn, ICloneDeep, ICreateObjectVariable, IEnumInversion, IInherit, ICreateObject, IGetInstance, IClassDecorator } from "./
|
|
1
|
+
import { IGetValue, ISetValue, IMixIn, ICloneDeep, ICreateObjectVariable, IEnumInversion, IInherit, ICreateObject, IGetInstance, IClassDecorator } from "./index.js";
|
|
2
2
|
export declare const getValue: IGetValue;
|
|
3
3
|
export declare const setValue: ISetValue;
|
|
4
4
|
export declare const mixIn: IMixIn;
|
package/dist/esm/object.js
CHANGED
|
@@ -7,7 +7,7 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
|
7
7
|
}
|
|
8
8
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
9
|
};
|
|
10
|
-
import { getType } from "./
|
|
10
|
+
import { getType } from "./index.js";
|
|
11
11
|
export var getValue = function (object, key, defaultValue) {
|
|
12
12
|
if (defaultValue === void 0) {
|
|
13
13
|
defaultValue = '';
|
package/dist/esm/request.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { IRequest } from "./
|
|
1
|
+
import { IRequest } from "./index.js";
|
|
2
2
|
export declare class Request implements IRequest {
|
|
3
3
|
origin: string;
|
|
4
4
|
constructor();
|
|
5
|
-
fixOrigin(origin: any):
|
|
5
|
+
fixOrigin(origin: any): this;
|
|
6
6
|
envDesc(): "Window" | "Node";
|
|
7
|
+
ajax(url: any, opts: any): void;
|
|
8
|
+
fetch(): Promise<Response>;
|
|
9
|
+
http(): void;
|
|
7
10
|
}
|
|
8
11
|
export declare const GET: () => void;
|
|
9
12
|
export declare const POST: () => void;
|
|
10
13
|
export declare const PUT: () => void;
|
|
11
14
|
export declare const DELETE: () => void;
|
|
15
|
+
export declare const OPTION: () => void;
|
package/dist/esm/request.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { defer } from "./index.js";
|
|
1
2
|
var Request = function () {
|
|
2
3
|
function Request() {}
|
|
3
4
|
Request.prototype.fixOrigin = function (origin) {
|
|
4
|
-
|
|
5
|
+
this.origin = origin;
|
|
6
|
+
return this;
|
|
5
7
|
};
|
|
6
8
|
Request.prototype.envDesc = function () {
|
|
7
9
|
if (Window) {
|
|
@@ -9,10 +11,46 @@ var Request = function () {
|
|
|
9
11
|
}
|
|
10
12
|
return "Node";
|
|
11
13
|
};
|
|
14
|
+
Request.prototype.ajax = function (url, opts) {
|
|
15
|
+
var _a = defer(),
|
|
16
|
+
promise = _a.promise,
|
|
17
|
+
resolve = _a.resolve,
|
|
18
|
+
reject = _a.reject;
|
|
19
|
+
var _b = opts.method,
|
|
20
|
+
method = _b === void 0 ? "GET" : _b,
|
|
21
|
+
_c = opts.params,
|
|
22
|
+
params = _c === void 0 ? {} : _c,
|
|
23
|
+
_d = opts.body,
|
|
24
|
+
body = _d === void 0 ? {} : _d,
|
|
25
|
+
_e = opts.async,
|
|
26
|
+
async = _e === void 0 ? true : _e,
|
|
27
|
+
_f = opts.timeout,
|
|
28
|
+
timeout = _f === void 0 ? 30 * 1000 : _f;
|
|
29
|
+
var xhr = new XMLHttpRequest();
|
|
30
|
+
switch (method) {
|
|
31
|
+
case 'GET':
|
|
32
|
+
break;
|
|
33
|
+
default:
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
xhr.addEventListener('load', function () {
|
|
37
|
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
|
38
|
+
try {} catch (error) {}
|
|
39
|
+
} else {}
|
|
40
|
+
});
|
|
41
|
+
xhr.open(method, url, async);
|
|
42
|
+
xhr.send(body);
|
|
43
|
+
xhr.timeout = async && timeout;
|
|
44
|
+
};
|
|
45
|
+
Request.prototype.fetch = function () {
|
|
46
|
+
return fetch("");
|
|
47
|
+
};
|
|
48
|
+
Request.prototype.http = function () {};
|
|
12
49
|
return Request;
|
|
13
50
|
}();
|
|
14
51
|
export { Request };
|
|
15
52
|
export var GET = function () {};
|
|
16
53
|
export var POST = function () {};
|
|
17
54
|
export var PUT = function () {};
|
|
18
|
-
export var DELETE = function () {};
|
|
55
|
+
export var DELETE = function () {};
|
|
56
|
+
export var OPTION = function () {};
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export interface IObject<T> {
|
|
|
4
4
|
}
|
|
5
5
|
export interface IPromise extends IObject<any> {
|
|
6
6
|
promise: Promise<void>;
|
|
7
|
-
resolve: () => unknown;
|
|
8
|
-
reject: () => unknown;
|
|
7
|
+
resolve: (res: any) => unknown;
|
|
8
|
+
reject: (err: any) => unknown;
|
|
9
9
|
}
|
|
10
10
|
export declare type IInstance<T> = {
|
|
11
11
|
_instance: Function;
|
|
@@ -46,8 +46,9 @@ export declare type IRemoveHandler = <T extends Document>(ele: T, type: string,
|
|
|
46
46
|
export declare type IDispatchEvent = <T extends Document>(ele: T, data: any) => void;
|
|
47
47
|
export declare type IRequest = {
|
|
48
48
|
origin: string;
|
|
49
|
-
fixOrigin: <T = string>(origin: T) =>
|
|
49
|
+
fixOrigin: <T = string>(origin: T) => IRequest;
|
|
50
50
|
envDesc: () => "Window" | "Node";
|
|
51
|
+
fetch: () => Promise<Response>;
|
|
51
52
|
};
|
|
52
53
|
export declare type IGet = (url: string, params: IObject<any>) => Promise<void>;
|
|
53
54
|
export {};
|
package/index.html
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Document</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<script type="module">
|
|
11
|
+
import { Request } from "./dist/esm/request.js";
|
|
12
|
+
console.log(Request);
|
|
13
|
+
</script>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "utils-lib-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "JavaScript工具函数,封装的一些常用的js函数",
|
|
5
5
|
"main": "./dist/common/index.js",
|
|
6
6
|
"types": "./dist/common/index.d.ts",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"debug": "start cmd /k pnpm run build:hot & pnpm run node:hot",
|
|
14
14
|
"node:hot": "nodemon ./dist/common/index.js",
|
|
15
|
+
"build:hot:esm": "tsc -p tsconfig.es.json -w",
|
|
15
16
|
"build:hot": "tsc -p tsconfig.json -w",
|
|
16
17
|
"build": "pnpm run tsc:build && pnpm run babel:mjs && pnpm run babel:cjs",
|
|
17
18
|
"tsc:build": "rm -fr dist && tsc -p tsconfig.json && tsc -p tsconfig.es.json",
|
package/tsconfig.es.json
CHANGED