Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Co-authored-by: Omar López <zomars@me.com>
15 lines
457 B
TypeScript
15 lines
457 B
TypeScript
export function getApiName({
|
|
namespace,
|
|
mainApiName = "Cal",
|
|
}: {
|
|
namespace: string | null;
|
|
mainApiName?: string;
|
|
}) {
|
|
if (!namespace) {
|
|
return mainApiName;
|
|
}
|
|
const isAValidVariableName = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(namespace);
|
|
// Try to use dot notation if possible because it's more readable otherwise use bracket notation
|
|
return isAValidVariableName ? `${mainApiName}.ns.${namespace}` : `${mainApiName}.ns["${namespace}"]`;
|
|
}
|