moderator-toolbox-nxg-for-reddit / modules/announcements/noteUtils

modules/announcements/noteUtils

Functions

appendNote()

appendNote(existing, note): AnnouncementsWikiData

Defined in: extension/data/modules/announcements/noteUtils.ts:51

Returns a new announcements document with note prepended to the existing notes (newest first), preserving version. Does not mutate existing.

Parameters

existing

AnnouncementsWikiData

The current announcements document.

note

AnnouncementNote

The note to add.

Returns

AnnouncementsWikiData


filterByPublishAt()

filterByPublishAt(notes, nowSeconds): AnnouncementNote[]

Defined in: extension/data/modules/announcements/noteUtils.ts:85

Filters out scheduled notes whose publishAt is still in the future - the client-side half of “publish later”. A note is eligible when it has no publishAt or its publishAt is at/before nowSeconds.

Parameters

notes

AnnouncementNote[]

Notes to filter.

nowSeconds

number

Current time in epoch seconds.

Returns

AnnouncementNote[]


formatDateStamp()

formatDateStamp(date): string

Defined in: extension/data/modules/announcements/noteUtils.ts:15

Formats a Date as a YYYY-MM-DD string in local time. Local time is intentional: announcement ids are human-facing labels keyed to the publishing mod’s calendar day, not an absolute instant.

Parameters

date

Date

The date to format.

Returns

string


generateAnnouncementId()

generateAnnouncementId(notes, today?): string

Defined in: extension/data/modules/announcements/noteUtils.ts:33

Generates a stable, collision-free announcement id of the form YYYY-MM-DD-N, where N is one greater than the highest existing index for today’s date stamp.

Using the highest index (not the count) is what keeps ids unique: removing a note lowers the count, so a count-based scheme could hand out an index a surviving note already uses - and removeAnnouncement filters by id, so a duplicate id would strip both. Indexing past the max never reuses a freed slot within the day.

Parameters

notes

AnnouncementNote[]

Existing notes (used only to find today’s highest index).

today?

Date = ...

The reference date; defaults to now. Injectable for testing.

Returns

string


isHttpUrl()

isHttpUrl(value): boolean

Defined in: extension/data/modules/announcements/noteUtils.ts:69

Returns true only if value parses as an absolute http:/https: URL. Used both to validate the author-supplied link and to guard it at render time: other schemes (notably javascript: and data:) parse fine via URL but must never become a clickable href, since the card renders in the user’s Reddit page context.

Parameters

value

string

The candidate URL string.

Returns

boolean