From f5e29189f70c5c8532916504a1a22f8c586f6e73 Mon Sep 17 00:00:00 2001
From: navewindre <boneyaard@gmail.com>
Date: Tue, 11 Nov 2025 08:11:24 +0100
Subject: new web

---
 web/src/util.tsx | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 web/src/util.tsx

(limited to 'web/src/util.tsx')

diff --git a/web/src/util.tsx b/web/src/util.tsx
new file mode 100644
index 0000000..1b1ccc0
--- /dev/null
+++ b/web/src/util.tsx
@@ -0,0 +1,42 @@
+export function escapeHtml( html: string ) {
+  const entityMap = {
+    '&': '&amp;',
+    '<': '&lt;',
+    '>': '&gt;',
+    '"': '&quot;',
+    "'": '&#39;',
+    '/': '&#x2F;',
+    '`': '&#x60;',
+    '=': '&#x3D;'
+  };
+
+  return String( html ).replace( /[&<>"'`=\/]/g, ( s ) => {
+    return entityMap[s];
+  } );
+}
+
+export function parseJWT( token: string ) : any {
+  const parts = token.split( '.' );
+  let encoded = parts[1];
+  encoded = encoded.replace(/-/g, '+').replace(/_/g, '/');
+  const pad = encoded.length % 4;
+  if( pad === 1 )
+    throw new Error( 'what the fuck' );
+  if( pad > 1 )
+    encoded += new Array( 5 - pad ).join( '=' );
+
+  const payload = JSON.parse( atob( encoded ) );
+  return payload;
+}
+
+export function sizeHumanReadable( size: number ) {
+  if( size < 1024 )
+    return size + ' B';
+  else if( size < 1024 * 1024 )
+    return ( size / 1024 ).toFixed( 2 ) + ' KB';
+  else if( size < 1024 * 1024 * 1024 )
+    return ( size / 1024 / 1024 ).toFixed( 2 ) + ' MB';
+  else
+    return ( size / 1024 / 1024 / 1024 ).toFixed( 2 ) + ' GB';
+}
+
-- 
cgit v1.2.3

