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 fruits = ['Apple 🍏', 'Banana 🍌', 'Strawberry 🍓', 'Blueberry 🫐']; | |
// Wybieranie po indexie | |
✅ fruits.at(0); // Apple 🍏 | |
✅ fruits.at(3); // Blueberry 🫐 | |
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
.box { | |
background-image: url("large-balloons.jpg"); | |
background-image: image-set( | |
url("large-balloons.avif") type("image/avif"), | |
url("large-balloons.jpg") type("image/jpeg")); | |
} |
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 assert<T>( | |
condition: T, | |
message, | |
): asserts condition is Exclude<T, null | undefined> { | |
if (condition === null || condition === undefined) { | |
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
type Recurse<T> = | |
T extends { __rec: unknown } | |
? Recurse<_Recurse<T>> | |
: T; | |
type _Recurse<T> = | |
T extends { __rec: never } ? never | |
: T extends { __rec: { __rec: infer U } } ? { __rec: _Recurse<U> } | |
: T extends { __rec: infer U } ? U | |
: 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
// Usage: type CamelCase = CamelizeString<'snake_case'> -> snakeCase | |
export type CamelizeString<Value> = | |
Value extends string ? | |
Value extends `${infer T}_${infer U}` ? | |
`${T}${Capitalize<CamelizeString<U>>}` : | |
Value : Value | |
type KeyOf<Object extends Record<string, unknown>> = Extract<keyof Object, 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 ParseRouteParameters<Route> = Route extends `${string}/:${infer Param}/${infer Rest}` | |
? { [Entry in Param | keyof ParseRouteParameters<`/${Rest}`>]: string } | |
: Route extends `${string}/:${infer Param}` | |
? { [Entry in Param]: string } | |
: {}; | |
type X = ParseRouteParameters<'/api/:what/:is/notyou/:happening'>; | |
// type X = { | |
// what: 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 UnionFromTuple<Tuple extends readonly (string | number | boolean)[]> = Tuple[number]; | |
const animals = ['🦙', '🦑', '🐍', '🦘'] as const; | |
type Animal = UnionFromTuple<typeof animals>; | |
// type Animal = '🦙' | '🦑' | '🐍' | '🦘' |