nope/lib/helpers/idMethods.ts

40 lines
648 B
TypeScript
Raw Normal View History

2020-11-06 08:10:30 +00:00
/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @desc [description]
*/
2021-11-12 07:57:03 +00:00
import { v4 } from "uuid";
import { varifyString } from "./stringMethods";
2020-08-25 22:11:26 +00:00
2021-11-12 07:57:03 +00:00
/**
* Generates an ID.
*
* @author M.Karkowski
* @export
* @param {{
* prestring?: string,
* useAsVar?: boolean
* }} [options={}]
* @return {string}
2021-11-12 07:57:03 +00:00
*/
2021-12-04 07:25:26 +00:00
export function generateId(
options: {
// PreString for the Var.
prestring?: string;
useAsVar?: boolean;
} = {}
): string {
2021-11-12 07:57:03 +00:00
let id = v4();
if (typeof options.prestring === "string") {
id = options.prestring + id;
2020-09-08 14:59:06 +00:00
}
2021-11-12 07:57:03 +00:00
if (options.useAsVar) {
id = varifyString(id);
}
2021-11-12 07:57:03 +00:00
return id;
2021-12-04 07:25:26 +00:00
}