Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
ts: Convert rtl.js to TypeScript.
xoldyckk6f009c5e652d
diff --git a/web/src/rtl.js b/web/src/rtl.tssimilarity index 93%rename from web/src/rtl.jsrename to web/src/rtl.tsindex 5598d54d2bf..440c16db404 100644--- a/web/src/rtl.js+++ b/web/src/rtl.ts@@ -1,4 +1,5 @@import _ from "lodash";+import assert from "minimalistic-assert";// How to determine the direction of a paragraph (P1-P3): https://www.unicode.org/reports/tr9/tr9-35.html#The_Paragraph_Level// Embedding level: https://www.unicode.org/reports/tr9/tr9-35.html#BD2@@ -21,7 +22,7 @@ import _ from "lodash";* @param {string} raw* @returns {number[]}*/-function convert_from_raw(digits, part_length, raw) {+function convert_from_raw(digits: string, part_length: number, raw: string): number[] {const result = [];for (let i = 0; i < raw.length; ) {let t = 0;@@ -86,7 +87,7 @@ const lr_ranges = [* @param {number} ch A character to get its bidirectional class.* @returns {'I' | 'PDI' | 'R' | 'L' | 'Other'}*/-function get_bidi_class(ch) {+function get_bidi_class(ch: number): "I" | "PDI" | "R" | "L" | "Other" {if (i_chars.has(ch)) {return "I"; // LRI, RLI, FSI}@@ -109,10 +110,10 @@ function get_bidi_class(ch) {* @param {string} str The string to get its direction.* @returns {'ltr' | 'rtl'}*/-export function get_direction(str) {+export function get_direction(str: string): "ltr" | "rtl" {let isolations = 0;for (const ch of str) {- const bidi_class = get_bidi_class(ch.codePointAt(0));+ const bidi_class = get_bidi_class(ch.codePointAt(0)!);switch (bidi_class) {case "I":// LRI, RLI, FSI@@ -139,9 +140,10 @@ export function get_direction(str) {return "ltr";}-export function set_rtl_class_for_textarea($textarea) {+export function set_rtl_class_for_textarea($textarea: JQuery<HTMLTextAreaElement>): void {// Set the rtl class if the text has an rtl direction, remove it otherwiselet text = $textarea.val();+ assert(typeof text === "string", "Passed HTML element must be a textarea.");if (text.startsWith("```quote")) {text = text.slice(8);}