Skip to content

Commit bf83abf

Browse files
committed
added StackExchange global object and tests
1 parent 3126a5a commit bf83abf

File tree

4 files changed

+144
-2
lines changed

4 files changed

+144
-2
lines changed

index.d.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import "@stackoverflow/stacks/dist/js/stacks.js";
2+
import "jquery";
23

34
declare global {
45
namespace Stacks {
@@ -71,6 +72,100 @@ declare global {
7172
options?: TooltipOptions
7273
): void;
7374
}
75+
76+
namespace StackExchange {
77+
const helpers: {
78+
hideToasts(): void;
79+
isInNetwork(url: string): boolean;
80+
parseUrl(url: string): string;
81+
showConfirmModal(modal: ModalType): Promise<boolean>;
82+
showModal(popup: JQuery | Element | null): void;
83+
showToast(
84+
message: string,
85+
info: { type: string; transientTimeout: number }
86+
): void;
87+
};
88+
89+
interface UserInfo {
90+
fkey: string;
91+
userId: number;
92+
isModerator: boolean;
93+
isRegistered: boolean;
94+
accountId: number;
95+
canSeeDeletedPosts: boolean;
96+
gravatar: string;
97+
keyboardShortcuts: boolean;
98+
profileUrl: string;
99+
rep: number;
100+
tid: string;
101+
userType: number;
102+
}
103+
104+
interface RealtimeInfo {
105+
active: boolean;
106+
newest: boolean;
107+
tagged: boolean;
108+
staleDisconnectIntervalInHours: number;
109+
}
110+
111+
interface SiteInfo {
112+
childUrl: string;
113+
cookieDomain: string;
114+
description: string;
115+
enableNewTagCreationWarning: boolean;
116+
enableSocialMediaInSharePopup: boolean;
117+
id: number;
118+
insertSpaceAfterNameTabCompletion: boolean;
119+
isNoticesTabEnabled: boolean;
120+
name: string;
121+
negativeVoteScoreFloor: null;
122+
protocol: "http" | "https";
123+
styleCodeWithHighlightjs: boolean;
124+
}
125+
126+
interface JobPreferences {
127+
maxNumDeveloperRoles: number;
128+
maxNumIndustries: number;
129+
}
130+
131+
interface Story {
132+
dislikedTagsMaxLength: number;
133+
likedTagsMaxLength: number;
134+
minCompleteBodyLength: number;
135+
}
136+
137+
interface Events {
138+
postEditionSection: { title: 1; body: 2; tags: 3 };
139+
postType: { question: 1 };
140+
}
141+
142+
const options: {
143+
user: UserInfo;
144+
jobPreferences: JobPreferences;
145+
locale: string;
146+
networkMetaHostname: string;
147+
realtime: RealtimeInfo;
148+
routeName: string;
149+
serverTime: number;
150+
serverTimeOffsetSec: number;
151+
events: Events;
152+
site: SiteInfo;
153+
story: Story;
154+
svgIconHash: string;
155+
svgIconPath: string;
156+
};
157+
const comments: {
158+
uiForPost(comments: JQuery): {
159+
addShow(value1: boolean, value2: boolean): void;
160+
showComments(
161+
value1: string,
162+
value2: string | null,
163+
value3: boolean,
164+
value4: boolean
165+
): void;
166+
};
167+
};
168+
}
74169
}
75170

76171
export {};

package-lock.json

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
},
3838
"types": "./index.d.ts",
3939
"dependencies": {
40-
"@stackoverflow/stacks": "^0.68.0"
40+
"@stackoverflow/stacks": "^0.68.0",
41+
"@types/jquery": "^3.5.6"
4142
}
4243
}

stackexchange.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const $modal = $("<div>pretend modal</div>");
2+
3+
// $ExpectType void
4+
StackExchange.helpers.showModal($modal);
5+
6+
// $ExpectType void
7+
StackExchange.helpers.showModal(document.createElement("div"));
8+
9+
// $ExpectType void
10+
StackExchange.helpers.showModal(null);
11+
12+
// $ExpectError
13+
StackExchange.helpers.showModal();
14+
15+
// $ExpectType boolean
16+
StackExchange.helpers.isInNetwork("stackoverflow.com");
17+
18+
// $ExpectError
19+
StackExchange.helpers.isInNetwork();

0 commit comments

Comments
 (0)