@handy-common-utils/misc-utils
Advanced tools
Comparing version 1.6.0 to 1.6.1
@@ -65,12 +65,12 @@ /** | ||
* @param text the string literal to be escaped | ||
* @returns escaped string that can be used inside of RegExp | ||
* @returns escaped string that can be used inside of RegExp, or an empty string if the input is null or undefined | ||
*/ | ||
export declare function escapeForRegExp(text: string): string; | ||
export declare function escapeForRegExp(text: string | undefined | null): string; | ||
/** | ||
* Escape replacement string for using it inside of RegExp replacement parameter. | ||
* (From: https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex) | ||
* @param text the replacement string to be escaped | ||
* @param text the replacement string to be escaped, or an empty string if the input is null or undefined | ||
* @returns escaped replacement string that can be used inside of RegExp replacement parameter | ||
*/ | ||
export declare function escapeForRegExpReplacement(text: string): string; | ||
export declare function escapeForRegExpReplacement(text: string | undefined | null): string; | ||
//# sourceMappingURL=codec.d.ts.map |
@@ -117,5 +117,8 @@ "use strict"; | ||
* @param text the string literal to be escaped | ||
* @returns escaped string that can be used inside of RegExp | ||
* @returns escaped string that can be used inside of RegExp, or an empty string if the input is null or undefined | ||
*/ | ||
function escapeForRegExp(text) { | ||
if (text == null) { | ||
return ''; | ||
} | ||
// eslint-disable-next-line unicorn/better-regex | ||
@@ -128,8 +131,11 @@ return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string | ||
* (From: https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex) | ||
* @param text the replacement string to be escaped | ||
* @param text the replacement string to be escaped, or an empty string if the input is null or undefined | ||
* @returns escaped replacement string that can be used inside of RegExp replacement parameter | ||
*/ | ||
function escapeForRegExpReplacement(text) { | ||
if (text == null) { | ||
return ''; | ||
} | ||
return text.replace(/\$/g, '$$$$'); | ||
} | ||
exports.escapeForRegExpReplacement = escapeForRegExpReplacement; |
{ | ||
"name": "@handy-common-utils/misc-utils", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "Miscellaneous utilities", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -666,3 +666,3 @@ # @handy-common-utils/misc-utils | ||
| :------ | :------ | :------ | | ||
| `text` | `string` | the string literal to be escaped | | ||
| `text` | `undefined` \| ``null`` \| `string` | the string literal to be escaped | | ||
@@ -673,3 +673,3 @@ ###### Returns | ||
escaped string that can be used inside of RegExp | ||
escaped string that can be used inside of RegExp, or an empty string if the input is null or undefined | ||
@@ -689,3 +689,3 @@ ___ | ||
| :------ | :------ | :------ | | ||
| `text` | `string` | the replacement string to be escaped | | ||
| `text` | `undefined` \| ``null`` \| `string` | the replacement string to be escaped, or an empty string if the input is null or undefined | | ||
@@ -692,0 +692,0 @@ ###### Returns |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
141405
1225