@js-utils-kit/valid 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.
- package/LICENSE +21 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +494 -0
- package/dist/index.d.mts +494 -0
- package/dist/index.mjs +1 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sriman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e=require(`@js-utils-kit/types`);function t(e){return/[\p{P}]$/u.test(e)}function n(e){return/\s/.test(e)}function r(e){return/^[a-zA-Z]+$/.test(e)}function i(e){return e!=null}function a(e){return i(e)&&Array.isArray(e)}function o(){return typeof window<`u`&&window.document!==void 0}function s(e){return/^[a-z][a-zA-Z0-9]*$/.test(e)}function c(){return process.env.NODE_ENV===e.Environment.DEV}function l(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);if(e.length>254)return!1;let t=e.split(`@`);if(t.length!==2)return!1;let[n,r]=t;return n.length===0||n.length>64||r.length===0||r.length>255?!1:!(!/^[a-zA-Z0-9_%+-]+(\.[a-zA-Z0-9_%+-]+)*$/.test(n)||!/^(?!.*\.\.)(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.[A-Za-z0-9-]{1,63}(?<!-))*\.[A-Za-z]{2,}$/.test(r))}function u(e){return typeof e==`object`&&!!e&&Object.keys(e).length===0&&!a(e)}function d(e){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test(e)}function f(e){return/^[a-z]+$/.test(e)}function p(){return typeof process<`u`&&process.versions!==null&&process.versions.node!==null}function m(e){return typeof e==`object`&&!!e&&Object.keys(e).length>0&&!a(e)}function h(e){return e!=null&&typeof e==`string`}function g(e,t=!0){return h(e)?typeof e==`string`&&(t?e.trim().length>0:e.length>0):!1}function _(e){return!isNaN(Number(e))&&!isNaN(parseFloat(e))}function v(e){return i(e)&&typeof e==`object`&&!a(e)&&Object.getPrototypeOf(e)===Object.prototype}function y(e){return/^[A-Z][a-zA-Z0-9]*$/.test(e)}function b(){return process.env.NODE_ENV===e.Environment.PROD}function x(e){return/^[a-z0-9]+(_[a-z0-9]+)*$/.test(e)}function S(){return process.env.NODE_ENV===e.Environment.TEST}function C(e){return e==null}function w(e){return/^[A-Z]+$/.test(e)}function T(e){try{return new URL(e),!0}catch{return!1}}function E(e){return/^[A-Z]/.test(e)}exports.endsWithPunctuation=t,exports.hasWhitespace=n,exports.isAlphabetic=r,exports.isArray=a,exports.isBrowser=o,exports.isCamelCase=s,exports.isDefined=i,exports.isDev=c,exports.isEmail=l,exports.isEmptyObject=u,exports.isKebabCase=d,exports.isLowerCase=f,exports.isNode=p,exports.isNonEmptyObject=m,exports.isNonEmptyString=g,exports.isNumericString=_,exports.isObject=v,exports.isPascalCase=y,exports.isProd=b,exports.isSnakeCase=x,exports.isString=h,exports.isTest=S,exports.isURL=T,exports.isUndefinedOrNull=C,exports.isUpperCase=w,exports.startsWithUppercase=E,Object.keys(e).forEach(function(t){t!==`default`&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
export * from "@js-utils-kit/types";
|
|
2
|
+
|
|
3
|
+
//#region src/endsWithPunctuation.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a string ends with any Unicode punctuation character.
|
|
7
|
+
*
|
|
8
|
+
* @returns True if the string ends with a punctuation character.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* endsWithPunctuation("Hi!") // true
|
|
13
|
+
* endsWithPunctuation("Hello—") // true
|
|
14
|
+
* endsWithPunctuation("Okay") // false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function endsWithPunctuation(/** The string to check */
|
|
18
|
+
value: string): boolean;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/hasWhitespace.d.ts
|
|
21
|
+
/**
|
|
22
|
+
* Checks if a string contains any whitespace.
|
|
23
|
+
*
|
|
24
|
+
* @returns True if the string contains whitespace.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* hasWhitespace("Hello world") // true
|
|
29
|
+
* hasWhitespace("Nowordspace") // false
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function hasWhitespace(/** The string to check */
|
|
33
|
+
value: string): boolean;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/isAlphabetic.d.ts
|
|
36
|
+
/**
|
|
37
|
+
* Checks if a string contains only alphabetic characters (A–Z, a–z).
|
|
38
|
+
*
|
|
39
|
+
* @returns - `true` if the string contains only letters; otherwise, `false`.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* isAlphabetic("Hello"); // true
|
|
44
|
+
* isAlphabetic("world123"); // false
|
|
45
|
+
* isAlphabetic("Test!"); // false
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function isAlphabetic(/** The string to check */
|
|
49
|
+
value: string): boolean;
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/isArray.d.ts
|
|
52
|
+
/**
|
|
53
|
+
* Checks if a value is a defined array.
|
|
54
|
+
*
|
|
55
|
+
* @returns True if the value is a defined array, false otherwise.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* console.log(isArray([1, 2, 3])); // true
|
|
60
|
+
* console.log(isArray([])); // true
|
|
61
|
+
* console.log(isArray({})); // false
|
|
62
|
+
* console.log(isArray(null)); // false
|
|
63
|
+
* console.log(isArray(undefined)); // false
|
|
64
|
+
* console.log(isArray("hello")); // false
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function isArray<T>(/** The value to check */
|
|
68
|
+
value: T): boolean;
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/isBrowser.d.ts
|
|
71
|
+
/**
|
|
72
|
+
* Checks if the current runtime environment is a browser.
|
|
73
|
+
*
|
|
74
|
+
* This function helps detect whether code is executing in a web browser
|
|
75
|
+
* by confirming the existence of the global `window` and `document` objects.
|
|
76
|
+
*
|
|
77
|
+
* @returns `true` if running in a browser, otherwise `false`.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* if (isBrowser()) {
|
|
82
|
+
* console.log('Running in a browser environment');
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function isBrowser(): boolean;
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/isCamelCase.d.ts
|
|
89
|
+
/**
|
|
90
|
+
* Checks if a string is in camelCase format.
|
|
91
|
+
*
|
|
92
|
+
* @returns True if the string is camelCase.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* isCamelCase("helloWorld") // true
|
|
97
|
+
* isCamelCase("HelloWorld") // false
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
declare function isCamelCase(/** The input string */
|
|
101
|
+
value: string): boolean;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/isDefined.d.ts
|
|
104
|
+
/**
|
|
105
|
+
* Checks if a value is neither null nor undefined.
|
|
106
|
+
*
|
|
107
|
+
* @returns True if the value is defined (not null or undefined), false otherwise.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* isDefined(42); // true
|
|
112
|
+
* isDefined("hello"); // true
|
|
113
|
+
* isDefined(null); // false
|
|
114
|
+
* isDefined(undefined); // false
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
declare function isDefined<T>(/** The value to check */
|
|
118
|
+
value: T): boolean;
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/isDev.d.ts
|
|
121
|
+
/**
|
|
122
|
+
* Checks if the current environment is development.
|
|
123
|
+
*
|
|
124
|
+
* This is determined by comparing `process.env.NODE_ENV` with `'development'`.
|
|
125
|
+
*
|
|
126
|
+
* @returns `true` if `NODE_ENV` is set to development.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* if (isDev()) {
|
|
131
|
+
* console.log('Dev mode enabled');
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
declare function isDev(): boolean;
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/isEmail.d.ts
|
|
138
|
+
/**
|
|
139
|
+
* Checks whether a given string is a valid email address.
|
|
140
|
+
*
|
|
141
|
+
* @remarks
|
|
142
|
+
* This function uses a practical regular expression to validate email addresses,
|
|
143
|
+
* allowing most common formats while ignoring edge cases defined by full RFC 5322.
|
|
144
|
+
* It requires the presence of an `@` symbol and at least one `.` after it.
|
|
145
|
+
*
|
|
146
|
+
* **Limits enforced**:
|
|
147
|
+
* - Local part (before `@`): 1–64 characters
|
|
148
|
+
* - Domain part (after `@`): 1–255 characters
|
|
149
|
+
* - Total email length: ≤ 254 characters
|
|
150
|
+
*
|
|
151
|
+
*
|
|
152
|
+
* @throws {TypeError} Throws if value is not a string.
|
|
153
|
+
*
|
|
154
|
+
* @returns - `true` if the string is a valid email; otherwise, `false`.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* isEmail('user@example.com'); // true
|
|
159
|
+
* isEmail('first.last@college.university.in'); // true
|
|
160
|
+
* isEmail('invalid-email'); // false
|
|
161
|
+
* isEmail('name@domain'); // false
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function isEmail(/** The string to validate as an email address */
|
|
165
|
+
value: string): boolean;
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/isEmptyObject.d.ts
|
|
168
|
+
/**
|
|
169
|
+
* Checks if a value is an empty object (has no enumerable own properties).
|
|
170
|
+
*
|
|
171
|
+
* @returns True if the value is a non-null object with no enumerable own properties, false otherwise.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* isEmptyObject({}); // true
|
|
176
|
+
* isEmptyObject({ key: 'value' }); // false
|
|
177
|
+
* isEmptyObject(null); // false
|
|
178
|
+
* isEmptyObject([]); // false
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
declare function isEmptyObject(/** The value to check */
|
|
182
|
+
value: object): boolean;
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/isKebabCase.d.ts
|
|
185
|
+
/**
|
|
186
|
+
* Checks if a string is in kebab-case format.
|
|
187
|
+
*
|
|
188
|
+
* @returns True if the string is kebab-case.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* isKebabCase("hello-world") // true
|
|
193
|
+
* isKebabCase("hello_world") // false
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
declare function isKebabCase(/** The input string */
|
|
197
|
+
value: string): boolean;
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/isLowerCase.d.ts
|
|
200
|
+
/**
|
|
201
|
+
* Checks if a string contains only lowercase letters.
|
|
202
|
+
*
|
|
203
|
+
* @returns True if all letters are lowercase.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* isLowerCase("hello") // true
|
|
208
|
+
* isLowerCase("Hello") // false
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
declare function isLowerCase(/** The input string */
|
|
212
|
+
value: string): boolean;
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/isNode.d.ts
|
|
215
|
+
/**
|
|
216
|
+
* Checks if the current runtime environment is Node.js.
|
|
217
|
+
*
|
|
218
|
+
* This function is useful to conditionally execute server-side logic.
|
|
219
|
+
* It detects the Node.js environment by verifying the presence of the
|
|
220
|
+
* global `process` object and its `versions.node` property.
|
|
221
|
+
*
|
|
222
|
+
* @returns `true` if running in Node.js, otherwise `false`.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* if (isNode()) {
|
|
227
|
+
* console.log('Running in Node.js environment');
|
|
228
|
+
* }
|
|
229
|
+
* ```
|
|
230
|
+
*
|
|
231
|
+
* @see {@link https://nodejs.org/api/process.html | Node.js process documentation}
|
|
232
|
+
*/
|
|
233
|
+
declare function isNode(): boolean;
|
|
234
|
+
//#endregion
|
|
235
|
+
//#region src/isNonEmptyObject.d.ts
|
|
236
|
+
/**
|
|
237
|
+
* Checks if a value is a non-empty object (has at least one enumerable own property).
|
|
238
|
+
*
|
|
239
|
+
* @returns True if the value is a non-null object with at least one enumerable own property, false otherwise.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* isNonEmptyObject({ key: 'value' }); // true
|
|
244
|
+
* isNonEmptyObject({}); // false
|
|
245
|
+
* isNonEmptyObject(null); // false
|
|
246
|
+
* isNonEmptyObject([]); // false
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
declare function isNonEmptyObject(/** The value to check */
|
|
250
|
+
value: object): boolean;
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/isNonEmptyString.d.ts
|
|
253
|
+
/**
|
|
254
|
+
* Determines whether the given value is a non-empty string.
|
|
255
|
+
*
|
|
256
|
+
* This function first checks if the input is a string using {@link isString}.
|
|
257
|
+
* If it is not a string, the function returns `false`.
|
|
258
|
+
* If it is a string, it then checks whether the string contains any non-empty content.
|
|
259
|
+
*
|
|
260
|
+
* By default, the function trims the string before checking its length,
|
|
261
|
+
* which means strings containing only whitespace (e.g., `" "`) will be considered empty.
|
|
262
|
+
* This behavior can be controlled using the `trim` parameter.
|
|
263
|
+
*
|
|
264
|
+
* @template T - The type of the value being checked.
|
|
265
|
+
*
|
|
266
|
+
* @returns - A boolean indicating whether the input is a non-empty string.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* isNonEmptyString('hello'); // true
|
|
271
|
+
* isNonEmptyString(' '); // false (trim is true by default)
|
|
272
|
+
* isNonEmptyString(' ', false); // true (whitespace is counted)
|
|
273
|
+
* isNonEmptyString(123); // false
|
|
274
|
+
* isNonEmptyString(null); // false
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
declare function isNonEmptyString<T>(/** The value to validate as a non-empty string */
|
|
278
|
+
value: T,
|
|
279
|
+
/**
|
|
280
|
+
* Whether to trim whitespace from the string before checking its length.
|
|
281
|
+
*
|
|
282
|
+
* @default true
|
|
283
|
+
*/
|
|
284
|
+
trim?: boolean): boolean;
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/isNumericString.d.ts
|
|
287
|
+
/**
|
|
288
|
+
* Checks whether a given string represents a valid numeric value.
|
|
289
|
+
*
|
|
290
|
+
* This function attempts to convert the input string to a number using
|
|
291
|
+
* both `Number()` and `parseFloat()`. It returns `true` only if both
|
|
292
|
+
* conversions do not result in `NaN`, ensuring that the input is
|
|
293
|
+
* a fully numeric string.
|
|
294
|
+
*
|
|
295
|
+
* Accepts integers, decimals, scientific notation (e.g. "1e5"), and
|
|
296
|
+
* ignores surrounding whitespace. Does not allow trailing or embedded characters
|
|
297
|
+
* like "123abc" or "abc123".
|
|
298
|
+
*
|
|
299
|
+
* @returns - `true` if the string represents a valid number; otherwise, `false`.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* isNumericString("42"); // true
|
|
304
|
+
* isNumericString("-3.14"); // true
|
|
305
|
+
* isNumericString("1e5"); // true
|
|
306
|
+
* isNumericString(" 123 "); // true
|
|
307
|
+
* isNumericString("123abc"); // false
|
|
308
|
+
* isNumericString("abc123"); // false
|
|
309
|
+
* ```
|
|
310
|
+
* See also:
|
|
311
|
+
* - {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number Number()}
|
|
312
|
+
* - {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat parseFloat()}
|
|
313
|
+
* - {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN isNaN()}
|
|
314
|
+
*/
|
|
315
|
+
declare function isNumericString(/** The string to validate */
|
|
316
|
+
value: string): boolean;
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/isObject.d.ts
|
|
319
|
+
/**
|
|
320
|
+
* Checks if a value is a plain object (created by {} or new Object()).
|
|
321
|
+
*
|
|
322
|
+
* @returns True if the value is a plain object, false otherwise.
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```ts
|
|
326
|
+
* isObject({}); // true
|
|
327
|
+
* isObject(new Object()); // true
|
|
328
|
+
* isObject([]); // false
|
|
329
|
+
* isObject(new Date()); // false
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
declare function isObject<T>(/** The value to check */
|
|
333
|
+
value: T): boolean;
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/isPascalCase.d.ts
|
|
336
|
+
/**
|
|
337
|
+
* Checks if a string is in PascalCase format.
|
|
338
|
+
*
|
|
339
|
+
* @returns True if the string is PascalCase.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```ts
|
|
343
|
+
* isPascalCase("HelloWorld") // true
|
|
344
|
+
* isPascalCase("helloWorld") // false
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
declare function isPascalCase(/** The input string */
|
|
348
|
+
value: string): boolean;
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/isProd.d.ts
|
|
351
|
+
/**
|
|
352
|
+
* Checks if the current environment is production.
|
|
353
|
+
*
|
|
354
|
+
* This is determined by comparing `process.env.NODE_ENV` with `'production'`.
|
|
355
|
+
*
|
|
356
|
+
* @returns `true` if `NODE_ENV` is set to production.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```ts
|
|
360
|
+
* if (isProd()) {
|
|
361
|
+
* enableAnalytics();
|
|
362
|
+
* }
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
365
|
+
declare function isProd(): boolean;
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/isSnakeCase.d.ts
|
|
368
|
+
/**
|
|
369
|
+
* Checks if a string is in snake_case format.
|
|
370
|
+
*
|
|
371
|
+
* @returns True if the string is snake_case.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```ts
|
|
375
|
+
* isSnakeCase("hello_world") // true
|
|
376
|
+
* isSnakeCase("hello-world") // false
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
declare function isSnakeCase(/** The input string */
|
|
380
|
+
value: string): boolean;
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/isString.d.ts
|
|
383
|
+
/**
|
|
384
|
+
* Determines whether the provided value is a string.
|
|
385
|
+
*
|
|
386
|
+
* This function returns `true` if the input is a non-null, non-undefined
|
|
387
|
+
* primitive string. It acts as a type guard, so TypeScript will narrow
|
|
388
|
+
* the type to `string` when used in conditionals.
|
|
389
|
+
*
|
|
390
|
+
* @template T - The type of the input value.
|
|
391
|
+
*
|
|
392
|
+
* @returns - Whether the value is a string (`true`) or not (`false`).
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```ts
|
|
396
|
+
* isString("hello"); // true
|
|
397
|
+
* isString(123); // false
|
|
398
|
+
* isString(null); // false
|
|
399
|
+
* isString(undefined); // false
|
|
400
|
+
*
|
|
401
|
+
* const value: unknown = "test";
|
|
402
|
+
* if (isString(value)) {
|
|
403
|
+
* console.log(value.toUpperCase());
|
|
404
|
+
* }
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
declare function isString<T>(/** The value to be checked */
|
|
408
|
+
value: T): boolean;
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src/isTest.d.ts
|
|
411
|
+
/**
|
|
412
|
+
* Checks if the current environment is testing.
|
|
413
|
+
*
|
|
414
|
+
* This is determined by comparing `process.env.NODE_ENV` with `'test'`.
|
|
415
|
+
*
|
|
416
|
+
* @returns `true` if `NODE_ENV` is set to test.
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
* ```ts
|
|
420
|
+
* if (isTest()) {
|
|
421
|
+
* mockDatabase();
|
|
422
|
+
* }
|
|
423
|
+
* ```
|
|
424
|
+
*/
|
|
425
|
+
declare function isTest(): boolean;
|
|
426
|
+
//#endregion
|
|
427
|
+
//#region src/isUndefinedOrNull.d.ts
|
|
428
|
+
/**
|
|
429
|
+
* Checks if a value is either null or undefined.
|
|
430
|
+
*
|
|
431
|
+
* @returns True if the value is null or undefined, false otherwise.
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ```ts
|
|
435
|
+
* isUndefinedOrNull(null); // true
|
|
436
|
+
* isUndefinedOrNull(undefined); // true
|
|
437
|
+
* isUndefinedOrNull(0); // false
|
|
438
|
+
* isUndefinedOrNull(""); // false
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
441
|
+
declare function isUndefinedOrNull<T>(/** The value to check */
|
|
442
|
+
value: T): boolean;
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region src/isUpperCase.d.ts
|
|
445
|
+
/**
|
|
446
|
+
* Checks if a string contains only uppercase letters.
|
|
447
|
+
*
|
|
448
|
+
* @returns True if all letters are uppercase.
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```ts
|
|
452
|
+
* isUpperCase("HELLO") // true
|
|
453
|
+
* isUpperCase("Hello") // false
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
declare function isUpperCase(/** The input string */
|
|
457
|
+
value: string): boolean;
|
|
458
|
+
//#endregion
|
|
459
|
+
//#region src/isURL.d.ts
|
|
460
|
+
/**
|
|
461
|
+
* Checks whether a given string is a valid absolute URL.
|
|
462
|
+
*
|
|
463
|
+
* This function uses the native `URL` constructor to determine if the input is a valid,
|
|
464
|
+
* absolute URL with a supported protocol (e.g., `http`, `https`, `ftp`, etc.).
|
|
465
|
+
*
|
|
466
|
+
* @returns - `true` if the string is a valid absolute URL; otherwise, `false`.
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```ts
|
|
470
|
+
* isURL('https://example.com'); // true
|
|
471
|
+
* isURL('ftp://files.example.com'); // true
|
|
472
|
+
* isURL('invalid-url'); // false
|
|
473
|
+
* isURL('/relative/path'); // false
|
|
474
|
+
* ```
|
|
475
|
+
*/
|
|
476
|
+
declare function isURL(/** The string to validate as a URL */
|
|
477
|
+
value: string): boolean;
|
|
478
|
+
//#endregion
|
|
479
|
+
//#region src/startsWithUppercase.d.ts
|
|
480
|
+
/**
|
|
481
|
+
* Checks if a string starts with an uppercase letter.
|
|
482
|
+
*
|
|
483
|
+
* @returns True if the first character is uppercase, false otherwise.
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* ```ts
|
|
487
|
+
* startsWithUppercase('Hello') // true
|
|
488
|
+
* startsWithUppercase('world') // false
|
|
489
|
+
* ```
|
|
490
|
+
*/
|
|
491
|
+
declare function startsWithUppercase(/** The input string to check */
|
|
492
|
+
value: string): boolean;
|
|
493
|
+
//#endregion
|
|
494
|
+
export { endsWithPunctuation, hasWhitespace, isAlphabetic, isArray, isBrowser, isCamelCase, isDefined, isDev, isEmail, isEmptyObject, isKebabCase, isLowerCase, isNode, isNonEmptyObject, isNonEmptyString, isNumericString, isObject, isPascalCase, isProd, isSnakeCase, isString, isTest, isURL, isUndefinedOrNull, isUpperCase, startsWithUppercase };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
export * from "@js-utils-kit/types";
|
|
2
|
+
|
|
3
|
+
//#region src/endsWithPunctuation.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a string ends with any Unicode punctuation character.
|
|
7
|
+
*
|
|
8
|
+
* @returns True if the string ends with a punctuation character.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* endsWithPunctuation("Hi!") // true
|
|
13
|
+
* endsWithPunctuation("Hello—") // true
|
|
14
|
+
* endsWithPunctuation("Okay") // false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function endsWithPunctuation(/** The string to check */
|
|
18
|
+
value: string): boolean;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/hasWhitespace.d.ts
|
|
21
|
+
/**
|
|
22
|
+
* Checks if a string contains any whitespace.
|
|
23
|
+
*
|
|
24
|
+
* @returns True if the string contains whitespace.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* hasWhitespace("Hello world") // true
|
|
29
|
+
* hasWhitespace("Nowordspace") // false
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function hasWhitespace(/** The string to check */
|
|
33
|
+
value: string): boolean;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/isAlphabetic.d.ts
|
|
36
|
+
/**
|
|
37
|
+
* Checks if a string contains only alphabetic characters (A–Z, a–z).
|
|
38
|
+
*
|
|
39
|
+
* @returns - `true` if the string contains only letters; otherwise, `false`.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* isAlphabetic("Hello"); // true
|
|
44
|
+
* isAlphabetic("world123"); // false
|
|
45
|
+
* isAlphabetic("Test!"); // false
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function isAlphabetic(/** The string to check */
|
|
49
|
+
value: string): boolean;
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/isArray.d.ts
|
|
52
|
+
/**
|
|
53
|
+
* Checks if a value is a defined array.
|
|
54
|
+
*
|
|
55
|
+
* @returns True if the value is a defined array, false otherwise.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* console.log(isArray([1, 2, 3])); // true
|
|
60
|
+
* console.log(isArray([])); // true
|
|
61
|
+
* console.log(isArray({})); // false
|
|
62
|
+
* console.log(isArray(null)); // false
|
|
63
|
+
* console.log(isArray(undefined)); // false
|
|
64
|
+
* console.log(isArray("hello")); // false
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function isArray<T>(/** The value to check */
|
|
68
|
+
value: T): boolean;
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/isBrowser.d.ts
|
|
71
|
+
/**
|
|
72
|
+
* Checks if the current runtime environment is a browser.
|
|
73
|
+
*
|
|
74
|
+
* This function helps detect whether code is executing in a web browser
|
|
75
|
+
* by confirming the existence of the global `window` and `document` objects.
|
|
76
|
+
*
|
|
77
|
+
* @returns `true` if running in a browser, otherwise `false`.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* if (isBrowser()) {
|
|
82
|
+
* console.log('Running in a browser environment');
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function isBrowser(): boolean;
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/isCamelCase.d.ts
|
|
89
|
+
/**
|
|
90
|
+
* Checks if a string is in camelCase format.
|
|
91
|
+
*
|
|
92
|
+
* @returns True if the string is camelCase.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* isCamelCase("helloWorld") // true
|
|
97
|
+
* isCamelCase("HelloWorld") // false
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
declare function isCamelCase(/** The input string */
|
|
101
|
+
value: string): boolean;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/isDefined.d.ts
|
|
104
|
+
/**
|
|
105
|
+
* Checks if a value is neither null nor undefined.
|
|
106
|
+
*
|
|
107
|
+
* @returns True if the value is defined (not null or undefined), false otherwise.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* isDefined(42); // true
|
|
112
|
+
* isDefined("hello"); // true
|
|
113
|
+
* isDefined(null); // false
|
|
114
|
+
* isDefined(undefined); // false
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
declare function isDefined<T>(/** The value to check */
|
|
118
|
+
value: T): boolean;
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/isDev.d.ts
|
|
121
|
+
/**
|
|
122
|
+
* Checks if the current environment is development.
|
|
123
|
+
*
|
|
124
|
+
* This is determined by comparing `process.env.NODE_ENV` with `'development'`.
|
|
125
|
+
*
|
|
126
|
+
* @returns `true` if `NODE_ENV` is set to development.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* if (isDev()) {
|
|
131
|
+
* console.log('Dev mode enabled');
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
declare function isDev(): boolean;
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/isEmail.d.ts
|
|
138
|
+
/**
|
|
139
|
+
* Checks whether a given string is a valid email address.
|
|
140
|
+
*
|
|
141
|
+
* @remarks
|
|
142
|
+
* This function uses a practical regular expression to validate email addresses,
|
|
143
|
+
* allowing most common formats while ignoring edge cases defined by full RFC 5322.
|
|
144
|
+
* It requires the presence of an `@` symbol and at least one `.` after it.
|
|
145
|
+
*
|
|
146
|
+
* **Limits enforced**:
|
|
147
|
+
* - Local part (before `@`): 1–64 characters
|
|
148
|
+
* - Domain part (after `@`): 1–255 characters
|
|
149
|
+
* - Total email length: ≤ 254 characters
|
|
150
|
+
*
|
|
151
|
+
*
|
|
152
|
+
* @throws {TypeError} Throws if value is not a string.
|
|
153
|
+
*
|
|
154
|
+
* @returns - `true` if the string is a valid email; otherwise, `false`.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* isEmail('user@example.com'); // true
|
|
159
|
+
* isEmail('first.last@college.university.in'); // true
|
|
160
|
+
* isEmail('invalid-email'); // false
|
|
161
|
+
* isEmail('name@domain'); // false
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function isEmail(/** The string to validate as an email address */
|
|
165
|
+
value: string): boolean;
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/isEmptyObject.d.ts
|
|
168
|
+
/**
|
|
169
|
+
* Checks if a value is an empty object (has no enumerable own properties).
|
|
170
|
+
*
|
|
171
|
+
* @returns True if the value is a non-null object with no enumerable own properties, false otherwise.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* isEmptyObject({}); // true
|
|
176
|
+
* isEmptyObject({ key: 'value' }); // false
|
|
177
|
+
* isEmptyObject(null); // false
|
|
178
|
+
* isEmptyObject([]); // false
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
declare function isEmptyObject(/** The value to check */
|
|
182
|
+
value: object): boolean;
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/isKebabCase.d.ts
|
|
185
|
+
/**
|
|
186
|
+
* Checks if a string is in kebab-case format.
|
|
187
|
+
*
|
|
188
|
+
* @returns True if the string is kebab-case.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* isKebabCase("hello-world") // true
|
|
193
|
+
* isKebabCase("hello_world") // false
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
declare function isKebabCase(/** The input string */
|
|
197
|
+
value: string): boolean;
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/isLowerCase.d.ts
|
|
200
|
+
/**
|
|
201
|
+
* Checks if a string contains only lowercase letters.
|
|
202
|
+
*
|
|
203
|
+
* @returns True if all letters are lowercase.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* isLowerCase("hello") // true
|
|
208
|
+
* isLowerCase("Hello") // false
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
declare function isLowerCase(/** The input string */
|
|
212
|
+
value: string): boolean;
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/isNode.d.ts
|
|
215
|
+
/**
|
|
216
|
+
* Checks if the current runtime environment is Node.js.
|
|
217
|
+
*
|
|
218
|
+
* This function is useful to conditionally execute server-side logic.
|
|
219
|
+
* It detects the Node.js environment by verifying the presence of the
|
|
220
|
+
* global `process` object and its `versions.node` property.
|
|
221
|
+
*
|
|
222
|
+
* @returns `true` if running in Node.js, otherwise `false`.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* if (isNode()) {
|
|
227
|
+
* console.log('Running in Node.js environment');
|
|
228
|
+
* }
|
|
229
|
+
* ```
|
|
230
|
+
*
|
|
231
|
+
* @see {@link https://nodejs.org/api/process.html | Node.js process documentation}
|
|
232
|
+
*/
|
|
233
|
+
declare function isNode(): boolean;
|
|
234
|
+
//#endregion
|
|
235
|
+
//#region src/isNonEmptyObject.d.ts
|
|
236
|
+
/**
|
|
237
|
+
* Checks if a value is a non-empty object (has at least one enumerable own property).
|
|
238
|
+
*
|
|
239
|
+
* @returns True if the value is a non-null object with at least one enumerable own property, false otherwise.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* isNonEmptyObject({ key: 'value' }); // true
|
|
244
|
+
* isNonEmptyObject({}); // false
|
|
245
|
+
* isNonEmptyObject(null); // false
|
|
246
|
+
* isNonEmptyObject([]); // false
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
declare function isNonEmptyObject(/** The value to check */
|
|
250
|
+
value: object): boolean;
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/isNonEmptyString.d.ts
|
|
253
|
+
/**
|
|
254
|
+
* Determines whether the given value is a non-empty string.
|
|
255
|
+
*
|
|
256
|
+
* This function first checks if the input is a string using {@link isString}.
|
|
257
|
+
* If it is not a string, the function returns `false`.
|
|
258
|
+
* If it is a string, it then checks whether the string contains any non-empty content.
|
|
259
|
+
*
|
|
260
|
+
* By default, the function trims the string before checking its length,
|
|
261
|
+
* which means strings containing only whitespace (e.g., `" "`) will be considered empty.
|
|
262
|
+
* This behavior can be controlled using the `trim` parameter.
|
|
263
|
+
*
|
|
264
|
+
* @template T - The type of the value being checked.
|
|
265
|
+
*
|
|
266
|
+
* @returns - A boolean indicating whether the input is a non-empty string.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* isNonEmptyString('hello'); // true
|
|
271
|
+
* isNonEmptyString(' '); // false (trim is true by default)
|
|
272
|
+
* isNonEmptyString(' ', false); // true (whitespace is counted)
|
|
273
|
+
* isNonEmptyString(123); // false
|
|
274
|
+
* isNonEmptyString(null); // false
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
declare function isNonEmptyString<T>(/** The value to validate as a non-empty string */
|
|
278
|
+
value: T,
|
|
279
|
+
/**
|
|
280
|
+
* Whether to trim whitespace from the string before checking its length.
|
|
281
|
+
*
|
|
282
|
+
* @default true
|
|
283
|
+
*/
|
|
284
|
+
trim?: boolean): boolean;
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/isNumericString.d.ts
|
|
287
|
+
/**
|
|
288
|
+
* Checks whether a given string represents a valid numeric value.
|
|
289
|
+
*
|
|
290
|
+
* This function attempts to convert the input string to a number using
|
|
291
|
+
* both `Number()` and `parseFloat()`. It returns `true` only if both
|
|
292
|
+
* conversions do not result in `NaN`, ensuring that the input is
|
|
293
|
+
* a fully numeric string.
|
|
294
|
+
*
|
|
295
|
+
* Accepts integers, decimals, scientific notation (e.g. "1e5"), and
|
|
296
|
+
* ignores surrounding whitespace. Does not allow trailing or embedded characters
|
|
297
|
+
* like "123abc" or "abc123".
|
|
298
|
+
*
|
|
299
|
+
* @returns - `true` if the string represents a valid number; otherwise, `false`.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* isNumericString("42"); // true
|
|
304
|
+
* isNumericString("-3.14"); // true
|
|
305
|
+
* isNumericString("1e5"); // true
|
|
306
|
+
* isNumericString(" 123 "); // true
|
|
307
|
+
* isNumericString("123abc"); // false
|
|
308
|
+
* isNumericString("abc123"); // false
|
|
309
|
+
* ```
|
|
310
|
+
* See also:
|
|
311
|
+
* - {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number Number()}
|
|
312
|
+
* - {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat parseFloat()}
|
|
313
|
+
* - {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN isNaN()}
|
|
314
|
+
*/
|
|
315
|
+
declare function isNumericString(/** The string to validate */
|
|
316
|
+
value: string): boolean;
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/isObject.d.ts
|
|
319
|
+
/**
|
|
320
|
+
* Checks if a value is a plain object (created by {} or new Object()).
|
|
321
|
+
*
|
|
322
|
+
* @returns True if the value is a plain object, false otherwise.
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```ts
|
|
326
|
+
* isObject({}); // true
|
|
327
|
+
* isObject(new Object()); // true
|
|
328
|
+
* isObject([]); // false
|
|
329
|
+
* isObject(new Date()); // false
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
declare function isObject<T>(/** The value to check */
|
|
333
|
+
value: T): boolean;
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/isPascalCase.d.ts
|
|
336
|
+
/**
|
|
337
|
+
* Checks if a string is in PascalCase format.
|
|
338
|
+
*
|
|
339
|
+
* @returns True if the string is PascalCase.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```ts
|
|
343
|
+
* isPascalCase("HelloWorld") // true
|
|
344
|
+
* isPascalCase("helloWorld") // false
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
declare function isPascalCase(/** The input string */
|
|
348
|
+
value: string): boolean;
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/isProd.d.ts
|
|
351
|
+
/**
|
|
352
|
+
* Checks if the current environment is production.
|
|
353
|
+
*
|
|
354
|
+
* This is determined by comparing `process.env.NODE_ENV` with `'production'`.
|
|
355
|
+
*
|
|
356
|
+
* @returns `true` if `NODE_ENV` is set to production.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```ts
|
|
360
|
+
* if (isProd()) {
|
|
361
|
+
* enableAnalytics();
|
|
362
|
+
* }
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
365
|
+
declare function isProd(): boolean;
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/isSnakeCase.d.ts
|
|
368
|
+
/**
|
|
369
|
+
* Checks if a string is in snake_case format.
|
|
370
|
+
*
|
|
371
|
+
* @returns True if the string is snake_case.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```ts
|
|
375
|
+
* isSnakeCase("hello_world") // true
|
|
376
|
+
* isSnakeCase("hello-world") // false
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
declare function isSnakeCase(/** The input string */
|
|
380
|
+
value: string): boolean;
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/isString.d.ts
|
|
383
|
+
/**
|
|
384
|
+
* Determines whether the provided value is a string.
|
|
385
|
+
*
|
|
386
|
+
* This function returns `true` if the input is a non-null, non-undefined
|
|
387
|
+
* primitive string. It acts as a type guard, so TypeScript will narrow
|
|
388
|
+
* the type to `string` when used in conditionals.
|
|
389
|
+
*
|
|
390
|
+
* @template T - The type of the input value.
|
|
391
|
+
*
|
|
392
|
+
* @returns - Whether the value is a string (`true`) or not (`false`).
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```ts
|
|
396
|
+
* isString("hello"); // true
|
|
397
|
+
* isString(123); // false
|
|
398
|
+
* isString(null); // false
|
|
399
|
+
* isString(undefined); // false
|
|
400
|
+
*
|
|
401
|
+
* const value: unknown = "test";
|
|
402
|
+
* if (isString(value)) {
|
|
403
|
+
* console.log(value.toUpperCase());
|
|
404
|
+
* }
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
declare function isString<T>(/** The value to be checked */
|
|
408
|
+
value: T): boolean;
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src/isTest.d.ts
|
|
411
|
+
/**
|
|
412
|
+
* Checks if the current environment is testing.
|
|
413
|
+
*
|
|
414
|
+
* This is determined by comparing `process.env.NODE_ENV` with `'test'`.
|
|
415
|
+
*
|
|
416
|
+
* @returns `true` if `NODE_ENV` is set to test.
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
* ```ts
|
|
420
|
+
* if (isTest()) {
|
|
421
|
+
* mockDatabase();
|
|
422
|
+
* }
|
|
423
|
+
* ```
|
|
424
|
+
*/
|
|
425
|
+
declare function isTest(): boolean;
|
|
426
|
+
//#endregion
|
|
427
|
+
//#region src/isUndefinedOrNull.d.ts
|
|
428
|
+
/**
|
|
429
|
+
* Checks if a value is either null or undefined.
|
|
430
|
+
*
|
|
431
|
+
* @returns True if the value is null or undefined, false otherwise.
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ```ts
|
|
435
|
+
* isUndefinedOrNull(null); // true
|
|
436
|
+
* isUndefinedOrNull(undefined); // true
|
|
437
|
+
* isUndefinedOrNull(0); // false
|
|
438
|
+
* isUndefinedOrNull(""); // false
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
441
|
+
declare function isUndefinedOrNull<T>(/** The value to check */
|
|
442
|
+
value: T): boolean;
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region src/isUpperCase.d.ts
|
|
445
|
+
/**
|
|
446
|
+
* Checks if a string contains only uppercase letters.
|
|
447
|
+
*
|
|
448
|
+
* @returns True if all letters are uppercase.
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```ts
|
|
452
|
+
* isUpperCase("HELLO") // true
|
|
453
|
+
* isUpperCase("Hello") // false
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
declare function isUpperCase(/** The input string */
|
|
457
|
+
value: string): boolean;
|
|
458
|
+
//#endregion
|
|
459
|
+
//#region src/isURL.d.ts
|
|
460
|
+
/**
|
|
461
|
+
* Checks whether a given string is a valid absolute URL.
|
|
462
|
+
*
|
|
463
|
+
* This function uses the native `URL` constructor to determine if the input is a valid,
|
|
464
|
+
* absolute URL with a supported protocol (e.g., `http`, `https`, `ftp`, etc.).
|
|
465
|
+
*
|
|
466
|
+
* @returns - `true` if the string is a valid absolute URL; otherwise, `false`.
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```ts
|
|
470
|
+
* isURL('https://example.com'); // true
|
|
471
|
+
* isURL('ftp://files.example.com'); // true
|
|
472
|
+
* isURL('invalid-url'); // false
|
|
473
|
+
* isURL('/relative/path'); // false
|
|
474
|
+
* ```
|
|
475
|
+
*/
|
|
476
|
+
declare function isURL(/** The string to validate as a URL */
|
|
477
|
+
value: string): boolean;
|
|
478
|
+
//#endregion
|
|
479
|
+
//#region src/startsWithUppercase.d.ts
|
|
480
|
+
/**
|
|
481
|
+
* Checks if a string starts with an uppercase letter.
|
|
482
|
+
*
|
|
483
|
+
* @returns True if the first character is uppercase, false otherwise.
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* ```ts
|
|
487
|
+
* startsWithUppercase('Hello') // true
|
|
488
|
+
* startsWithUppercase('world') // false
|
|
489
|
+
* ```
|
|
490
|
+
*/
|
|
491
|
+
declare function startsWithUppercase(/** The input string to check */
|
|
492
|
+
value: string): boolean;
|
|
493
|
+
//#endregion
|
|
494
|
+
export { endsWithPunctuation, hasWhitespace, isAlphabetic, isArray, isBrowser, isCamelCase, isDefined, isDev, isEmail, isEmptyObject, isKebabCase, isLowerCase, isNode, isNonEmptyObject, isNonEmptyString, isNumericString, isObject, isPascalCase, isProd, isSnakeCase, isString, isTest, isURL, isUndefinedOrNull, isUpperCase, startsWithUppercase };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Environment as e}from"@js-utils-kit/types";export*from"@js-utils-kit/types";function t(e){return/[\p{P}]$/u.test(e)}function n(e){return/\s/.test(e)}function r(e){return/^[a-zA-Z]+$/.test(e)}function i(e){return e!=null}function a(e){return i(e)&&Array.isArray(e)}function o(){return typeof window<`u`&&window.document!==void 0}function s(e){return/^[a-z][a-zA-Z0-9]*$/.test(e)}function c(){return process.env.NODE_ENV===e.DEV}function l(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);if(e.length>254)return!1;let t=e.split(`@`);if(t.length!==2)return!1;let[n,r]=t;return n.length===0||n.length>64||r.length===0||r.length>255?!1:!(!/^[a-zA-Z0-9_%+-]+(\.[a-zA-Z0-9_%+-]+)*$/.test(n)||!/^(?!.*\.\.)(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.[A-Za-z0-9-]{1,63}(?<!-))*\.[A-Za-z]{2,}$/.test(r))}function u(e){return typeof e==`object`&&!!e&&Object.keys(e).length===0&&!a(e)}function d(e){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test(e)}function f(e){return/^[a-z]+$/.test(e)}function p(){return typeof process<`u`&&process.versions!==null&&process.versions.node!==null}function m(e){return typeof e==`object`&&!!e&&Object.keys(e).length>0&&!a(e)}function h(e){return e!=null&&typeof e==`string`}function g(e,t=!0){return h(e)?typeof e==`string`&&(t?e.trim().length>0:e.length>0):!1}function _(e){return!isNaN(Number(e))&&!isNaN(parseFloat(e))}function v(e){return i(e)&&typeof e==`object`&&!a(e)&&Object.getPrototypeOf(e)===Object.prototype}function y(e){return/^[A-Z][a-zA-Z0-9]*$/.test(e)}function b(){return process.env.NODE_ENV===e.PROD}function x(e){return/^[a-z0-9]+(_[a-z0-9]+)*$/.test(e)}function S(){return process.env.NODE_ENV===e.TEST}function C(e){return e==null}function w(e){return/^[A-Z]+$/.test(e)}function T(e){try{return new URL(e),!0}catch{return!1}}function E(e){return/^[A-Z]/.test(e)}export{t as endsWithPunctuation,n as hasWhitespace,r as isAlphabetic,a as isArray,o as isBrowser,s as isCamelCase,i as isDefined,c as isDev,l as isEmail,u as isEmptyObject,d as isKebabCase,f as isLowerCase,p as isNode,m as isNonEmptyObject,g as isNonEmptyString,_ as isNumericString,v as isObject,y as isPascalCase,b as isProd,x as isSnakeCase,h as isString,S as isTest,T as isURL,C as isUndefinedOrNull,w as isUpperCase,E as startsWithUppercase};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@js-utils-kit/valid",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Validation utilities",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"private": false,
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/teneplaysofficial/js-utils-kit",
|
|
10
|
+
"directory": "packages/valid"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/teneplaysofficial/js-utils-kit/issues"
|
|
14
|
+
},
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Sriman",
|
|
17
|
+
"email": "136729116+TenEplaysOfficial@users.noreply.github.com",
|
|
18
|
+
"url": "https://tene.vercel.app"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"validation",
|
|
22
|
+
"predicate",
|
|
23
|
+
"checks",
|
|
24
|
+
"utility"
|
|
25
|
+
],
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22"
|
|
31
|
+
},
|
|
32
|
+
"type": "module",
|
|
33
|
+
"main": "./dist/index.cjs",
|
|
34
|
+
"module": "./dist/index.mjs",
|
|
35
|
+
"types": "./dist/index.d.cts",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"import": "./dist/index.mjs",
|
|
39
|
+
"require": "./dist/index.cjs"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@js-utils-kit/types": "1.0.0"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsdown",
|
|
47
|
+
"test": "vitest run"
|
|
48
|
+
}
|
|
49
|
+
}
|