utils-lib-js 1.6.2 → 1.6.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.
Files changed (72) hide show
  1. package/dist/bundle/array.d.ts +10 -0
  2. package/dist/bundle/base.d.ts +14 -0
  3. package/dist/bundle/element.d.ts +6 -0
  4. package/dist/bundle/event.d.ts +14 -0
  5. package/dist/bundle/function.d.ts +12 -0
  6. package/dist/bundle/index.d.ts +51 -0
  7. package/dist/bundle/index.js +1023 -0
  8. package/dist/bundle/object.d.ts +30 -0
  9. package/dist/bundle/request.d.ts +60 -0
  10. package/dist/bundle/static.d.ts +16 -0
  11. package/dist/bundle/storage.d.ts +9 -0
  12. package/dist/bundle/types.d.ts +103 -0
  13. package/dist/cjs/array.d.ts +10 -10
  14. package/dist/cjs/array.js +19 -19
  15. package/dist/cjs/base.d.ts +14 -14
  16. package/dist/cjs/base.js +56 -56
  17. package/dist/cjs/element.d.ts +6 -6
  18. package/dist/cjs/element.js +16 -16
  19. package/dist/cjs/event.d.ts +14 -14
  20. package/dist/cjs/event.js +53 -53
  21. package/dist/cjs/function.d.ts +12 -12
  22. package/dist/cjs/function.js +66 -66
  23. package/dist/cjs/index.d.ts +51 -51
  24. package/dist/cjs/index.js +54 -54
  25. package/dist/cjs/object.d.ts +30 -30
  26. package/dist/cjs/object.js +190 -190
  27. package/dist/cjs/request.d.ts +60 -60
  28. package/dist/cjs/request.js +239 -239
  29. package/dist/cjs/static.d.ts +16 -16
  30. package/dist/cjs/static.js +18 -18
  31. package/dist/cjs/storage.d.ts +9 -9
  32. package/dist/cjs/storage.js +41 -41
  33. package/dist/cjs/types.d.ts +103 -103
  34. package/dist/cjs/types.js +2 -2
  35. package/dist/esm/array.d.ts +10 -10
  36. package/dist/esm/array.js +13 -13
  37. package/dist/esm/base.d.ts +14 -14
  38. package/dist/esm/base.js +48 -48
  39. package/dist/esm/element.d.ts +6 -6
  40. package/dist/esm/element.js +12 -12
  41. package/dist/esm/event.d.ts +14 -14
  42. package/dist/esm/event.js +45 -45
  43. package/dist/esm/function.d.ts +12 -12
  44. package/dist/esm/function.js +59 -59
  45. package/dist/esm/index.d.ts +51 -51
  46. package/dist/esm/index.js +35 -35
  47. package/dist/esm/object.d.ts +30 -30
  48. package/dist/esm/object.js +174 -174
  49. package/dist/esm/request.d.ts +60 -60
  50. package/dist/esm/request.js +236 -236
  51. package/dist/esm/static.d.ts +16 -16
  52. package/dist/esm/static.js +15 -15
  53. package/dist/esm/storage.d.ts +9 -9
  54. package/dist/esm/storage.js +35 -35
  55. package/dist/esm/types.d.ts +103 -103
  56. package/dist/esm/types.js +1 -1
  57. package/dist/umd/array.d.ts +10 -0
  58. package/dist/umd/base.d.ts +14 -0
  59. package/dist/umd/element.d.ts +6 -0
  60. package/dist/umd/event.d.ts +14 -0
  61. package/dist/umd/function.d.ts +12 -0
  62. package/dist/umd/index.d.ts +51 -0
  63. package/dist/umd/index.js +1024 -0
  64. package/dist/umd/object.d.ts +30 -0
  65. package/dist/umd/request.d.ts +60 -0
  66. package/dist/umd/static.d.ts +16 -0
  67. package/dist/umd/storage.d.ts +9 -0
  68. package/dist/umd/types.d.ts +103 -0
  69. package/package.json +12 -4
  70. package/pnpm-lock.yaml +279 -8
  71. package/rollup.config.js +35 -0
  72. package/tsconfig.umd.json +6 -0
@@ -1,103 +1,103 @@
1
- export type IKey = string | symbol | number;
2
- export interface IObject<T> {
3
- [key: IKey]: T | IObject<any>;
4
- }
5
- export interface IPromise extends IObject<any> {
6
- promise: Promise<void>;
7
- resolve: (res: any) => unknown;
8
- reject: (err: any) => unknown;
9
- }
10
- export type IInstance<T> = {
11
- _instance: Function;
12
- } & T;
13
- export type IDemoteArray<T> = Array<IDemoteArray<T> | T>;
14
- export type IRandomNum = (min: number, max: number, bool?: boolean) => number;
15
- export type IUrlSplit = (url: string) => IObject<any>;
16
- export type IUrlJoin = (url: string, query: object) => string;
17
- export type IGetType<T> = (data: any) => typeof data | T[keyof T] | "null";
18
- export type IGetTypeByList = (data: any, whiteList: string[]) => boolean;
19
- export type IGetValue = <T, U = IObject<T> | IObject<T>[IKey]>(object: U, key: string, defaultValue?: any) => U;
20
- export type ISetValue = <T>(object: IObject<T>, key: string, value?: any) => IObject<T>;
21
- export type IMixIn = <U extends IObject<any>>(target?: U, source?: IObject<any>, overwrite?: boolean) => U;
22
- export type IEnumInversion = (target: IObject<string>) => IObject<string>;
23
- export type ICloneDeep = (target?: any) => any;
24
- export type ICreateObjectVariable = (type: string, source?: any) => any;
25
- export type ICreateObject = <T, U extends T>(source: T) => U;
26
- export type IInherit = <T extends Function>(source: T, target?: Function) => Function;
27
- export type IGetInstance = (classProto: IInstance<FunctionConstructor>, overwrite?: boolean, ...params: any[]) => Function;
28
- export type IClassDecorator = (params: IObject<any>) => <TFunction extends Function>(target: TFunction) => void;
29
- export type IStringToJson = (target: string) => IObject<any> | null;
30
- export type IJsonToString = (target: IObject<any>) => string;
31
- export type IThrottle = (fn: Function, time: number) => (...args: any[]) => void;
32
- export type IDebounce = (fn: Function, time: number) => (...args: any[]) => void;
33
- export type IDefer = () => IPromise;
34
- export type ICatchAwait<T extends Promise<any>> = (defer: T) => T;
35
- export type IArrayRandom<T extends any[]> = (arr: T) => T;
36
- export type IArrayUniq<T extends any[]> = (arr: T) => T;
37
- export type IArrayDemote<T extends IDemoteArray<any>> = (arr: T, result?: T) => T;
38
- interface IElementParams<T> {
39
- ele: T | string;
40
- style: CSSStyleDeclaration;
41
- attr: Attr;
42
- parent: T;
43
- }
44
- export type ICreateElement<T = HTMLElement> = (params: IElementParams<T>) => T;
45
- export type IAddHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void;
46
- export type IStopBubble = (e: Event) => void;
47
- export type IStopDefault = (e: Event) => void;
48
- export type IRemoveHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void;
49
- export type IDispatchEvent = <T extends Document>(ele: T, data: any) => void;
50
- export type IRequestParams<T> = T | IObject<any> | null;
51
- export type IUrl = string;
52
- export type IEnv = 'Window' | 'Node';
53
- export type IDataType = "text" | "json" | "blob" | "formData" | "arrayBuffer";
54
- export type IRequestMethods = "GET" | "POST" | "DELETE" | "PUT" | "OPTION" | "HEAD" | "PATCH";
55
- export type IRequestBody = IRequestParams<BodyInit>;
56
- export type IRequestHeaders = IRequestParams<HeadersInit>;
57
- export type IRequestBaseFn = (url: IUrl, opts: IRequestOptions) => Promise<any>;
58
- export type IRequestFn = (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => Promise<any>;
59
- export type IRequestOptions = {
60
- method?: IRequestMethods;
61
- query?: IRequestParams<IObject<any>>;
62
- body?: IRequestBody;
63
- headers?: IRequestHeaders;
64
- controller?: AbortController;
65
- timeout?: number;
66
- timer?: number | unknown | null;
67
- [key: string]: any;
68
- };
69
- export type IInterceptors = {
70
- use(type: "request" | "response" | "error", fn: Function): IInterceptors;
71
- get reqFn(): Function;
72
- get resFn(): Function;
73
- get errFn(): Function;
74
- };
75
- export type IRequestBase = {
76
- readonly origin: string;
77
- chackUrl: (url: IUrl) => boolean;
78
- envDesc: () => IEnv;
79
- errorFn: <Err = any, R = Function>(reject: R) => (err: Err) => R;
80
- clearTimer: (opts: IRequestOptions) => void;
81
- initAbort: (opts: IRequestOptions) => IRequestOptions;
82
- requestType: () => IRequestBaseFn;
83
- fixOrigin: (fixStr: string) => string;
84
- fetch: IRequestBaseFn;
85
- http: IRequestBaseFn;
86
- getDataByType: (type: IDataType, response: Response) => Promise<any>;
87
- formatBodyString: (bodyString: string) => IObject<Function>;
88
- };
89
- export type IRequestInit = {
90
- initDefaultParams: (url: IUrl, opts: IRequestOptions) => any;
91
- initFetchParams: (url: IUrl, opts: IRequestOptions) => any;
92
- initHttpParams: (url: IUrl, opts: IRequestOptions) => any;
93
- };
94
- export type IRequest = {
95
- GET: IRequestFn;
96
- POST: IRequestFn;
97
- DELETE: IRequestFn;
98
- PUT: IRequestFn;
99
- OPTIONS: IRequestFn;
100
- HEAD: IRequestFn;
101
- PATCH: IRequestFn;
102
- } & IRequestBase;
103
- export {};
1
+ export type IKey = string | symbol | number;
2
+ export interface IObject<T> {
3
+ [key: IKey]: T | IObject<any>;
4
+ }
5
+ export interface IPromise extends IObject<any> {
6
+ promise: Promise<void>;
7
+ resolve: (res: any) => unknown;
8
+ reject: (err: any) => unknown;
9
+ }
10
+ export type IInstance<T> = {
11
+ _instance: Function;
12
+ } & T;
13
+ export type IDemoteArray<T> = Array<IDemoteArray<T> | T>;
14
+ export type IRandomNum = (min: number, max: number, bool?: boolean) => number;
15
+ export type IUrlSplit = (url: string) => IObject<any>;
16
+ export type IUrlJoin = (url: string, query: object) => string;
17
+ export type IGetType<T> = (data: any) => typeof data | T[keyof T] | "null";
18
+ export type IGetTypeByList = (data: any, whiteList: string[]) => boolean;
19
+ export type IGetValue = <T, U = IObject<T> | IObject<T>[IKey]>(object: U, key: string, defaultValue?: any) => U;
20
+ export type ISetValue = <T>(object: IObject<T>, key: string, value?: any) => IObject<T>;
21
+ export type IMixIn = <U extends IObject<any>>(target?: U, source?: IObject<any>, overwrite?: boolean) => U;
22
+ export type IEnumInversion = (target: IObject<string>) => IObject<string>;
23
+ export type ICloneDeep = (target?: any) => any;
24
+ export type ICreateObjectVariable = (type: string, source?: any) => any;
25
+ export type ICreateObject = <T, U extends T>(source: T) => U;
26
+ export type IInherit = <T extends Function>(source: T, target?: Function) => Function;
27
+ export type IGetInstance = (classProto: IInstance<FunctionConstructor>, overwrite?: boolean, ...params: any[]) => Function;
28
+ export type IClassDecorator = (params: IObject<any>) => <TFunction extends Function>(target: TFunction) => void;
29
+ export type IStringToJson = (target: string) => IObject<any> | null;
30
+ export type IJsonToString = (target: IObject<any>) => string;
31
+ export type IThrottle = (fn: Function, time: number) => (...args: any[]) => void;
32
+ export type IDebounce = (fn: Function, time: number) => (...args: any[]) => void;
33
+ export type IDefer = () => IPromise;
34
+ export type ICatchAwait<T extends Promise<any>> = (defer: T) => T;
35
+ export type IArrayRandom<T extends any[]> = (arr: T) => T;
36
+ export type IArrayUniq<T extends any[]> = (arr: T) => T;
37
+ export type IArrayDemote<T extends IDemoteArray<any>> = (arr: T, result?: T) => T;
38
+ interface IElementParams<T> {
39
+ ele: T | string;
40
+ style: CSSStyleDeclaration;
41
+ attr: Attr;
42
+ parent: T;
43
+ }
44
+ export type ICreateElement<T = HTMLElement> = (params: IElementParams<T>) => T;
45
+ export type IAddHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void;
46
+ export type IStopBubble = (e: Event) => void;
47
+ export type IStopDefault = (e: Event) => void;
48
+ export type IRemoveHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void;
49
+ export type IDispatchEvent = <T extends Document>(ele: T, data: any) => void;
50
+ export type IRequestParams<T> = T | IObject<any> | null;
51
+ export type IUrl = string;
52
+ export type IEnv = 'Window' | 'Node';
53
+ export type IDataType = "text" | "json" | "blob" | "formData" | "arrayBuffer";
54
+ export type IRequestMethods = "GET" | "POST" | "DELETE" | "PUT" | "OPTION" | "HEAD" | "PATCH";
55
+ export type IRequestBody = IRequestParams<BodyInit>;
56
+ export type IRequestHeaders = IRequestParams<HeadersInit>;
57
+ export type IRequestBaseFn = (url: IUrl, opts: IRequestOptions) => Promise<any>;
58
+ export type IRequestFn = (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => Promise<any>;
59
+ export type IRequestOptions = {
60
+ method?: IRequestMethods;
61
+ query?: IRequestParams<IObject<any>>;
62
+ body?: IRequestBody;
63
+ headers?: IRequestHeaders;
64
+ controller?: AbortController;
65
+ timeout?: number;
66
+ timer?: number | unknown | null;
67
+ [key: string]: any;
68
+ };
69
+ export type IInterceptors = {
70
+ use(type: "request" | "response" | "error", fn: Function): IInterceptors;
71
+ get reqFn(): Function;
72
+ get resFn(): Function;
73
+ get errFn(): Function;
74
+ };
75
+ export type IRequestBase = {
76
+ readonly origin: string;
77
+ chackUrl: (url: IUrl) => boolean;
78
+ envDesc: () => IEnv;
79
+ errorFn: <Err = any, R = Function>(reject: R) => (err: Err) => R;
80
+ clearTimer: (opts: IRequestOptions) => void;
81
+ initAbort: (opts: IRequestOptions) => IRequestOptions;
82
+ requestType: () => IRequestBaseFn;
83
+ fixOrigin: (fixStr: string) => string;
84
+ fetch: IRequestBaseFn;
85
+ http: IRequestBaseFn;
86
+ getDataByType: (type: IDataType, response: Response) => Promise<any>;
87
+ formatBodyString: (bodyString: string) => IObject<Function>;
88
+ };
89
+ export type IRequestInit = {
90
+ initDefaultParams: (url: IUrl, opts: IRequestOptions) => any;
91
+ initFetchParams: (url: IUrl, opts: IRequestOptions) => any;
92
+ initHttpParams: (url: IUrl, opts: IRequestOptions) => any;
93
+ };
94
+ export type IRequest = {
95
+ GET: IRequestFn;
96
+ POST: IRequestFn;
97
+ DELETE: IRequestFn;
98
+ PUT: IRequestFn;
99
+ OPTIONS: IRequestFn;
100
+ HEAD: IRequestFn;
101
+ PATCH: IRequestFn;
102
+ } & IRequestBase;
103
+ export {};
package/dist/cjs/types.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +1,10 @@
1
- import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./index.js";
2
- export declare const arrayRandom: IArrayRandom<any[]>;
3
- export declare const arrayUniq: IArrayUniq<any[]>;
4
- export declare const arrayDemote: IArrayDemote<IDemoteArray<any>>;
5
- declare const _default: {
6
- arrayRandom: IArrayRandom<any[]>;
7
- arrayUniq: IArrayUniq<any[]>;
8
- arrayDemote: IArrayDemote<IDemoteArray<any>>;
9
- };
10
- export default _default;
1
+ import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./index.js";
2
+ export declare const arrayRandom: IArrayRandom<any[]>;
3
+ export declare const arrayUniq: IArrayUniq<any[]>;
4
+ export declare const arrayDemote: IArrayDemote<IDemoteArray<any>>;
5
+ declare const _default: {
6
+ arrayRandom: IArrayRandom<any[]>;
7
+ arrayUniq: IArrayUniq<any[]>;
8
+ arrayDemote: IArrayDemote<IDemoteArray<any>>;
9
+ };
10
+ export default _default;
package/dist/esm/array.js CHANGED
@@ -1,13 +1,13 @@
1
- import { getType } from "./index.js";
2
- export var arrayRandom = function (arr) { return arr.sort(function () { return Math.random() - 0.5; }); };
3
- export var arrayUniq = function (arr) { return Array.from(new Set(arr)); };
4
- export var arrayDemote = function (arr, result) {
5
- if (result === void 0) { result = []; }
6
- arr.forEach(function (i) { return getType(i) === "array" ? arrayDemote(i, result) : result.push(i); });
7
- return result;
8
- };
9
- export default {
10
- arrayRandom: arrayRandom,
11
- arrayUniq: arrayUniq,
12
- arrayDemote: arrayDemote
13
- };
1
+ import { getType } from "./index.js";
2
+ export var arrayRandom = function (arr) { return arr.sort(function () { return Math.random() - 0.5; }); };
3
+ export var arrayUniq = function (arr) { return Array.from(new Set(arr)); };
4
+ export var arrayDemote = function (arr, result) {
5
+ if (result === void 0) { result = []; }
6
+ arr.forEach(function (i) { return getType(i) === "array" ? arrayDemote(i, result) : result.push(i); });
7
+ return result;
8
+ };
9
+ export default {
10
+ arrayRandom: arrayRandom,
11
+ arrayUniq: arrayUniq,
12
+ arrayDemote: arrayDemote
13
+ };
@@ -1,14 +1,14 @@
1
- import { IRandomNum, IUrlSplit, IUrlJoin, IGetType, IGetTypeByList, types } from "./index.js";
2
- export declare const randomNum: IRandomNum;
3
- export declare const urlSplit: IUrlSplit;
4
- export declare const urlJoin: IUrlJoin;
5
- export declare const getType: IGetType<types>;
6
- export declare const getTypeByList: IGetTypeByList;
7
- declare const _default: {
8
- randomNum: IRandomNum;
9
- urlSplit: IUrlSplit;
10
- urlJoin: IUrlJoin;
11
- getType: IGetType<types>;
12
- getTypeByList: IGetTypeByList;
13
- };
14
- export default _default;
1
+ import { IRandomNum, IUrlSplit, IUrlJoin, IGetType, IGetTypeByList, types } from "./index.js";
2
+ export declare const randomNum: IRandomNum;
3
+ export declare const urlSplit: IUrlSplit;
4
+ export declare const urlJoin: IUrlJoin;
5
+ export declare const getType: IGetType<types>;
6
+ export declare const getTypeByList: IGetTypeByList;
7
+ declare const _default: {
8
+ randomNum: IRandomNum;
9
+ urlSplit: IUrlSplit;
10
+ urlJoin: IUrlJoin;
11
+ getType: IGetType<types>;
12
+ getTypeByList: IGetTypeByList;
13
+ };
14
+ export default _default;
package/dist/esm/base.js CHANGED
@@ -1,48 +1,48 @@
1
- import { types } from "./index.js";
2
- export var randomNum = function (min, max, bool) {
3
- if (bool === void 0) { bool = false; }
4
- return Math.floor(Math.random() * (max - min + (bool ? 1 : 0)) + min);
5
- };
6
- export var urlSplit = function (url) {
7
- var result = {};
8
- if (!url.includes("?")) {
9
- return result;
10
- }
11
- var params = url.split("?")[1].split("&");
12
- params.forEach(function (i) {
13
- var key = i.split("=")[0];
14
- result[key] = i.split("=")[1];
15
- });
16
- return result;
17
- };
18
- export var urlJoin = function (url, query) {
19
- if (query === void 0) { query = {}; }
20
- var queryObject = Object.keys(query);
21
- if (queryObject.length === 0)
22
- return url;
23
- var params = queryObject.map(function (i) { return "".concat(i, "=").concat(query[i]); });
24
- return "".concat(url).concat(url.includes("?") ? "&" : '?').concat(params.join("&"));
25
- };
26
- export var getType = function (data) {
27
- var type = typeof data;
28
- if (data === null) {
29
- return "null";
30
- }
31
- else if (type === "object") {
32
- var key = Object.prototype.toString.call(data);
33
- return types[key];
34
- }
35
- return type;
36
- };
37
- export var getTypeByList = function (data, whiteList) {
38
- if (whiteList === void 0) { whiteList = []; }
39
- var __type = getType(data);
40
- return whiteList.indexOf(__type) > 0;
41
- };
42
- export default {
43
- randomNum: randomNum,
44
- urlSplit: urlSplit,
45
- urlJoin: urlJoin,
46
- getType: getType,
47
- getTypeByList: getTypeByList,
48
- };
1
+ import { types } from "./index.js";
2
+ export var randomNum = function (min, max, bool) {
3
+ if (bool === void 0) { bool = false; }
4
+ return Math.floor(Math.random() * (max - min + (bool ? 1 : 0)) + min);
5
+ };
6
+ export var urlSplit = function (url) {
7
+ var result = {};
8
+ if (!url.includes("?")) {
9
+ return result;
10
+ }
11
+ var params = url.split("?")[1].split("&");
12
+ params.forEach(function (i) {
13
+ var key = i.split("=")[0];
14
+ result[key] = i.split("=")[1];
15
+ });
16
+ return result;
17
+ };
18
+ export var urlJoin = function (url, query) {
19
+ if (query === void 0) { query = {}; }
20
+ var queryObject = Object.keys(query);
21
+ if (queryObject.length === 0)
22
+ return url;
23
+ var params = queryObject.map(function (i) { return "".concat(i, "=").concat(query[i]); });
24
+ return "".concat(url).concat(url.includes("?") ? "&" : '?').concat(params.join("&"));
25
+ };
26
+ export var getType = function (data) {
27
+ var type = typeof data;
28
+ if (data === null) {
29
+ return "null";
30
+ }
31
+ else if (type === "object") {
32
+ var key = Object.prototype.toString.call(data);
33
+ return types[key];
34
+ }
35
+ return type;
36
+ };
37
+ export var getTypeByList = function (data, whiteList) {
38
+ if (whiteList === void 0) { whiteList = []; }
39
+ var __type = getType(data);
40
+ return whiteList.indexOf(__type) > 0;
41
+ };
42
+ export default {
43
+ randomNum: randomNum,
44
+ urlSplit: urlSplit,
45
+ urlJoin: urlJoin,
46
+ getType: getType,
47
+ getTypeByList: getTypeByList,
48
+ };
@@ -1,6 +1,6 @@
1
- import { ICreateElement } from "./index.js";
2
- export declare const createElement: ICreateElement;
3
- declare const _default: {
4
- createElement: ICreateElement<HTMLElement>;
5
- };
6
- export default _default;
1
+ import { ICreateElement } from "./index.js";
2
+ export declare const createElement: ICreateElement;
3
+ declare const _default: {
4
+ createElement: ICreateElement;
5
+ };
6
+ export default _default;
@@ -1,12 +1,12 @@
1
- export var createElement = function (_a) {
2
- var _b, _c;
3
- var ele = _a.ele, style = _a.style, attr = _a.attr, parent = _a.parent;
4
- var element = ele instanceof HTMLElement ? ele : document.createElement(ele !== null && ele !== void 0 ? ele : 'div');
5
- style && ((_b = Object.keys(style)) === null || _b === void 0 ? void 0 : _b.forEach(function (key) { return element.style[key] = style[key]; }));
6
- attr && ((_c = Object.keys(style)) === null || _c === void 0 ? void 0 : _c.forEach(function (key) { return element[key] = attr[key]; }));
7
- parent && parent.appendChild(element);
8
- return element;
9
- };
10
- export default {
11
- createElement: createElement
12
- };
1
+ export var createElement = function (_a) {
2
+ var _b, _c;
3
+ var ele = _a.ele, style = _a.style, attr = _a.attr, parent = _a.parent;
4
+ var element = ele instanceof HTMLElement ? ele : document.createElement(ele !== null && ele !== void 0 ? ele : 'div');
5
+ style && ((_b = Object.keys(style)) === null || _b === void 0 ? void 0 : _b.forEach(function (key) { return element.style[key] = style[key]; }));
6
+ attr && ((_c = Object.keys(style)) === null || _c === void 0 ? void 0 : _c.forEach(function (key) { return element[key] = attr[key]; }));
7
+ parent && parent.appendChild(element);
8
+ return element;
9
+ };
10
+ export default {
11
+ createElement: createElement
12
+ };
@@ -1,14 +1,14 @@
1
- import { IAddHandler, IStopBubble, IStopDefault, IRemoveHandler, IDispatchEvent } from "./index.js";
2
- export declare const addHandler: IAddHandler;
3
- export declare const stopBubble: IStopBubble;
4
- export declare const stopDefault: IStopDefault;
5
- export declare const removeHandler: IRemoveHandler;
6
- export declare const dispatchEvent: IDispatchEvent;
7
- declare const _default: {
8
- addHandler: IAddHandler;
9
- stopBubble: IStopBubble;
10
- stopDefault: IStopDefault;
11
- removeHandler: IRemoveHandler;
12
- dispatchEvent: IDispatchEvent;
13
- };
14
- export default _default;
1
+ import { IAddHandler, IStopBubble, IStopDefault, IRemoveHandler, IDispatchEvent } from "./index.js";
2
+ export declare const addHandler: IAddHandler;
3
+ export declare const stopBubble: IStopBubble;
4
+ export declare const stopDefault: IStopDefault;
5
+ export declare const removeHandler: IRemoveHandler;
6
+ export declare const dispatchEvent: IDispatchEvent;
7
+ declare const _default: {
8
+ addHandler: IAddHandler;
9
+ stopBubble: IStopBubble;
10
+ stopDefault: IStopDefault;
11
+ removeHandler: IRemoveHandler;
12
+ dispatchEvent: IDispatchEvent;
13
+ };
14
+ export default _default;
package/dist/esm/event.js CHANGED
@@ -1,45 +1,45 @@
1
- export var addHandler = function (ele, type, handler) {
2
- if (ele.addEventListener) {
3
- ele.addEventListener(type, handler, false);
4
- }
5
- else {
6
- ele["on" + type] = handler;
7
- }
8
- };
9
- export var stopBubble = function (event) {
10
- event = event || window.event;
11
- if (event.stopPropagation) {
12
- event.stopPropagation();
13
- }
14
- else {
15
- event.cancelBubble = false;
16
- }
17
- };
18
- export var stopDefault = function (event) {
19
- event = event || window.event;
20
- if (event.preventDefault) {
21
- event.preventDefault();
22
- }
23
- else {
24
- event.returnValue = false;
25
- }
26
- };
27
- export var removeHandler = function (ele, type, handler) {
28
- if (ele.removeEventListener) {
29
- ele.removeEventListener(type, handler, false);
30
- }
31
- else {
32
- ele["on" + type] = null;
33
- }
34
- };
35
- export var dispatchEvent = function (ele, data) {
36
- var evts = new Event(data);
37
- ele.dispatchEvent(evts);
38
- };
39
- export default {
40
- addHandler: addHandler,
41
- stopBubble: stopBubble,
42
- stopDefault: stopDefault,
43
- removeHandler: removeHandler,
44
- dispatchEvent: dispatchEvent,
45
- };
1
+ export var addHandler = function (ele, type, handler) {
2
+ if (ele.addEventListener) {
3
+ ele.addEventListener(type, handler, false);
4
+ }
5
+ else {
6
+ ele["on" + type] = handler;
7
+ }
8
+ };
9
+ export var stopBubble = function (event) {
10
+ event = event || window.event;
11
+ if (event.stopPropagation) {
12
+ event.stopPropagation();
13
+ }
14
+ else {
15
+ event.cancelBubble = false;
16
+ }
17
+ };
18
+ export var stopDefault = function (event) {
19
+ event = event || window.event;
20
+ if (event.preventDefault) {
21
+ event.preventDefault();
22
+ }
23
+ else {
24
+ event.returnValue = false;
25
+ }
26
+ };
27
+ export var removeHandler = function (ele, type, handler) {
28
+ if (ele.removeEventListener) {
29
+ ele.removeEventListener(type, handler, false);
30
+ }
31
+ else {
32
+ ele["on" + type] = null;
33
+ }
34
+ };
35
+ export var dispatchEvent = function (ele, data) {
36
+ var evts = new Event(data);
37
+ ele.dispatchEvent(evts);
38
+ };
39
+ export default {
40
+ addHandler: addHandler,
41
+ stopBubble: stopBubble,
42
+ stopDefault: stopDefault,
43
+ removeHandler: removeHandler,
44
+ dispatchEvent: dispatchEvent,
45
+ };
@@ -1,12 +1,12 @@
1
- import { ICatchAwait, IThrottle, IDebounce, IDefer } from "./index.js";
2
- export declare const throttle: IThrottle;
3
- export declare const debounce: IDebounce;
4
- export declare const defer: IDefer;
5
- export declare const catchAwait: ICatchAwait<Promise<any>>;
6
- declare const _default: {
7
- throttle: IThrottle;
8
- debounce: IDebounce;
9
- defer: IDefer;
10
- catchAwait: ICatchAwait<Promise<any>>;
11
- };
12
- export default _default;
1
+ import { ICatchAwait, IThrottle, IDebounce, IDefer } from "./index.js";
2
+ export declare const throttle: IThrottle;
3
+ export declare const debounce: IDebounce;
4
+ export declare const defer: IDefer;
5
+ export declare const catchAwait: ICatchAwait<Promise<any>>;
6
+ declare const _default: {
7
+ throttle: IThrottle;
8
+ debounce: IDebounce;
9
+ defer: IDefer;
10
+ catchAwait: ICatchAwait<Promise<any>>;
11
+ };
12
+ export default _default;