Skip to content

Commit 150fab6

Browse files
committed
adds typings
1 parent 0148f8d commit 150fab6

2 files changed

Lines changed: 85 additions & 1 deletion

File tree

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.4",
44
"description": "Dev.to hooks for Github API",
55
"main": "src/index.js",
6+
"types": "types.d.ts",
67
"repository": "https://github.com/bdbch/react-devto",
78
"author": "@d2k",
89
"license": "MIT",
@@ -18,7 +19,8 @@
1819
"src/*.js",
1920
"src/*.json",
2021
"src/**/*.js",
21-
"src/**/*.json"
22+
"src/**/*.json",
23+
"types.d.ts"
2224
],
2325
"scripts": {},
2426
"devDependencies": {

types.d.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
declare module "@d2k/react-devto" {
2+
export interface IBaseUser {
3+
name: string;
4+
username: string;
5+
twitter_username?: string;
6+
github_username?: string;
7+
website_url?: string;
8+
profile_image?: string;
9+
profile_image_90?: string;
10+
}
11+
12+
export interface IUser extends IBaseUser {
13+
type_of: "user";
14+
summary?: string;
15+
location?: string;
16+
joined_at?: string;
17+
following?: boolean;
18+
}
19+
20+
export interface ITag {
21+
id?: number;
22+
name: string;
23+
bg_color_hex: string;
24+
text_color_hex: string;
25+
}
26+
27+
export interface IPost {
28+
type_of: "article";
29+
id: number;
30+
title: string;
31+
description?: string;
32+
cover_image?: string;
33+
published_at: string;
34+
tag_list?: string[];
35+
slug: string;
36+
path: string;
37+
url: string;
38+
canonical_url: string;
39+
comments_count: number;
40+
positive_reactions_count: number;
41+
published_timestamp: string;
42+
user: IBaseUser;
43+
flare_tag?: ITag;
44+
}
45+
46+
export interface IResponse {
47+
loading: boolean;
48+
error?: string;
49+
}
50+
51+
export interface IArticlesResponse extends IResponse {
52+
articles?: IPost[];
53+
}
54+
55+
export interface IUserResponse extends IResponse {
56+
user?: IUser;
57+
}
58+
59+
export interface IFollowSuggestionsResponse extends IResponse {
60+
suggestions?: IUser[];
61+
}
62+
63+
export interface ITagsResponse extends IResponse {
64+
tags?: ITag[];
65+
}
66+
67+
/** Fetches Dev.to articles and returns an array of 20 items */
68+
function useArticles(
69+
page?: number,
70+
tag?: string,
71+
username?: string
72+
): IArticlesResponse;
73+
74+
/** Fetches a user from Dev.to by either a username or id */
75+
function useUser(username?: string, id?: string): IUserResponse;
76+
77+
/** Fetches follow suggestions */
78+
function useFollowSuggestions(): IFollowSuggestionsResponse;
79+
80+
/** Fetches tags */
81+
function useTags(page?: number): ITagsResponse;
82+
}

0 commit comments

Comments
 (0)