| 26 | * General Utility class |
| 27 | */ |
| 28 | export default class Utils { |
| 29 | /** |
| 30 | * Removes an element from a 1D array |
| 31 | * |
| 32 | * ```js |
| 33 | * |
| 34 | * ``` |
| 35 | * @param arr The array to filter. |
| 36 | * @param index The index to filter by. |
| 37 | */ |
| 38 | removeElementFromArray(arr: ArrayType1D, index: number): ArrayType1D { |
| 39 | const newArr = arr.filter((_, i: number) => i != index); |
| 40 | return newArr; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Check if value is a string. |
| 45 | * @param value The value to check. |
| 46 | * @returns |
| 47 | */ |
| 48 | isString<T>(value: T): boolean { |
| 49 | return typeof value === "string"; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Checks if value is a number. |
| 54 | * @param value The value to check. |
| 55 | * @returns |
| 56 | */ |
| 57 | isNumber<T>(value: T): boolean { |
| 58 | return typeof value === "number" && isFinite(value); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Checks if value is an object. |
| 63 | * @param value The value to check. |
| 64 | * @returns |
| 65 | */ |
| 66 | isObject(value: any): boolean { |
| 67 | return value && typeof value === "object" && value.constructor && value.constructor.name === "Object"; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Checks if a value is null |
| 72 | * @param value The value to check. |
| 73 | * @returns |
| 74 | */ |
| 75 | isNull<T>(value: T): boolean { |
| 76 | return value === null; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Checks if a value is undefined |
| 81 | * @param value The value to check. |
| 82 | * @returns |
| 83 | */ |
| 84 | isUndefined<T>(value: T): boolean { |
| 85 | return typeof value === "undefined"; |
nothing calls this directly
no outgoing calls
no test coverage detected