@pocketprep/ui-kit 3.4.78 → 3.4.79

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.
package/lib/utils.ts CHANGED
@@ -66,6 +66,10 @@ export const studyModes = {
66
66
  },
67
67
  } as const
68
68
 
69
+ export const escapeRegex = (string: string) => {
70
+ return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&')
71
+ }
72
+
69
73
  export const highlightKeywordsInText = (params: {
70
74
  text: string
71
75
  keywordDefinitions: { keyword: string }[]
@@ -79,7 +83,7 @@ export const highlightKeywordsInText = (params: {
79
83
  const keywords = params.keywordDefinitions.map(k => k.keyword)
80
84
 
81
85
  return keywords.reduce((acc, word) => {
82
- const regex = new RegExp(`(\\W)(${word})(\\W)`, 'i')
86
+ const regex = new RegExp(`(\\W)(${escapeRegex(word)})(\\W)`, 'i')
83
87
  return acc.replace(
84
88
  regex,
85
89
  `$1<span class="keyword-highlight${params.isDarkMode
@@ -89,4 +93,4 @@ export const highlightKeywordsInText = (params: {
89
93
  <span style="pointer-events: none;">$2</span></span>$3`
90
94
  )
91
95
  }, params.text)
92
- }
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pocketprep/ui-kit",
3
- "version": "3.4.78",
3
+ "version": "3.4.79",
4
4
  "description": "Pocket Prep UI Kit",
5
5
  "author": "pocketprep",
6
6
  "scripts": {