ibs-format
Advanced tools
+85
-6
@@ -13,3 +13,61 @@ function ibsFormat(value, arr, linky, escaping) { | ||
| if (value != "" && value != null && value != undefined && arr && arr.length > 0) { | ||
| // Preprocess to handle empty formatting markers | ||
| if (arr[0].constructor === Array) { | ||
| arr.forEach(function (formatConfig) { | ||
| let marker = formatConfig[1]; | ||
| // Create regex to match empty formatting markers (marker followed by optional whitespace then same marker) | ||
| let escapedMarker = marker.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
| let emptyMarkerRegex = new RegExp(escapedMarker + '\\s*' + escapedMarker, 'g'); | ||
| // Find all empty marker pairs and track their positions | ||
| let matches = []; | ||
| let match; | ||
| while ((match = emptyMarkerRegex.exec(value)) !== null) { | ||
| matches.push({ | ||
| start: match.index, | ||
| end: match.index + match[0].length, | ||
| content: match[0] | ||
| }); | ||
| // Reset lastIndex to avoid infinite loop with zero-length matches | ||
| if (match.index === emptyMarkerRegex.lastIndex) { | ||
| emptyMarkerRegex.lastIndex++; | ||
| } | ||
| } | ||
| // Process matches from end to start to avoid index shifting | ||
| for (let i = matches.length - 1; i >= 0; i--) { | ||
| let matchObj = matches[i]; | ||
| let beforeMatch = value.substring(0, matchObj.start); | ||
| let afterMatch = value.substring(matchObj.end); | ||
| // Replace with just the markers (no formatting) | ||
| value = beforeMatch + marker + marker + afterMatch; | ||
| } | ||
| }); | ||
| } else { | ||
| let marker = arr[1]; | ||
| let escapedMarker = marker.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
| let emptyMarkerRegex = new RegExp(escapedMarker + '\\s*' + escapedMarker, 'g'); | ||
| let matches = []; | ||
| let match; | ||
| while ((match = emptyMarkerRegex.exec(value)) !== null) { | ||
| matches.push({ | ||
| start: match.index, | ||
| end: match.index + match[0].length, | ||
| content: match[0] | ||
| }); | ||
| if (match.index === emptyMarkerRegex.lastIndex) { | ||
| emptyMarkerRegex.lastIndex++; | ||
| } | ||
| } | ||
| for (let i = matches.length - 1; i >= 0; i--) { | ||
| let matchObj = matches[i]; | ||
| let beforeMatch = value.substring(0, matchObj.start); | ||
| let afterMatch = value.substring(matchObj.end); | ||
| value = beforeMatch + marker + marker + afterMatch; | ||
| } | ||
| } | ||
| if (arr[0].constructor === Array) { | ||
| arr.map(function (e) { | ||
@@ -122,6 +180,15 @@ e[2] = (e[0].length + 1).toString(); | ||
| } | ||
| e = e.replace('**', "<" + tag + ">"); | ||
| e = e.replace('**', "</" + tag + ">"); | ||
| // Check if there's content between the ** markers | ||
| let firstIndex = box[0]; | ||
| let lastIndex = box[box.length - 1]; | ||
| let contentBetween = e.substring(firstIndex + 2, lastIndex); | ||
| if (contentBetween.trim().length > 0) { | ||
| e = e.replace('**', "<" + tag + ">"); | ||
| e = e.replace('**', "</" + tag + ">"); | ||
| } | ||
| box = []; | ||
| } | ||
| arr.push(e); | ||
@@ -167,2 +234,3 @@ }); | ||
| } else { | ||
| // Check if there's actual content between paired asterisks across words | ||
| if (flag == "1") { | ||
@@ -194,4 +262,10 @@ e = e.replace(/\x2a/g, "<" + tag + ">"); | ||
| let lastIndex = box[box.length - 1]; | ||
| e = replaceChar(e, "<" + tag + ">", firstIndex); | ||
| e = replaceChar(e, "</" + tag + ">", lastIndex + trim); | ||
| // Check if there's content between the * markers | ||
| let contentBetween = e.substring(firstIndex + 1, lastIndex); | ||
| if (contentBetween.trim().length > 0) { | ||
| e = replaceChar(e, "<" + tag + ">", firstIndex); | ||
| e = replaceChar(e, "</" + tag + ">", lastIndex + trim); | ||
| } | ||
| box = []; | ||
@@ -272,4 +346,9 @@ } | ||
| e = replaceChar(e, "<" + tag + ">", firstIndex); | ||
| e = replaceChar(e, "</" + tag + ">", lastIndex + trim); | ||
| // Check if there's content between the formatting markers | ||
| let contentBetween = e.substring(firstIndex + iden.length, lastIndex); | ||
| if (contentBetween.trim().length > 0) { | ||
| e = replaceChar(e, "<" + tag + ">", firstIndex); | ||
| e = replaceChar(e, "</" + tag + ">", lastIndex + trim); | ||
| } | ||
@@ -276,0 +355,0 @@ box = []; |
+1
-1
| { | ||
| "name": "ibs-format", | ||
| "version": "1.4.13", | ||
| "version": "1.4.14", | ||
| "description": "Detect the user-defined identifiers in the text and convert them into HTML tags like bold, italic, strike, and many more having XSS (Cross-site scripting) security with escaping functionality, also detect the links like URLs, email, and IP addresses and wrap them into Anchor tag `<a>`.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+9
-9
| # Description | ||
| Detect the user-defined identifiers in the text and convert them into HTML tags like bold, italic, strike, and many more having XSS (Cross-site scripting) security with escaping functionality, also detect the links like URLs, email, and IP addresses and wrap them into Anchor tag `<a>`. | ||
| Text formatting in Javascript. Detect the user-defined identifiers in the text and convert them into HTML tags like bold, italic, strike, and many more having XSS (Cross-site scripting) security with escaping functionality, also detect the links like URLs, email, and IP addresses and wrap them into Anchor tag `<a>` with also other user define formatting. | ||
| ## Table of Contents | ||
| - [Online Demo](#demo) | ||
| - [Online Demo](#online-demo) | ||
| - [Supported browsers](#browsers) | ||
@@ -12,8 +12,8 @@ - [Installation](#installation) | ||
| - [Links Detecting](#links-detecting) | ||
| - [Cross Site Scripting (XSS)](#cross-site-scripting) | ||
| - [Format the text at run time using custom Pipe](#pipe) | ||
| - [Use the external 'ngx-linkifyjs' library for detecting the links](#linkifyjs) | ||
| - [Cross Site Scripting (XSS)](#cross-site-scripting-(xss)) | ||
| - [Format the text at run time using custom Pipe](#format-the-text-at-run-time-using-custom-pipe) | ||
| - [Use the external 'ngx-linkifyjs' library for detecting the links](#use-the-external-'ngx-linkifyjs'-library-for-detecting-the-links) | ||
| - [Precautions](#precautions) | ||
| <a name="demo"/> | ||
| <a name="online-demo"/> | ||
@@ -126,3 +126,3 @@ # Online Demo | ||
| ``` | ||
| <a name="cross-site-scripting"/> | ||
| <a name="cross-site-scripting-(xss)"/> | ||
@@ -143,3 +143,3 @@ # Cross Site Scripting (XSS). | ||
| <a name="pipe"/> | ||
| <a name="format-the-text-at-run-time-using-custom-pipe"/> | ||
@@ -182,3 +182,3 @@ # Format the text at run time using custom Pipe. | ||
| <a name="linkifyjs"/> | ||
| <a name="use-the-external-'ngx-linkifyjs'-library-for-detecting-the-links"/> | ||
@@ -185,0 +185,0 @@ # Use the external 'ngx-linkifyjs' library for detecting the links |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
21563
18.25%388
21.25%1
Infinity%