tuijs-util 1.3.4 → 1.3.5
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/package.json +1 -1
- package/src/cjs/index.cjs +60 -86
- package/src/esm/index.js +0 -1
- package/src/esm/lib/util.check.js +72 -69
package/package.json
CHANGED
package/src/cjs/index.cjs
CHANGED
|
@@ -58,7 +58,7 @@ function checkFqdn(string) {
|
|
|
58
58
|
}
|
|
59
59
|
return regExFqdn.test(string);
|
|
60
60
|
} catch (er) {
|
|
61
|
-
throw new Error(er.message);
|
|
61
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -76,7 +76,7 @@ function checkUrl(string) {
|
|
|
76
76
|
;
|
|
77
77
|
return regExUrl.test(string); // Returns false if the url is invalid
|
|
78
78
|
} catch (er) {
|
|
79
|
-
throw new Error(er.message);
|
|
79
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -94,164 +94,139 @@ function checkSpecialChar(string) {
|
|
|
94
94
|
;
|
|
95
95
|
return regExSpecial.test(string);
|
|
96
96
|
} catch (er) {
|
|
97
|
-
throw new Error(er.message);
|
|
97
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
|
-
* Checks for
|
|
102
|
+
* Checks for number values in a string (Uses RegEx)
|
|
103
103
|
* @param {string} string
|
|
104
|
-
* @returns {boolean} - Returns true if
|
|
104
|
+
* @returns {boolean} - Returns true if a number is found and false if not.
|
|
105
105
|
* @throws {Error} - Throws error message if error occurs.
|
|
106
106
|
*/
|
|
107
|
-
function
|
|
107
|
+
function checkNum(string) {
|
|
108
108
|
try {
|
|
109
109
|
if (typeof string !== 'string' || string.length === 0) {
|
|
110
110
|
return false;
|
|
111
111
|
}
|
|
112
112
|
;
|
|
113
|
-
return
|
|
113
|
+
return regExNumbers.test(string);
|
|
114
114
|
} catch (er) {
|
|
115
|
-
throw new Error(er.message);
|
|
115
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
|
-
* Checks for
|
|
120
|
+
* Checks for lowercase characters (Uses RegEx)
|
|
121
121
|
* @param {string} string
|
|
122
|
-
* @returns {boolean} - Returns true if
|
|
122
|
+
* @returns {boolean} - Returns true if a lowercase character is found and false if not.
|
|
123
123
|
* @throws {Error} - Throws error message if error occurs.
|
|
124
124
|
*/
|
|
125
|
-
function
|
|
125
|
+
function checkLowercase(string) {
|
|
126
126
|
try {
|
|
127
127
|
if (typeof string !== 'string' || string.length === 0) {
|
|
128
128
|
return false;
|
|
129
129
|
}
|
|
130
130
|
;
|
|
131
|
-
return
|
|
131
|
+
return regExLettersLower.test(string);
|
|
132
132
|
} catch (er) {
|
|
133
|
-
throw new Error(er.message);
|
|
133
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
// Check for a list of text???
|
|
138
137
|
/**
|
|
139
|
-
*
|
|
138
|
+
* Checks for uppercase characters (Uses RegEx)
|
|
139
|
+
* @param {string} string
|
|
140
|
+
* @returns {boolean} - Returns true if a uppercase character is found and false if not.
|
|
141
|
+
* @throws {Error} - Throws error message if error occurs.
|
|
140
142
|
*/
|
|
141
|
-
function
|
|
143
|
+
function checkUppercase(string) {
|
|
142
144
|
try {
|
|
143
|
-
|
|
144
|
-
if (typeof input !== 'string') {
|
|
145
|
+
if (typeof string !== 'string' || string.length === 0) {
|
|
145
146
|
return false;
|
|
146
147
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
// Check if all items are non-empty strings
|
|
150
|
-
for (let item of items) {
|
|
151
|
-
item = item.trim(); // Trim any leading or trailing whitespace
|
|
152
|
-
if (item === '') {
|
|
153
|
-
return false; // Empty item found
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return true;
|
|
148
|
+
;
|
|
149
|
+
return regExLettersUpper.test(string);
|
|
157
150
|
} catch (er) {
|
|
158
|
-
throw new Error(er.message);
|
|
151
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
159
152
|
}
|
|
160
153
|
}
|
|
161
154
|
|
|
162
155
|
/**
|
|
163
|
-
* Checks
|
|
164
|
-
* @param {
|
|
165
|
-
* @returns {boolean} - Returns true if
|
|
156
|
+
* Checks for a valid email address. (Uses RegEx).
|
|
157
|
+
* @param {string} string
|
|
158
|
+
* @returns {boolean} - Returns true if email pattern test is successful and false if the string is not validated or the RegEx test fails.
|
|
166
159
|
* @throws {Error} - Throws error message if error occurs.
|
|
167
160
|
*/
|
|
168
|
-
function
|
|
161
|
+
function checkEmail(string) {
|
|
169
162
|
try {
|
|
170
|
-
|
|
163
|
+
if (typeof string !== 'string' || string.length === 0) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
;
|
|
167
|
+
return regExEmail.test(string);
|
|
171
168
|
} catch (er) {
|
|
172
|
-
throw new Error(er.message);
|
|
169
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
173
170
|
}
|
|
174
171
|
}
|
|
175
172
|
|
|
176
173
|
/**
|
|
177
|
-
* Checks
|
|
178
|
-
* @param {
|
|
179
|
-
* @returns {boolean} - Returns true if
|
|
174
|
+
* Checks for a space in a string
|
|
175
|
+
* @param {string} string
|
|
176
|
+
* @returns {boolean} - Returns true if space is found and false if the string is not validated or if a space is not found.
|
|
180
177
|
* @throws {Error} - Throws error message if error occurs.
|
|
181
178
|
*/
|
|
182
|
-
function
|
|
179
|
+
function checkSpaces(string) {
|
|
183
180
|
try {
|
|
184
|
-
|
|
181
|
+
if (typeof string !== 'string' || string.length === 0) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
;
|
|
185
|
+
return str.indexOf(' ') >= 0;
|
|
185
186
|
} catch (er) {
|
|
186
|
-
throw new Error(er.message);
|
|
187
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
190
|
|
|
190
191
|
/**
|
|
191
|
-
* Checks an input to determine if it is
|
|
192
|
+
* Checks an input to determine if it is an Array.
|
|
192
193
|
* @param {*} input
|
|
193
|
-
* @returns {boolean} - Returns true if the input is
|
|
194
|
-
*/
|
|
195
|
-
function checkIsJson(input) {
|
|
196
|
-
try {
|
|
197
|
-
JSON.parse(input);
|
|
198
|
-
return true;
|
|
199
|
-
} catch (er) {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Checks for number values in a string (Uses RegEx)
|
|
206
|
-
* @param {string} string
|
|
207
|
-
* @returns {boolean} - Returns true if a number is found and false if not.
|
|
194
|
+
* @returns {boolean} - Returns true if the input is an Array and false if not.
|
|
208
195
|
* @throws {Error} - Throws error message if error occurs.
|
|
209
196
|
*/
|
|
210
|
-
function
|
|
197
|
+
function checkIsArray(input) {
|
|
211
198
|
try {
|
|
212
|
-
|
|
213
|
-
return false;
|
|
214
|
-
}
|
|
215
|
-
;
|
|
216
|
-
return regExNumbers.test(string);
|
|
199
|
+
return Array.isArray(input);
|
|
217
200
|
} catch (er) {
|
|
218
|
-
throw new Error(er.message);
|
|
201
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
219
202
|
}
|
|
220
203
|
}
|
|
221
204
|
|
|
222
205
|
/**
|
|
223
|
-
* Checks
|
|
224
|
-
* @param {
|
|
225
|
-
* @returns {boolean} - Returns true if
|
|
206
|
+
* Checks an input to determine if it is an Object.
|
|
207
|
+
* @param {*} input
|
|
208
|
+
* @returns {boolean} - Returns true if the input is an Object and false if not.
|
|
226
209
|
* @throws {Error} - Throws error message if error occurs.
|
|
227
210
|
*/
|
|
228
|
-
function
|
|
211
|
+
function checkIsObject(input) {
|
|
229
212
|
try {
|
|
230
|
-
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
;
|
|
234
|
-
return regExLettersLower.test(string);
|
|
213
|
+
return input !== null && typeof input === 'object' && input.constructor === Object;
|
|
235
214
|
} catch (er) {
|
|
236
|
-
throw new Error(er.message);
|
|
215
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
237
216
|
}
|
|
238
217
|
}
|
|
239
218
|
|
|
240
219
|
/**
|
|
241
|
-
* Checks
|
|
242
|
-
* @param {
|
|
243
|
-
* @returns {boolean} - Returns true if
|
|
244
|
-
* @throws {Error} - Throws error message if error occurs.
|
|
220
|
+
* Checks an input to determine if it is valid JSON.
|
|
221
|
+
* @param {*} input
|
|
222
|
+
* @returns {boolean} - Returns true if the input is valid JSON and false if not.
|
|
245
223
|
*/
|
|
246
|
-
function
|
|
224
|
+
function checkIsJson(input) {
|
|
247
225
|
try {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
;
|
|
252
|
-
return regExLettersUpper.test(string);
|
|
226
|
+
const parsed = JSON.parse(input);
|
|
227
|
+
return (typeof parsed === 'object' || typeof parsed === 'number' || typeof parsed === 'boolean' || typeof parsed === 'string') && parsed !== null;
|
|
253
228
|
} catch (er) {
|
|
254
|
-
|
|
229
|
+
return false;
|
|
255
230
|
}
|
|
256
231
|
}
|
|
257
232
|
|
|
@@ -584,7 +559,6 @@ exports.checkEmail = checkEmail;
|
|
|
584
559
|
exports.checkFqdn = checkFqdn;
|
|
585
560
|
exports.checkIsArray = checkIsArray;
|
|
586
561
|
exports.checkIsJson = checkIsJson;
|
|
587
|
-
exports.checkIsList = checkIsList;
|
|
588
562
|
exports.checkIsObject = checkIsObject;
|
|
589
563
|
exports.checkLowercase = checkLowercase;
|
|
590
564
|
exports.checkNum = checkNum;
|
package/src/esm/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export function checkFqdn(string) {
|
|
|
13
13
|
}
|
|
14
14
|
return regExFqdn.test(string);
|
|
15
15
|
} catch (er) {
|
|
16
|
-
throw new Error(er.message);
|
|
16
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -31,7 +31,7 @@ export function checkUrl(string) {
|
|
|
31
31
|
};
|
|
32
32
|
return regExUrl.test(string); // Returns false if the url is invalid
|
|
33
33
|
} catch (er) {
|
|
34
|
-
throw new Error(er.message);
|
|
34
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -48,66 +48,92 @@ export function checkSpecialChar(string) {
|
|
|
48
48
|
};
|
|
49
49
|
return regExSpecial.test(string);
|
|
50
50
|
} catch (er) {
|
|
51
|
-
throw new Error(er.message);
|
|
51
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
* Checks for
|
|
56
|
+
* Checks for number values in a string (Uses RegEx)
|
|
57
57
|
* @param {string} string
|
|
58
|
-
* @returns {boolean} - Returns true if
|
|
58
|
+
* @returns {boolean} - Returns true if a number is found and false if not.
|
|
59
59
|
* @throws {Error} - Throws error message if error occurs.
|
|
60
60
|
*/
|
|
61
|
-
export function
|
|
61
|
+
export function checkNum(string) {
|
|
62
62
|
try {
|
|
63
63
|
if (typeof string !== 'string' || string.length === 0) {
|
|
64
64
|
return false;
|
|
65
65
|
};
|
|
66
|
-
return
|
|
66
|
+
return regExNumbers.test(string);
|
|
67
67
|
} catch (er) {
|
|
68
|
-
throw new Error(er.message);
|
|
68
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
* Checks for
|
|
73
|
+
* Checks for lowercase characters (Uses RegEx)
|
|
74
74
|
* @param {string} string
|
|
75
|
-
* @returns {boolean} - Returns true if
|
|
75
|
+
* @returns {boolean} - Returns true if a lowercase character is found and false if not.
|
|
76
76
|
* @throws {Error} - Throws error message if error occurs.
|
|
77
77
|
*/
|
|
78
|
-
export function
|
|
78
|
+
export function checkLowercase(string) {
|
|
79
79
|
try {
|
|
80
80
|
if (typeof string !== 'string' || string.length === 0) {
|
|
81
81
|
return false;
|
|
82
82
|
};
|
|
83
|
-
return
|
|
83
|
+
return regExLettersLower.test(string);
|
|
84
84
|
} catch (er) {
|
|
85
|
-
throw new Error(er.message);
|
|
85
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
// Check for a list of text???
|
|
90
89
|
/**
|
|
91
|
-
*
|
|
90
|
+
* Checks for uppercase characters (Uses RegEx)
|
|
91
|
+
* @param {string} string
|
|
92
|
+
* @returns {boolean} - Returns true if a uppercase character is found and false if not.
|
|
93
|
+
* @throws {Error} - Throws error message if error occurs.
|
|
92
94
|
*/
|
|
93
|
-
export function
|
|
95
|
+
export function checkUppercase(string) {
|
|
94
96
|
try {
|
|
95
|
-
|
|
96
|
-
if (typeof input !== 'string') {
|
|
97
|
+
if (typeof string !== 'string' || string.length === 0) {
|
|
97
98
|
return false;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
99
|
+
};
|
|
100
|
+
return regExLettersUpper.test(string);
|
|
101
|
+
} catch (er) {
|
|
102
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Checks for a valid email address. (Uses RegEx).
|
|
108
|
+
* @param {string} string
|
|
109
|
+
* @returns {boolean} - Returns true if email pattern test is successful and false if the string is not validated or the RegEx test fails.
|
|
110
|
+
* @throws {Error} - Throws error message if error occurs.
|
|
111
|
+
*/
|
|
112
|
+
export function checkEmail(string) {
|
|
113
|
+
try {
|
|
114
|
+
if (typeof string !== 'string' || string.length === 0) {
|
|
115
|
+
return false;
|
|
116
|
+
};
|
|
117
|
+
return regExEmail.test(string);
|
|
118
|
+
} catch (er) {
|
|
119
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Checks for a space in a string
|
|
125
|
+
* @param {string} string
|
|
126
|
+
* @returns {boolean} - Returns true if space is found and false if the string is not validated or if a space is not found.
|
|
127
|
+
* @throws {Error} - Throws error message if error occurs.
|
|
128
|
+
*/
|
|
129
|
+
export function checkSpaces(string) {
|
|
130
|
+
try {
|
|
131
|
+
if (typeof string !== 'string' || string.length === 0) {
|
|
132
|
+
return false;
|
|
133
|
+
};
|
|
134
|
+
return str.indexOf(' ') >= 0;
|
|
109
135
|
} catch (er) {
|
|
110
|
-
throw new Error(er.message);
|
|
136
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
111
137
|
}
|
|
112
138
|
}
|
|
113
139
|
|
|
@@ -121,7 +147,7 @@ export function checkIsArray(input) {
|
|
|
121
147
|
try {
|
|
122
148
|
return Array.isArray(input);
|
|
123
149
|
} catch (er) {
|
|
124
|
-
throw new Error(er.message);
|
|
150
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
125
151
|
}
|
|
126
152
|
}
|
|
127
153
|
|
|
@@ -135,7 +161,7 @@ export function checkIsObject(input) {
|
|
|
135
161
|
try {
|
|
136
162
|
return input !== null && typeof input === 'object' && input.constructor === Object;
|
|
137
163
|
} catch (er) {
|
|
138
|
-
throw new Error(er.message);
|
|
164
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
139
165
|
}
|
|
140
166
|
}
|
|
141
167
|
|
|
@@ -146,60 +172,37 @@ export function checkIsObject(input) {
|
|
|
146
172
|
*/
|
|
147
173
|
export function checkIsJson(input) {
|
|
148
174
|
try {
|
|
149
|
-
JSON.parse(input);
|
|
150
|
-
return
|
|
175
|
+
const parsed = JSON.parse(input);
|
|
176
|
+
return (typeof parsed === 'object' || typeof parsed === 'number' || typeof parsed === 'boolean' || typeof parsed === 'string') && parsed !== null;
|
|
151
177
|
} catch (er) {
|
|
152
178
|
return false;
|
|
153
179
|
}
|
|
154
180
|
}
|
|
155
181
|
|
|
156
182
|
/**
|
|
157
|
-
* Checks
|
|
158
|
-
* @param {
|
|
159
|
-
* @returns {boolean} - Returns true if
|
|
160
|
-
* @throws {Error} - Throws error message if error occurs.
|
|
161
|
-
*/
|
|
162
|
-
export function checkNum(string) {
|
|
163
|
-
try {
|
|
164
|
-
if (typeof string !== 'string' || string.length === 0) {
|
|
165
|
-
return false;
|
|
166
|
-
};
|
|
167
|
-
return regExNumbers.test(string);
|
|
168
|
-
} catch (er) {
|
|
169
|
-
throw new Error(er.message);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Checks for lowercase characters (Uses RegEx)
|
|
175
|
-
* @param {string} string
|
|
176
|
-
* @returns {boolean} - Returns true if a lowercase character is found and false if not.
|
|
183
|
+
* Checks an input to determine if it is an Element.
|
|
184
|
+
* @param {*} input
|
|
185
|
+
* @returns {boolean} - Returns true if the input is an Element and false if not.
|
|
177
186
|
* @throws {Error} - Throws error message if error occurs.
|
|
178
187
|
*/
|
|
179
|
-
export function
|
|
188
|
+
export function checkIsElement(input) {
|
|
180
189
|
try {
|
|
181
|
-
|
|
182
|
-
return false;
|
|
183
|
-
};
|
|
184
|
-
return regExLettersLower.test(string);
|
|
190
|
+
return input instanceof Element;
|
|
185
191
|
} catch (er) {
|
|
186
|
-
throw new Error(er.message);
|
|
192
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
187
193
|
}
|
|
188
194
|
}
|
|
189
195
|
|
|
190
196
|
/**
|
|
191
|
-
* Checks
|
|
192
|
-
* @param {
|
|
193
|
-
* @returns {boolean} - Returns true if
|
|
197
|
+
* Checks an input to determine if it is a Function.
|
|
198
|
+
* @param {*} input
|
|
199
|
+
* @returns {boolean} - Returns true if the input is a Function and false if not.
|
|
194
200
|
* @throws {Error} - Throws error message if error occurs.
|
|
195
201
|
*/
|
|
196
|
-
export function
|
|
202
|
+
export function checkIsFunction(input) {
|
|
197
203
|
try {
|
|
198
|
-
|
|
199
|
-
return false;
|
|
200
|
-
};
|
|
201
|
-
return regExLettersUpper.test(string);
|
|
204
|
+
return typeof input === 'function';
|
|
202
205
|
} catch (er) {
|
|
203
|
-
throw new Error(er.message);
|
|
206
|
+
throw new Error(`TUI Util Error: ${er.message}`);
|
|
204
207
|
}
|
|
205
208
|
}
|