@brandup/ui-helpers 1.0.1
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/README.md +11 -0
- package/dist/cjs/index.js +166 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/mjs/index.js +164 -0
- package/dist/mjs/index.js.map +1 -0
- package/dist/types.d.ts +26 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# brandup-ui-helpers
|
|
2
|
+
|
|
3
|
+
[]()
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install NPM package [@brandup/ui-helpers](https://www.npmjs.com/package/@brandup/ui-helpers).
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm i @brandup/ui-helpers@latest
|
|
11
|
+
```
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
'use strict';
|
|
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) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (obj.constructor && !obj.hasOwnProperty.call(obj, "constructor") && !obj.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf")) {
|
|
49
|
+
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
|
+
};
|
|
145
|
+
}
|
|
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
|
+
;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
exports.Utility = Utility;
|
|
166
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,164 @@
|
|
|
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) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (obj.constructor && !obj.hasOwnProperty.call(obj, "constructor") && !obj.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf")) {
|
|
47
|
+
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
|
+
};
|
|
143
|
+
}
|
|
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
|
+
;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export { Utility };
|
|
164
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { Utility };
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@brandup/ui-helpers",
|
|
3
|
+
"description": "JavaScript helpers",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"brandup",
|
|
6
|
+
"javascript",
|
|
7
|
+
"typescript",
|
|
8
|
+
"dom",
|
|
9
|
+
"ui"
|
|
10
|
+
],
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Dmitry Kovyazin",
|
|
13
|
+
"email": "it@brandup.online"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/brandup-online/brandup-ui/npm/brandup-ui-helpers",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/brandup-online/brandup-ui.git"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/brandup-online/brandup-ui/issues",
|
|
22
|
+
"email": "it@brandup.online"
|
|
23
|
+
},
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"version": "1.0.1",
|
|
26
|
+
"main": "dist/cjs/index.js",
|
|
27
|
+
"module": "dist/mjs/index.js",
|
|
28
|
+
"types": "dist/types.d.ts",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@rollup/plugin-commonjs": "^25.0.8",
|
|
31
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
32
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
33
|
+
"rollup": "^4.19.0",
|
|
34
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
35
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
36
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
37
|
+
"tslib": "^2.6.3",
|
|
38
|
+
"typescript": "^5.5.3"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"README.md"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "rollup -c --bundleConfigAsCjs",
|
|
46
|
+
"watch": "rollup -c -w --bundleConfigAsCjs"
|
|
47
|
+
}
|
|
48
|
+
}
|