string-extn 1.0.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.
@@ -0,0 +1,63 @@
1
+ import GraphemeSplitter from 'grapheme-splitter';
2
+ const splitter = new GraphemeSplitter();
3
+ /**
4
+ * Counts the number of grapheme clusters (user-perceived characters) in a Unicode string.
5
+ *
6
+ * This function properly handles complex Unicode characters including:
7
+ * - Emoji with skin tone modifiers (e.g., πŸ‘πŸ½)
8
+ * - Multi-codepoint emoji sequences (e.g., family emoji πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦)
9
+ * - Flag emoji (e.g., πŸ‡ΊπŸ‡Έ)
10
+ * - Accented characters and combining marks
11
+ *
12
+ * @param str - The Unicode string to count.
13
+ * @returns The number of grapheme clusters in the string.
14
+ *
15
+ * @example
16
+ * lengthUnicode('hello') // => 5
17
+ * lengthUnicode('πŸ‘πŸ½πŸ‘') // => 2 (skin tone modifier counted as part of first emoji)
18
+ * lengthUnicode('πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦') // => 1 (complex emoji sequence counted as single grapheme)
19
+ */
20
+ export function lengthUnicode(str) {
21
+ return splitter.countGraphemes(str);
22
+ }
23
+ /**
24
+ * Extracts a section of a Unicode string by grapheme cluster indices.
25
+ *
26
+ * This function correctly slices strings containing complex Unicode characters where
27
+ * multiple codepoints form a single user-perceived character. Use this instead of
28
+ * {@link slice} for proper Unicode-aware slicing.
29
+ *
30
+ * @param str - The Unicode string to slice.
31
+ * @param start - The starting grapheme cluster index (inclusive). Negative indices count from the end.
32
+ * @param end - The ending grapheme cluster index (exclusive). Negative indices count from the end. Optional.
33
+ * @returns A new string containing the extracted grapheme clusters.
34
+ *
35
+ * @example
36
+ * unicodeSlice('hello', 1, 4) // => 'ell'
37
+ * unicodeSlice('πŸ‘πŸ½πŸ‘πŸ˜€', 0, 2) // => 'πŸ‘πŸ½πŸ‘' (correctly handles skin tone modifier)
38
+ * unicodeSlice('πŸ˜€πŸ˜πŸ˜‚', 1) // => 'πŸ˜πŸ˜‚'
39
+ */
40
+ export function unicodeSlice(str, start, end) {
41
+ const chars = splitter.splitGraphemes(str);
42
+ return chars.slice(start, end).join('');
43
+ }
44
+ /**
45
+ * Reverses the order of grapheme clusters in a Unicode string.
46
+ *
47
+ * This function properly reverses strings containing complex Unicode characters where
48
+ * multiple codepoints form a single user-perceived character. It maintains the integrity
49
+ * of multi-codepoint emoji and other complex grapheme clusters. Use this instead of
50
+ * {@link reverse} for Unicode-aware reversal.
51
+ *
52
+ * @param str - The Unicode string to reverse.
53
+ * @returns A new string with grapheme clusters in reverse order.
54
+ *
55
+ * @example
56
+ * reverseUnicode('hello') // => 'olleh'
57
+ * reverseUnicode('πŸ‘πŸ½πŸ‘') // => 'πŸ‘πŸ‘πŸ½' (preserves emoji integrity)
58
+ * reverseUnicode('πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦πŸ˜€') // => 'πŸ˜€πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦' (maintains complex emoji as single unit)
59
+ */
60
+ export function reverseUnicode(str) {
61
+ return splitter.splitGraphemes(str).reverse().join('');
62
+ }
63
+ //# sourceMappingURL=unicode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unicode.js","sourceRoot":"","sources":["../src/unicode.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,mBAAmB,CAAC;AAEjD,MAAM,QAAQ,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,OAAO,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,KAAa,EAAE,GAAY;IACnE,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IAC3C,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,OAAO,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzD,CAAC"}
@@ -0,0 +1,264 @@
1
+ /**
2
+ * Validates if a string is a valid email address format.
3
+ *
4
+ * @param input - The string to validate
5
+ * @returns true if the string is a valid email format, false otherwise
6
+ *
7
+ * @example
8
+ * isEmail("user@example.com") // returns true
9
+ * isEmail("invalid.email") // returns false
10
+ * isEmail("user@domain") // returns false
11
+ */
12
+ export declare function isEmail(input: string): boolean;
13
+ /**
14
+ * Validates if a string is a valid UUID (Universally Unique Identifier).
15
+ *
16
+ * @param input - The string to validate
17
+ * @returns true if the string matches UUID format (v1-v5), false otherwise
18
+ *
19
+ * @example
20
+ * isUUID("550e8400-e29b-41d4-a716-446655440000") // returns true
21
+ * isUUID("invalid-uuid") // returns false
22
+ *
23
+ * @note Supports UUID versions 1 through 5 with RFC 4122 compliance
24
+ */
25
+ export declare function isUUID(input: string): boolean;
26
+ /**
27
+ * Validates if a string can be converted to a valid number.
28
+ *
29
+ * @param input - The string to validate
30
+ * @returns true if the string represents a valid number, false otherwise
31
+ *
32
+ * @example
33
+ * isNumeric("123") // returns true
34
+ * isNumeric("3.14") // returns true
35
+ * isNumeric("-42") // returns true
36
+ * isNumeric("abc") // returns false
37
+ */
38
+ export declare function isNumeric(input: string): boolean;
39
+ /**
40
+ * Validates if a string is a valid URL using the URL constructor.
41
+ *
42
+ * @param input - The string to validate
43
+ * @returns true if the string is a valid URL, false otherwise
44
+ *
45
+ * @example
46
+ * isURL("https://example.com") // returns true
47
+ * isURL("https://example.com/path?query=value") // returns true
48
+ * isURL("not a url") // returns false
49
+ *
50
+ * @note Uses native URL API for validation, supporting absolute and relative URLs
51
+ */
52
+ export declare function isURL(input: string): boolean;
53
+ /**
54
+ * Validates if a string is a valid hexadecimal color code.
55
+ *
56
+ * @param input - The string to validate
57
+ * @returns true if the string is a valid 3-digit or 6-digit hex color, false otherwise
58
+ *
59
+ * @example
60
+ * isHexColor("#fff") // returns true
61
+ * isHexColor("#ffffff") // returns true
62
+ * isHexColor("fff") // returns true (# is optional)
63
+ * isHexColor("#gggggg") // returns false
64
+ */
65
+ export declare function isHexColor(input: string): boolean;
66
+ /**
67
+ * Validates if a string is a valid phone number in E.164 format.
68
+ *
69
+ * @param input - The string to validate
70
+ * @returns true if the string matches E.164 phone number format, false otherwise
71
+ *
72
+ * @example
73
+ * isPhoneNumber("+14155552671") // returns true
74
+ * isPhoneNumber("14155552671") // returns true (+ is optional)
75
+ * isPhoneNumber("415 555 2671") // returns false (spaces not allowed)
76
+ *
77
+ * @note Follows E.164 format: optional + followed by 1-15 digits, first digit must be 1-9
78
+ */
79
+ export declare function isPhoneNumber(input: string): boolean;
80
+ /**
81
+ * Validates if a string can be parsed as a valid date.
82
+ *
83
+ * @param input - The string to validate
84
+ * @returns true if the string represents a valid date, false otherwise
85
+ *
86
+ * @example
87
+ * isDate("2024-01-27") // returns true
88
+ * isDate("January 27, 2024") // returns true
89
+ * isDate("2024-13-45") // returns false (invalid date)
90
+ *
91
+ * @note Uses the native Date.parse() method for validation
92
+ */
93
+ export declare function isDate(input: string): boolean;
94
+ /**
95
+ * Validates if a string is a strong password meeting security requirements.
96
+ *
97
+ * @param input - The string to validate
98
+ * @returns true if the password is strong, false otherwise
99
+ *
100
+ * @example
101
+ * isStrongPassword("MyPassword123!") // returns true
102
+ * isStrongPassword("weak") // returns false
103
+ * isStrongPassword("NoSpecialChar123") // returns false
104
+ *
105
+ * @note Requires: minimum 8 characters, at least one lowercase letter, one uppercase letter,
106
+ * one digit, and one special character (@$!%*?&)
107
+ */
108
+ export declare function isStrongPassword(input: string): boolean;
109
+ /**
110
+ * Validates if a string is valid JSON.
111
+ *
112
+ * @param input - The string to validate
113
+ * @returns true if the string is valid JSON, false otherwise
114
+ *
115
+ * @example
116
+ * isJSON('{\"key\": \"value\"}') // returns true
117
+ * isJSON('[1, 2, 3]') // returns true
118
+ * isJSON('invalid json') // returns false
119
+ *
120
+ * @note Uses native JSON.parse() for validation
121
+ */
122
+ export declare function isJSON(input: string): boolean;
123
+ /**
124
+ * Validates if a string is valid Base64 encoded data.
125
+ *
126
+ * @param input - The string to validate
127
+ * @returns true if the string is valid Base64 format, false otherwise
128
+ *
129
+ * @example
130
+ * isBase64("SGVsbG8gV29ybGQ=") // returns true
131
+ * isBase64("SGVsbG8gV29ybGQ") // returns true
132
+ * isBase64("!!!Invalid!!!") // returns false
133
+ */
134
+ export declare function isBase64(input: string): boolean;
135
+ /**
136
+ * Validates if a string contains only alphabetic characters (no numbers or special characters).
137
+ *
138
+ * @param input - The string to validate
139
+ * @returns true if the string contains only letters, false otherwise
140
+ *
141
+ * @example
142
+ * isAlphabetic("HelloWorld") // returns true
143
+ * isAlphabetic("Hello World") // returns false (contains space)
144
+ * isAlphabetic("Hello123") // returns false (contains numbers)
145
+ */
146
+ export declare function isAlphabetic(input: string): boolean;
147
+ /**
148
+ * Validates if a string contains only alphanumeric characters (letters and digits).
149
+ *
150
+ * @param input - The string to validate
151
+ * @returns true if the string contains only letters and numbers, false otherwise
152
+ *
153
+ * @example
154
+ * isAlphanumeric("Hello123") // returns true
155
+ * isAlphanumeric("Hello-123") // returns false (contains hyphen)
156
+ * isAlphanumeric("Hello 123") // returns false (contains space)
157
+ */
158
+ export declare function isAlphanumeric(input: string): boolean;
159
+ /**
160
+ * Validates if a string contains only lowercase alphabetic characters.
161
+ *
162
+ * @param input - The string to validate
163
+ * @returns true if the string contains only lowercase letters, false otherwise
164
+ *
165
+ * @example
166
+ * isLowerCase("hello") // returns true
167
+ * isLowerCase("Hello") // returns false (contains uppercase)
168
+ * isLowerCase("hello123") // returns false (contains numbers)
169
+ */
170
+ export declare function isLowerCase(input: string): boolean;
171
+ /**
172
+ * Validates if a string contains only uppercase alphabetic characters.
173
+ *
174
+ * @param input - The string to validate
175
+ * @returns true if the string contains only uppercase letters, false otherwise
176
+ *
177
+ * @example
178
+ * isUpperCase("HELLO") // returns true
179
+ * isUpperCase("Hello") // returns false (contains lowercase)
180
+ * isUpperCase("HELLO123") // returns false (contains numbers)
181
+ */
182
+ export declare function isUpperCase(input: string): boolean;
183
+ /**
184
+ * Validates if a string contains only whitespace characters (spaces, tabs, newlines, etc.).
185
+ *
186
+ * @param input - The string to validate
187
+ * @returns true if the string contains only whitespace, false otherwise
188
+ *
189
+ * @example
190
+ * isWhitespace(" ") // returns true
191
+ * isWhitespace("\t\n") // returns true
192
+ * isWhitespace(" a ") // returns false (contains non-whitespace)
193
+ */
194
+ export declare function isWhitespace(input: string): boolean;
195
+ /**
196
+ * Validates if a string is a palindrome (reads the same forwards and backwards).
197
+ *
198
+ * @param input - The string to validate
199
+ * @returns true if the string is a palindrome, false otherwise
200
+ *
201
+ * @example
202
+ * isPalindrome("racecar") // returns true
203
+ * isPalindrome("A man, a plan, a canal: Panama") // returns true (ignores punctuation and case)
204
+ * isPalindrome("hello") // returns false
205
+ *
206
+ * @note Case-insensitive and ignores non-alphanumeric characters
207
+ */
208
+ export declare function isPalindrome(input: string): boolean;
209
+ /**
210
+ * Validates if a string contains only hexadecimal characters (0-9, A-F).
211
+ *
212
+ * @param input - The string to validate
213
+ * @returns true if the string is valid hexadecimal, false otherwise
214
+ *
215
+ * @example
216
+ * isHexadecimal("1A2B3C") // returns true
217
+ * isHexadecimal("DEADBEEF") // returns true
218
+ * isHexadecimal("12XYZ") // returns false (contains invalid characters)
219
+ */
220
+ export declare function isHexadecimal(input: string): boolean;
221
+ /**
222
+ * Validates if a string is a valid Roman numeral.
223
+ *
224
+ * @param input - The string to validate
225
+ * @returns true if the string is a valid Roman numeral, false otherwise
226
+ *
227
+ * @example
228
+ * isRomanNumeral("XIV") // returns true
229
+ * isRomanNumeral("MCMXCIV") // returns true
230
+ * isRomanNumeral("IIII") // returns false (should be IV)
231
+ *
232
+ * @note Validates standard Roman numeral notation (I, V, X, L, C, D, M)
233
+ */
234
+ export declare function isRomanNumeral(input: string): boolean;
235
+ /**
236
+ * Validates if a string is a valid IPv4 address.
237
+ *
238
+ * @param input - The string to validate
239
+ * @returns true if the string is a valid IPv4 address, false otherwise
240
+ *
241
+ * @example
242
+ * isIPv4("192.168.1.1") // returns true
243
+ * isIPv4("255.255.255.255") // returns true
244
+ * isIPv4("256.1.1.1") // returns false (256 exceeds maximum)
245
+ *
246
+ * @note Validates standard IPv4 dotted-decimal notation (0.0.0.0 to 255.255.255.255)
247
+ */
248
+ export declare function isIPv4(input: string): boolean;
249
+ /**
250
+ * Validates if a string is a valid IPv6 address.
251
+ *
252
+ * @param input - The string to validate
253
+ * @returns true if the string is a valid IPv6 address, false otherwise
254
+ *
255
+ * @example
256
+ * isIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334") // returns true
257
+ * isIPv6("::1") // returns true (loopback)
258
+ * isIPv6("::ffff:192.168.1.1") // returns true (IPv4-mapped)
259
+ * isIPv6("invalid") // returns false
260
+ *
261
+ * @note Supports full notation, compressed notation, and IPv4-mapped IPv6 addresses
262
+ */
263
+ export declare function isIPv6(input: string): boolean;
264
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE9C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAI7C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEhD;AACD;;;;;;;;;;;;GAYG;AAC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AAM,GAAG,OAAO,CAIrD;AACD;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7C;AACD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7C"}
@@ -0,0 +1,326 @@
1
+ import { isIP } from 'net';
2
+ /**
3
+ * Validates if a string is a valid email address format.
4
+ *
5
+ * @param input - The string to validate
6
+ * @returns true if the string is a valid email format, false otherwise
7
+ *
8
+ * @example
9
+ * isEmail("user@example.com") // returns true
10
+ * isEmail("invalid.email") // returns false
11
+ * isEmail("user@domain") // returns false
12
+ */
13
+ export function isEmail(input) {
14
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(input);
15
+ }
16
+ /**
17
+ * Validates if a string is a valid UUID (Universally Unique Identifier).
18
+ *
19
+ * @param input - The string to validate
20
+ * @returns true if the string matches UUID format (v1-v5), false otherwise
21
+ *
22
+ * @example
23
+ * isUUID("550e8400-e29b-41d4-a716-446655440000") // returns true
24
+ * isUUID("invalid-uuid") // returns false
25
+ *
26
+ * @note Supports UUID versions 1 through 5 with RFC 4122 compliance
27
+ */
28
+ export function isUUID(input) {
29
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(input);
30
+ }
31
+ /**
32
+ * Validates if a string can be converted to a valid number.
33
+ *
34
+ * @param input - The string to validate
35
+ * @returns true if the string represents a valid number, false otherwise
36
+ *
37
+ * @example
38
+ * isNumeric("123") // returns true
39
+ * isNumeric("3.14") // returns true
40
+ * isNumeric("-42") // returns true
41
+ * isNumeric("abc") // returns false
42
+ */
43
+ export function isNumeric(input) {
44
+ return !isNaN(Number(input));
45
+ }
46
+ /**
47
+ * Validates if a string is a valid URL using the URL constructor.
48
+ *
49
+ * @param input - The string to validate
50
+ * @returns true if the string is a valid URL, false otherwise
51
+ *
52
+ * @example
53
+ * isURL("https://example.com") // returns true
54
+ * isURL("https://example.com/path?query=value") // returns true
55
+ * isURL("not a url") // returns false
56
+ *
57
+ * @note Uses native URL API for validation, supporting absolute and relative URLs
58
+ */
59
+ export function isURL(input) {
60
+ try {
61
+ new URL(input);
62
+ return true;
63
+ }
64
+ catch {
65
+ return false;
66
+ }
67
+ }
68
+ /**
69
+ * Validates if a string is a valid hexadecimal color code.
70
+ *
71
+ * @param input - The string to validate
72
+ * @returns true if the string is a valid 3-digit or 6-digit hex color, false otherwise
73
+ *
74
+ * @example
75
+ * isHexColor("#fff") // returns true
76
+ * isHexColor("#ffffff") // returns true
77
+ * isHexColor("fff") // returns true (# is optional)
78
+ * isHexColor("#gggggg") // returns false
79
+ */
80
+ export function isHexColor(input) {
81
+ return /^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(input);
82
+ }
83
+ /**
84
+ * Validates if a string is a valid phone number in E.164 format.
85
+ *
86
+ * @param input - The string to validate
87
+ * @returns true if the string matches E.164 phone number format, false otherwise
88
+ *
89
+ * @example
90
+ * isPhoneNumber("+14155552671") // returns true
91
+ * isPhoneNumber("14155552671") // returns true (+ is optional)
92
+ * isPhoneNumber("415 555 2671") // returns false (spaces not allowed)
93
+ *
94
+ * @note Follows E.164 format: optional + followed by 1-15 digits, first digit must be 1-9
95
+ */
96
+ export function isPhoneNumber(input) {
97
+ // Require at least 4 digits (total) to avoid overly short numeric strings
98
+ return /^\+?[1-9]\d{3,14}$/.test(input);
99
+ }
100
+ /**
101
+ * Validates if a string can be parsed as a valid date.
102
+ *
103
+ * @param input - The string to validate
104
+ * @returns true if the string represents a valid date, false otherwise
105
+ *
106
+ * @example
107
+ * isDate("2024-01-27") // returns true
108
+ * isDate("January 27, 2024") // returns true
109
+ * isDate("2024-13-45") // returns false (invalid date)
110
+ *
111
+ * @note Uses the native Date.parse() method for validation
112
+ */
113
+ export function isDate(input) {
114
+ return !isNaN(Date.parse(input));
115
+ }
116
+ /**
117
+ * Validates if a string is a strong password meeting security requirements.
118
+ *
119
+ * @param input - The string to validate
120
+ * @returns true if the password is strong, false otherwise
121
+ *
122
+ * @example
123
+ * isStrongPassword("MyPassword123!") // returns true
124
+ * isStrongPassword("weak") // returns false
125
+ * isStrongPassword("NoSpecialChar123") // returns false
126
+ *
127
+ * @note Requires: minimum 8 characters, at least one lowercase letter, one uppercase letter,
128
+ * one digit, and one special character (@$!%*?&)
129
+ */
130
+ export function isStrongPassword(input) {
131
+ return /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/.test(input);
132
+ }
133
+ /**
134
+ * Validates if a string is valid JSON.
135
+ *
136
+ * @param input - The string to validate
137
+ * @returns true if the string is valid JSON, false otherwise
138
+ *
139
+ * @example
140
+ * isJSON('{\"key\": \"value\"}') // returns true
141
+ * isJSON('[1, 2, 3]') // returns true
142
+ * isJSON('invalid json') // returns false
143
+ *
144
+ * @note Uses native JSON.parse() for validation
145
+ */
146
+ export function isJSON(input) {
147
+ try {
148
+ JSON.parse(input);
149
+ return true;
150
+ }
151
+ catch {
152
+ return false;
153
+ }
154
+ }
155
+ /**
156
+ * Validates if a string is valid Base64 encoded data.
157
+ *
158
+ * @param input - The string to validate
159
+ * @returns true if the string is valid Base64 format, false otherwise
160
+ *
161
+ * @example
162
+ * isBase64("SGVsbG8gV29ybGQ=") // returns true
163
+ * isBase64("SGVsbG8gV29ybGQ") // returns true
164
+ * isBase64("!!!Invalid!!!") // returns false
165
+ */
166
+ export function isBase64(input) {
167
+ // Empty string considered valid by tests
168
+ if (input === "")
169
+ return true;
170
+ // Accept Base64 with or without padding; disallow invalid characters
171
+ if (!/^[A-Za-z0-9+/]+=*$/.test(input))
172
+ return false;
173
+ // invalid if length mod 4 === 1
174
+ return input.length % 4 !== 1;
175
+ }
176
+ /**
177
+ * Validates if a string contains only alphabetic characters (no numbers or special characters).
178
+ *
179
+ * @param input - The string to validate
180
+ * @returns true if the string contains only letters, false otherwise
181
+ *
182
+ * @example
183
+ * isAlphabetic("HelloWorld") // returns true
184
+ * isAlphabetic("Hello World") // returns false (contains space)
185
+ * isAlphabetic("Hello123") // returns false (contains numbers)
186
+ */
187
+ export function isAlphabetic(input) {
188
+ return /^[A-Za-z]+$/.test(input);
189
+ }
190
+ /**
191
+ * Validates if a string contains only alphanumeric characters (letters and digits).
192
+ *
193
+ * @param input - The string to validate
194
+ * @returns true if the string contains only letters and numbers, false otherwise
195
+ *
196
+ * @example
197
+ * isAlphanumeric("Hello123") // returns true
198
+ * isAlphanumeric("Hello-123") // returns false (contains hyphen)
199
+ * isAlphanumeric("Hello 123") // returns false (contains space)
200
+ */
201
+ export function isAlphanumeric(input) {
202
+ return /^[A-Za-z0-9]+$/.test(input);
203
+ }
204
+ /**
205
+ * Validates if a string contains only lowercase alphabetic characters.
206
+ *
207
+ * @param input - The string to validate
208
+ * @returns true if the string contains only lowercase letters, false otherwise
209
+ *
210
+ * @example
211
+ * isLowerCase("hello") // returns true
212
+ * isLowerCase("Hello") // returns false (contains uppercase)
213
+ * isLowerCase("hello123") // returns false (contains numbers)
214
+ */
215
+ export function isLowerCase(input) {
216
+ return /^[a-z]+$/.test(input);
217
+ }
218
+ /**
219
+ * Validates if a string contains only uppercase alphabetic characters.
220
+ *
221
+ * @param input - The string to validate
222
+ * @returns true if the string contains only uppercase letters, false otherwise
223
+ *
224
+ * @example
225
+ * isUpperCase("HELLO") // returns true
226
+ * isUpperCase("Hello") // returns false (contains lowercase)
227
+ * isUpperCase("HELLO123") // returns false (contains numbers)
228
+ */
229
+ export function isUpperCase(input) {
230
+ return /^[A-Z]+$/.test(input);
231
+ }
232
+ /**
233
+ * Validates if a string contains only whitespace characters (spaces, tabs, newlines, etc.).
234
+ *
235
+ * @param input - The string to validate
236
+ * @returns true if the string contains only whitespace, false otherwise
237
+ *
238
+ * @example
239
+ * isWhitespace(" ") // returns true
240
+ * isWhitespace("\t\n") // returns true
241
+ * isWhitespace(" a ") // returns false (contains non-whitespace)
242
+ */
243
+ export function isWhitespace(input) {
244
+ return /^\s+$/.test(input);
245
+ }
246
+ /**
247
+ * Validates if a string is a palindrome (reads the same forwards and backwards).
248
+ *
249
+ * @param input - The string to validate
250
+ * @returns true if the string is a palindrome, false otherwise
251
+ *
252
+ * @example
253
+ * isPalindrome("racecar") // returns true
254
+ * isPalindrome("A man, a plan, a canal: Panama") // returns true (ignores punctuation and case)
255
+ * isPalindrome("hello") // returns false
256
+ *
257
+ * @note Case-insensitive and ignores non-alphanumeric characters
258
+ */
259
+ export function isPalindrome(input) {
260
+ const cleaned = input.replace(/[\W_]/g, "").toLowerCase();
261
+ return cleaned === cleaned.split("").reverse().join("");
262
+ }
263
+ /**
264
+ * Validates if a string contains only hexadecimal characters (0-9, A-F).
265
+ *
266
+ * @param input - The string to validate
267
+ * @returns true if the string is valid hexadecimal, false otherwise
268
+ *
269
+ * @example
270
+ * isHexadecimal("1A2B3C") // returns true
271
+ * isHexadecimal("DEADBEEF") // returns true
272
+ * isHexadecimal("12XYZ") // returns false (contains invalid characters)
273
+ */
274
+ export function isHexadecimal(input) {
275
+ return /^[0-9A-Fa-f]+$/.test(input);
276
+ }
277
+ /**
278
+ * Validates if a string is a valid Roman numeral.
279
+ *
280
+ * @param input - The string to validate
281
+ * @returns true if the string is a valid Roman numeral, false otherwise
282
+ *
283
+ * @example
284
+ * isRomanNumeral("XIV") // returns true
285
+ * isRomanNumeral("MCMXCIV") // returns true
286
+ * isRomanNumeral("IIII") // returns false (should be IV)
287
+ *
288
+ * @note Validates standard Roman numeral notation (I, V, X, L, C, D, M)
289
+ */
290
+ export function isRomanNumeral(input) {
291
+ return /^(M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$)/i.test(input);
292
+ }
293
+ /**
294
+ * Validates if a string is a valid IPv4 address.
295
+ *
296
+ * @param input - The string to validate
297
+ * @returns true if the string is a valid IPv4 address, false otherwise
298
+ *
299
+ * @example
300
+ * isIPv4("192.168.1.1") // returns true
301
+ * isIPv4("255.255.255.255") // returns true
302
+ * isIPv4("256.1.1.1") // returns false (256 exceeds maximum)
303
+ *
304
+ * @note Validates standard IPv4 dotted-decimal notation (0.0.0.0 to 255.255.255.255)
305
+ */
306
+ export function isIPv4(input) {
307
+ return isIP(input) === 4;
308
+ }
309
+ /**
310
+ * Validates if a string is a valid IPv6 address.
311
+ *
312
+ * @param input - The string to validate
313
+ * @returns true if the string is a valid IPv6 address, false otherwise
314
+ *
315
+ * @example
316
+ * isIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334") // returns true
317
+ * isIPv6("::1") // returns true (loopback)
318
+ * isIPv6("::ffff:192.168.1.1") // returns true (IPv4-mapped)
319
+ * isIPv6("invalid") // returns false
320
+ *
321
+ * @note Supports full notation, compressed notation, and IPv4-mapped IPv6 addresses
322
+ */
323
+ export function isIPv6(input) {
324
+ return isIP(input) === 6;
325
+ }
326
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAE3B;;;;;;;;;;GAUG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa;IACnC,OAAO,4BAA4B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,MAAM,CAAC,KAAa;IAClC,OAAO,4EAA4E,CAAC,IAAI,CACtF,KAAK,CACN,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/B,CAAC;AACD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa;IACjC,IAAI,CAAC;QACH,IAAI,GAAG,CAAC,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