class Person {
name!: string
age!: number
private gender!: "aircraft"
}
This file contains hidden or 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
| import { castArray } from "lodash" | |
| import { isRecord } from "./common" | |
| class BEM { | |
| /** | |
| * | |
| * @returns `class1 class2` | |
| */ | |
| merge(...classNames: Array<string | null | undefined>): string { |
This file contains hidden or 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 EventEmitterListener = (...args: never[]) => void | |
| class EventEmitter<Events extends Record<EventName, EventEmitterListener>, EventName extends keyof Events = keyof Events> { | |
| private callbacks: Partial<Record<keyof never, Set<EventEmitterListener>>> = {} | |
| public on<Event extends keyof Events>(event: Event, callback: Events[Event]) { | |
| this.callbacks[event] ??= new Set | |
| this.callbacks[event]?.add(callback as EventEmitterListener) | |
| } | |
| public off<Event extends keyof Events>(event: Event, callback: Events[Event]) { |
This file contains hidden or 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
| import type { marked } from "marked" | |
| import { Lexer, Renderer } from "marked" | |
| import { createElement, Key, ReactNode, useState } from "react" | |
| // You can use your own external link component. | |
| const ExternalLink = "a" | |
| /** | |
| * | |
| * Tries to create `ReactElement`, if text is not `marked`, return as it is. | |
| * |
This file contains hidden or 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
| /** | |
| * This class represent keys and values mapping (swapping). | |
| * | |
| * ### Research | |
| * - https://www.google.com/search?q=bidirectional+map+js&oq=bidirectional+map+js&aqs=chrome..69i57.2532j0j7&sourceid=chrome&ie=UTF-8 | |
| * - https://www.google.com/search?q=bilateral+mapping+npm | |
| * - https://startfunction.com/2020/11/26/bidirectional-map-javascript/#initialize | |
| * - https://startfunction.com/bidirectional-map-javascript/ | |
| * - https://www.npmjs.com/package/bi-directional-map | |
| */ |
This file contains hidden or 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 SnakeToCamelCase<S extends string> = S extends `${infer Start}_${infer Rest}` ? `${Start}${Capitalize<SnakeToCamelCase<Rest>>}` : S | |
| type SnakeToCamelCase__TEST__ = SnakeToCamelCase<"my_account_profile"> // myAccountProfile |
Reduces (or parses or maps) OpenAPI Swagger Schema to interface (or type) saving links to origin.
I am a laziest person ever, I never wanted to write a bit of boilerplate code.
I dreamed of having a parser of Swagger schema, so I just download it once and I have all actions (or path or endpoints) in one place.
In the beginning, I wrote all endpoints manually, then I wrote this parser to parse to Actions.ts and Schemas.ts files, that was enough for that time.
This file contains hidden or 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 ExtractInterpolations<T extends string> = T extends `${infer _Start}{${infer V}}${infer Rest}` ? V | ExtractInterpolations<Rest> : never | |
| /** | |
| * Interpolates {variable} in string | |
| */ | |
| function interpolate<T extends string>(value: T, vars: Record<ExtractInterpolations<T>, string | number>): string { | |
| const varKeys = Object.keys(vars) as ExtractInterpolations<T>[] | |
| return varKeys.reduce((result: string, next) => result.replace(new RegExp(`{${next}}`, "g"), String(vars[next])), value) | |
| } |