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 NestedKeys<T> = T extends object | |
? { | |
[K in keyof T]-?: K extends string | |
? T[K] extends infer U | |
? U extends object | |
? K | `${K}.${NestedKeys<U>}` | |
: K | |
: never | |
: never; | |
}[keyof 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
type ProxyType<T> = { | |
[P in keyof T]: Record<string, ProxyType<T[P]> & Callable> & Callable | |
} | |
type Callable = { | |
(arg?: string): string | |
} | |
export function createPath<T extends {}>(_input: T): ProxyType<T> { | |
const proxy: any = (path: 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 PathConfig = { [key: string]: PathConfig } | |
type Collection<T extends PathConfig> = ((id?: string) => string) & { | |
[K in keyof T]: Collection<T[K]> & ((id?: string) => string) | |
} | |
function collection<T extends PathConfig>( | |
basePath: string, | |
name: string, | |
subCollections?: 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
async function copyPageLink() { | |
let pageTitle = document.title | |
let pageURL = window.location.href | |
const str = `<a href="${pageURL}">${pageTitle}</a>` | |
function listener(e) { | |
e.clipboardData.setData('text/html', str) | |
e.clipboardData.setData('text/plain', str) | |
e.preventDefault() | |
} | |
document.addEventListener('copy', listener) |
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
function getStringId(index) { | |
const symbols = | |
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | |
let num = index | |
let id = '' | |
do { | |
id = symbols[num % 62] + id | |
num = Math.floor(num / 62) | |
} while (num > 0) | |
return id |
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
const getN2 = | |
(maxN: number) => | |
(s: string): number => { | |
let hash = 0 | |
for (let i = 0; i < s.length; i++) { | |
// Compute a hash by rotating the previous hash and XORing with the current character | |
hash = (hash << 5) ^ (hash >> 27) ^ s.charCodeAt(i) | |
} |
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 Primitive = string | number | boolean | undefined | null | |
type UnionToIntersection<U> = ( | |
U extends unknown ? (k: U) => void : never | |
) extends (k: infer I) => void | |
? I | |
: never | |
type AddPrefixToKeys< | |
Prefix extends 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 esbuild from 'esbuild' | |
import { firebaseConfig } from '@lumiere/config' | |
import { initializeApp } from 'firebase-admin/app' | |
import { getAuth } from 'firebase-admin/auth' | |
import { expect } from '@playwright/test' | |
import { test } from './setup' | |
const app = initializeApp() | |
const auth = getAuth(app) |
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
const objectify = <T, EXT extends Object>( | |
f: (v: string) => T, | |
ext?: EXT, | |
root?: string | |
): Record<string, T> & EXT => | |
new Proxy(f, { | |
get: (target, prop) => | |
typeof prop === 'string' | |
? ext?.[prop] || target(prop as string) | |
: () => root, |
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
Object.entries(import.meta.glob('../locales/*.yaml')) | |
.map(([path, f]) => [/locales\/(.+?)\.yaml/.exec(path)?.[1], f] as any) | |
.forEach(([key, f]) => { | |
console.log({ key, f }) | |
locales[key] = true | |
if (key !== 'en') register(key, f) | |
}) |
NewerOlder