Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
eslint: Fix unicorn/prefer-code-point.
Anders Kaseorg951b81e2bd46
diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.jsindex 5145bea8f1a..ba020fbb728 100644--- a/frontend_tests/node_tests/composebox_typeahead.js+++ b/frontend_tests/node_tests/composebox_typeahead.js@@ -832,7 +832,7 @@ test("initialize", ({override, mock_template}) => {// Adds a `no break-space` at the end. This should fail// if there wasn't any logic replacing `no break-space`// with normal space.- query = "cordelia, lear's" + String.fromCharCode(160);+ query = "cordelia, lear's\u00A0";assert.equal(matcher(query, cordelia), true);assert.equal(matcher(query, othello), false);diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.jsindex 531356e6384..df11c444bec 100644--- a/frontend_tests/node_tests/hotkey.js+++ b/frontend_tests/node_tests/hotkey.js@@ -215,7 +215,7 @@ run_test("mappings", () => {function process(s) {const e = {- which: s.charCodeAt(0),+ which: s.codePointAt(0),};try {return hotkey.process_keypress(e);diff --git a/static/js/emoji_picker.js b/static/js/emoji_picker.jsindex 9185d45baef..0662ec0c07d 100644--- a/static/js/emoji_picker.js+++ b/static/js/emoji_picker.js@@ -540,7 +540,7 @@ function process_keypress(e) {new_query = old_query.slice(0, -1);} else {// Handles any printable character.- const key_str = String.fromCharCode(e.which);+ const key_str = String.fromCodePoint(e.which);new_query = old_query + key_str;}diff --git a/static/js/pill_typeahead.js b/static/js/pill_typeahead.jsindex 3ba994fac1b..2c34b83f287 100644--- a/static/js/pill_typeahead.js+++ b/static/js/pill_typeahead.js@@ -76,7 +76,7 @@ export function set_up(input, pills, opts) {},matcher(item) {let query = this.query.toLowerCase();- query = query.replace(/\u00A0/g, String.fromCharCode(32));+ query = query.replace(/\u00A0/g, " ");if (include_streams(query)) {query = query.trim().slice(1);diff --git a/static/js/rtl.js b/static/js/rtl.jsindex f83a8322d51..0ceadedf90d 100644--- a/static/js/rtl.js+++ b/static/js/rtl.js@@ -109,27 +109,8 @@ function get_bidi_class(ch) {*/export function get_direction(str) {let isolations = 0;- for (let i = 0; i < str.length; i += 1) {- // Extracting high and low surrogates and putting them together.- // See https://en.wikipedia.org/wiki/UTF-16#Description or section 3 of https://tools.ietf.org/html/rfc2781.- let ch = str.charCodeAt(i);- if (ch >= 0xd800 && ch < 0xdc00) {- // 0xd800 <= ch < 0xdc00- // ch is inside high surrogate range.- // If it made a surrogate pair with the next character, put them together.- // Otherwise, ignore the encoding error and leave it as it is.- const ch2 = i + 1 < str.length ? str.charCodeAt(i + 1) : 0;- if (ch2 >= 0xdc00 && ch2 < 0xe000) {- // 0xdc00 <= ch2 < 0xe000- // ch = ch & 0x3ff;- ch -= 0xd800;- // ch = 0x10000 | (ch << 10) | (ch2 & 0x3ff);- ch = 0x10000 + ch * 0x400 + (ch2 - 0xdc00);- i += 1;- }- }-- const bidi_class = get_bidi_class(ch);+ for (const ch of str) {+ const bidi_class = get_bidi_class(ch.codePointAt(0));switch (bidi_class) {case "I":// LRI, RLI, FSIdiff --git a/static/shared/js/typeahead.js b/static/shared/js/typeahead.jsindex d151fc1ed3e..6ab730c4abb 100644--- a/static/shared/js/typeahead.js+++ b/static/shared/js/typeahead.js@@ -87,7 +87,7 @@ function clean_query(query) {// contenteditable widget such as the composebox PM section, the// space at the end was a `no break-space (U+00A0)` instead of// `space (U+0020)`, which lead to no matches in those cases.- query = query.replace(/\u00A0/g, String.fromCharCode(32));+ query = query.replace(/\u00A0/g, " ");return query;}