Skip to content

Instantly share code, notes, and snippets.

@sklinov
sklinov / spinner.svg
Created June 23, 2023 07:43
Native spinning svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sklinov
sklinov / rgbToHex.js
Created March 28, 2022 08:40
Bitwise RGB to HEX conversion
/*
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)}`;
}
@sklinov
sklinov / isType.ts
Last active May 20, 2021 09:25
isType typeguard
/**
*
* @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)
}