@brandup/ui-helpers 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/cjs/index.js CHANGED
@@ -1,166 +1,117 @@
1
1
  'use strict';
2
2
 
3
- class Utility {
4
- static arrayToObject(array) {
5
- if (array) {
6
- const result = {};
7
- for (let i = 0; i < array.length; i++)
8
- result[array[i].Key] = array[i].Value;
9
- return result;
10
- }
11
- return null;
12
- }
13
- static objectToArray(obj) {
14
- if (!obj)
15
- return null;
16
- const result = new Array();
17
- for (const key in obj)
18
- result.push({ Key: key, Value: obj[key] });
19
- return result;
20
- }
21
- static getWordEnd(count, word, one, two, five) {
22
- const tt = count % 100;
23
- if (tt >= 5 && tt <= 20)
24
- return word + (Utility.isString(five) ? five : "");
25
- const t = count % 10;
26
- return (t === 1 ?
27
- (word + (Utility.isString(one) ? one : "")) :
28
- ((t >= 2 && t <= 4) ?
29
- (word + (Utility.isString(two) ? two : "")) :
30
- (word + (Utility.isString(five) ? five : ""))));
31
- }
32
- static isString(value) {
33
- return (typeof value === "string" || value instanceof String);
34
- }
35
- static isArray(value) {
36
- return (value instanceof Array);
37
- }
38
- static isUndefined(value) {
39
- return (typeof value === "undefined");
40
- }
41
- static isFunction(value) {
42
- return (typeof value === "function");
43
- }
44
- static isPlainObject(obj) {
45
- if (!obj || toString.call(obj) !== "[object Object]" || obj.nodeType || obj.setInterval) {
3
+ function hasProperty(obj, property) {
4
+ if (!obj)
5
+ return false;
6
+ const props = property.split(".");
7
+ let t = obj;
8
+ for (let i = 0; i < props.length; i++) {
9
+ if (!t)
46
10
  return false;
47
- }
48
- if (obj.constructor && !obj.hasOwnProperty.call(obj, "constructor") && !obj.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf")) {
11
+ const pName = props[i];
12
+ if (!(pName in t))
49
13
  return false;
50
- }
51
- let key;
52
- for (key in obj) {
53
- continue;
54
- }
55
- return key === undefined || obj.hasOwnProperty.call(obj, key);
56
- }
57
- static joinString(separator, items) {
58
- if (!Utility.isArray(items))
59
- throw "Param items is not array.";
60
- let str = "";
61
- for (let i = 0; i < items.length; i++)
62
- str += (i > 0 ? separator : "") + items[i];
63
- return str;
64
- }
65
- static stringIsNullOrEmpty(str) {
66
- return !Utility.isString(str) || str === null || str === "";
67
- }
68
- static hasProperty(obj, property) {
69
- if (!obj)
70
- return false;
71
- const props = (property.indexOf(".") >= 0 ? property.split(".") : [property]);
72
- let t = obj;
73
- for (let i = 0; i < props.length; i++) {
74
- if (!t)
75
- return false;
76
- const pName = props[i];
77
- if (!t.hasOwnProperty(pName))
78
- return false;
79
- t = t[pName];
80
- }
81
- return true;
82
- }
83
- static getProperty(obj, property) {
84
- if (!obj)
85
- return null;
86
- const props = (property.indexOf(".") >= 0 ? property.split(".") : [property]);
87
- let t = obj;
88
- for (let i = 0; i < props.length; i++) {
89
- const pName = props[i];
90
- if (!t.hasOwnProperty(pName))
91
- return null;
92
- t = t[pName];
93
- }
94
- return t;
95
- }
96
- static extend(...params) {
97
- let options, name, src, copy, copyIsArray, clone, target = params[0] || {}, i = 1, length = params.length;
98
- if (typeof target !== "object" && !Utility.isFunction(target))
99
- target = {};
100
- if (length === i) {
101
- //target = this;
102
- --i;
103
- }
104
- for (; i < length; i++) {
105
- if ((options = params[i]) != null) {
106
- for (name in options) {
107
- src = target[name];
108
- copy = options[name];
109
- if (target === copy)
110
- continue;
111
- if (copy && (Utility.isPlainObject(copy) || (copyIsArray = Utility.isArray(copy)))) {
112
- if (copyIsArray) {
113
- copyIsArray = false;
114
- clone = src && Utility.isArray(src) ? src : [];
115
- }
116
- else
117
- clone = src && Utility.isPlainObject(src) ? src : {};
118
- target[name] = Utility.extend(clone, copy);
119
- }
120
- else if (copy !== undefined)
121
- target[name] = copy;
122
- }
123
- }
124
- }
125
- return target;
126
- }
127
- static createDelegate(context, func) {
128
- return (...params) => func.apply(context, params);
129
- }
130
- static createDelegate2(context, func, args) {
131
- return (...params) => {
132
- const args2 = new Array();
133
- if (args && args.length) {
134
- for (let i = 0; i < args.length; i++) {
135
- args2.push(args[i]);
136
- }
137
- }
138
- if (params.length) {
139
- for (let i = 0; i < params.length; i++) {
140
- args2.push(params[i]);
141
- }
142
- }
143
- return func.apply(context, args2);
144
- };
14
+ t = t[pName];
145
15
  }
146
- static createDelegate3(context, func, args) {
147
- return (...params) => {
148
- const args2 = new Array();
149
- if (params.length) {
150
- for (let i = 0; i < params.length; i++) {
151
- args2.push(params[i]);
152
- }
153
- }
154
- if (args && args.length) {
155
- for (let i = 0; i < args.length; i++) {
156
- args2.push(args[i]);
157
- }
158
- }
159
- return func.apply(context, args2);
160
- };
161
- }
162
- ;
16
+ return true;
17
+ }
18
+ function getProperty(obj, property) {
19
+ if (!obj)
20
+ return null;
21
+ const props = property.split(".");
22
+ let t = obj;
23
+ for (let i = 0; i < props.length; i++) {
24
+ const pName = props[i];
25
+ if (!(pName in t))
26
+ return undefined;
27
+ t = t[pName];
28
+ }
29
+ return t;
30
+ }
31
+
32
+ var object = /*#__PURE__*/Object.freeze({
33
+ __proto__: null,
34
+ getProperty: getProperty,
35
+ hasProperty: hasProperty
36
+ });
37
+
38
+ function isFunction(value) {
39
+ return (typeof value === "function");
163
40
  }
41
+ function isString(value) {
42
+ return (typeof value === "string" || value instanceof String);
43
+ }
44
+
45
+ var type = /*#__PURE__*/Object.freeze({
46
+ __proto__: null,
47
+ isFunction: isFunction,
48
+ isString: isString
49
+ });
50
+
51
+ const minWait = (func, minTime) => {
52
+ if (!minTime)
53
+ return func;
54
+ const beginTime = Date.now();
55
+ const ret = (...args) => {
56
+ const rightTime = getRightTime(beginTime, minTime);
57
+ if (rightTime)
58
+ window.setTimeout(() => func(...args), rightTime);
59
+ else
60
+ func(...args);
61
+ };
62
+ return ret;
63
+ };
64
+ function minWaitAsync(func, minTime) {
65
+ if (!minTime)
66
+ return func();
67
+ const beginTime = Date.now();
68
+ return func()
69
+ .then(data => {
70
+ const rightTime = getRightTime(beginTime, minTime);
71
+ if (rightTime)
72
+ return new Promise(resolve => window.setTimeout(() => resolve(data), rightTime));
73
+ else
74
+ return data;
75
+ });
76
+ }
77
+ const getRightTime = (start, minTime) => {
78
+ const finishTime = Date.now();
79
+ const w = minTime - (finishTime - start);
80
+ return w > minTime * 0.1 ? w : 0;
81
+ };
82
+ function delay(time, abort) {
83
+ return new Promise(resolve => {
84
+ const timer = window.setTimeout(() => resolve(), time);
85
+ abort.addEventListener("abort", () => {
86
+ window.clearTimeout(timer);
87
+ resolve();
88
+ });
89
+ });
90
+ }
91
+
92
+ var func = /*#__PURE__*/Object.freeze({
93
+ __proto__: null,
94
+ delay: delay,
95
+ minWait: minWait,
96
+ minWaitAsync: minWaitAsync
97
+ });
98
+
99
+ function getWordEnd(count, word, one, two, five) {
100
+ const tt = count % 100;
101
+ if (tt >= 5 && tt <= 20)
102
+ return word + (five || "");
103
+ const t = count % 10;
104
+ return (t === 1 ?
105
+ (word + (one || "")) : ((t >= 2 && t <= 4) ? (word + (two || "")) : (word + (five || ""))));
106
+ }
107
+
108
+ var word = /*#__PURE__*/Object.freeze({
109
+ __proto__: null,
110
+ getWordEnd: getWordEnd
111
+ });
164
112
 
165
- exports.Utility = Utility;
113
+ exports.FuncHelper = func;
114
+ exports.ObjectHelper = object;
115
+ exports.TypeHelper = type;
116
+ exports.WordHelper = word;
166
117
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/mjs/index.js CHANGED
@@ -1,164 +1,112 @@
1
- class Utility {
2
- static arrayToObject(array) {
3
- if (array) {
4
- const result = {};
5
- for (let i = 0; i < array.length; i++)
6
- result[array[i].Key] = array[i].Value;
7
- return result;
8
- }
9
- return null;
10
- }
11
- static objectToArray(obj) {
12
- if (!obj)
13
- return null;
14
- const result = new Array();
15
- for (const key in obj)
16
- result.push({ Key: key, Value: obj[key] });
17
- return result;
18
- }
19
- static getWordEnd(count, word, one, two, five) {
20
- const tt = count % 100;
21
- if (tt >= 5 && tt <= 20)
22
- return word + (Utility.isString(five) ? five : "");
23
- const t = count % 10;
24
- return (t === 1 ?
25
- (word + (Utility.isString(one) ? one : "")) :
26
- ((t >= 2 && t <= 4) ?
27
- (word + (Utility.isString(two) ? two : "")) :
28
- (word + (Utility.isString(five) ? five : ""))));
29
- }
30
- static isString(value) {
31
- return (typeof value === "string" || value instanceof String);
32
- }
33
- static isArray(value) {
34
- return (value instanceof Array);
35
- }
36
- static isUndefined(value) {
37
- return (typeof value === "undefined");
38
- }
39
- static isFunction(value) {
40
- return (typeof value === "function");
41
- }
42
- static isPlainObject(obj) {
43
- if (!obj || toString.call(obj) !== "[object Object]" || obj.nodeType || obj.setInterval) {
1
+ function hasProperty(obj, property) {
2
+ if (!obj)
3
+ return false;
4
+ const props = property.split(".");
5
+ let t = obj;
6
+ for (let i = 0; i < props.length; i++) {
7
+ if (!t)
44
8
  return false;
45
- }
46
- if (obj.constructor && !obj.hasOwnProperty.call(obj, "constructor") && !obj.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf")) {
9
+ const pName = props[i];
10
+ if (!(pName in t))
47
11
  return false;
48
- }
49
- let key;
50
- for (key in obj) {
51
- continue;
52
- }
53
- return key === undefined || obj.hasOwnProperty.call(obj, key);
54
- }
55
- static joinString(separator, items) {
56
- if (!Utility.isArray(items))
57
- throw "Param items is not array.";
58
- let str = "";
59
- for (let i = 0; i < items.length; i++)
60
- str += (i > 0 ? separator : "") + items[i];
61
- return str;
62
- }
63
- static stringIsNullOrEmpty(str) {
64
- return !Utility.isString(str) || str === null || str === "";
65
- }
66
- static hasProperty(obj, property) {
67
- if (!obj)
68
- return false;
69
- const props = (property.indexOf(".") >= 0 ? property.split(".") : [property]);
70
- let t = obj;
71
- for (let i = 0; i < props.length; i++) {
72
- if (!t)
73
- return false;
74
- const pName = props[i];
75
- if (!t.hasOwnProperty(pName))
76
- return false;
77
- t = t[pName];
78
- }
79
- return true;
80
- }
81
- static getProperty(obj, property) {
82
- if (!obj)
83
- return null;
84
- const props = (property.indexOf(".") >= 0 ? property.split(".") : [property]);
85
- let t = obj;
86
- for (let i = 0; i < props.length; i++) {
87
- const pName = props[i];
88
- if (!t.hasOwnProperty(pName))
89
- return null;
90
- t = t[pName];
91
- }
92
- return t;
93
- }
94
- static extend(...params) {
95
- let options, name, src, copy, copyIsArray, clone, target = params[0] || {}, i = 1, length = params.length;
96
- if (typeof target !== "object" && !Utility.isFunction(target))
97
- target = {};
98
- if (length === i) {
99
- //target = this;
100
- --i;
101
- }
102
- for (; i < length; i++) {
103
- if ((options = params[i]) != null) {
104
- for (name in options) {
105
- src = target[name];
106
- copy = options[name];
107
- if (target === copy)
108
- continue;
109
- if (copy && (Utility.isPlainObject(copy) || (copyIsArray = Utility.isArray(copy)))) {
110
- if (copyIsArray) {
111
- copyIsArray = false;
112
- clone = src && Utility.isArray(src) ? src : [];
113
- }
114
- else
115
- clone = src && Utility.isPlainObject(src) ? src : {};
116
- target[name] = Utility.extend(clone, copy);
117
- }
118
- else if (copy !== undefined)
119
- target[name] = copy;
120
- }
121
- }
122
- }
123
- return target;
124
- }
125
- static createDelegate(context, func) {
126
- return (...params) => func.apply(context, params);
127
- }
128
- static createDelegate2(context, func, args) {
129
- return (...params) => {
130
- const args2 = new Array();
131
- if (args && args.length) {
132
- for (let i = 0; i < args.length; i++) {
133
- args2.push(args[i]);
134
- }
135
- }
136
- if (params.length) {
137
- for (let i = 0; i < params.length; i++) {
138
- args2.push(params[i]);
139
- }
140
- }
141
- return func.apply(context, args2);
142
- };
12
+ t = t[pName];
143
13
  }
144
- static createDelegate3(context, func, args) {
145
- return (...params) => {
146
- const args2 = new Array();
147
- if (params.length) {
148
- for (let i = 0; i < params.length; i++) {
149
- args2.push(params[i]);
150
- }
151
- }
152
- if (args && args.length) {
153
- for (let i = 0; i < args.length; i++) {
154
- args2.push(args[i]);
155
- }
156
- }
157
- return func.apply(context, args2);
158
- };
159
- }
160
- ;
14
+ return true;
15
+ }
16
+ function getProperty(obj, property) {
17
+ if (!obj)
18
+ return null;
19
+ const props = property.split(".");
20
+ let t = obj;
21
+ for (let i = 0; i < props.length; i++) {
22
+ const pName = props[i];
23
+ if (!(pName in t))
24
+ return undefined;
25
+ t = t[pName];
26
+ }
27
+ return t;
28
+ }
29
+
30
+ var object = /*#__PURE__*/Object.freeze({
31
+ __proto__: null,
32
+ getProperty: getProperty,
33
+ hasProperty: hasProperty
34
+ });
35
+
36
+ function isFunction(value) {
37
+ return (typeof value === "function");
161
38
  }
39
+ function isString(value) {
40
+ return (typeof value === "string" || value instanceof String);
41
+ }
42
+
43
+ var type = /*#__PURE__*/Object.freeze({
44
+ __proto__: null,
45
+ isFunction: isFunction,
46
+ isString: isString
47
+ });
48
+
49
+ const minWait = (func, minTime) => {
50
+ if (!minTime)
51
+ return func;
52
+ const beginTime = Date.now();
53
+ const ret = (...args) => {
54
+ const rightTime = getRightTime(beginTime, minTime);
55
+ if (rightTime)
56
+ window.setTimeout(() => func(...args), rightTime);
57
+ else
58
+ func(...args);
59
+ };
60
+ return ret;
61
+ };
62
+ function minWaitAsync(func, minTime) {
63
+ if (!minTime)
64
+ return func();
65
+ const beginTime = Date.now();
66
+ return func()
67
+ .then(data => {
68
+ const rightTime = getRightTime(beginTime, minTime);
69
+ if (rightTime)
70
+ return new Promise(resolve => window.setTimeout(() => resolve(data), rightTime));
71
+ else
72
+ return data;
73
+ });
74
+ }
75
+ const getRightTime = (start, minTime) => {
76
+ const finishTime = Date.now();
77
+ const w = minTime - (finishTime - start);
78
+ return w > minTime * 0.1 ? w : 0;
79
+ };
80
+ function delay(time, abort) {
81
+ return new Promise(resolve => {
82
+ const timer = window.setTimeout(() => resolve(), time);
83
+ abort.addEventListener("abort", () => {
84
+ window.clearTimeout(timer);
85
+ resolve();
86
+ });
87
+ });
88
+ }
89
+
90
+ var func = /*#__PURE__*/Object.freeze({
91
+ __proto__: null,
92
+ delay: delay,
93
+ minWait: minWait,
94
+ minWaitAsync: minWaitAsync
95
+ });
96
+
97
+ function getWordEnd(count, word, one, two, five) {
98
+ const tt = count % 100;
99
+ if (tt >= 5 && tt <= 20)
100
+ return word + (five || "");
101
+ const t = count % 10;
102
+ return (t === 1 ?
103
+ (word + (one || "")) : ((t >= 2 && t <= 4) ? (word + (two || "")) : (word + (five || ""))));
104
+ }
105
+
106
+ var word = /*#__PURE__*/Object.freeze({
107
+ __proto__: null,
108
+ getWordEnd: getWordEnd
109
+ });
162
110
 
163
- export { Utility };
111
+ export { func as FuncHelper, object as ObjectHelper, type as TypeHelper, word as WordHelper };
164
112
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/types.d.ts CHANGED
@@ -1,26 +1,37 @@
1
- declare class Utility {
2
- static arrayToObject(array: Array<{
3
- Key: string;
4
- Value: any;
5
- }>): any;
6
- static objectToArray(obj: any): Array<{
7
- Key: string;
8
- Value: any;
9
- }> | null;
10
- static getWordEnd(count: number, word: string, one?: string, two?: string, five?: string): string;
11
- static isString(value: any): value is string | String;
12
- static isArray(value: any): value is any[];
13
- static isUndefined(value: any): value is undefined;
14
- static isFunction(value: any): boolean;
15
- static isPlainObject(obj: any): boolean;
16
- static joinString(separator: string, items: Array<any>): string;
17
- static stringIsNullOrEmpty(str: string): boolean;
18
- static hasProperty(obj: any, property: string): boolean;
19
- static getProperty(obj: any, property: string): any;
20
- static extend(...params: any[]): any;
21
- static createDelegate(context: any, func: (...params: Array<any>) => void): (...params: Array<any>) => void;
22
- static createDelegate2(context: any, func: (...params: Array<any>) => void, args?: Array<any>): (...params: Array<any>) => void;
23
- static createDelegate3(context: any, func: (...params: Array<any>) => void, args?: Array<any>): (...params: Array<any>) => void;
1
+ declare function hasProperty(obj: any, property: string): boolean;
2
+ declare function getProperty(obj: any, property: string): any;
3
+
4
+ declare const object_getProperty: typeof getProperty;
5
+ declare const object_hasProperty: typeof hasProperty;
6
+ declare namespace object {
7
+ export { object_getProperty as getProperty, object_hasProperty as hasProperty };
8
+ }
9
+
10
+ declare function isFunction(value: any): boolean;
11
+ declare function isString(value: any): value is string | String;
12
+
13
+ declare const type_isFunction: typeof isFunction;
14
+ declare const type_isString: typeof isString;
15
+ declare namespace type {
16
+ export { type_isFunction as isFunction, type_isString as isString };
17
+ }
18
+
19
+ declare const minWait: (func: (...args: any[]) => void, minTime?: number) => (...args: any[]) => void;
20
+ declare function minWaitAsync<TResult>(func: () => Promise<TResult>, minTime?: number): Promise<TResult>;
21
+ declare function delay(time: number, abort: AbortSignal): Promise<void>;
22
+
23
+ declare const func_delay: typeof delay;
24
+ declare const func_minWait: typeof minWait;
25
+ declare const func_minWaitAsync: typeof minWaitAsync;
26
+ declare namespace func {
27
+ export { func_delay as delay, func_minWait as minWait, func_minWaitAsync as minWaitAsync };
28
+ }
29
+
30
+ declare function getWordEnd(count: number, word: string, one?: string, two?: string, five?: string): string;
31
+
32
+ declare const word_getWordEnd: typeof getWordEnd;
33
+ declare namespace word {
34
+ export { word_getWordEnd as getWordEnd };
24
35
  }
25
36
 
26
- export { Utility };
37
+ export { func as FuncHelper, object as ObjectHelper, type as TypeHelper, word as WordHelper };
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "email": "it@brandup.online"
23
23
  },
24
24
  "license": "Apache-2.0",
25
- "version": "1.0.3",
25
+ "version": "1.0.4",
26
26
  "main": "dist/cjs/index.js",
27
27
  "module": "dist/mjs/index.js",
28
28
  "types": "dist/types.d.ts",