Skip to content

Commit 6748a73

Browse files
feature: implement extract names from json function
1 parent 7e234b4 commit 6748a73

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/lib/extractNamesFromJson.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// The reason for these interfaces is so that typescript neatly throws an error when a user
2+
// adds a json that is not a followers.json or following.json format
3+
4+
interface ExpectedJSON {
5+
title: string;
6+
media_list_data: unknown[];
7+
string_list_data: stringListData[];
8+
}
9+
10+
interface stringListData{
11+
href: string;
12+
value: string;
13+
timestamp: number;
14+
}
15+
16+
export default function ExtractNamesFromJson(json: ExpectedJSON[]) {
17+
const usernames = json.map(user => user.string_list_data[0].value);
18+
return usernames;
19+
}

0 commit comments

Comments
 (0)