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 axios, { AxiosInstance, AxiosRequestConfig, AxiosStatic, CancelTokenSource } from "axios"; | |
import { useCallback, useEffect, useMemo, useRef } from "react"; | |
type Tokens = { [k: string]: CancelTokenSource | undefined }; | |
const createUid = () => | |
Math.random() | |
.toString(36) | |
.substring(16); |
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 classNamesDedupe from "classnames/dedupe"; | |
import React, { useState, DependencyList, useMemo } from "react"; | |
type ClassArray = ClassValue[]; | |
type ClassDictionary = { [id: string]: any }; | |
export type ClassValue = string | number | ClassDictionary | ClassArray | undefined | null | boolean; | |
export const useClassNames = (dependency: DependencyList, ...classes: ClassValue[]) => |
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 React, { useLayoutEffect, useMemo, useState } from "react"; | |
import { useClassNames } from "styleguide"; | |
type Html = React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>; | |
type StyledArgs<E, T> = ((args: E & T) => string | number) | string | number; | |
function Styled<ExtraProps = unknown, Element = Html>(tag: string) { | |
return ([first, ...placeholders]: TemplateStringsArray, ...a: StyledArgs<Element, ExtraProps>[]) => { | |
return ({ children, ...props }: Html & ExtraProps) => { |
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 React, { useLayoutEffect, useMemo } from "react"; | |
import { useClassNames } from "styleguide"; | |
const AD_REPLACER_R = /(a)(d)/gi; | |
const charsLength = 52; | |
const getAlphabeticChar = (code: number) => String.fromCharCode(code + (code > 25 ? 39 : 97)); | |
function generateAlphabeticName(code: number) { | |
let name = ""; | |
let x; |
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 { add, differenceInDays, eachDayOfInterval, endOfMonth, isSameMonth, startOfMonth, sub } from "date-fns"; | |
import { dec, inc } from "ramda"; | |
import React, { useEffect, useMemo, useState } from "react"; | |
import "styleguide/dist/index.css"; | |
const getWeekDays = (locale: string) => | |
Array.from({ length: 7 }).map((_, v) => | |
new Date(Date.UTC(1970, 0, 5 + v)).toLocaleDateString(locale, { weekday: "short" }) | |
); |
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 Locale = { | |
decimal: "."; | |
thousands: ","; | |
grouping: [3]; | |
currency: ["$", ""]; | |
minus: "-"; | |
numerals?: string; | |
percent?: string; | |
nan?: 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
import { useState, useEffect } from "react"; | |
type Checks = Map<string, boolean>; | |
const createFromMap = (list: Input[]): Checks => new Map(list.map((x) => [x.name!, x.checked!])); | |
const getOnlyChecked = (map: Checks) => { | |
const values: string[] = []; | |
map.forEach((checked, key) => (checked ? values.push(key) : undefined)); | |
return values; |
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
interface PromiseLike<T> { | |
then<R1 = T, R2 = never>( | |
resolve?: ((value: T) => R1 | PromiseLike<R1>) | undefined | null, | |
reject?: ((reason: any) => R2 | PromiseLike<R2>) | undefined | null | |
): PromiseLike<R1 | R2>; | |
} | |
type ReadonlyPromise<T> = PromiseLike<Readonly<T>> | Readonly<T>; | |
const PromiseAll = async <T>(...values: ReadonlyPromise<T>[]): Promise<T> => { |
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
export const equals = (a: any, b: any): boolean => { | |
if (a === b) { | |
return true; | |
} | |
if (a instanceof Date && b instanceof Date) { | |
return a.getTime() === b.getTime(); | |
} | |
if (!a || !b || (typeof a !== "object" && typeof b !== "object")) { | |
return a === b; | |
} |
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
class SymbolMap<K extends object, V> implements Map<K, V> { | |
private map: Map<K, V>; | |
constructor() { | |
this.map = new Map<K, V>(); | |
this.size = 0; | |
} | |
clear(): void { | |
this.map.clear(); |