2026-04-22 07:47:23 +02:00
|
|
|
namespace formgen.helpers.string
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
2026-04-22 22:24:32 +02:00
|
|
|
let _indices : Record<string, int> = {};
|
2026-04-22 07:47:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
export function coin(
|
|
|
|
|
template : string,
|
|
|
|
|
arguments_ : Record<string,string>
|
|
|
|
|
) : string
|
|
|
|
|
{
|
|
|
|
|
let result = template;
|
|
|
|
|
for (const [key, value] of Object.entries(arguments_))
|
|
|
|
|
{
|
|
|
|
|
result = result.replace(
|
|
|
|
|
new RegExp("{{" + key + "}}", "g"),
|
|
|
|
|
value
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
export function generate(
|
2026-04-22 22:24:32 +02:00
|
|
|
{
|
|
|
|
|
"prefix": prefix = "",
|
|
|
|
|
}
|
|
|
|
|
:
|
|
|
|
|
{
|
|
|
|
|
prefix ?: string;
|
|
|
|
|
}
|
|
|
|
|
=
|
|
|
|
|
{
|
|
|
|
|
}
|
2026-04-22 07:47:23 +02:00
|
|
|
) : string
|
|
|
|
|
{
|
2026-04-22 22:24:32 +02:00
|
|
|
if (! (prefix in _indices))
|
|
|
|
|
{
|
|
|
|
|
_indices[prefix] = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
_indices[prefix] += 1;
|
|
|
|
|
return (prefix + _indices[prefix].toFixed(0));
|
2026-04-22 07:47:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|