diff options
Diffstat (limited to 'src/lib/strings')
-rw-r--r-- | src/lib/strings/rich-text-detection.ts | 2 | ||||
-rw-r--r-- | src/lib/strings/time.ts | 14 | ||||
-rw-r--r-- | src/lib/strings/url-helpers.ts | 12 |
3 files changed, 21 insertions, 7 deletions
diff --git a/src/lib/strings/rich-text-detection.ts b/src/lib/strings/rich-text-detection.ts index 51d09ec5d..931617cd1 100644 --- a/src/lib/strings/rich-text-detection.ts +++ b/src/lib/strings/rich-text-detection.ts @@ -27,7 +27,7 @@ export function detectLinkables(text: string): DetectedLinkable[] { matchValue = matchValue.slice(1) } - // strip ending puncuation + // strip ending punctuation if (/[.,;!?]$/.test(matchValue)) { matchValue = matchValue.slice(0, -1) } diff --git a/src/lib/strings/time.ts b/src/lib/strings/time.ts index 588b84459..3f2847558 100644 --- a/src/lib/strings/time.ts +++ b/src/lib/strings/time.ts @@ -1,8 +1,8 @@ const MINUTE = 60 const HOUR = MINUTE * 60 const DAY = HOUR * 24 -const MONTH = DAY * 28 -const YEAR = DAY * 365 +const WEEK = DAY * 7 + export function ago(date: number | string | Date): string { let ts: number if (typeof date === 'string') { @@ -19,12 +19,14 @@ export function ago(date: number | string | Date): string { return `${Math.floor(diffSeconds / MINUTE)}m` } else if (diffSeconds < DAY) { return `${Math.floor(diffSeconds / HOUR)}h` - } else if (diffSeconds < MONTH) { + } else if (diffSeconds < WEEK) { return `${Math.floor(diffSeconds / DAY)}d` - } else if (diffSeconds < YEAR) { - return `${Math.floor(diffSeconds / MONTH)}mo` } else { - return new Date(ts).toLocaleDateString() + return new Date(ts).toLocaleDateString('en-us', { + year: 'numeric', + month: 'short', + day: 'numeric', + }) } } diff --git a/src/lib/strings/url-helpers.ts b/src/lib/strings/url-helpers.ts index a5412920e..d6d43b89d 100644 --- a/src/lib/strings/url-helpers.ts +++ b/src/lib/strings/url-helpers.ts @@ -82,6 +82,18 @@ export function isBskyPostUrl(url: string): boolean { return false } +export function isBskyCustomFeedUrl(url: string): boolean { + if (isBskyAppUrl(url)) { + try { + const urlp = new URL(url) + return /profile\/(?<name>[^/]+)\/feed\/(?<rkey>[^/]+)/i.test( + urlp.pathname, + ) + } catch {} + } + return false +} + export function convertBskyAppUrlIfNeeded(url: string): string { if (isBskyAppUrl(url)) { try { |