Skip to content

Commit

Permalink
improve transform of sketch name to valid variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
twelch committed Nov 20, 2024
1 parent 110297d commit 5811610
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/base-project/.storybook/genReportStories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ for (const storyConfig of storyConfigs) {
...(childProperties ? { childProperties } : {}),
};

// convert sketch name to a valid variable name
const sketchVariableName = sketch.properties.name
.replaceAll("-", "_")
.replaceAll(" ", "_");
// Convert sketch name to valid variable name, which is displayed as the story name
const sketchVariableName = uuid()
.replace(/^[^a-zA-Z$_\p{L}]/u, "_") // Replace invalid starting characters
.replaceAll(/[^a-zA-Z0-9$_\p{L}]/gu, "_"); // Replace invalid subsequent characters

const story = `
import React from "react";
Expand Down

0 comments on commit 5811610

Please sign in to comment.