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
class FindAndPopCollection<T> { | |
private _array: T[]; | |
constructor(_array: T[]) { | |
this._array = _array.slice(); | |
} | |
findAndRemove(predicate: (value: T) => boolean) { | |
const index = this._array.findIndex(predicate); | |
if (index !== -1) { |
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
import { convertLongMonthDayToShort } from "server/domain/client/convertLongMonthDayToShort"; | |
describe("convertLongMonthDayToShort", () => { | |
it.each([ | |
[undefined, undefined], | |
[null, null], | |
["1/1", "1/1"], | |
["8/31", "8/31"], | |
["3/31", "3/31"], | |
["4/30", "4/30"], |
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
import type { MatcherFunction } from "expect"; | |
function assertIsElement(el: unknown): asserts el is HTMLElement { | |
const isElement = el instanceof HTMLElement; | |
if (!isElement) { | |
throw new TypeError("Not an HTMLElement"); | |
} | |
} | |
export const toBeAriaDisabled: MatcherFunction<[element: unknown]> = function (element) { |
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 mockServer = nock("http://localhost", { allowUnmocked: false }); | |
mockServer.put(`/api/clients/${client.id}/bills/bulk`).reply(200, bills); | |
const getCapturedPayload = getNockPayloadCapturer(mockServer); | |
await userEvent.click(screen.getByRole("button", { name: "Save" })); | |
const capturedPayload = await waitFor(getCapturedPayload); |
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
// https://twitter.com/GabrielVergnaud/status/1622899119856525313 | |
type Prettify<T> = { | |
[K in keyof T]: 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
type ValidateShape<T, Shape> = | |
T extends Shape ? | |
Exclude<keyof T, keyof Shape> extends never ? | |
T : never : never; | |
type Exact<A, B> = | |
A extends B ? | |
B extends A ? A | |
: never | |
: 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
import React from "react"; | |
import { BrowserRouter, Redirect } from "react-router-dom"; | |
import { CompatRouter, Routes, Route } from "react-router-dom-v5-compat"; | |
import { Internal1 } from "./Internal1"; | |
import { Loadable } from "./Loadable"; | |
const Loading = () => ( | |
<div style={{ width: "100%", height: "100vh", background: "red" }}>Loading</div> | |
); |
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
import { useRef, useState, useEffect } from "react"; | |
export function useIntersectionObserver<THTMLElement extends HTMLElement>( | |
options?: IntersectionObserverInit, | |
) { | |
const ref = useRef<THTMLElement>(null); | |
const [entry, setEntry] = useState<IntersectionObserverEntry | undefined>(); | |
const optionsRef = useRef(options); |
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
import { useEffect } from "react"; | |
function useEmulateMediaPrint() { | |
useEffect(() => { | |
const modifiedCSSRules: Map<CSSMediaRule, string> = new Map(); | |
for (const styleSheet of document.styleSheets) { | |
for (const cssRule of styleSheet.cssRules) { | |
if (cssRule instanceof CSSMediaRule) { |
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 function moveCursorWithinInput(input, position) { | |
if (input.setSelectionRange) { | |
input.focus(); | |
input.setSelectionRange(position, position); | |
} else if (input.createTextRange) { | |
var range = input.createTextRange(); | |
range.collapse(true); | |
range.moveEnd('character', position); | |
range.moveStart('character', position); | |
range.select(); |
NewerOlder