@js-utils-kit/valid 1.0.1 → 1.2.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/dist/index.cjs +1 -1
- package/dist/index.d.cts +136 -8
- package/dist/index.d.mts +136 -8
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1 +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
|
|
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 e==null?!0:typeof e==`string`?e.trim().length===0:Array.isArray(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:Object.prototype.toString.call(e)===`[object Object]`?Object.keys(e).length===0:!1}function d(e){return typeof e==`object`&&!!e&&Object.keys(e).length===0&&!a(e)}function f(e){return!e}function p(e){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test(e)}function m(e){return/^[a-z]+$/.test(e)}function h(){return typeof process<`u`&&process.versions!==null&&process.versions.node!==null}function g(e){return typeof e==`object`&&!!e&&Object.keys(e).length>0&&!a(e)}function _(e){return e!=null&&typeof e==`string`}function v(e,t=!0){return _(e)?typeof e==`string`&&(t?e.trim().length>0:e.length>0):!1}function y(e){return!isNaN(Number(e))&&!isNaN(parseFloat(e))}function b(e){return i(e)&&typeof e==`object`&&!a(e)&&Object.getPrototypeOf(e)===Object.prototype}function x(e){return/^[A-Z][a-zA-Z0-9]*$/.test(e)}function S(){return process.env.NODE_ENV===e.Environment.PROD}function C(e){return/^[a-z0-9]+(_[a-z0-9]+)*$/.test(e)}function w(){return process.env.NODE_ENV===e.Environment.TEST}function T(e){return!!e}function E(e){return e==null}function D(e){return/^[A-Z]+$/.test(e)}function O(e){try{return new URL(e),!0}catch{return!1}}function k(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.isEmpty=u,exports.isEmptyObject=d,exports.isFalsy=f,exports.isKebabCase=p,exports.isLowerCase=m,exports.isNode=h,exports.isNonEmptyObject=g,exports.isNonEmptyString=v,exports.isNumericString=y,exports.isObject=b,exports.isPascalCase=x,exports.isProd=S,exports.isSnakeCase=C,exports.isString=_,exports.isTest=w,exports.isTruthy=T,exports.isURL=O,exports.isUndefinedOrNull=E,exports.isUpperCase=D,exports.startsWithUppercase=k;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export * from "@js-utils-kit/types";
|
|
2
|
-
|
|
3
1
|
//#region src/endsWithPunctuation.d.ts
|
|
4
|
-
|
|
5
2
|
/**
|
|
6
3
|
* Checks if a string ends with any Unicode punctuation character.
|
|
7
4
|
*
|
|
@@ -14,8 +11,7 @@ export * from "@js-utils-kit/types";
|
|
|
14
11
|
* endsWithPunctuation("Okay") // false
|
|
15
12
|
* ```
|
|
16
13
|
*/
|
|
17
|
-
declare function endsWithPunctuation(/** The string to check */
|
|
18
|
-
value: string): boolean;
|
|
14
|
+
declare function endsWithPunctuation(/** The string to check */value: string): boolean;
|
|
19
15
|
//#endregion
|
|
20
16
|
//#region src/hasWhitespace.d.ts
|
|
21
17
|
/**
|
|
@@ -29,8 +25,7 @@ value: string): boolean;
|
|
|
29
25
|
* hasWhitespace("Nowordspace") // false
|
|
30
26
|
* ```
|
|
31
27
|
*/
|
|
32
|
-
declare function hasWhitespace(/** The string to check */
|
|
33
|
-
value: string): boolean;
|
|
28
|
+
declare function hasWhitespace(/** The string to check */value: string): boolean;
|
|
34
29
|
//#endregion
|
|
35
30
|
//#region src/isAlphabetic.d.ts
|
|
36
31
|
/**
|
|
@@ -46,6 +41,7 @@ value: string): boolean;
|
|
|
46
41
|
* ```
|
|
47
42
|
*/
|
|
48
43
|
declare function isAlphabetic(/** The string to check */
|
|
44
|
+
|
|
49
45
|
value: string): boolean;
|
|
50
46
|
//#endregion
|
|
51
47
|
//#region src/isArray.d.ts
|
|
@@ -65,6 +61,7 @@ value: string): boolean;
|
|
|
65
61
|
* ```
|
|
66
62
|
*/
|
|
67
63
|
declare function isArray<T>(/** The value to check */
|
|
64
|
+
|
|
68
65
|
value: T): boolean;
|
|
69
66
|
//#endregion
|
|
70
67
|
//#region src/isBrowser.d.ts
|
|
@@ -98,6 +95,7 @@ declare function isBrowser(): boolean;
|
|
|
98
95
|
* ```
|
|
99
96
|
*/
|
|
100
97
|
declare function isCamelCase(/** The input string */
|
|
98
|
+
|
|
101
99
|
value: string): boolean;
|
|
102
100
|
//#endregion
|
|
103
101
|
//#region src/isDefined.d.ts
|
|
@@ -115,6 +113,7 @@ value: string): boolean;
|
|
|
115
113
|
* ```
|
|
116
114
|
*/
|
|
117
115
|
declare function isDefined<T>(/** The value to check */
|
|
116
|
+
|
|
118
117
|
value: T): boolean;
|
|
119
118
|
//#endregion
|
|
120
119
|
//#region src/isDev.d.ts
|
|
@@ -162,8 +161,46 @@ declare function isDev(): boolean;
|
|
|
162
161
|
* ```
|
|
163
162
|
*/
|
|
164
163
|
declare function isEmail(/** The string to validate as an email address */
|
|
164
|
+
|
|
165
165
|
value: string): boolean;
|
|
166
166
|
//#endregion
|
|
167
|
+
//#region src/isEmpty.d.ts
|
|
168
|
+
/**
|
|
169
|
+
* Checks whether a value is empty.
|
|
170
|
+
*
|
|
171
|
+
* Empty values include:
|
|
172
|
+
* - `null` or `undefined`
|
|
173
|
+
* - Empty strings (including whitespace-only strings)
|
|
174
|
+
* - Arrays with length `0`
|
|
175
|
+
* - Objects with no own enumerable properties
|
|
176
|
+
* - Maps and Sets with size `0`
|
|
177
|
+
*
|
|
178
|
+
* @returns `true` if the value is empty, otherwise `false`
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* isEmpty(null); // true
|
|
183
|
+
* isEmpty(''); // true
|
|
184
|
+
* isEmpty(' '); // true
|
|
185
|
+
* isEmpty([]); // true
|
|
186
|
+
* isEmpty({}); // true
|
|
187
|
+
* isEmpty(new Map()); // true
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* isEmpty('hello'); // false
|
|
193
|
+
* isEmpty([1]); // false
|
|
194
|
+
* isEmpty({ a: 1 }); // false
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
declare function isEmpty<T>(
|
|
198
|
+
/**
|
|
199
|
+
* The value to check.
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
value: T): boolean;
|
|
203
|
+
//#endregion
|
|
167
204
|
//#region src/isEmptyObject.d.ts
|
|
168
205
|
/**
|
|
169
206
|
* Checks if a value is an empty object (has no enumerable own properties).
|
|
@@ -179,8 +216,47 @@ value: string): boolean;
|
|
|
179
216
|
* ```
|
|
180
217
|
*/
|
|
181
218
|
declare function isEmptyObject(/** The value to check */
|
|
219
|
+
|
|
182
220
|
value: object): boolean;
|
|
183
221
|
//#endregion
|
|
222
|
+
//#region src/isFalsy.d.ts
|
|
223
|
+
/**
|
|
224
|
+
* Checks whether a value is falsy.
|
|
225
|
+
*
|
|
226
|
+
* Falsy values include:
|
|
227
|
+
* - `false`
|
|
228
|
+
* - `0`
|
|
229
|
+
* - `""`
|
|
230
|
+
* - `null`
|
|
231
|
+
* - `undefined`
|
|
232
|
+
* - `NaN`
|
|
233
|
+
*
|
|
234
|
+
* @returns `true` if the value is falsy, otherwise `false`
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* isFalsy(0); // true
|
|
239
|
+
* isFalsy(''); // true
|
|
240
|
+
* isFalsy(null); // true
|
|
241
|
+
* isFalsy(undefined);// true
|
|
242
|
+
* isFalsy(NaN); // true
|
|
243
|
+
* ```
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* isFalsy(1); // false
|
|
248
|
+
* isFalsy('hello'); // false
|
|
249
|
+
* isFalsy([]); // false
|
|
250
|
+
* isFalsy({}); // false
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
declare function isFalsy<T>(
|
|
254
|
+
/**
|
|
255
|
+
* The value to check.
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
value: T): boolean;
|
|
259
|
+
//#endregion
|
|
184
260
|
//#region src/isKebabCase.d.ts
|
|
185
261
|
/**
|
|
186
262
|
* Checks if a string is in kebab-case format.
|
|
@@ -194,6 +270,7 @@ value: object): boolean;
|
|
|
194
270
|
* ```
|
|
195
271
|
*/
|
|
196
272
|
declare function isKebabCase(/** The input string */
|
|
273
|
+
|
|
197
274
|
value: string): boolean;
|
|
198
275
|
//#endregion
|
|
199
276
|
//#region src/isLowerCase.d.ts
|
|
@@ -209,6 +286,7 @@ value: string): boolean;
|
|
|
209
286
|
* ```
|
|
210
287
|
*/
|
|
211
288
|
declare function isLowerCase(/** The input string */
|
|
289
|
+
|
|
212
290
|
value: string): boolean;
|
|
213
291
|
//#endregion
|
|
214
292
|
//#region src/isNode.d.ts
|
|
@@ -247,6 +325,7 @@ declare function isNode(): boolean;
|
|
|
247
325
|
* ```
|
|
248
326
|
*/
|
|
249
327
|
declare function isNonEmptyObject(/** The value to check */
|
|
328
|
+
|
|
250
329
|
value: object): boolean;
|
|
251
330
|
//#endregion
|
|
252
331
|
//#region src/isNonEmptyString.d.ts
|
|
@@ -275,12 +354,14 @@ value: object): boolean;
|
|
|
275
354
|
* ```
|
|
276
355
|
*/
|
|
277
356
|
declare function isNonEmptyString<T>(/** The value to validate as a non-empty string */
|
|
357
|
+
|
|
278
358
|
value: T,
|
|
279
359
|
/**
|
|
280
360
|
* Whether to trim whitespace from the string before checking its length.
|
|
281
361
|
*
|
|
282
362
|
* @default true
|
|
283
363
|
*/
|
|
364
|
+
|
|
284
365
|
trim?: boolean): boolean;
|
|
285
366
|
//#endregion
|
|
286
367
|
//#region src/isNumericString.d.ts
|
|
@@ -313,6 +394,7 @@ trim?: boolean): boolean;
|
|
|
313
394
|
* - {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN isNaN()}
|
|
314
395
|
*/
|
|
315
396
|
declare function isNumericString(/** The string to validate */
|
|
397
|
+
|
|
316
398
|
value: string): boolean;
|
|
317
399
|
//#endregion
|
|
318
400
|
//#region src/isObject.d.ts
|
|
@@ -330,6 +412,7 @@ value: string): boolean;
|
|
|
330
412
|
* ```
|
|
331
413
|
*/
|
|
332
414
|
declare function isObject<T>(/** The value to check */
|
|
415
|
+
|
|
333
416
|
value: T): boolean;
|
|
334
417
|
//#endregion
|
|
335
418
|
//#region src/isPascalCase.d.ts
|
|
@@ -345,6 +428,7 @@ value: T): boolean;
|
|
|
345
428
|
* ```
|
|
346
429
|
*/
|
|
347
430
|
declare function isPascalCase(/** The input string */
|
|
431
|
+
|
|
348
432
|
value: string): boolean;
|
|
349
433
|
//#endregion
|
|
350
434
|
//#region src/isProd.d.ts
|
|
@@ -377,6 +461,7 @@ declare function isProd(): boolean;
|
|
|
377
461
|
* ```
|
|
378
462
|
*/
|
|
379
463
|
declare function isSnakeCase(/** The input string */
|
|
464
|
+
|
|
380
465
|
value: string): boolean;
|
|
381
466
|
//#endregion
|
|
382
467
|
//#region src/isString.d.ts
|
|
@@ -405,6 +490,7 @@ value: string): boolean;
|
|
|
405
490
|
* ```
|
|
406
491
|
*/
|
|
407
492
|
declare function isString<T>(/** The value to be checked */
|
|
493
|
+
|
|
408
494
|
value: T): boolean;
|
|
409
495
|
//#endregion
|
|
410
496
|
//#region src/isTest.d.ts
|
|
@@ -424,6 +510,44 @@ value: T): boolean;
|
|
|
424
510
|
*/
|
|
425
511
|
declare function isTest(): boolean;
|
|
426
512
|
//#endregion
|
|
513
|
+
//#region src/isTruthy.d.ts
|
|
514
|
+
/**
|
|
515
|
+
* Checks whether a value is truthy.
|
|
516
|
+
*
|
|
517
|
+
* Falsy values include:
|
|
518
|
+
* - `false`
|
|
519
|
+
* - `0`
|
|
520
|
+
* - `""` (empty string)
|
|
521
|
+
* - `null`
|
|
522
|
+
* - `undefined`
|
|
523
|
+
* - `NaN`
|
|
524
|
+
*
|
|
525
|
+
* @returns `true` if the value is truthy, otherwise `false`.
|
|
526
|
+
*
|
|
527
|
+
* @example
|
|
528
|
+
* ```ts
|
|
529
|
+
* isTruthy(0); // false
|
|
530
|
+
* isTruthy(''); // false
|
|
531
|
+
* isTruthy(null); // false
|
|
532
|
+
* isTruthy(undefined); // false
|
|
533
|
+
* isTruthy(NaN); // false
|
|
534
|
+
* ```
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* ```ts
|
|
538
|
+
* isTruthy(1); // true
|
|
539
|
+
* isTruthy('hello'); // true
|
|
540
|
+
* isTruthy([]); // true
|
|
541
|
+
* isTruthy({}); // true
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
declare function isTruthy<T>(
|
|
545
|
+
/**
|
|
546
|
+
* The value to check.
|
|
547
|
+
*/
|
|
548
|
+
|
|
549
|
+
value: T): boolean;
|
|
550
|
+
//#endregion
|
|
427
551
|
//#region src/isUndefinedOrNull.d.ts
|
|
428
552
|
/**
|
|
429
553
|
* Checks if a value is either null or undefined.
|
|
@@ -439,6 +563,7 @@ declare function isTest(): boolean;
|
|
|
439
563
|
* ```
|
|
440
564
|
*/
|
|
441
565
|
declare function isUndefinedOrNull<T>(/** The value to check */
|
|
566
|
+
|
|
442
567
|
value: T): boolean;
|
|
443
568
|
//#endregion
|
|
444
569
|
//#region src/isUpperCase.d.ts
|
|
@@ -454,6 +579,7 @@ value: T): boolean;
|
|
|
454
579
|
* ```
|
|
455
580
|
*/
|
|
456
581
|
declare function isUpperCase(/** The input string */
|
|
582
|
+
|
|
457
583
|
value: string): boolean;
|
|
458
584
|
//#endregion
|
|
459
585
|
//#region src/isURL.d.ts
|
|
@@ -474,6 +600,7 @@ value: string): boolean;
|
|
|
474
600
|
* ```
|
|
475
601
|
*/
|
|
476
602
|
declare function isURL(/** The string to validate as a URL */
|
|
603
|
+
|
|
477
604
|
value: string): boolean;
|
|
478
605
|
//#endregion
|
|
479
606
|
//#region src/startsWithUppercase.d.ts
|
|
@@ -489,6 +616,7 @@ value: string): boolean;
|
|
|
489
616
|
* ```
|
|
490
617
|
*/
|
|
491
618
|
declare function startsWithUppercase(/** The input string to check */
|
|
619
|
+
|
|
492
620
|
value: string): boolean;
|
|
493
621
|
//#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 };
|
|
622
|
+
export { endsWithPunctuation, hasWhitespace, isAlphabetic, isArray, isBrowser, isCamelCase, isDefined, isDev, isEmail, isEmpty, isEmptyObject, isFalsy, isKebabCase, isLowerCase, isNode, isNonEmptyObject, isNonEmptyString, isNumericString, isObject, isPascalCase, isProd, isSnakeCase, isString, isTest, isTruthy, isURL, isUndefinedOrNull, isUpperCase, startsWithUppercase };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export * from "@js-utils-kit/types";
|
|
2
|
-
|
|
3
1
|
//#region src/endsWithPunctuation.d.ts
|
|
4
|
-
|
|
5
2
|
/**
|
|
6
3
|
* Checks if a string ends with any Unicode punctuation character.
|
|
7
4
|
*
|
|
@@ -14,8 +11,7 @@ export * from "@js-utils-kit/types";
|
|
|
14
11
|
* endsWithPunctuation("Okay") // false
|
|
15
12
|
* ```
|
|
16
13
|
*/
|
|
17
|
-
declare function endsWithPunctuation(/** The string to check */
|
|
18
|
-
value: string): boolean;
|
|
14
|
+
declare function endsWithPunctuation(/** The string to check */value: string): boolean;
|
|
19
15
|
//#endregion
|
|
20
16
|
//#region src/hasWhitespace.d.ts
|
|
21
17
|
/**
|
|
@@ -29,8 +25,7 @@ value: string): boolean;
|
|
|
29
25
|
* hasWhitespace("Nowordspace") // false
|
|
30
26
|
* ```
|
|
31
27
|
*/
|
|
32
|
-
declare function hasWhitespace(/** The string to check */
|
|
33
|
-
value: string): boolean;
|
|
28
|
+
declare function hasWhitespace(/** The string to check */value: string): boolean;
|
|
34
29
|
//#endregion
|
|
35
30
|
//#region src/isAlphabetic.d.ts
|
|
36
31
|
/**
|
|
@@ -46,6 +41,7 @@ value: string): boolean;
|
|
|
46
41
|
* ```
|
|
47
42
|
*/
|
|
48
43
|
declare function isAlphabetic(/** The string to check */
|
|
44
|
+
|
|
49
45
|
value: string): boolean;
|
|
50
46
|
//#endregion
|
|
51
47
|
//#region src/isArray.d.ts
|
|
@@ -65,6 +61,7 @@ value: string): boolean;
|
|
|
65
61
|
* ```
|
|
66
62
|
*/
|
|
67
63
|
declare function isArray<T>(/** The value to check */
|
|
64
|
+
|
|
68
65
|
value: T): boolean;
|
|
69
66
|
//#endregion
|
|
70
67
|
//#region src/isBrowser.d.ts
|
|
@@ -98,6 +95,7 @@ declare function isBrowser(): boolean;
|
|
|
98
95
|
* ```
|
|
99
96
|
*/
|
|
100
97
|
declare function isCamelCase(/** The input string */
|
|
98
|
+
|
|
101
99
|
value: string): boolean;
|
|
102
100
|
//#endregion
|
|
103
101
|
//#region src/isDefined.d.ts
|
|
@@ -115,6 +113,7 @@ value: string): boolean;
|
|
|
115
113
|
* ```
|
|
116
114
|
*/
|
|
117
115
|
declare function isDefined<T>(/** The value to check */
|
|
116
|
+
|
|
118
117
|
value: T): boolean;
|
|
119
118
|
//#endregion
|
|
120
119
|
//#region src/isDev.d.ts
|
|
@@ -162,8 +161,46 @@ declare function isDev(): boolean;
|
|
|
162
161
|
* ```
|
|
163
162
|
*/
|
|
164
163
|
declare function isEmail(/** The string to validate as an email address */
|
|
164
|
+
|
|
165
165
|
value: string): boolean;
|
|
166
166
|
//#endregion
|
|
167
|
+
//#region src/isEmpty.d.ts
|
|
168
|
+
/**
|
|
169
|
+
* Checks whether a value is empty.
|
|
170
|
+
*
|
|
171
|
+
* Empty values include:
|
|
172
|
+
* - `null` or `undefined`
|
|
173
|
+
* - Empty strings (including whitespace-only strings)
|
|
174
|
+
* - Arrays with length `0`
|
|
175
|
+
* - Objects with no own enumerable properties
|
|
176
|
+
* - Maps and Sets with size `0`
|
|
177
|
+
*
|
|
178
|
+
* @returns `true` if the value is empty, otherwise `false`
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* isEmpty(null); // true
|
|
183
|
+
* isEmpty(''); // true
|
|
184
|
+
* isEmpty(' '); // true
|
|
185
|
+
* isEmpty([]); // true
|
|
186
|
+
* isEmpty({}); // true
|
|
187
|
+
* isEmpty(new Map()); // true
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* isEmpty('hello'); // false
|
|
193
|
+
* isEmpty([1]); // false
|
|
194
|
+
* isEmpty({ a: 1 }); // false
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
declare function isEmpty<T>(
|
|
198
|
+
/**
|
|
199
|
+
* The value to check.
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
value: T): boolean;
|
|
203
|
+
//#endregion
|
|
167
204
|
//#region src/isEmptyObject.d.ts
|
|
168
205
|
/**
|
|
169
206
|
* Checks if a value is an empty object (has no enumerable own properties).
|
|
@@ -179,8 +216,47 @@ value: string): boolean;
|
|
|
179
216
|
* ```
|
|
180
217
|
*/
|
|
181
218
|
declare function isEmptyObject(/** The value to check */
|
|
219
|
+
|
|
182
220
|
value: object): boolean;
|
|
183
221
|
//#endregion
|
|
222
|
+
//#region src/isFalsy.d.ts
|
|
223
|
+
/**
|
|
224
|
+
* Checks whether a value is falsy.
|
|
225
|
+
*
|
|
226
|
+
* Falsy values include:
|
|
227
|
+
* - `false`
|
|
228
|
+
* - `0`
|
|
229
|
+
* - `""`
|
|
230
|
+
* - `null`
|
|
231
|
+
* - `undefined`
|
|
232
|
+
* - `NaN`
|
|
233
|
+
*
|
|
234
|
+
* @returns `true` if the value is falsy, otherwise `false`
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* isFalsy(0); // true
|
|
239
|
+
* isFalsy(''); // true
|
|
240
|
+
* isFalsy(null); // true
|
|
241
|
+
* isFalsy(undefined);// true
|
|
242
|
+
* isFalsy(NaN); // true
|
|
243
|
+
* ```
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* isFalsy(1); // false
|
|
248
|
+
* isFalsy('hello'); // false
|
|
249
|
+
* isFalsy([]); // false
|
|
250
|
+
* isFalsy({}); // false
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
declare function isFalsy<T>(
|
|
254
|
+
/**
|
|
255
|
+
* The value to check.
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
value: T): boolean;
|
|
259
|
+
//#endregion
|
|
184
260
|
//#region src/isKebabCase.d.ts
|
|
185
261
|
/**
|
|
186
262
|
* Checks if a string is in kebab-case format.
|
|
@@ -194,6 +270,7 @@ value: object): boolean;
|
|
|
194
270
|
* ```
|
|
195
271
|
*/
|
|
196
272
|
declare function isKebabCase(/** The input string */
|
|
273
|
+
|
|
197
274
|
value: string): boolean;
|
|
198
275
|
//#endregion
|
|
199
276
|
//#region src/isLowerCase.d.ts
|
|
@@ -209,6 +286,7 @@ value: string): boolean;
|
|
|
209
286
|
* ```
|
|
210
287
|
*/
|
|
211
288
|
declare function isLowerCase(/** The input string */
|
|
289
|
+
|
|
212
290
|
value: string): boolean;
|
|
213
291
|
//#endregion
|
|
214
292
|
//#region src/isNode.d.ts
|
|
@@ -247,6 +325,7 @@ declare function isNode(): boolean;
|
|
|
247
325
|
* ```
|
|
248
326
|
*/
|
|
249
327
|
declare function isNonEmptyObject(/** The value to check */
|
|
328
|
+
|
|
250
329
|
value: object): boolean;
|
|
251
330
|
//#endregion
|
|
252
331
|
//#region src/isNonEmptyString.d.ts
|
|
@@ -275,12 +354,14 @@ value: object): boolean;
|
|
|
275
354
|
* ```
|
|
276
355
|
*/
|
|
277
356
|
declare function isNonEmptyString<T>(/** The value to validate as a non-empty string */
|
|
357
|
+
|
|
278
358
|
value: T,
|
|
279
359
|
/**
|
|
280
360
|
* Whether to trim whitespace from the string before checking its length.
|
|
281
361
|
*
|
|
282
362
|
* @default true
|
|
283
363
|
*/
|
|
364
|
+
|
|
284
365
|
trim?: boolean): boolean;
|
|
285
366
|
//#endregion
|
|
286
367
|
//#region src/isNumericString.d.ts
|
|
@@ -313,6 +394,7 @@ trim?: boolean): boolean;
|
|
|
313
394
|
* - {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN isNaN()}
|
|
314
395
|
*/
|
|
315
396
|
declare function isNumericString(/** The string to validate */
|
|
397
|
+
|
|
316
398
|
value: string): boolean;
|
|
317
399
|
//#endregion
|
|
318
400
|
//#region src/isObject.d.ts
|
|
@@ -330,6 +412,7 @@ value: string): boolean;
|
|
|
330
412
|
* ```
|
|
331
413
|
*/
|
|
332
414
|
declare function isObject<T>(/** The value to check */
|
|
415
|
+
|
|
333
416
|
value: T): boolean;
|
|
334
417
|
//#endregion
|
|
335
418
|
//#region src/isPascalCase.d.ts
|
|
@@ -345,6 +428,7 @@ value: T): boolean;
|
|
|
345
428
|
* ```
|
|
346
429
|
*/
|
|
347
430
|
declare function isPascalCase(/** The input string */
|
|
431
|
+
|
|
348
432
|
value: string): boolean;
|
|
349
433
|
//#endregion
|
|
350
434
|
//#region src/isProd.d.ts
|
|
@@ -377,6 +461,7 @@ declare function isProd(): boolean;
|
|
|
377
461
|
* ```
|
|
378
462
|
*/
|
|
379
463
|
declare function isSnakeCase(/** The input string */
|
|
464
|
+
|
|
380
465
|
value: string): boolean;
|
|
381
466
|
//#endregion
|
|
382
467
|
//#region src/isString.d.ts
|
|
@@ -405,6 +490,7 @@ value: string): boolean;
|
|
|
405
490
|
* ```
|
|
406
491
|
*/
|
|
407
492
|
declare function isString<T>(/** The value to be checked */
|
|
493
|
+
|
|
408
494
|
value: T): boolean;
|
|
409
495
|
//#endregion
|
|
410
496
|
//#region src/isTest.d.ts
|
|
@@ -424,6 +510,44 @@ value: T): boolean;
|
|
|
424
510
|
*/
|
|
425
511
|
declare function isTest(): boolean;
|
|
426
512
|
//#endregion
|
|
513
|
+
//#region src/isTruthy.d.ts
|
|
514
|
+
/**
|
|
515
|
+
* Checks whether a value is truthy.
|
|
516
|
+
*
|
|
517
|
+
* Falsy values include:
|
|
518
|
+
* - `false`
|
|
519
|
+
* - `0`
|
|
520
|
+
* - `""` (empty string)
|
|
521
|
+
* - `null`
|
|
522
|
+
* - `undefined`
|
|
523
|
+
* - `NaN`
|
|
524
|
+
*
|
|
525
|
+
* @returns `true` if the value is truthy, otherwise `false`.
|
|
526
|
+
*
|
|
527
|
+
* @example
|
|
528
|
+
* ```ts
|
|
529
|
+
* isTruthy(0); // false
|
|
530
|
+
* isTruthy(''); // false
|
|
531
|
+
* isTruthy(null); // false
|
|
532
|
+
* isTruthy(undefined); // false
|
|
533
|
+
* isTruthy(NaN); // false
|
|
534
|
+
* ```
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* ```ts
|
|
538
|
+
* isTruthy(1); // true
|
|
539
|
+
* isTruthy('hello'); // true
|
|
540
|
+
* isTruthy([]); // true
|
|
541
|
+
* isTruthy({}); // true
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
declare function isTruthy<T>(
|
|
545
|
+
/**
|
|
546
|
+
* The value to check.
|
|
547
|
+
*/
|
|
548
|
+
|
|
549
|
+
value: T): boolean;
|
|
550
|
+
//#endregion
|
|
427
551
|
//#region src/isUndefinedOrNull.d.ts
|
|
428
552
|
/**
|
|
429
553
|
* Checks if a value is either null or undefined.
|
|
@@ -439,6 +563,7 @@ declare function isTest(): boolean;
|
|
|
439
563
|
* ```
|
|
440
564
|
*/
|
|
441
565
|
declare function isUndefinedOrNull<T>(/** The value to check */
|
|
566
|
+
|
|
442
567
|
value: T): boolean;
|
|
443
568
|
//#endregion
|
|
444
569
|
//#region src/isUpperCase.d.ts
|
|
@@ -454,6 +579,7 @@ value: T): boolean;
|
|
|
454
579
|
* ```
|
|
455
580
|
*/
|
|
456
581
|
declare function isUpperCase(/** The input string */
|
|
582
|
+
|
|
457
583
|
value: string): boolean;
|
|
458
584
|
//#endregion
|
|
459
585
|
//#region src/isURL.d.ts
|
|
@@ -474,6 +600,7 @@ value: string): boolean;
|
|
|
474
600
|
* ```
|
|
475
601
|
*/
|
|
476
602
|
declare function isURL(/** The string to validate as a URL */
|
|
603
|
+
|
|
477
604
|
value: string): boolean;
|
|
478
605
|
//#endregion
|
|
479
606
|
//#region src/startsWithUppercase.d.ts
|
|
@@ -489,6 +616,7 @@ value: string): boolean;
|
|
|
489
616
|
* ```
|
|
490
617
|
*/
|
|
491
618
|
declare function startsWithUppercase(/** The input string to check */
|
|
619
|
+
|
|
492
620
|
value: string): boolean;
|
|
493
621
|
//#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 };
|
|
622
|
+
export { endsWithPunctuation, hasWhitespace, isAlphabetic, isArray, isBrowser, isCamelCase, isDefined, isDev, isEmail, isEmpty, isEmptyObject, isFalsy, isKebabCase, isLowerCase, isNode, isNonEmptyObject, isNonEmptyString, isNumericString, isObject, isPascalCase, isProd, isSnakeCase, isString, isTest, isTruthy, isURL, isUndefinedOrNull, isUpperCase, startsWithUppercase };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Environment as e}from"@js-utils-kit/types";
|
|
1
|
+
import{Environment as e}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 e==null?!0:typeof e==`string`?e.trim().length===0:Array.isArray(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:Object.prototype.toString.call(e)===`[object Object]`?Object.keys(e).length===0:!1}function d(e){return typeof e==`object`&&!!e&&Object.keys(e).length===0&&!a(e)}function f(e){return!e}function p(e){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test(e)}function m(e){return/^[a-z]+$/.test(e)}function h(){return typeof process<`u`&&process.versions!==null&&process.versions.node!==null}function g(e){return typeof e==`object`&&!!e&&Object.keys(e).length>0&&!a(e)}function _(e){return e!=null&&typeof e==`string`}function v(e,t=!0){return _(e)?typeof e==`string`&&(t?e.trim().length>0:e.length>0):!1}function y(e){return!isNaN(Number(e))&&!isNaN(parseFloat(e))}function b(e){return i(e)&&typeof e==`object`&&!a(e)&&Object.getPrototypeOf(e)===Object.prototype}function x(e){return/^[A-Z][a-zA-Z0-9]*$/.test(e)}function S(){return process.env.NODE_ENV===e.PROD}function C(e){return/^[a-z0-9]+(_[a-z0-9]+)*$/.test(e)}function w(){return process.env.NODE_ENV===e.TEST}function T(e){return!!e}function E(e){return e==null}function D(e){return/^[A-Z]+$/.test(e)}function O(e){try{return new URL(e),!0}catch{return!1}}function k(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 isEmpty,d as isEmptyObject,f as isFalsy,p as isKebabCase,m as isLowerCase,h as isNode,g as isNonEmptyObject,v as isNonEmptyString,y as isNumericString,b as isObject,x as isPascalCase,S as isProd,C as isSnakeCase,_ as isString,w as isTest,T as isTruthy,O as isURL,E as isUndefinedOrNull,D as isUpperCase,k as startsWithUppercase};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@js-utils-kit/valid",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Validation utilities",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"types": "./dist/index.d.cts",
|
|
37
37
|
"exports": {
|
|
38
38
|
".": {
|
|
39
|
-
"
|
|
40
|
-
"
|
|
39
|
+
"require": "./dist/index.cjs",
|
|
40
|
+
"import": "./dist/index.mjs"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@js-utils-kit/types": "1.
|
|
44
|
+
"@js-utils-kit/types": "1.2.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "tsdown",
|