• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

oetherington / bluesky-embed-react / 12323894398

13 Dec 2024 10:20PM UTC coverage: 65.369% (-1.6%) from 67.008%
12323894398

Pull #19

github

web-flow
Merge e4e374ad6 into afedac89b
Pull Request #19: Bump react, react-dom and @types/react

53 of 123 branches covered (43.09%)

Branch coverage included in aggregate %.

266 of 365 relevant lines covered (72.88%)

65.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.81
/src/helpers.ts
1
import type { CSSProperties } from "react";
2

3
export type BlueskyListPosition = {
4
        index: number;
5
        total: number;
6
};
7

8
export const getBlueskyListStyles = (
33✔
9
        listPosition: BlueskyListPosition | undefined,
10
        borderRadius: string | number,
11
): CSSProperties => {
12
        const listStyles: CSSProperties = {};
245✔
13
        if (listPosition) {
245!
14
                const { index, total } = listPosition;
×
15
                if (index === 0) {
×
16
                        listStyles.borderTopLeftRadius = borderRadius;
×
17
                        listStyles.borderTopRightRadius = borderRadius;
×
18
                }
19
                if (index === total - 1) {
×
20
                        listStyles.borderBottomLeftRadius = borderRadius;
×
21
                        listStyles.borderBottomRightRadius = borderRadius;
×
22
                }
23
                if (index > 0) {
×
24
                        listStyles.borderTopWidth = 0;
×
25
                }
26
        } else {
27
                listStyles.borderRadius = borderRadius;
245✔
28
        }
29
        return listStyles;
245✔
30
};
31

32
export const getBlueskyProfileUrl = (app: string, userHandleOrDid: string) =>
33✔
33
        `${app}/profile/${userHandleOrDid}`;
123✔
34

35
export const getBlueskyTagUrl = (app: string, tagName: string) =>
33✔
36
        `${app}/hashtag/${tagName}`;
×
37

38
export const getBlueskyPostUrl = (
33✔
39
        app: string,
40
        userHandleOrDid: string,
41
        postId: string,
42
) => `${getBlueskyProfileUrl(app, userHandleOrDid)}/post/${postId}`;
41✔
43

44
export const blueskyUriToPostId = (uri: string) => {
33✔
45
        const parts = uri.split("/");
41✔
46
        return parts[parts.length - 1] ?? "";
41!
47
};
48

49
export const getBlueskyLinkProps = (openLinksInNewTab: boolean) =>
33✔
50
        openLinksInNewTab ? { target: "_blank", rel: "noopener noreferrer" } : {};
146!
51

52
export const formatBlueskyShortDate = (dateString: string) => {
33✔
53
        const now = new Date().getTime();
41✔
54
        const then = new Date(dateString).getTime();
41✔
55
        const seconds = Math.floor((now - then) / 1000);
41✔
56
        let interval = seconds / 31536000;
41✔
57
        if (interval > 1) {
41!
58
                return `${Math.floor(interval)}yr`;
×
59
        }
60
        interval = seconds / 2592000;
41✔
61
        if (interval > 1) {
41✔
62
                return `${Math.floor(interval)}mo`;
27✔
63
        }
64
        interval = seconds / 86400;
14✔
65
        if (interval > 1) {
14✔
66
                return `${Math.floor(interval)}d`;
14✔
67
        }
68
        interval = seconds / 3600;
×
69
        if (interval > 1) {
×
70
                return `${Math.floor(interval)}h`;
×
71
        }
72
        interval = seconds / 60;
×
73
        if (interval > 1) {
×
74
                return `${Math.floor(interval)}m`;
×
75
        }
76
        return `${Math.floor(seconds)}s`;
×
77
};
78

79
export const formatBlueskyLongDate = (dateString: string) => {
33✔
80
        const date = new Date(dateString);
41✔
81
        const day = date.toLocaleDateString(undefined, {
41✔
82
                year: "numeric",
83
                month: "long",
84
                day: "numeric",
85
        });
86
        const time = date.toLocaleTimeString(undefined, {
41✔
87
                hour: "numeric",
88
                minute: "numeric",
89
        });
90
        return `${day} at ${time}`;
41✔
91
};
92

93
export class BlueskyError extends Error {}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc