11
11
* }
12
12
* ```
13
13
*
14
- * @param value The value to check
14
+ * @param value - The value to check
15
15
*/
16
16
const isRecord = (
17
17
value : unknown
@@ -35,7 +35,7 @@ const isRecord = (
35
35
* }
36
36
* ```
37
37
*
38
- * @param value The value to check
38
+ * @param value - The value to check
39
39
*/
40
40
const isString = ( value : unknown ) : value is string => {
41
41
return typeof value === 'string' ;
@@ -54,7 +54,7 @@ const isString = (value: unknown): value is string => {
54
54
* }
55
55
* ```
56
56
*
57
- * @param value The value to check
57
+ * @param value - The value to check
58
58
*/
59
59
const isNumber = ( value : unknown ) : value is number => {
60
60
return typeof value === 'number' ;
@@ -73,7 +73,7 @@ const isNumber = (value: unknown): value is number => {
73
73
* }
74
74
* ```
75
75
*
76
- * @param value The value to check
76
+ * @param value - The value to check
77
77
*/
78
78
const isIntegerNumber = ( value : unknown ) : value is number => {
79
79
return isNumber ( value ) && Number . isInteger ( value ) ;
@@ -94,7 +94,7 @@ const isIntegerNumber = (value: unknown): value is number => {
94
94
*
95
95
* @see https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/types-grammar/ch4.md#toboolean
96
96
*
97
- * @param value The value to check
97
+ * @param value - The value to check
98
98
*/
99
99
const isTruthy = ( value : unknown ) : boolean => {
100
100
if ( isString ( value ) ) {
@@ -129,7 +129,7 @@ const isTruthy = (value: unknown): boolean => {
129
129
* }
130
130
* ```
131
131
*
132
- * @param value The value to check
132
+ * @param value - The value to check
133
133
*/
134
134
const isNull = ( value : unknown ) : value is null => {
135
135
return Object . is ( value , null ) ;
@@ -148,12 +148,34 @@ const isNull = (value: unknown): value is null => {
148
148
* }
149
149
* ```
150
150
*
151
- * @param value The value to check
151
+ * @param value - The value to check
152
152
*/
153
153
const isNullOrUndefined = ( value : unknown ) : value is null | undefined => {
154
154
return isNull ( value ) || Object . is ( value , undefined ) ;
155
155
} ;
156
156
157
+ /**
158
+ * Check if string is undefined, null, empty.
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * import { isStringUndefinedNullEmpty } from '@aws-lambda-powertools/commons/typeUtils';
163
+ *
164
+ * const value = 'foo';
165
+ * if (isStringUndefinedNullEmpty(value)) {
166
+ * // value is either undefined, null, or an empty string
167
+ * }
168
+ * ```
169
+ *
170
+ * @param value - The value to check
171
+ */
172
+ const isStringUndefinedNullEmpty = ( value : unknown ) => {
173
+ if ( isNullOrUndefined ( value ) ) return true ;
174
+ if ( ! isString ( value ) ) return true ;
175
+ if ( value . trim ( ) . length === 0 ) return true ;
176
+ return false ;
177
+ } ;
178
+
157
179
/**
158
180
* Get the type of a value as a string.
159
181
*
@@ -167,7 +189,7 @@ const isNullOrUndefined = (value: unknown): value is null | undefined => {
167
189
* const unknownType = getType(Symbol('foo')); // 'unknown'
168
190
* ```
169
191
*
170
- * @param value The value to check
192
+ * @param value - The value to check
171
193
*/
172
194
const getType = ( value : unknown ) : string => {
173
195
if ( Array . isArray ( value ) ) {
@@ -210,8 +232,8 @@ const getType = (value: unknown): string => {
210
232
* const otherEqual = areArraysEqual(otherLeft, otherRight); // false
211
233
* ```
212
234
*
213
- * @param left The left array to compare
214
- * @param right The right array to compare
235
+ * @param left - The left array to compare
236
+ * @param right - The right array to compare
215
237
*/
216
238
const areArraysEqual = ( left : unknown [ ] , right : unknown [ ] ) : boolean => {
217
239
if ( left . length !== right . length ) {
@@ -237,8 +259,8 @@ const areArraysEqual = (left: unknown[], right: unknown[]): boolean => {
237
259
* const otherEqual = areRecordsEqual(otherLeft, otherRight); // false
238
260
* ```
239
261
*
240
- * @param left The left record to compare
241
- * @param right The right record to compare
262
+ * @param left - The left record to compare
263
+ * @param right - The right record to compare
242
264
*/
243
265
const areRecordsEqual = (
244
266
left : Record < string , unknown > ,
@@ -283,8 +305,8 @@ const areRecordsEqual = (
283
305
* const yetAnotherEqual = isStrictEqual(yetAnotherLeft, yetAnotherRight); // true
284
306
* ```
285
307
*
286
- * @param left Left side of strict equality comparison
287
- * @param right Right side of strict equality comparison
308
+ * @param left - Left side of strict equality comparison
309
+ * @param right - Right side of strict equality comparison
288
310
*/
289
311
const isStrictEqual = ( left : unknown , right : unknown ) : boolean => {
290
312
if ( left === right ) {
@@ -314,6 +336,7 @@ export {
314
336
isTruthy ,
315
337
isNull ,
316
338
isNullOrUndefined ,
339
+ isStringUndefinedNullEmpty ,
317
340
getType ,
318
341
isStrictEqual ,
319
342
} ;
0 commit comments