tuijs-util 1.4.11 → 1.5.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tuijs-util",
3
- "version": "1.4.11",
3
+ "version": "1.5.0",
4
4
  "module": "src/esm/index.js",
5
5
  "main": "src/cjs/index.cjs",
6
6
  "exports": {
package/src/cjs/index.cjs CHANGED
@@ -3,17 +3,23 @@
3
3
  /**
4
4
  * List of RegEx variables for different patterns.
5
5
  */
6
- const regExLetters = /^[a-zA-Z]+$/;
7
- const regExLettersLower = /^[a-z]+$/;
8
- const regExLettersUpper = /^[A-Z]+$/;
9
- const regExNumbers = /^\d+$/;
10
- const regExBin = /^[01]+$/; // Matches entire string for binary characters
6
+ const regExAllLetters = /^[a-zA-Z]+$/;
7
+ const regExAnyLetter = /[a-zA-Z]/; // Matches if string contains any letter
8
+ const regExAllLowercase = /^[a-z]+$/;
9
+ const regExAnyLowercase = /[a-z]/; // Matches if string contains any lowercase letter
10
+ const regExAllUppercase = /^[A-Z]+$/;
11
+ const regExAnyUppercase = /[A-Z]/; // Matches if string contains any uppercase letter
12
+ const regExAllNumbers = /^\d+$/;
13
+ const regExAnyNumber = /\d/; // Matches if string contains any number
14
+ const regExAllBin = /^[01]+$/; // Matches entire string for binary characters
15
+ const regExAnyBin = /[01]/; // Matches if string contains any binary character
11
16
  const regExBinChar = /[01]/g; // Matches individual binary characters.
12
17
  const regExBinNon = /[^01]/g; // Matches characters not in the binary range
13
- const regExHex = /^[0-9A-Fa-f]+$/; // Matches entire string for hexadecimal characters
18
+ const regExAllHex = /^[0-9A-Fa-f]+$/; // Matches entire string for hexadecimal characters
19
+ const regExAnyHex = /[0-9A-Fa-f]/; // Matches if string contains any hexadecimal character
14
20
  const regExHexChar = /[0-9A-Fa-f]/g; // Matches individual hexadecimal characters.
15
21
  const regExHexNon = /[^0-9A-Fa-f]/g; // Matches characters not in the hexadecimal range
16
- const regExSpecial = /^[\!\@\#\$\%\^\&\*\(\)\_\+\-\=\[\]\{\}\|\;\:\'\"\,\.\<\>\/\?\`\\\~]+$/;
22
+ const regExAnySpecial = /[\!\@\#\$\%\^\&\*\(\)\_\+\-\=\[\]\{\}\|\;\:\'\"\,\.\<\>\/\?\`\\\~]/;
17
23
  const regExFqdn = /^(?=.{1,253}$)(([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+([a-zA-Z]{2,}|[a-zA-Z0-9-]{2,}))$/;
18
24
  const regExUrl = new RegExp('^(https?:\\/\\/)?' +
19
25
  // protocol
@@ -144,16 +150,16 @@ function checkIpv6(string) {
144
150
  /**
145
151
  * Checks for special characters (Uses RegEx).
146
152
  * @param {string} string
147
- * @returns {boolean} - Returns true if a special character is found and false if the string is not validated or the RegEx test fails.
153
+ * @returns {boolean} - Returns true if any special character is found and false if the string is not validated or the RegEx test fails.
148
154
  * @throws {Error} - Throws error message if error occurs.
149
155
  */
150
- function checkSpecialChar(string) {
156
+ function checkAnySpecialChar(string) {
151
157
  try {
152
158
  if (typeof string !== 'string' || string.length === 0) {
153
159
  return false;
154
160
  }
155
161
  ;
156
- return regExSpecial.test(string);
162
+ return regExAnySpecial.test(string);
157
163
  } catch (er) {
158
164
  console.error(er);
159
165
  }
@@ -165,13 +171,13 @@ function checkSpecialChar(string) {
165
171
  * @returns {boolean} - Returns true if a number is found and false if not.
166
172
  * @throws {Error} - Throws error message if error occurs.
167
173
  */
168
- function checkNum(string) {
174
+ function checkAnyNum(string) {
169
175
  try {
170
176
  if (typeof string !== 'string' || string.length === 0) {
171
177
  return false;
172
178
  }
173
179
  ;
174
- return regExNumbers.test(string);
180
+ return regExAnyNumber.test(string);
175
181
  } catch (er) {
176
182
  console.error(er);
177
183
  }
@@ -183,13 +189,13 @@ function checkNum(string) {
183
189
  * @returns {boolean} - Returns true if a lowercase character is found and false if not.
184
190
  * @throws {Error} - Throws error message if error occurs.
185
191
  */
186
- function checkLowercase(string) {
192
+ function checkAnyLowercase(string) {
187
193
  try {
188
194
  if (typeof string !== 'string' || string.length === 0) {
189
195
  return false;
190
196
  }
191
197
  ;
192
- return regExLettersLower.test(string);
198
+ return regExAnyLowercase.test(string);
193
199
  } catch (er) {
194
200
  console.error(er);
195
201
  }
@@ -201,49 +207,49 @@ function checkLowercase(string) {
201
207
  * @returns {boolean} - Returns true if a uppercase character is found and false if not.
202
208
  * @throws {Error} - Throws error message if error occurs.
203
209
  */
204
- function checkUppercase(string) {
210
+ function checkAnyUppercase(string) {
205
211
  try {
206
212
  if (typeof string !== 'string' || string.length === 0) {
207
213
  return false;
208
214
  }
209
215
  ;
210
- return regExLettersUpper.test(string);
216
+ return regExAnyUppercase.test(string);
211
217
  } catch (er) {
212
218
  console.error(er);
213
219
  }
214
220
  }
215
221
 
216
222
  /**
217
- * Checks for a valid email address. (Uses RegEx).
223
+ * Checks for a space in a string
218
224
  * @param {string} string
219
- * @returns {boolean} - Returns true if email pattern test is successful and false if the string is not validated or the RegEx test fails.
225
+ * @returns {boolean} - Returns true if space is found and false if the string is not validated or if a space is not found.
220
226
  * @throws {Error} - Throws error message if error occurs.
221
227
  */
222
- function checkEmail(string) {
228
+ function checkAnySpaces(string) {
223
229
  try {
224
230
  if (typeof string !== 'string' || string.length === 0) {
225
231
  return false;
226
232
  }
227
233
  ;
228
- return regExEmail.test(string);
234
+ return string.indexOf(' ') >= 0;
229
235
  } catch (er) {
230
236
  console.error(er);
231
237
  }
232
238
  }
233
239
 
234
240
  /**
235
- * Checks for a space in a string
241
+ * Checks for a valid email address. (Uses RegEx).
236
242
  * @param {string} string
237
- * @returns {boolean} - Returns true if space is found and false if the string is not validated or if a space is not found.
243
+ * @returns {boolean} - Returns true if email pattern test is successful and false if the string is not validated or the RegEx test fails.
238
244
  * @throws {Error} - Throws error message if error occurs.
239
245
  */
240
- function checkSpaces(string) {
246
+ function checkEmail(string) {
241
247
  try {
242
248
  if (typeof string !== 'string' || string.length === 0) {
243
249
  return false;
244
250
  }
245
251
  ;
246
- return string.indexOf(' ') >= 0;
252
+ return regExEmail.test(string);
247
253
  } catch (er) {
248
254
  console.error(er);
249
255
  }
@@ -1108,6 +1114,11 @@ function parseFunctionString(string) {
1108
1114
  }
1109
1115
 
1110
1116
  exports.addLeadZero = addLeadZero;
1117
+ exports.checkAnyLowercase = checkAnyLowercase;
1118
+ exports.checkAnyNum = checkAnyNum;
1119
+ exports.checkAnySpaces = checkAnySpaces;
1120
+ exports.checkAnySpecialChar = checkAnySpecialChar;
1121
+ exports.checkAnyUppercase = checkAnyUppercase;
1111
1122
  exports.checkEmail = checkEmail;
1112
1123
  exports.checkFqdn = checkFqdn;
1113
1124
  exports.checkIp = checkIp;
@@ -1118,13 +1129,8 @@ exports.checkIsElement = checkIsElement;
1118
1129
  exports.checkIsFunction = checkIsFunction;
1119
1130
  exports.checkIsJson = checkIsJson;
1120
1131
  exports.checkIsObject = checkIsObject;
1121
- exports.checkLowercase = checkLowercase;
1122
1132
  exports.checkMac = checkMac;
1123
- exports.checkNum = checkNum;
1124
- exports.checkSpaces = checkSpaces;
1125
- exports.checkSpecialChar = checkSpecialChar;
1126
1133
  exports.checkSubnetMask = checkSubnetMask;
1127
- exports.checkUppercase = checkUppercase;
1128
1134
  exports.checkUrl = checkUrl;
1129
1135
  exports.convertBitsToMask = convertBitsToMask;
1130
1136
  exports.convertMaskToBits = convertMaskToBits;
@@ -1142,19 +1148,27 @@ exports.listUpChar = listUpChar;
1142
1148
  exports.parseFunctionString = parseFunctionString;
1143
1149
  exports.parseTemplate = parseTemplate;
1144
1150
  exports.preloadImages = preloadImages;
1145
- exports.regExBin = regExBin;
1151
+ exports.regExAllBin = regExAllBin;
1152
+ exports.regExAllHex = regExAllHex;
1153
+ exports.regExAllLetters = regExAllLetters;
1154
+ exports.regExAllLowercase = regExAllLowercase;
1155
+ exports.regExAllNumbers = regExAllNumbers;
1156
+ exports.regExAllUppercase = regExAllUppercase;
1157
+ exports.regExAnyBin = regExAnyBin;
1158
+ exports.regExAnyHex = regExAnyHex;
1159
+ exports.regExAnyLetter = regExAnyLetter;
1160
+ exports.regExAnyLowercase = regExAnyLowercase;
1161
+ exports.regExAnyNumber = regExAnyNumber;
1162
+ exports.regExAnySpecial = regExAnySpecial;
1163
+ exports.regExAnyUppercase = regExAnyUppercase;
1146
1164
  exports.regExBinChar = regExBinChar;
1147
1165
  exports.regExBinNon = regExBinNon;
1148
1166
  exports.regExEmail = regExEmail;
1149
1167
  exports.regExFqdn = regExFqdn;
1150
- exports.regExHex = regExHex;
1151
1168
  exports.regExHexChar = regExHexChar;
1152
1169
  exports.regExHexNon = regExHexNon;
1153
1170
  exports.regExIpv4 = regExIpv4;
1154
1171
  exports.regExIpv6 = regExIpv6;
1155
- exports.regExLetters = regExLetters;
1156
- exports.regExLettersLower = regExLettersLower;
1157
- exports.regExLettersUpper = regExLettersUpper;
1158
1172
  exports.regExMacColonPairs = regExMacColonPairs;
1159
1173
  exports.regExMacColonQuads = regExMacColonQuads;
1160
1174
  exports.regExMacDotPairs = regExMacDotPairs;
@@ -1162,8 +1176,6 @@ exports.regExMacDotQuads = regExMacDotQuads;
1162
1176
  exports.regExMacHyphenPairs = regExMacHyphenPairs;
1163
1177
  exports.regExMacHyphenQuads = regExMacHyphenQuads;
1164
1178
  exports.regExMacNoSeparator = regExMacNoSeparator;
1165
- exports.regExNumbers = regExNumbers;
1166
- exports.regExSpecial = regExSpecial;
1167
1179
  exports.regExUrl = regExUrl;
1168
1180
  exports.removeChar = removeChar;
1169
1181
  exports.reqGet = reqGet;
package/src/esm/index.js CHANGED
@@ -1,4 +1,9 @@
1
1
  export {
2
+ checkAnyLowercase,
3
+ checkAnyNum,
4
+ checkAnySpaces,
5
+ checkAnySpecialChar,
6
+ checkAnyUppercase,
2
7
  checkEmail,
3
8
  checkFqdn,
4
9
  checkIp,
@@ -9,21 +14,16 @@ export {
9
14
  checkIsFunction,
10
15
  checkIsJson,
11
16
  checkIsObject,
12
- checkLowercase,
13
17
  checkMac,
14
- checkNum,
15
- checkSpaces,
16
- checkSpecialChar,
17
18
  checkSubnetMask,
18
- checkUppercase,
19
19
  checkUrl
20
- } from './lib/util.check.js';
20
+ } from './lib/_check.js';
21
21
  export {
22
22
  elmCleaner,
23
23
  elmCleanerArray,
24
24
  elmCleanerTr,
25
- parseTemplate,
26
- } from './lib/util.dom.js';
25
+ parseTemplate
26
+ } from './lib/_dom.js';
27
27
  export {
28
28
  createReqInstance,
29
29
  reqGet,
@@ -33,7 +33,7 @@ export {
33
33
  reqPostJson,
34
34
  urlAddHttp,
35
35
  urlAddHttps
36
- } from './lib/util.http.js';
36
+ } from './lib/_http.js';
37
37
  export {
38
38
  listHtmlTags,
39
39
  listLowChar,
@@ -41,7 +41,7 @@ export {
41
41
  listSpecChar,
42
42
  listSubnets,
43
43
  listUpChar
44
- } from './lib/util.lists.js';
44
+ } from './lib/_lists.js';
45
45
  export {
46
46
  addLeadZero,
47
47
  convertBitsToMask,
@@ -50,24 +50,32 @@ export {
50
50
  preloadImages,
51
51
  scrollIntoView,
52
52
  sleep
53
- } from './lib/util.misc.js';
53
+ } from './lib/_misc.js';
54
54
  export {
55
55
  parseFunctionString
56
- } from './lib/util.parse.js';
56
+ } from './lib/_parse.js';
57
57
  export {
58
- regExBin,
58
+ regExAllBin,
59
+ regExAllHex,
60
+ regExAllLetters,
61
+ regExAllLowercase,
62
+ regExAllNumbers,
63
+ regExAllUppercase,
64
+ regExAnyBin,
65
+ regExAnyHex,
66
+ regExAnyLetter,
67
+ regExAnyLowercase,
68
+ regExAnyNumber,
69
+ regExAnySpecial,
70
+ regExAnyUppercase,
59
71
  regExBinChar,
60
72
  regExBinNon,
61
73
  regExEmail,
62
74
  regExFqdn,
63
- regExHex,
64
75
  regExHexChar,
65
76
  regExHexNon,
66
77
  regExIpv4,
67
78
  regExIpv6,
68
- regExLetters,
69
- regExLettersLower,
70
- regExLettersUpper,
71
79
  regExMacColonPairs,
72
80
  regExMacColonQuads,
73
81
  regExMacDotPairs,
@@ -75,9 +83,6 @@ export {
75
83
  regExMacHyphenPairs,
76
84
  regExMacHyphenQuads,
77
85
  regExMacNoSeparator,
78
- regExNumbers,
79
- regExSpecial,
80
86
  regExUrl,
81
87
  removeChar
82
- } from './lib/util.regex.js';
83
-
88
+ } from './lib/_regex.js';
@@ -1,8 +1,8 @@
1
1
  import {
2
- regExNumbers,
3
- regExLettersLower,
4
- regExLettersUpper,
5
- regExSpecial,
2
+ regExAnyNumber,
3
+ regExAnyLowercase,
4
+ regExAnyUppercase,
5
+ regExAnySpecial,
6
6
  regExFqdn,
7
7
  regExUrl,
8
8
  regExEmail,
@@ -15,7 +15,7 @@ import {
15
15
  regExMacHyphenQuads,
16
16
  regExMacDotPairs,
17
17
  regExMacDotQuads
18
- } from "./util.regex.js";
18
+ } from "./_regex.js";
19
19
 
20
20
  /**
21
21
  * Checks for a valid FQDN (Uses RegEx).
@@ -111,15 +111,15 @@ export function checkIpv6(string) {
111
111
  /**
112
112
  * Checks for special characters (Uses RegEx).
113
113
  * @param {string} string
114
- * @returns {boolean} - Returns true if a special character is found and false if the string is not validated or the RegEx test fails.
114
+ * @returns {boolean} - Returns true if any special character is found and false if the string is not validated or the RegEx test fails.
115
115
  * @throws {Error} - Throws error message if error occurs.
116
116
  */
117
- export function checkSpecialChar(string) {
117
+ export function checkAnySpecialChar(string) {
118
118
  try {
119
119
  if (typeof string !== 'string' || string.length === 0) {
120
120
  return false;
121
121
  };
122
- return regExSpecial.test(string);
122
+ return regExAnySpecial.test(string);
123
123
  } catch (er) {
124
124
  console.error(er);
125
125
  }
@@ -131,12 +131,12 @@ export function checkSpecialChar(string) {
131
131
  * @returns {boolean} - Returns true if a number is found and false if not.
132
132
  * @throws {Error} - Throws error message if error occurs.
133
133
  */
134
- export function checkNum(string) {
134
+ export function checkAnyNum(string) {
135
135
  try {
136
136
  if (typeof string !== 'string' || string.length === 0) {
137
137
  return false;
138
138
  };
139
- return regExNumbers.test(string);
139
+ return regExAnyNumber.test(string);
140
140
  } catch (er) {
141
141
  console.error(er);
142
142
  }
@@ -148,12 +148,12 @@ export function checkNum(string) {
148
148
  * @returns {boolean} - Returns true if a lowercase character is found and false if not.
149
149
  * @throws {Error} - Throws error message if error occurs.
150
150
  */
151
- export function checkLowercase(string) {
151
+ export function checkAnyLowercase(string) {
152
152
  try {
153
153
  if (typeof string !== 'string' || string.length === 0) {
154
154
  return false;
155
155
  };
156
- return regExLettersLower.test(string);
156
+ return regExAnyLowercase.test(string);
157
157
  } catch (er) {
158
158
  console.error(er);
159
159
  }
@@ -165,46 +165,46 @@ export function checkLowercase(string) {
165
165
  * @returns {boolean} - Returns true if a uppercase character is found and false if not.
166
166
  * @throws {Error} - Throws error message if error occurs.
167
167
  */
168
- export function checkUppercase(string) {
168
+ export function checkAnyUppercase(string) {
169
169
  try {
170
170
  if (typeof string !== 'string' || string.length === 0) {
171
171
  return false;
172
172
  };
173
- return regExLettersUpper.test(string);
173
+ return regExAnyUppercase.test(string);
174
174
  } catch (er) {
175
175
  console.error(er);
176
176
  }
177
177
  }
178
178
 
179
179
  /**
180
- * Checks for a valid email address. (Uses RegEx).
180
+ * Checks for a space in a string
181
181
  * @param {string} string
182
- * @returns {boolean} - Returns true if email pattern test is successful and false if the string is not validated or the RegEx test fails.
182
+ * @returns {boolean} - Returns true if space is found and false if the string is not validated or if a space is not found.
183
183
  * @throws {Error} - Throws error message if error occurs.
184
184
  */
185
- export function checkEmail(string) {
185
+ export function checkAnySpaces(string) {
186
186
  try {
187
187
  if (typeof string !== 'string' || string.length === 0) {
188
188
  return false;
189
189
  };
190
- return regExEmail.test(string);
190
+ return string.indexOf(' ') >= 0;
191
191
  } catch (er) {
192
192
  console.error(er);
193
193
  }
194
194
  }
195
195
 
196
196
  /**
197
- * Checks for a space in a string
197
+ * Checks for a valid email address. (Uses RegEx).
198
198
  * @param {string} string
199
- * @returns {boolean} - Returns true if space is found and false if the string is not validated or if a space is not found.
199
+ * @returns {boolean} - Returns true if email pattern test is successful and false if the string is not validated or the RegEx test fails.
200
200
  * @throws {Error} - Throws error message if error occurs.
201
201
  */
202
- export function checkSpaces(string) {
202
+ export function checkEmail(string) {
203
203
  try {
204
204
  if (typeof string !== 'string' || string.length === 0) {
205
205
  return false;
206
206
  };
207
- return string.indexOf(' ') >= 0;
207
+ return regExEmail.test(string);
208
208
  } catch (er) {
209
209
  console.error(er);
210
210
  }
@@ -1,4 +1,4 @@
1
- import { checkUrl, checkIsJson } from './util.check.js';
1
+ import { checkUrl } from './_check.js';
2
2
 
3
3
  /**
4
4
  * Adds 'http://' if valid URL and 'http://' or 'https://' is missing.
@@ -1,4 +1,4 @@
1
- import { checkSubnetMask } from "./util.check.js";
1
+ import { checkSubnetMask } from "./_check.js";
2
2
 
3
3
  /**
4
4
  * Adds zero in front of numbers less than 10 and returns as a string.
@@ -1,14 +1,20 @@
1
1
  /**
2
2
  * List of RegEx variables for different patterns.
3
3
  */
4
- export const regExLetters = /^[a-zA-Z]+$/;
5
- export const regExLettersLower = /^[a-z]+$/;
6
- export const regExLettersUpper = /^[A-Z]+$/;
7
- export const regExNumbers = /^\d+$/;
8
- export const regExBin = /^[01]+$/; // Matches entire string for binary characters
4
+ export const regExAllLetters = /^[a-zA-Z]+$/;
5
+ export const regExAnyLetter = /[a-zA-Z]/; // Matches if string contains any letter
6
+ export const regExAllLowercase = /^[a-z]+$/;
7
+ export const regExAnyLowercase = /[a-z]/; // Matches if string contains any lowercase letter
8
+ export const regExAllUppercase = /^[A-Z]+$/;
9
+ export const regExAnyUppercase = /[A-Z]/; // Matches if string contains any uppercase letter
10
+ export const regExAllNumbers = /^\d+$/;
11
+ export const regExAnyNumber = /\d/; // Matches if string contains any number
12
+ export const regExAllBin = /^[01]+$/; // Matches entire string for binary characters
13
+ export const regExAnyBin = /[01]/; // Matches if string contains any binary character
9
14
  export const regExBinChar = /[01]/g; // Matches individual binary characters.
10
15
  export const regExBinNon = /[^01]/g; // Matches characters not in the binary range
11
- export const regExHex = /^[0-9A-Fa-f]+$/; // Matches entire string for hexadecimal characters
16
+ export const regExAllHex = /^[0-9A-Fa-f]+$/; // Matches entire string for hexadecimal characters
17
+ export const regExAnyHex = /[0-9A-Fa-f]/; // Matches if string contains any hexadecimal character
12
18
  export const regExHexChar = /[0-9A-Fa-f]/g // Matches individual hexadecimal characters.
13
19
  export const regExHexNon = /[^0-9A-Fa-f]/g; // Matches characters not in the hexadecimal range
14
20
  export const regExAnySpecial = /[\!\@\#\$\%\^\&\*\(\)\_\+\-\=\[\]\{\}\|\;\:\'\"\,\.\<\>\/\?\`\\\~]/;
File without changes
File without changes
File without changes