Fix #75: Short uuid handling

This commit is contained in:
Mehdi Benadel
2025-05-12 11:00:35 +02:00
committed by John Livingston
parent 5b8ccdf5ae
commit bb78c61b08
8 changed files with 83 additions and 17 deletions

View File

@ -1,16 +1,35 @@
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
// SPDX-FileCopyrightText: 2025 Mehdi Benadel <https://mehdibenadel.com>
//
// SPDX-License-Identifier: AGPL-3.0-only
const short = require('short-uuid')
const translator = short()
function shortToUUID (shortUUID: string): string {
if (!shortUUID) return shortUUID
return translator.toUUID(shortUUID)
}
function isShortUUID (value: string): boolean {
if (!value) return false
return value.length === translator.maxLength
}
function parseConfigUUIDs (s: string): string[] {
if (!s) {
return []
}
let a = s.split('\n')
a = a.map(line => {
return line.replace(/#.*$/, '')
line = line.replace(/#.*$/, '')
.replace(/^\s+/, '')
.replace(/\s+$/, '')
return isShortUUID(line) ? shortToUUID(line) : line
})
return a.filter(line => line !== '')
}