Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

markdown_config: Convert module to TypeScript.

Anders Kaseorgc2c0429dd147
diff --git a/web/src/emoji.ts b/web/src/emoji.ts
index 61a9f4ec5f8..752de8f7408 100644
--- a/web/src/emoji.ts
+++ b/web/src/emoji.ts
@@ -32,7 +32,7 @@ type EmojiParams = {
emoji_codes: ServerUnicodeEmojiData;
};
-type EmoticonTranslation = {
+export type EmoticonTranslation = {
regex: RegExp;
replacement_text: string;
};
diff --git a/web/src/markdown_config.js b/web/src/markdown_config.ts
similarity index 56%
rename from web/src/markdown_config.js
rename to web/src/markdown_config.ts
index 43857491e92..3e49bf9ddc7 100644
--- a/web/src/markdown_config.js
+++ b/web/src/markdown_config.ts
@@ -1,8 +1,11 @@
+import type url_template_lib from "url-template";
+
import * as emoji from "./emoji";
import * as hash_util from "./hash_util";
import * as linkifiers from "./linkifiers";
import * as people from "./people";
import * as stream_data from "./stream_data";
+import type {Stream} from "./sub_store";
import * as user_groups from "./user_groups";
import {user_settings} from "./user_settings";
@@ -28,7 +31,48 @@ import {user_settings} from "./user_settings";
when the lookups fail.
*/
-function abstract_map(map) {
+// TODO/typescript: Move this to markdown
+type AbstractMap<K, V> = {
+ keys(): Iterator<K>;
+ entries(): Iterator<[K, V]>;
+ get(k: K): V | undefined;
+};
+
+// TODO/typescript: Move this to markdown
+type MarkdownHelpers = {
+ // user stuff
+ get_actual_name_from_user_id(user_id: number): string | undefined;
+ get_user_id_from_name(full_name: string): number | undefined;
+ is_valid_full_name_and_user_id(full_name: string, user_id: number): boolean;
+ my_user_id(): number;
+ is_valid_user_id(user_id: number): boolean;
+
+ // user groups
+ get_user_group_from_name(name: string): {id: number; name: string} | undefined;
+ is_member_of_user_group(user_id: number, user_group_id: number): boolean;
+
+ // stream hashes
+ get_stream_by_name(stream_name: string): {stream_id: number; name: string} | undefined;
+ stream_hash(stream_id: number): string;
+ stream_topic_hash(stream_id: number, topic: string): string;
+
+ // settings
+ should_translate_emoticons(): boolean;
+
+ // emojis
+ get_emoji_name(codepoint: string): string | undefined;
+ get_emoji_codepoint(emoji_name: string): string | undefined;
+ get_emoticon_translations(): {regex: RegExp; replacement_text: string}[];
+ get_realm_emoji_url(emoji_name: string): string | undefined;
+
+ // linkifiers
+ get_linkifier_map(): AbstractMap<
+ RegExp,
+ {url_template: url_template_lib.Template; group_number_to_name: Record<number, string>}
+ >;
+};
+
+function abstract_map<K, V>(map: Map<K, V>): AbstractMap<K, V> {
return {
keys: () => map.keys(),
entries: () => map.entries(),
@@ -36,7 +80,7 @@ function abstract_map(map) {
};
}
-function stream(obj) {
+function stream(obj: Stream | undefined): {stream_id: number; name: string} | undefined {
if (obj === undefined) {
return undefined;
}
@@ -47,7 +91,9 @@ function stream(obj) {
};
}
-function user_group(obj) {
+function user_group(
+ obj: user_groups.UserGroup | undefined,
+): {id: number; name: string} | undefined {
if (obj === undefined) {
return undefined;
}
@@ -58,7 +104,7 @@ function user_group(obj) {
};
}
-export const get_helpers = () => ({
+export const get_helpers = (): MarkdownHelpers => ({
// user stuff
get_actual_name_from_user_id: people.get_actual_name_from_user_id,
get_user_id_from_name: people.get_user_id_from_name,