utils-lib-js 1.0.1 → 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.
@@ -1,4 +1,4 @@
1
- import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./types";
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>>;
@@ -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 base_1 = require("./base");
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, base_1.getType)(i) === "array" ? (0, exports.arrayDemote)(i, result) : result.push(i);
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
  };
@@ -1,5 +1,4 @@
1
- import { IRandomNum, IUrlSplit, IUrlJoin, IGetType } from "./types";
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;
@@ -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 static_1 = require("./static");
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 static_1.types[key];
39
+ return index_js_1.types[key];
40
40
  }
41
41
  return type;
42
42
  };
@@ -1,2 +1,2 @@
1
- import { ICreateElement } from "./types";
1
+ import { ICreateElement } from "./index.js";
2
2
  export declare const createElement: ICreateElement;
@@ -1,4 +1,4 @@
1
- import { IAddHandler, IStopBubble, IStopDefault, IRemoveHandler, IDispatchEvent } from "./types";
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;
@@ -1,4 +1,4 @@
1
- import { ICatchAwait, IThrottle, IDebounce, IDefer } from "./types";
1
+ import { ICatchAwait, IThrottle, IDebounce, IDefer } from "./index.js";
2
2
  export declare const throttle: IThrottle;
3
3
  export declare const debounce: IDebounce;
4
4
  export declare const defer: IDefer;
@@ -1,8 +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 "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";
@@ -17,11 +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("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);
@@ -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 "./index.js";
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;
@@ -1,8 +1,17 @@
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;
5
- var base_1 = require("./base");
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 index_js_1 = require("./index.js");
6
15
  var getValue = function (object, key, defaultValue) {
7
16
  if (defaultValue === void 0) {
8
17
  defaultValue = '';
@@ -72,7 +81,7 @@ var isNotObject = function (source, type) {
72
81
  };
73
82
  exports.isNotObject = isNotObject;
74
83
  var cloneDeep = function (target) {
75
- var __type = (0, base_1.getType)(target);
84
+ var __type = (0, index_js_1.getType)(target);
76
85
  if ((0, exports.isNotObject)(target, __type)) return target;
77
86
  var __init = (0, exports.createObjectVariable)(__type, target);
78
87
  if (__type === "map") {
@@ -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,15 @@
1
+ import { IRequest } from "./index.js";
2
+ export declare class Request implements IRequest {
3
+ origin: string;
4
+ constructor();
5
+ fixOrigin(origin: any): this;
6
+ envDesc(): "Window" | "Node";
7
+ ajax(url: any, opts: any): void;
8
+ fetch(): Promise<Response>;
9
+ http(): void;
10
+ }
11
+ export declare const GET: () => void;
12
+ export declare const POST: () => void;
13
+ export declare const PUT: () => void;
14
+ export declare const DELETE: () => void;
15
+ export declare const OPTION: () => void;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.OPTION = exports.DELETE = exports.PUT = exports.POST = exports.GET = exports.Request = void 0;
5
+ var index_js_1 = require("./index.js");
6
+ var Request = function () {
7
+ function Request() {}
8
+ Request.prototype.fixOrigin = function (origin) {
9
+ this.origin = origin;
10
+ return this;
11
+ };
12
+ Request.prototype.envDesc = function () {
13
+ if (Window) {
14
+ return "Window";
15
+ }
16
+ return "Node";
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 () {};
53
+ return Request;
54
+ }();
55
+ exports.Request = Request;
56
+ var GET = function () {};
57
+ exports.GET = GET;
58
+ var POST = function () {};
59
+ exports.POST = POST;
60
+ var PUT = function () {};
61
+ exports.PUT = PUT;
62
+ var DELETE = function () {};
63
+ exports.DELETE = DELETE;
64
+ var OPTION = function () {};
65
+ exports.OPTION = OPTION;
@@ -0,0 +1,3 @@
1
+ export declare const setStorage: (key: string, val: any) => void;
2
+ export declare const getStorage: (key: string) => any;
3
+ export declare const clearStorage: (key: string) => void;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.clearStorage = exports.getStorage = exports.setStorage = void 0;
5
+ var setStorage = function (key, val) {
6
+ try {
7
+ localStorage.setItem(key, JSON.stringify(val));
8
+ } catch (error) {
9
+ console.error(error);
10
+ }
11
+ };
12
+ exports.setStorage = setStorage;
13
+ var getStorage = function (key) {
14
+ try {
15
+ var str = localStorage.getItem(key);
16
+ if (str === null || str === undefined) {
17
+ return null;
18
+ }
19
+ return JSON.parse(str);
20
+ } catch (error) {
21
+ console.error(error);
22
+ return null;
23
+ }
24
+ };
25
+ exports.getStorage = getStorage;
26
+ var clearStorage = function (key) {
27
+ try {
28
+ key && localStorage.removeItem(key);
29
+ !key && localStorage.clear();
30
+ } catch (error) {
31
+ console.error(error);
32
+ }
33
+ };
34
+ exports.clearStorage = clearStorage;
@@ -4,9 +4,12 @@ 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
+ 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,11 @@ 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) => IRequest;
50
+ envDesc: () => "Window" | "Node";
51
+ fetch: () => Promise<Response>;
52
+ };
53
+ export declare type IGet = (url: string, params: IObject<any>) => Promise<void>;
42
54
  export {};
@@ -1,4 +1,4 @@
1
- import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./types";
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
@@ -1,4 +1,4 @@
1
- import { getType } from "./base";
1
+ import { getType } from "./index.js";
2
2
  export var arrayRandom = function (arr) {
3
3
  return arr.sort(function () {
4
4
  return Math.random() - 0.5;
@@ -1,5 +1,4 @@
1
- import { IRandomNum, IUrlSplit, IUrlJoin, IGetType } from "./types";
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
@@ -1,4 +1,4 @@
1
- import { types } from "./static";
1
+ import { types } from "./index.js";
2
2
  export var randomNum = function (min, max, bool) {
3
3
  if (bool === void 0) {
4
4
  bool = false;
@@ -1,2 +1,2 @@
1
- import { ICreateElement } from "./types";
1
+ import { ICreateElement } from "./index.js";
2
2
  export declare const createElement: ICreateElement;
@@ -1,4 +1,4 @@
1
- import { IAddHandler, IStopBubble, IStopDefault, IRemoveHandler, IDispatchEvent } from "./types";
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;
@@ -1,4 +1,4 @@
1
- import { ICatchAwait, IThrottle, IDebounce, IDefer } from "./types";
1
+ import { ICatchAwait, IThrottle, IDebounce, IDefer } from "./index.js";
2
2
  export declare const throttle: IThrottle;
3
3
  export declare const debounce: IDebounce;
4
4
  export declare const defer: IDefer;
@@ -1,8 +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 "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,8 +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 "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";
@@ -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 "./index.js";
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;
@@ -1,4 +1,13 @@
1
- import { getType } from "./base";
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
+ };
10
+ import { getType } from "./index.js";
2
11
  export var getValue = function (object, key, defaultValue) {
3
12
  if (defaultValue === void 0) {
4
13
  defaultValue = '';
@@ -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,15 @@
1
+ import { IRequest } from "./index.js";
2
+ export declare class Request implements IRequest {
3
+ origin: string;
4
+ constructor();
5
+ fixOrigin(origin: any): this;
6
+ envDesc(): "Window" | "Node";
7
+ ajax(url: any, opts: any): void;
8
+ fetch(): Promise<Response>;
9
+ http(): void;
10
+ }
11
+ export declare const GET: () => void;
12
+ export declare const POST: () => void;
13
+ export declare const PUT: () => void;
14
+ export declare const DELETE: () => void;
15
+ export declare const OPTION: () => void;
@@ -0,0 +1,56 @@
1
+ import { defer } from "./index.js";
2
+ var Request = function () {
3
+ function Request() {}
4
+ Request.prototype.fixOrigin = function (origin) {
5
+ this.origin = origin;
6
+ return this;
7
+ };
8
+ Request.prototype.envDesc = function () {
9
+ if (Window) {
10
+ return "Window";
11
+ }
12
+ return "Node";
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 () {};
49
+ return Request;
50
+ }();
51
+ export { Request };
52
+ export var GET = function () {};
53
+ export var POST = function () {};
54
+ export var PUT = function () {};
55
+ export var DELETE = function () {};
56
+ export var OPTION = function () {};
@@ -0,0 +1,3 @@
1
+ export declare const setStorage: (key: string, val: any) => void;
2
+ export declare const getStorage: (key: string) => any;
3
+ export declare const clearStorage: (key: string) => void;
@@ -0,0 +1,27 @@
1
+ export var setStorage = function (key, val) {
2
+ try {
3
+ localStorage.setItem(key, JSON.stringify(val));
4
+ } catch (error) {
5
+ console.error(error);
6
+ }
7
+ };
8
+ export var getStorage = function (key) {
9
+ try {
10
+ var str = localStorage.getItem(key);
11
+ if (str === null || str === undefined) {
12
+ return null;
13
+ }
14
+ return JSON.parse(str);
15
+ } catch (error) {
16
+ console.error(error);
17
+ return null;
18
+ }
19
+ };
20
+ export var clearStorage = function (key) {
21
+ try {
22
+ key && localStorage.removeItem(key);
23
+ !key && localStorage.clear();
24
+ } catch (error) {
25
+ console.error(error);
26
+ }
27
+ };
@@ -4,9 +4,12 @@ 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
+ 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,11 @@ 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) => IRequest;
50
+ envDesc: () => "Window" | "Node";
51
+ fetch: () => Promise<Response>;
52
+ };
53
+ export declare type IGet = (url: string, params: IObject<any>) => Promise<void>;
42
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.1",
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
@@ -1,12 +1,8 @@
1
1
  {
2
2
  "extends": "./tsconfig",
3
3
  "compilerOptions": {
4
- "module": "es2015",
4
+ "module": "ES6",
5
5
  "outDir": "dist/esm",
6
- "moduleResolution": "node"
7
- },
8
- "exclude": [
9
- "**/__tests__/**",
10
- "**/example/**"
11
- ]
6
+ "rootDir": "src"
7
+ }
12
8
  }
File without changes
File without changes
File without changes
package/dist/esm/fetch.js DELETED
File without changes