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
/** | |
* Checks if type `T` is the `any` type. | |
* @see https://stackoverflow.com/a/49928360/3406963 | |
* @see https://github.com/dsherret/conditional-type-checks/blob/main/mod.ts | |
*/ | |
type IsAny<T> = 0 extends 1 & T ? true : false | |
type Example<S> = IsAny<S> extends false ? 'ok' : never | |
/** |
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
type UnionToType< | |
U extends Record<string, unknown> | |
> = { | |
[K in (U extends unknown ? keyof U : never)]: U extends unknown | |
? K extends keyof U ? U[K] : never | |
: never | |
} | |
type A = { | |
a: string |
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
type Writeable<T> = { | |
-readonly [Key in keyof T]: T[Key] | |
} | |
type DeepWriteable<T> = { | |
-readonly [Key in keyof T]: DeepWriteable<T[Key]> | |
} |
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
// @see https://stackoverflow.com/questions/60449479/typescript-extract-type-from-object-by-object-path-in-tuple | |
type ExtractType<O, T extends Array<any>> = { | |
[K in keyof O]: ((...a: T) => any) extends (a: any, ...args: infer Tail) => any | |
? Tail['length'] extends 0 | |
? O[K] | |
: ExtractType<O[K], Tail> | |
: never | |
}[T[0]] |
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
type NonEmptyArray<T> = [T, ...T[]] |
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
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never |
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
export type RequiredField<T, K extends keyof T> = T & Required<Pick<T, K>> |
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
// @see https://stackoverflow.com/questions/71459572/not-possible-to-detect-webview-with-javascript-and-user-agent-on-old-android-ver | |
const rules = [ | |
// If it says it's a webview, let's go with that. | |
'WebView', | |
// iOS webview will be the same as safari but missing "Safari". | |
'(iPhone|iPod|iPad)(?!.*Safari)', | |
// https://developer.chrome.com/docs/multidevice/user-agent/#webview_user_agent | |
'Android.*Version/[0-9].[0-9]', | |
// Also, we should save the wv detected for Lollipop. | |
// Android Lollipop and Above: webview will be the same as native, |
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
export const getCirclePath = (cx: number | undefined = 0, cy: number | undefined = 0, r: number | undefined = 0): string => { | |
return `M ${cx - r}, ${cy} a ${r}, ${r} 0 1,0 ${r * 2},0 a ${r},${r} 0 1,0 ${r * -2},0` | |
} |