graphviz-builder/lib/Helper.ts

17 lines
412 B
TypeScript
Raw Normal View History

2020-05-07 19:22:16 +02:00
/**
* removes invalid characters from a string and throws an error
* if left with an empty string
*
* @param name - name to check and transform
*/
2020-05-06 20:24:37 +02:00
function validate_name (name: string): string {
const new_name = name
.replace (/[^a-z0-9]/giu, '')
.replace (/^[0-9]+/iu, '');
if (new_name === '')
throw new Error (`invalid node name ${name}`);
return new_name;
}
export { validate_name };