tuijs-util 2.0.3 → 2.0.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/src/lib/misc.ts CHANGED
@@ -1,117 +1,117 @@
1
- import { checkSubnetMask } from "./check.js";
2
-
3
- export function addLeadZero(number: number | string): string | undefined {
4
- if (typeof number === 'string') {
5
- number = parseInt(number);
6
- }
7
- if (number === null || typeof number !== 'number' || number > 9) {
8
- throw new Error(`Invalid input.`);
9
- };
10
- return "0" + number;
11
-
12
- }
13
-
14
- export function generateUID(length: number = 16): string {
15
- if (typeof length !== 'number' || length <= 0) {
16
- throw new Error(`Invalid input. The 'length' parameter must be a positive number.`);
17
- }
18
- const timestampPart = Date.now().toString(36);
19
- const randomPart = Math.random().toString(36).slice(2, 2 + length);
20
- return 'uid-' + timestampPart + '-' + randomPart;
21
-
22
- }
23
-
24
- /**
25
- * Loads all images and returns a promise when loading is complete
26
- */
27
- export async function preloadImages(imageUrls: string[]): Promise<void> {
28
- const loadImage = (url: string) => {
29
- return new Promise((resolve, reject) => {
30
- const img = new Image();
31
- img.onload = () => resolve(url);
32
- img.onerror = () => reject(new Error(`Failed to load image at ${url}`));
33
- img.src = url;
34
- });
35
- };
36
- await Promise.all(imageUrls.map(loadImage));
37
- }
38
-
39
- /**
40
- * Sleeps for a given number of milliseconds
41
- */
42
- export function sleep(ms: number): Promise<void> {
43
- return new Promise(resolve => setTimeout(resolve, ms));
44
- }
45
-
46
- /**
47
- * NEED TO ADD NAME AND JSDOC
48
- * MAY NEED REWORD
49
- */
50
- export function scrollIntoView() {
51
- let allObservers: IntersectionObserver[] = [];
52
-
53
- function addObserver(targets: Element[], callback: (target: Element) => void, observerOptions: IntersectionObserverInit = { threshold: 0.5 }) {
54
- const observer = new IntersectionObserver((entries) => {
55
- entries.forEach(entry => {
56
- if (entry.isIntersecting) { // Only trigger when the element is intersecting
57
- callback(entry.target);
58
- }
59
- });
60
- }, observerOptions);
61
- for (let i = 0; i < targets.length; i++) {
62
- observer.observe(targets[i])
63
-
64
- }
65
- allObservers.push(observer);
66
- }
67
-
68
- function removeNamedObserver(name: string) {
69
- for (let i = 0; i < allObservers.length; i++) {
70
- if ((allObservers[i] as any).name === name) { // REMOVE ANY?
71
- allObservers[i].disconnect();
72
- allObservers.splice(i, 1);
73
- i--;
74
- }
75
- }
76
- }
77
-
78
- function removeAllObservers() {
79
- for (let i = 0; i < allObservers.length; i++) {
80
- allObservers[i].disconnect();
81
- }
82
- allObservers = [];
83
- }
84
-
85
- return {
86
- addObserver,
87
- removeNamedObserver,
88
- removeAllObservers
89
- }
90
- }
91
-
92
- export function convertBitsToMask(bits: number): string | undefined {
93
- if (bits < 0 || bits > 32) {
94
- throw new Error("Bit input must be between 0 and 32");
95
- }
96
- const mask: number = (0xffffffff << (32 - bits)) >>> 0;
97
- return [
98
- (mask >>> 24) & 0xff,
99
- (mask >>> 16) & 0xff,
100
- (mask >>> 8) & 0xff,
101
- mask & 0xff
102
- ].join('.');
103
-
104
- }
105
-
106
- export function convertMaskToBits(mask: string): number | undefined {
107
- if (!checkSubnetMask(mask)) {
108
- throw new Error("Invalid subnet mask.");
109
- }
110
- const maskArray = mask.split('.').map((num: string) => parseInt(num, 10));
111
- return maskArray
112
- .map((num: number) => num.toString(2).padStart(8, '0')) // ['11111111', '11111111', '11111111', '00000000']
113
- .join('') // '11111111111111111111111100000000'
114
- .split('') // ['1','1','1',...,'0','0']
115
- .filter((bit: string) => bit === '1') // Keep only the '1's
116
- .length; // Count them
117
- }
1
+ import { checkSubnetMask } from "./check.js";
2
+
3
+ export function addLeadZero(number: number | string): string | undefined {
4
+ if (typeof number === 'string') {
5
+ number = parseInt(number);
6
+ }
7
+ if (number === null || typeof number !== 'number' || number > 9) {
8
+ throw new Error(`Invalid input.`);
9
+ };
10
+ return "0" + number;
11
+
12
+ }
13
+
14
+ export function generateUID(length: number = 16): string {
15
+ if (typeof length !== 'number' || length <= 0) {
16
+ throw new Error(`Invalid input. The 'length' parameter must be a positive number.`);
17
+ }
18
+ const timestampPart = Date.now().toString(36);
19
+ const randomPart = Math.random().toString(36).slice(2, 2 + length);
20
+ return 'uid-' + timestampPart + '-' + randomPart;
21
+
22
+ }
23
+
24
+ /**
25
+ * Loads all images and returns a promise when loading is complete
26
+ */
27
+ export async function preloadImages(imageUrls: string[]): Promise<void> {
28
+ const loadImage = (url: string) => {
29
+ return new Promise((resolve, reject) => {
30
+ const img = new Image();
31
+ img.onload = () => resolve(url);
32
+ img.onerror = () => reject(new Error(`Failed to load image at ${url}`));
33
+ img.src = url;
34
+ });
35
+ };
36
+ await Promise.all(imageUrls.map(loadImage));
37
+ }
38
+
39
+ /**
40
+ * Sleeps for a given number of milliseconds
41
+ */
42
+ export function sleep(ms: number): Promise<void> {
43
+ return new Promise(resolve => setTimeout(resolve, ms));
44
+ }
45
+
46
+ /**
47
+ * NEED TO ADD NAME AND JSDOC
48
+ * MAY NEED REWORD
49
+ */
50
+ export function scrollIntoView() {
51
+ let allObservers: IntersectionObserver[] = [];
52
+
53
+ function addObserver(targets: Element[], callback: (target: Element) => void, observerOptions: IntersectionObserverInit = { threshold: 0.5 }) {
54
+ const observer = new IntersectionObserver((entries) => {
55
+ entries.forEach(entry => {
56
+ if (entry.isIntersecting) { // Only trigger when the element is intersecting
57
+ callback(entry.target);
58
+ }
59
+ });
60
+ }, observerOptions);
61
+ for (let i = 0; i < targets.length; i++) {
62
+ observer.observe(targets[i])
63
+
64
+ }
65
+ allObservers.push(observer);
66
+ }
67
+
68
+ function removeNamedObserver(name: string) {
69
+ for (let i = 0; i < allObservers.length; i++) {
70
+ if ((allObservers[i] as any).name === name) { // REMOVE ANY?
71
+ allObservers[i].disconnect();
72
+ allObservers.splice(i, 1);
73
+ i--;
74
+ }
75
+ }
76
+ }
77
+
78
+ function removeAllObservers() {
79
+ for (let i = 0; i < allObservers.length; i++) {
80
+ allObservers[i].disconnect();
81
+ }
82
+ allObservers = [];
83
+ }
84
+
85
+ return {
86
+ addObserver,
87
+ removeNamedObserver,
88
+ removeAllObservers
89
+ }
90
+ }
91
+
92
+ export function convertBitsToMask(bits: number): string | undefined {
93
+ if (bits < 0 || bits > 32) {
94
+ throw new Error("Bit input must be between 0 and 32");
95
+ }
96
+ const mask: number = (0xffffffff << (32 - bits)) >>> 0;
97
+ return [
98
+ (mask >>> 24) & 0xff,
99
+ (mask >>> 16) & 0xff,
100
+ (mask >>> 8) & 0xff,
101
+ mask & 0xff
102
+ ].join('.');
103
+
104
+ }
105
+
106
+ export function convertMaskToBits(mask: string): number | undefined {
107
+ if (!checkSubnetMask(mask)) {
108
+ throw new Error("Invalid subnet mask.");
109
+ }
110
+ const maskArray = mask.split('.').map((num: string) => parseInt(num, 10));
111
+ return maskArray
112
+ .map((num: number) => num.toString(2).padStart(8, '0')) // ['11111111', '11111111', '11111111', '00000000']
113
+ .join('') // '11111111111111111111111100000000'
114
+ .split('') // ['1','1','1',...,'0','0']
115
+ .filter((bit: string) => bit === '1') // Keep only the '1's
116
+ .length; // Count them
117
+ }
package/src/lib/parse.ts CHANGED
@@ -1,23 +1,23 @@
1
-
2
- /**
3
- * Parses a function and its parameters when it is in the form of a string.
4
- * This can be used to embed function strings into custom HTML elements.
5
- * The Function MUST exist in the window object.
6
- */
7
- export function parseFunctionString(string: string): Function | undefined {
8
- const match: RegExpMatchArray | null = string.match(/^(\w+)\((.*)\)$/); // Match "functionName(args)"
9
- if (!match) {
10
- throw new Error('Input does not match the expected pattern "functionName(args)".');
11
- }
12
- const funcName: string = match[1]; // Function name
13
- const args: string = match[2]; // Arguments as a single string
14
- const func = window[funcName as keyof Window];
15
- if (typeof func !== 'function') {
16
- throw new Error(`"${funcName}" is not a valid function.`);
17
- }
18
- const parsedArgs: string[] = args
19
- .split(',')
20
- .map(arg => arg.trim().replace(/^['"]|['"]$/g, '')) // Trim and remove quotes
21
- .filter(arg => arg !== ''); // Remove empty strings from args
22
- return () => func(...parsedArgs);
23
- }
1
+
2
+ /**
3
+ * Parses a function and its parameters when it is in the form of a string.
4
+ * This can be used to embed function strings into custom HTML elements.
5
+ * The Function MUST exist in the window object.
6
+ */
7
+ export function parseFunctionString(string: string): Function | undefined {
8
+ const match: RegExpMatchArray | null = string.match(/^(\w+)\((.*)\)$/); // Match "functionName(args)"
9
+ if (!match) {
10
+ throw new Error('Input does not match the expected pattern "functionName(args)".');
11
+ }
12
+ const funcName: string = match[1]; // Function name
13
+ const args: string = match[2]; // Arguments as a single string
14
+ const func = window[funcName as keyof Window];
15
+ if (typeof func !== 'function') {
16
+ throw new Error(`"${funcName}" is not a valid function.`);
17
+ }
18
+ const parsedArgs: string[] = args
19
+ .split(',')
20
+ .map(arg => arg.trim().replace(/^['"]|['"]$/g, '')) // Trim and remove quotes
21
+ .filter(arg => arg !== ''); // Remove empty strings from args
22
+ return () => func(...parsedArgs);
23
+ }
package/src/lib/regex.ts CHANGED
@@ -1,51 +1,51 @@
1
- /**
2
- * List of RegEx variables for different patterns.
3
- */
4
- export const regExAllLetter: RegExp = /^[a-zA-Z]+$/; // Matches strings containing only letters
5
- export const regExAnyLetter: RegExp = /[a-zA-Z]/g; // Finds/matches/replaces any letters in a string
6
- export const regExNotLetter: RegExp = /^[^a-zA-Z]+$/; // Matches strings containing no letters
7
- export const regExNonLetter: RegExp = /[^a-zA-Z]/g; // Finds/matches/replaces any non-letter characters in a string
8
- export const regExAllLowercase: RegExp = /^[a-z]+$/; // Matches strings containing only lowercase letters
9
- export const regExAnyLowercase: RegExp = /[a-z]/g; // Finds/matches/replaces any lowercase letters in a string
10
- export const regExNotLowercase: RegExp = /^[^a-z]+$/; // Matches strings containing no lowercase letters
11
- export const regExNonLowercase: RegExp = /[^a-z]/g; // Finds/matches/replaces any non-lowercase characters in a string
12
- export const regExAllUppercase: RegExp = /^[A-Z]+$/; // Matches strings containing only uppercase letters
13
- export const regExAnyUppercase: RegExp = /[A-Z]/g; // Finds/matches/replaces any uppercase letters in a string
14
- export const regExNotUppercase: RegExp = /^[^A-Z]+$/; // Matches strings containing no uppercase letters
15
- export const regExNonUppercase: RegExp = /[^A-Z]/g; // Finds/matches/replaces any non-uppercase characters in a string
16
- export const regExAllNumber: RegExp = /^[0-9]+$/; // Matches strings containing only numbers
17
- export const regExAnyNumber: RegExp = /[0-9]/g; // Finds/matches/replaces any numbers in a string
18
- export const regExNotNumber: RegExp = /^[^0-9]+$/; // Matches strings containing no numbers
19
- export const regExNonNumber: RegExp = /[^0-9]/g; // Finds/matches/replaces any non-number characters in a string
20
- export const regExAllBin: RegExp = /^[01]+$/; // Matches strings containing only binary characters
21
- export const regExAnyBin: RegExp = /[01]/g; // Finds/matches/replaces any binary characters in a string
22
- export const regExNotBin: RegExp = /^[^01]+$/; // Matches strings containing no binary characters
23
- export const regExNonBin: RegExp = /[^01]/g; // Finds/matches/replaces any non-binary characters in a string
24
- export const regExAllOct: RegExp = /^[0-7]+$/; // Matches strings containing only octal characters
25
- export const regExAnyOct: RegExp = /[0-7]/g; // Finds/matches/replaces any octal characters in a string
26
- export const regExNotOct: RegExp = /^[^0-7]+$/; // Matches strings containing no octal characters
27
- export const regExNonOct: RegExp = /[^0-7]/g; // Finds/matches/replaces any non-octal characters in a string
28
- export const regExAllHex: RegExp = /^[0-9A-Fa-f]+$/; // Matches strings containing only hexadecimal characters
29
- export const regExAnyHex: RegExp = /[0-9A-Fa-f]/g; // Finds/matches/replaces any hexadecimal characters in a string
30
- export const regExNotHex: RegExp = /^[^0-9A-Fa-f]+$/; // Matches strings containing no hexadecimal characters
31
- export const regExNonHex: RegExp = /[^0-9A-Fa-f]/g; // Finds/matches/replaces any non-hexadecimal characters in a string
32
- export const regExAnySpecial: RegExp = /[\!\@\#\$\%\^\&\*\(\)\_\+\-\=\[\]\{\}\|\;\:\'\"\,\.\<\>\/\?\`\\\~]/g; // Finds/matches/replaces any special characters in a string
33
- export const regExNotSpecial: RegExp = /^[^\!\@\#\$\%\^\&\*\(\)\_\+\-\=\[\]\{\}\|\;\:\'\"\,\.\<\>\/\?\`\\\~]+$/; // Matches strings containing no special characters
34
- export const regExFqdn: RegExp = /^(?=.{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,}))$/; // Matches valid FQDNs (Fully Qualified Domain Names)
35
- export const regExUrl = new RegExp( // Matches valid URLs (HTTP/HTTPS)
36
- '^(https?:\\/\\/)?' + // protocol
37
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
38
- '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
39
- '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
40
- '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
41
- '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
42
- export const regExEmail: RegExp = /^[\w-\.]+@([\w-]+\.)+[a-zA-Z]{2,}$/; // Matches valid email addresses
43
- export const regExIpv4: RegExp = /^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$/; // Matches valid IPv4 addresses
44
- export const regExIpv6: RegExp = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/; // Matches valid IPv6 addresses
45
- export const regExMacNoSeparator: RegExp = /^[0-9a-fA-F]{12}$/; // Matches valid MAC addresses with no separators (e.g., "001A2B3C4D5E")
46
- export const regExMacHyphenPairs: RegExp = /^[0-9a-fA-F]{2}(-[0-9a-fA-F]{2}){5}$/; // Matches valid MAC addresses with hyphen separators in pairs (e.g., "00-1A-2B-3C-4D-5E")
47
- export const regExMacHyphenQuads: RegExp = /^[0-9a-fA-F]{4}(-[0-9a-fA-F]{4}){2}$/; // Matches valid MAC addresses with hyphen separators in quads (e.g., "001A-2B3C-4D5E")
48
- export const regExMacDotPairs: RegExp = /^[0-9a-fA-F]{2}(\.[0-9a-fA-F]{2}){5}$/; // Matches valid MAC addresses with dot separators in pairs (e.g., "00.1A.2B.3C.4D.5E")
49
- export const regExMacDotQuads: RegExp = /^[0-9a-fA-F]{4}(\.[0-9a-fA-F]{4}){2}$/; // Matches valid MAC addresses with dot separators in quads (e.g., "001A.2B3C.4D5E")
50
- export const regExMacColonPairs: RegExp = /^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$/; // Matches valid MAC addresses with colon separators in pairs (e.g., "00:1A:2B:3C:4D:5E")
51
- export const regExMacColonQuads: RegExp = /^[0-9a-fA-F]{4}(:[0-9a-fA-F]{4}){2}$/; // Matches valid MAC addresses with colon separators in quads (e.g., "001A:2B3C:4D5E")
1
+ /**
2
+ * List of RegEx variables for different patterns.
3
+ */
4
+ export const regExAllLetter: RegExp = /^[a-zA-Z]+$/; // Matches strings containing only letters
5
+ export const regExAnyLetter: RegExp = /[a-zA-Z]/g; // Finds/matches/replaces any letters in a string
6
+ export const regExNotLetter: RegExp = /^[^a-zA-Z]+$/; // Matches strings containing no letters
7
+ export const regExNonLetter: RegExp = /[^a-zA-Z]/g; // Finds/matches/replaces any non-letter characters in a string
8
+ export const regExAllLowercase: RegExp = /^[a-z]+$/; // Matches strings containing only lowercase letters
9
+ export const regExAnyLowercase: RegExp = /[a-z]/g; // Finds/matches/replaces any lowercase letters in a string
10
+ export const regExNotLowercase: RegExp = /^[^a-z]+$/; // Matches strings containing no lowercase letters
11
+ export const regExNonLowercase: RegExp = /[^a-z]/g; // Finds/matches/replaces any non-lowercase characters in a string
12
+ export const regExAllUppercase: RegExp = /^[A-Z]+$/; // Matches strings containing only uppercase letters
13
+ export const regExAnyUppercase: RegExp = /[A-Z]/g; // Finds/matches/replaces any uppercase letters in a string
14
+ export const regExNotUppercase: RegExp = /^[^A-Z]+$/; // Matches strings containing no uppercase letters
15
+ export const regExNonUppercase: RegExp = /[^A-Z]/g; // Finds/matches/replaces any non-uppercase characters in a string
16
+ export const regExAllNumber: RegExp = /^[0-9]+$/; // Matches strings containing only numbers
17
+ export const regExAnyNumber: RegExp = /[0-9]/g; // Finds/matches/replaces any numbers in a string
18
+ export const regExNotNumber: RegExp = /^[^0-9]+$/; // Matches strings containing no numbers
19
+ export const regExNonNumber: RegExp = /[^0-9]/g; // Finds/matches/replaces any non-number characters in a string
20
+ export const regExAllBin: RegExp = /^[01]+$/; // Matches strings containing only binary characters
21
+ export const regExAnyBin: RegExp = /[01]/g; // Finds/matches/replaces any binary characters in a string
22
+ export const regExNotBin: RegExp = /^[^01]+$/; // Matches strings containing no binary characters
23
+ export const regExNonBin: RegExp = /[^01]/g; // Finds/matches/replaces any non-binary characters in a string
24
+ export const regExAllOct: RegExp = /^[0-7]+$/; // Matches strings containing only octal characters
25
+ export const regExAnyOct: RegExp = /[0-7]/g; // Finds/matches/replaces any octal characters in a string
26
+ export const regExNotOct: RegExp = /^[^0-7]+$/; // Matches strings containing no octal characters
27
+ export const regExNonOct: RegExp = /[^0-7]/g; // Finds/matches/replaces any non-octal characters in a string
28
+ export const regExAllHex: RegExp = /^[0-9A-Fa-f]+$/; // Matches strings containing only hexadecimal characters
29
+ export const regExAnyHex: RegExp = /[0-9A-Fa-f]/g; // Finds/matches/replaces any hexadecimal characters in a string
30
+ export const regExNotHex: RegExp = /^[^0-9A-Fa-f]+$/; // Matches strings containing no hexadecimal characters
31
+ export const regExNonHex: RegExp = /[^0-9A-Fa-f]/g; // Finds/matches/replaces any non-hexadecimal characters in a string
32
+ export const regExAnySpecial: RegExp = /[\!\@\#\$\%\^\&\*\(\)\_\+\-\=\[\]\{\}\|\;\:\'\"\,\.\<\>\/\?\`\\\~]/g; // Finds/matches/replaces any special characters in a string
33
+ export const regExNotSpecial: RegExp = /^[^\!\@\#\$\%\^\&\*\(\)\_\+\-\=\[\]\{\}\|\;\:\'\"\,\.\<\>\/\?\`\\\~]+$/; // Matches strings containing no special characters
34
+ export const regExFqdn: RegExp = /^(?=.{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,}))$/; // Matches valid FQDNs (Fully Qualified Domain Names)
35
+ export const regExUrl = new RegExp( // Matches valid URLs (HTTP/HTTPS)
36
+ '^(https?:\\/\\/)?' + // protocol
37
+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
38
+ '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
39
+ '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
40
+ '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
41
+ '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
42
+ export const regExEmail: RegExp = /^[\w-\.]+@([\w-]+\.)+[a-zA-Z]{2,}$/; // Matches valid email addresses
43
+ export const regExIpv4: RegExp = /^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$/; // Matches valid IPv4 addresses
44
+ export const regExIpv6: RegExp = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/; // Matches valid IPv6 addresses
45
+ export const regExMacNoSeparator: RegExp = /^[0-9a-fA-F]{12}$/; // Matches valid MAC addresses with no separators (e.g., "001A2B3C4D5E")
46
+ export const regExMacHyphenPairs: RegExp = /^[0-9a-fA-F]{2}(-[0-9a-fA-F]{2}){5}$/; // Matches valid MAC addresses with hyphen separators in pairs (e.g., "00-1A-2B-3C-4D-5E")
47
+ export const regExMacHyphenQuads: RegExp = /^[0-9a-fA-F]{4}(-[0-9a-fA-F]{4}){2}$/; // Matches valid MAC addresses with hyphen separators in quads (e.g., "001A-2B3C-4D5E")
48
+ export const regExMacDotPairs: RegExp = /^[0-9a-fA-F]{2}(\.[0-9a-fA-F]{2}){5}$/; // Matches valid MAC addresses with dot separators in pairs (e.g., "00.1A.2B.3C.4D.5E")
49
+ export const regExMacDotQuads: RegExp = /^[0-9a-fA-F]{4}(\.[0-9a-fA-F]{4}){2}$/; // Matches valid MAC addresses with dot separators in quads (e.g., "001A.2B3C.4D5E")
50
+ export const regExMacColonPairs: RegExp = /^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$/; // Matches valid MAC addresses with colon separators in pairs (e.g., "00:1A:2B:3C:4D:5E")
51
+ export const regExMacColonQuads: RegExp = /^[0-9a-fA-F]{4}(:[0-9a-fA-F]{4}){2}$/; // Matches valid MAC addresses with colon separators in quads (e.g., "001A:2B3C:4D5E")
package/tsconfig.json CHANGED
@@ -1,20 +1,20 @@
1
- {
2
- "compilerOptions": {
3
- "rootDir": "./src",
4
- "outDir": "./dist",
5
- "module": "ES2022",
6
- "target": "ES2020",
7
- "lib": ["ES2020", "DOM"],
8
- "moduleResolution": "node",
9
- "declaration": true,
10
- "declarationMap": true,
11
- "sourceMap": true,
12
- "strict": true,
13
- "esModuleInterop": true,
14
- "allowSyntheticDefaultImports": true,
15
- "forceConsistentCasingInFileNames": true,
16
- "skipLibCheck": true
17
- },
18
- "include": ["src/**/*"],
19
- "exclude": ["node_modules", "dist"]
20
- }
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "./src",
4
+ "outDir": "./dist",
5
+ "module": "ES2022",
6
+ "target": "ES2020",
7
+ "lib": ["ES2020", "DOM"],
8
+ "moduleResolution": "bundler",
9
+ "declaration": true,
10
+ "declarationMap": true,
11
+ "sourceMap": true,
12
+ "strict": true,
13
+ "esModuleInterop": true,
14
+ "allowSyntheticDefaultImports": true,
15
+ "forceConsistentCasingInFileNames": true,
16
+ "skipLibCheck": true
17
+ },
18
+ "include": ["src/**/*"],
19
+ "exclude": ["node_modules", "dist"]
20
+ }