Fix #75: Short uuid handling
This commit is contained in:
committed by
John Livingston
parent
5b8ccdf5ae
commit
bb78c61b08
@ -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 !== '')
|
||||
}
|
||||
|
Reference in New Issue
Block a user