@sit-onyx/storybook-utils 1.0.0-beta.34 → 1.0.0-beta.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/preview.ts +12 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sit-onyx/storybook-utils",
3
3
  "description": "Storybook utilities for Vue",
4
- "version": "1.0.0-beta.34",
4
+ "version": "1.0.0-beta.36",
5
5
  "type": "module",
6
6
  "author": "Schwarz IT KG",
7
7
  "license": "Apache-2.0",
@@ -26,8 +26,8 @@
26
26
  "@storybook/vue3": ">= 8.2.0",
27
27
  "storybook": ">= 8.2.0",
28
28
  "storybook-dark-mode": ">= 4",
29
- "@sit-onyx/icons": "^1.0.0-beta.0",
30
- "sit-onyx": "^1.0.0-beta.33"
29
+ "@sit-onyx/icons": "^1.0.0-beta.1",
30
+ "sit-onyx": "^1.0.0-beta.35"
31
31
  },
32
32
  "dependencies": {
33
33
  "deepmerge-ts": "^7.1.0"
package/src/preview.ts CHANGED
@@ -156,7 +156,10 @@ export const sourceCodeTransformer = (
156
156
  const escapedIconContent = `"${replaceAll(iconContent, '"', '\\"')}"`;
157
157
 
158
158
  if (code.includes(iconContent)) {
159
- code = code.replace(new RegExp(` (\\S+)=['"]${iconContent}['"]`), ` :$1="${importName}"`);
159
+ code = code.replace(
160
+ new RegExp(` (\\S+)=['"]${escapeRegExp(iconContent)}['"]`),
161
+ ` :$1="${importName}"`,
162
+ );
160
163
  additionalImports.push(`import ${importName} from "@sit-onyx/icons/${iconName}.svg?raw";`);
161
164
  } else if (code.includes(singleQuotedIconContent)) {
162
165
  // support icons inside objects
@@ -206,3 +209,11 @@ ${code}`;
206
209
  export const replaceAll = (value: string, searchValue: string | RegExp, replaceValue: string) => {
207
210
  return value.replace(new RegExp(searchValue, "gi"), replaceValue);
208
211
  };
212
+
213
+ /**
214
+ * Escapes the given string value to be used in `new RegExp()`.
215
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping
216
+ */
217
+ export const escapeRegExp = (string: string) => {
218
+ return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
219
+ };