테스트 환경
export const mapEntries = <T, U>( | |
obj: Record<string, T>, | |
fn: (entry: [string, T]) => [string, U], | |
) => Object.fromEntries(Object.entries(obj).map(fn)) |
const getUrl = (elem: Element) => elem.getAttribute("href")!.split("?")[0] | |
const setQuery = (selector: string, query: string) => () => { | |
const elem = document.querySelector(selector) | |
if (!elem) { | |
console.log(`elem with ${selector} not found`) | |
return | |
} | |
const newSearchParams = new URLSearchParams({ q: query }) | |
elem.setAttribute("href", `${getUrl(elem)}?${newSearchParams}`) |
테스트 환경
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-run --allow-env --unstable | |
import { Command } from "https://deno.land/x/cliffy@v0.25.7/command/mod.ts" | |
import { dirname, join } from "https://deno.land/std@0.190.0/path/mod.ts" | |
import { c, p } from "https://deno.land/x/copb@v1.0.1/mod.ts" | |
const mapKeys = | |
<A>(f: (k: string) => string) => (record: Readonly<Record<string, A>>): Record<string, A> => | |
Object.fromEntries(Object.entries(record).map(([k, v]) => [f(k), v])) |
import { | |
bgBrightRed, | |
bold, | |
brightGreen, | |
brightRed, | |
brightWhite, | |
brightYellow, | |
} from "https://deno.land/std@0.186.0/fmt/colors.ts" | |
import { c, p } from "https://deno.land/x/copb@v1.0.1/mod.ts" | |
import { match } from "npm:ts-pattern" |
declare global { | |
interface PromiseConstructor { | |
resolve<const T>(value: T): Promise<Awaited<T>> | |
} | |
} |
Deno는 Node.js를 만든 Ryan Dhal의 차세대 자바스크립트/타입스크립트 런타임입니다.
import { z } from "https://deno.land/x/zod@v3.20.5/mod.ts" | |
import { HasType } from "./type_helper.ts" | |
export type AnyZodEffect = z.ZodEffects<z.ZodTypeAny, unknown, unknown> | |
export type ObjectSchema = z.ZodObject<z.ZodRawShape> | |
/** Recursively checks if schema has a transform effect for either the whole object or a property. */ | |
export type HasZodEffect<T> = T extends ObjectSchema | |
? HasType<T["shape"], AnyZodEffect> extends true ? true |
import { assertEquals } from "https://deno.land/std@0.177.0/testing/asserts.ts" | |
/** @example | |
* const input = [1, 1, -1, 1, -1, 1] | |
* assertEquals(span(input, (x) => x > 0), [[1, 1], [-1, 1, -1, 1]]) | |
*/ | |
export const span = <T>(array: T[], predicate: (line: T) => boolean): [T[], T[]] => { | |
const index = array.findIndex((line) => !predicate(line)) | |
const before = index === -1 ? array : array.slice(0, index) | |
const after = index === -1 ? [] : array.slice(index) |
import { assertEquals } from "https://deno.land/std@0.177.0/testing/asserts.ts" | |
import { outdent } from "npm:outdent" | |
import { trisection } from "./partition_utils.ts" | |
import { walk } from "https://deno.land/std@0.182.0/fs/walk.ts" | |
import { asynciter } from "https://deno.land/x/asynciter@0.0.15/asynciter.ts" | |
import { fromFileUrl, join, resolve } from "https://deno.land/std@0.177.0/path/mod.ts" | |
export const SCRIPT_DIR = fromFileUrl(import.meta.url) | |
export const TOP_DIR = resolve(SCRIPT_DIR, "..", "..", "..") | |
export const JSON_DIR = join(TOP_DIR, "data") |