mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-22 11:15:23 -04:00
chore: create getPrimaryAlias utility function
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
d1b7c2a2db
commit
8c214820e1
2 changed files with 44 additions and 10 deletions
|
@ -6,6 +6,9 @@
|
|||
import base32Encode from 'base32-encode';
|
||||
import { randomBytes } from 'crypto';
|
||||
|
||||
import { Alias } from './alias.entity';
|
||||
import { Note } from './note.entity';
|
||||
|
||||
/**
|
||||
* Generate publicId for a note.
|
||||
* This is a randomly generated 128-bit value encoded with base32-encode using the crockford variant and converted to lowercase.
|
||||
|
@ -14,3 +17,17 @@ export function generatePublicId(): string {
|
|||
const randomId = randomBytes(16);
|
||||
return base32Encode(randomId, 'Crockford').toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the primary alias from a aliases of a note
|
||||
* @param {Note} note - the note from which the primary alias should be extracted
|
||||
*/
|
||||
export function getPrimaryAlias(note: Note): string | undefined {
|
||||
const listWithPrimaryAlias = note.aliases.filter(
|
||||
(alias: Alias) => alias.primary,
|
||||
);
|
||||
if (listWithPrimaryAlias.length !== 1) {
|
||||
return undefined;
|
||||
}
|
||||
return listWithPrimaryAlias[0].name;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue