]> Untitled Git - lemmy.git/blobdiff - ui/src/utils.ts
Merge branch 'dev' into federation
[lemmy.git] / ui / src / utils.ts
index fd23bf9ea251748838613334bac56827dad7c21f..480b41c7c313a6ffcd6403456583b4ee14fe2ee9 100644 (file)
@@ -91,7 +91,7 @@ export const themes = [
 
 export const emojiPicker = new EmojiButton({
   // Use the emojiShortName from native
-  // style: 'twemoji',
+  style: 'twemoji',
   theme: 'dark',
   position: 'auto-start',
   // TODO i18n
@@ -118,11 +118,11 @@ export const md = new markdown_it({
   typographer: true,
 })
   .use(markdown_it_container, 'spoiler', {
-    validate: function(params: any) {
+    validate: function (params: any) {
       return params.trim().match(/^spoiler\s+(.*)$/);
     },
 
-    render: function(tokens: any, idx: any) {
+    render: function (tokens: any, idx: any) {
       var m = tokens[idx].info.trim().match(/^spoiler\s+(.*)$/);
 
       if (tokens[idx].nesting === 1) {
@@ -138,7 +138,7 @@ export const md = new markdown_it({
     defs: objectFlip(emojiShortName),
   });
 
-md.renderer.rules.emoji = function(token, idx) {
+md.renderer.rules.emoji = function (token, idx) {
   return twemoji.parse(token[idx].content);
 };
 
@@ -284,7 +284,7 @@ export function debounce(
   let timeout: any;
 
   // Calling debounce returns a new anonymous function
-  return function() {
+  return function () {
     // reference the context and args for the setTimeout function
     var context = this,
       args = arguments;
@@ -300,7 +300,7 @@ export function debounce(
     clearTimeout(timeout);
 
     // Set the new timeout
-    timeout = setTimeout(function() {
+    timeout = setTimeout(function () {
       // Inside the timeout function, clear the timeout variable
       // which will let the next execution run when in 'immediate' mode
       timeout = null;
@@ -841,3 +841,7 @@ export function previewLines(text: string, lines: number = 3): string {
     .slice(0, lines * 2)
     .join('\n');
 }
+
+export function hostname(url: string): string {
+  return new URL(url).hostname;
+}