aboutsummaryrefslogtreecommitdiffstats
path: root/config/quickshell/modules/common/functions/string_utils.js
diff options
context:
space:
mode:
authorJa.KooLit <85185940+JaKooLit@users.noreply.github.com>2025-07-25 21:31:54 +0900
committerGitHub <noreply@github.com>2025-07-25 21:31:54 +0900
commitdd889d3aac40075ee73f76290c69ccc698673817 (patch)
tree67dc1026bc09a93cb5250e1c28adda15c592aff4 /config/quickshell/modules/common/functions/string_utils.js
parent637025eeb60391e5cc17c883aa6ee95799acac76 (diff)
parentaa3c94f1ad44038d6a71ee8e12a704e6089e31f6 (diff)
Merge pull request #775 from JaKooLit/development
Development to main
Diffstat (limited to 'config/quickshell/modules/common/functions/string_utils.js')
-rw-r--r--config/quickshell/modules/common/functions/string_utils.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/config/quickshell/modules/common/functions/string_utils.js b/config/quickshell/modules/common/functions/string_utils.js
new file mode 100644
index 00000000..c31edf49
--- /dev/null
+++ b/config/quickshell/modules/common/functions/string_utils.js
@@ -0,0 +1,53 @@
+/**
+ * Formats a string according to the args that are passed in
+ * @param { string } str
+ * @param {...any} args
+ * @returns
+ */
+function format(str, ...args) {
+ return str.replace(/{(\d+)}/g, (match, index) =>
+ typeof args[index] !== 'undefined' ? args[index] : match
+ );
+}
+
+/**
+ * Returns the domain of the passed in url or null
+ * @param { string } url
+ * @returns { string| null }
+ */
+function getDomain(url) {
+ const match = url.match(/^(?:https?:\/\/)?(?:www\.)?([^\/]+)/);
+ return match ? match[1] : null;
+}
+
+/**
+ * Returns the base url of the passed in url or null
+ * @param { string } url
+ * @returns { string | null }
+ */
+function getBaseUrl(url) {
+ const match = url.match(/^(https?:\/\/[^\/]+)(\/.*)?$/);
+ return match ? match[1] : null;
+}
+
+/**
+ * Escapes single quotes in shell commands
+ * @param { string } str
+ * @returns { string }
+ */
+function shellSingleQuoteEscape(str) {
+ // escape single quotes
+ return String(str)
+ // .replace(/\\/g, '\\\\')
+ .replace(/'/g, "'\\''");
+}
+
+function escapeHtml(str) {
+ if (typeof str !== 'string') return str;
+ return str
+ .replace(/&/g, '&amp;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;')
+ .replace(/"/g, '&quot;')
+ .replace(/'/g, '&#39;');
+}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage