Socket
Socket
Sign inDemoInstall

format-chat-message

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

format-chat-message - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

20

dist/index.js

@@ -5,6 +5,6 @@ "use strict";

const regexDefault = {
breakline: /\n/g,
htmlTags: /([*~_]|```)([a-zA-Z0-9*_~].+?)\1(?!\w)/g,
url: /(?:(?:https|http):\/\/|\b(?:[a-z\d]+\.))[a-zA-Z0-9\-.]+\.[a-zA-Z]{2,3}(\/\S*)?/gim,
phone: /(?:(?:\(?(\d{2,11})\))|(?:(\d{2,11})))?[-. ]?(\d{5}|\d{4})[-. ]?(\d{4})[-. <\s]/gm,
breakline: /\n/g,
};

@@ -26,6 +26,2 @@ const htmlTags = {

/**
* Handle breaklines
*/
breakline: () => "<br />",
/**
* Handle HTML Tags. Settings on array htmlTags

@@ -46,14 +42,15 @@ */

},
/**
* Handle breaklines
*/
breakline: () => "<br />",
};
const formatChatMessage = ({ message, customRegex, shouldFormat, }) => {
const regex = {
breakline: (customRegex === null || customRegex === void 0 ? void 0 : customRegex.breakline) || regexDefault.breakline,
htmlTags: (customRegex === null || customRegex === void 0 ? void 0 : customRegex.htmlTags) || regexDefault.htmlTags,
url: (customRegex === null || customRegex === void 0 ? void 0 : customRegex.url) || regexDefault.url,
phone: (customRegex === null || customRegex === void 0 ? void 0 : customRegex.phone) || regexDefault.phone,
breakline: (customRegex === null || customRegex === void 0 ? void 0 : customRegex.breakline) || regexDefault.breakline,
};
const formatOption = {
breakline: typeof (shouldFormat === null || shouldFormat === void 0 ? void 0 : shouldFormat.breakline) !== "undefined"
? shouldFormat.breakline
: shouldFormatDefault.breaklineDefault,
htmlTags: typeof (shouldFormat === null || shouldFormat === void 0 ? void 0 : shouldFormat.htmlTags) !== "undefined"

@@ -68,8 +65,11 @@ ? shouldFormat.htmlTags

: shouldFormatDefault.phoneDefault,
breakline: typeof (shouldFormat === null || shouldFormat === void 0 ? void 0 : shouldFormat.breakline) !== "undefined"
? shouldFormat.breakline
: shouldFormatDefault.breaklineDefault,
};
const format = {
breakline: (msg) => msg.replace(regex.breakline, formatter.breakline),
htmlTags: (msg) => msg.replace(regex.htmlTags, formatter.htmlTags),
url: (msg) => msg.replace(regex.url, formatter.link),
phone: (msg) => msg.replace(regex.phone, formatter.phone),
breakline: (msg) => msg.replace(regex.breakline, formatter.breakline),
};

@@ -76,0 +76,0 @@ const formattedMessage = Object.keys(formatOption).reduce((acc, item) => formatOption[`${item}`] === true ? format[`${item}`](acc) : acc, message);

{
"name": "format-chat-message",
"version": "0.0.5",
"version": "0.0.6",
"description": "A lib to format messages received through APIs of the main messengers such as WhatsApp and Facebook. Convert from messengers syntax to HTML tags.",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc