Format code

This commit is contained in:
Jon Staab
2026-03-06 09:16:15 -08:00
parent fa7b6bb526
commit 54ac2274d3
2 changed files with 26 additions and 9 deletions
+24 -7
View File
@@ -31,15 +31,32 @@ export type PublishedRoomMeta = Omit<RoomMeta, "event"> & {
event: TrustedEvent
}
export const makeRoomMeta = (room: Partial<RoomMeta> = {}): RoomMeta => {
const v = ["a", "e", "i", "o", "u", "ay", "ey", "oy", "ou", "ia", "ea", "ough", "oo", "ee", "argh"]
const c = ["p", "b", "t", "d", "k", "g", "ch", "sh", "th", "f", "v", "s", "z", "l", "r", "m", "n", "pl", "bl", "cl", "gl", "pr", "br", "tr", "dr", "kr", "gr", "fl", "sl", "fr", "thr", "str", "sk", "sp", "st"]
const n = 6 + Math.random()*2|0, s = [c, v]
Math.random() < 0.5 && s.reverse()
const pronounceableId = Array.from({length: n}, (_, i) => s[i%2].splice(Math.random()*s[i%2].length|0, 1)).join("") + (1 + Math.floor(Math.random() * 9))
const vowels = "a,e,i,o,u,ay,ey,oy,ou,ia,ea,ough,oo,ee,argh".split(",")
const consonants =
"p,b,t,d,k,g,ch,sh,th,f,v,s,z,l,r,m,n,pl,bl,cl,gl,pr,br,tr,dr,kr,gr,fl,sl,fr,thr,str,sk,sp,st".split(
",",
)
export const generateH = () => {
const n = (6 + Math.random() * 2) | 0
const s = [consonants, vowels]
if (Math.random() < 0.5) {
s.reverse()
}
return (
Array.from({length: n}, (_, i) =>
s[i % 2].splice((Math.random() * s[i % 2].length) | 0, 1),
).join("") +
(1 + Math.floor(Math.random() * 9))
)
}
export const makeRoomMeta = (room: Partial<RoomMeta> = {}): RoomMeta => {
return {
h: room.h ?? pronounceableId,
h: room.h ?? generateH(),
...room,
}
}