aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/user/User.js
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/modules/user/User.js')
-rw-r--r--desktop/modules/user/User.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/desktop/modules/user/User.js b/desktop/modules/user/User.js
new file mode 100644
index 0000000..8160b7f
--- /dev/null
+++ b/desktop/modules/user/User.js
@@ -0,0 +1,46 @@
+// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+.pragma library
+
+// Pure helpers for the user page, tested by test_user.js under node.
+
+// `userctl get` output into an object.
+function parse(text) {
+ const out = {};
+ for (const line of text.split("\n")) {
+ const i = line.indexOf("=");
+ if (i > 0) out[line.slice(0, i)] = line.slice(i + 1);
+ }
+ return out;
+}
+
+// `userctl keys` output into [{fpr, uid}].
+function keys(text) {
+ return text.split("\n").filter(l => l.includes("\t"))
+ .map(l => ({ fpr: l.slice(0, l.indexOf("\t")), uid: l.slice(l.indexOf("\t") + 1) }));
+}
+
+// `locale -a` prints it_IT.utf8; AccountsService stores it_IT.UTF-8.
+function locales(text) {
+ return text.split("\n")
+ .filter(l => /\.utf-?8$/i.test(l) && !/^C\./.test(l))
+ .map(l => l.replace(/\.utf-?8$/i, ".UTF-8"))
+ .sort();
+}
+
+// The name git gets, for the page's preview. ponytail: duplicates userctl's
+// gitname; both tests pin the same cases, keep them in step.
+function gitName(name) {
+ const w = name.trim().split(/\s+/).filter(s => s !== "");
+ if (w.length < 2) return w.join(" ");
+ return w.slice(0, -1).join(" ") + " " + Array.from(w[w.length - 1])[0] + ".";
+}