From 5fabbeb09aea782b7df05e8827b552e5ec44cf83 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 16 Oct 2026 09:57:22 +0200 Subject: feat(user): helpers for the user page Parsing userctl's output and locale -a, and the git name preview, kept out of QML so node can test them. Co-Authored-By: Claude Sonnet 5.5 --- desktop/modules/user/User.js | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 desktop/modules/user/User.js (limited to 'desktop/modules/user/User.js') 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. +// +// 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] + "."; +} -- cgit v1.2.3