1
0
Fork 0
forked from Mirrors/gomuks

web/util: remove oxfordHumanJoin

This commit is contained in:
Tulir Asokan 2024-12-08 17:34:11 +02:00
parent 332d71cadd
commit 3e460da67d
3 changed files with 4 additions and 7 deletions

View file

@ -15,18 +15,18 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import { PinnedEventsContent } from "@/api/types"
import { listDiff } from "@/util/diff.ts"
import { oxfordHumanJoin } from "@/util/join.ts"
import { humanJoin } from "@/util/join.ts"
import EventContentProps from "./props.ts"
function renderPinChanges(content: PinnedEventsContent, prevContent?: PinnedEventsContent): string {
const [added, removed] = listDiff(content.pinned ?? [], prevContent?.pinned ?? [])
if (added.length) {
if (removed.length) {
return `pinned ${oxfordHumanJoin(added)} and unpinned ${oxfordHumanJoin(removed)}`
return `pinned ${humanJoin(added)} and unpinned ${humanJoin(removed)}`
}
return `pinned ${oxfordHumanJoin(added)}`
return `pinned ${humanJoin(added)}`
} else if (removed.length) {
return `unpinned ${oxfordHumanJoin(removed)}`
return `unpinned ${humanJoin(removed)}`
} else {
return "sent a no-op pin event"
}

View file

@ -25,5 +25,3 @@ export function humanJoin(arr: string[], sep: string = ", ", lastSep: string = "
}
return arr.slice(0, -1).join(sep) + lastSep + arr[arr.length - 1]
}
export const oxfordHumanJoin = (arr: string[]) => humanJoin(arr, ", ", ", and ")

View file

@ -27,5 +27,4 @@ export function humanJoinReact(
</Fragment>)
}
export const oxfordHumanJoinReact = (arr: (string | JSX.Element)[]) => humanJoinReact(arr, ", ", ", and ")
export const joinReact = (arr: (string | JSX.Element)[]) => humanJoinReact(arr, " ", " ")