Add feed validation and display

This commit is contained in:
Jon Staab
2025-04-24 09:39:13 -07:00
parent 17e2bec9b2
commit 4031564c6c
10 changed files with 474 additions and 77 deletions
+14 -1
View File
@@ -10,7 +10,7 @@ export type Nil = null | undefined
export const isNil = <T>(x: T, ...args: unknown[]) => x === undefined || x === null
export const isNotNil = <T>(x: T, ...args: unknown[]) => x !== undefined || x !== null
export const isNotNil = <T>(x: T, ...args: unknown[]) => x !== undefined && x !== null
export const assertNotNil = <T>(x: T, ...args: unknown[]) => x!
@@ -1358,6 +1358,19 @@ export const ellipsize = (s: string, l: number, suffix = "...") => {
return s + suffix
}
/** Displays a list of items with oxford commas and a chosen conjunction */
export const displayList = <T>(xs: T[], conj = "and", n = 6) => {
if (xs.length > n + 2) {
return `${xs.slice(0, n).join(", ")}, ${conj} ${xs.length - n} others`
}
if (xs.length < 3) {
return xs.join(` ${conj} `)
}
return `${xs.slice(0, -1).join(", ")}, ${conj} ${xs.slice(-1).join("")}`
}
/** Generates a hash string from input string */
export const hash = (s: string) =>
Math.abs(s.split("").reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0)).toString()