Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Picked from https://blog.logrocket.com/interesting-use-cases-for-javascript-bitwise-operators/ | |
**/ | |
function rgbToHex ([red = 0, green = 0, blue = 0] = []) { | |
return `#${(red << 16 | green << 8 | blue).toString(16)}`; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @param {any} item item you want to typecheck | |
* @param {(keyof T)[]} keys keys that should be present in the type and not be undefined | |
* @returns {boolean} Later in code item is of T type on success | |
*/ | |
export const isType = <T extends unknown> (item: unknown, keys: (keyof T)[]):item is T => { | |
return item !== null && keys.every(key => (item as T)[key as keyof T] !== undefined) | |
} |