1111 * }
1212 * ```
1313 *
14- * @param value The value to check
14+ * @param value - The value to check
1515 */
1616const isRecord = (
1717 value : unknown
@@ -35,7 +35,7 @@ const isRecord = (
3535 * }
3636 * ```
3737 *
38- * @param value The value to check
38+ * @param value - The value to check
3939 */
4040const isString = ( value : unknown ) : value is string => {
4141 return typeof value === 'string' ;
@@ -54,7 +54,7 @@ const isString = (value: unknown): value is string => {
5454 * }
5555 * ```
5656 *
57- * @param value The value to check
57+ * @param value - The value to check
5858 */
5959const isNumber = ( value : unknown ) : value is number => {
6060 return typeof value === 'number' ;
@@ -73,7 +73,7 @@ const isNumber = (value: unknown): value is number => {
7373 * }
7474 * ```
7575 *
76- * @param value The value to check
76+ * @param value - The value to check
7777 */
7878const isIntegerNumber = ( value : unknown ) : value is number => {
7979 return isNumber ( value ) && Number . isInteger ( value ) ;
@@ -94,7 +94,7 @@ const isIntegerNumber = (value: unknown): value is number => {
9494 *
9595 * @see https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/types-grammar/ch4.md#toboolean
9696 *
97- * @param value The value to check
97+ * @param value - The value to check
9898 */
9999const isTruthy = ( value : unknown ) : boolean => {
100100 if ( isString ( value ) ) {
@@ -129,7 +129,7 @@ const isTruthy = (value: unknown): boolean => {
129129 * }
130130 * ```
131131 *
132- * @param value The value to check
132+ * @param value - The value to check
133133 */
134134const isNull = ( value : unknown ) : value is null => {
135135 return Object . is ( value , null ) ;
@@ -148,12 +148,34 @@ const isNull = (value: unknown): value is null => {
148148 * }
149149 * ```
150150 *
151- * @param value The value to check
151+ * @param value - The value to check
152152 */
153153const isNullOrUndefined = ( value : unknown ) : value is null | undefined => {
154154 return isNull ( value ) || Object . is ( value , undefined ) ;
155155} ;
156156
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+
157179/**
158180 * Get the type of a value as a string.
159181 *
@@ -167,7 +189,7 @@ const isNullOrUndefined = (value: unknown): value is null | undefined => {
167189 * const unknownType = getType(Symbol('foo')); // 'unknown'
168190 * ```
169191 *
170- * @param value The value to check
192+ * @param value - The value to check
171193 */
172194const getType = ( value : unknown ) : string => {
173195 if ( Array . isArray ( value ) ) {
@@ -210,8 +232,8 @@ const getType = (value: unknown): string => {
210232 * const otherEqual = areArraysEqual(otherLeft, otherRight); // false
211233 * ```
212234 *
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
215237 */
216238const areArraysEqual = ( left : unknown [ ] , right : unknown [ ] ) : boolean => {
217239 if ( left . length !== right . length ) {
@@ -237,8 +259,8 @@ const areArraysEqual = (left: unknown[], right: unknown[]): boolean => {
237259 * const otherEqual = areRecordsEqual(otherLeft, otherRight); // false
238260 * ```
239261 *
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
242264 */
243265const areRecordsEqual = (
244266 left : Record < string , unknown > ,
@@ -283,8 +305,8 @@ const areRecordsEqual = (
283305 * const yetAnotherEqual = isStrictEqual(yetAnotherLeft, yetAnotherRight); // true
284306 * ```
285307 *
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
288310 */
289311const isStrictEqual = ( left : unknown , right : unknown ) : boolean => {
290312 if ( left === right ) {
@@ -314,6 +336,7 @@ export {
314336 isTruthy ,
315337 isNull ,
316338 isNullOrUndefined ,
339+ isStringUndefinedNullEmpty ,
317340 getType ,
318341 isStrictEqual ,
319342} ;
0 commit comments