fix(plugin-tools): remove double and trailing underscores from filenames and lower case the result

This commit is contained in:
Joakim Carlstein 2023-11-10 09:33:08 +01:00
parent 0081f77e86
commit 16340940b7
2 changed files with 11 additions and 1 deletions

View file

@ -53,4 +53,9 @@ export const getTimestampPrefix = () => new Date().toISOString().replaceAll(/[-:
* @param name A migration name to sanitize
* @returns A sanitized migration name that can be used as a filename
*/
export const sanitizeMigrationName = (name: string) => name.replaceAll(/[\W/\\:|*?'"<>]/g, '_').trim();
export const sanitizeMigrationName = (name: string) =>
name
.replaceAll(/[\W/\\:|*?'"<>]+/g, '_')
.trim()
.replace(/_$/, '')
.toLocaleLowerCase();