* Extract the length property in case it's an array or a string. * Extract the size property in case it's a set. * Return null else. * @param value Either an array, set or undefined.
(value: unknown)
| 36 | * @param value Either an array, set or undefined. |
| 37 | */ |
| 38 | function lengthOrSize(value: unknown): number | null { |
| 39 | // non-strict comparison is intentional, to check for both `null` and `undefined` values |
| 40 | if (value == null) { |
| 41 | return null; |
| 42 | } else if (Array.isArray(value) || typeof value === 'string') { |
| 43 | return value.length; |
| 44 | } else if (value instanceof Set) { |
| 45 | return value.size; |
| 46 | } |
| 47 | |
| 48 | return null; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @description |
no test coverage detected
searching dependent graphs…