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
function error(message: string): never { | |
throw new Error(message) | |
} |
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
const enum LogLevel { | |
Info = 'info', | |
Warning = 'warning', | |
Error = 'error', | |
} | |
class Logger { | |
private static logStyle = { | |
info: 'color: #3498db; font-weight: bold;', | |
warning: 'color: #f39c12; font-weight: bold;', |
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
function transformToSnakeCase(input: string): string { | |
return input | |
.replace(/([a-z])([A-Z])/g, '$1_$2') // Insert underscore between lowercase and uppercase letters | |
.replace(/([0-9]+)([a-zA-Z])/g, '$1_$2') // Insert underscore between digits and letters | |
.replace(/([a-zA-Z])([0-9]+)/g, '$1_$2') // Insert underscore between letters and digits | |
.toUpperCase(); // Convert the result to uppercase | |
} |
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 Join<K, P> = K extends string | number ? | |
P extends string | number ? | |
`${K}${"" extends P ? "" : "."}${P}` | |
: never : never; | |
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...0[]] | |
type Paths<T, D extends number = 10> = [D] extends [never] ? never : T extends object ? | |
{ [K in keyof T]-?: K extends string | number ?`${K}` | Join<K, Paths<T[K], Prev[D]>> : never }[keyof 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
function isLeapYear(year: number): boolean { | |
return (year % 400 === 0) || (year % 100 !== 0 && year % 4 === 0); | |
} |