@sohanemon/utils 5.0.2 → 5.0.3
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/dist/functions/index.d.ts +11 -0
- package/dist/functions/index.js +13 -0
- package/package.json +1 -1
|
@@ -209,3 +209,14 @@ export declare const mergeRefs: MergeRefs;
|
|
|
209
209
|
* @example goToClientSideHash('my-element');
|
|
210
210
|
*/
|
|
211
211
|
export declare function goToClientSideHash(id: string, opts?: ScrollIntoViewOptions): void;
|
|
212
|
+
/**
|
|
213
|
+
* Escapes a string for use in a regular expression.
|
|
214
|
+
*
|
|
215
|
+
* @param str - The string to escape
|
|
216
|
+
* @returns - The escaped string
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* const escapedString = escapeRegExp('Hello, world!');
|
|
220
|
+
* // escapedString === 'Hello\\, world!'
|
|
221
|
+
*/
|
|
222
|
+
export declare function escapeRegExp(str: string): string;
|
package/dist/functions/index.js
CHANGED
|
@@ -374,3 +374,16 @@ export function goToClientSideHash(id, opts) {
|
|
|
374
374
|
el.scrollIntoView({ behavior: 'smooth', block: 'start', ...opts });
|
|
375
375
|
window.history.pushState(null, '', `#${id}`);
|
|
376
376
|
}
|
|
377
|
+
/**
|
|
378
|
+
* Escapes a string for use in a regular expression.
|
|
379
|
+
*
|
|
380
|
+
* @param str - The string to escape
|
|
381
|
+
* @returns - The escaped string
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* const escapedString = escapeRegExp('Hello, world!');
|
|
385
|
+
* // escapedString === 'Hello\\, world!'
|
|
386
|
+
*/
|
|
387
|
+
export function escapeRegExp(str) {
|
|
388
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
389
|
+
}
|