<commit_before>/**
 * @package      SD-NodeChat
 *
 * @author       <NAME> (SD) (http://saur.in)
 * @copyright    Copyright (C) 2014 <NAME>. All rights reserved.
 * @license      http://opensource.org/licenses/MIT, see LICENSE
 */

(function (window, document, $) {

    $.SDNodeChat = function (options) {

        var _defaults = {

            /**
             * @default     localhost
             * @type        Text
             * @value       server-IP address
             * @usage       This will be consider as default server for chat
             */
            server: "localhost",

            /**
             * @default     80
             * @type        Text
             * @value       Port number
             * @usage       This will be consider as default port for the chat server
             */
            port: "80",

            /**
             * @default     null
             * @type        [object Socket]
             * @value       [object Socket]
             * @usage       This socket object will be use to communicate to server.
             */
            socket: null,

            /**
             * @default     false
             * @type        boolean
             * @value       true/false
             * @usage       This can enable or disable log on server side.
             */
            debug: false,

            /**
             * @default     null
             * @type        Text
             * @value       username
             * @usage       This can enable or disable log on server side.
             */
            username: null,

            /**
             * @default     $('#messages')
             * @type        [object HTMLUListElement]
             * @value       [object HTMLUListElement]
             * @usage       This element will be consider as chat container
             */
            chatContainer: $('#messages'),

            /**
             * @default     $('#SendButtonID')
             * @type        [object HTMLButtonElement]
             * @value       [object HTMLButtonElement]
             * @usage       This element will be consider as an action to send chat
             */
            sendButton: $('#SendButtonID'),

            /**
             * @default     $('#chatTextBoxId')
             * @type        [object HTMLInputElement]
             * @value       [object HTMLInputElement]
             * @usage       This element will be consider as chat input it can also handle action to send chat
             */
            chatBox: $('#chatTextBox'),

            /**
             * @default     true
             * @type        boolean
             * @value       true/false
             * @usage       This can enable or disable enter key as sender on chatBox
             */
            enterToSend: true,

            /**
             * @default     $('#userContainer')
             * @type        [object HTMLUListElement]
             * @value       [object HTMLUListElement]
             * @usage       This element will be consider as a container of online users list.
             */
            usersContainer: $('#userContainer'),

            /**
             * @default     "Welcome to SD-NodeChat! For more info visit <a href="https://github.com/devsaurin/SD-NodeChat">SD-NodeChat@GitHub</a>"
             * @type        [text]
             * @value       [text]
             * @usage       This is to welcome a new user. It will be ignored if value not present.
             */
            welcomeNote: "Welcome to SD-NodeChat! For more info visit <a href=\"https://github.com/devsaurin/SD-NodeChat\">SD-NodeChat@GitHub</a>",
        }

        // extend default vaules
        var SDNodeChatConf = $.extend(_defaults, options);

        // remove trailing slash from URL using regular expression, if there any.
        SDNodeChatConf.server = SDNodeChatConf.server.replace(/\/$/, '');

        // Regualr expression for URL
        SDNodeChatConf.pattern = {};
        SDNodeChatConf.pattern.URL = /(https|http)(:\/\/)([\w\d.-]+)(:[\d]+)?([\/\w\d._-]+)?(\?[\w\d=&-_+!@%\+]+)?(#[\w\d!=%\+]+)?/ig;
        SDNodeChatConf.pattern.URLPlaceholder = '$1$2$3$4$5$6$7';

        return {
            /**
             *
             * @param       message {text}
             * @param       type    {text} ('self'/'other')
             * @returns     void
             * @usage       This function is use to display message.
             *              There are two ways to display messages
             *              1) type = 'self'    -> message from self
             *              2) type = 'other'   -> message from other users
             *              3) type = 'note'    -> Common notes to chat
             */
            addMsg : function (message, type) {
                var li = '<li class="' + type + '"><span>' + message + '</span></li>';
                $(SDNodeChatConf.chatContainer).append($(li));
                // scroll to new content
                this.scroll();
            },

            /**
             * @param       void
             * @returns     void
             * @usage       This function will be called when user send message. This function then add message
             *              to message container and will push message to server.
             */
            sendMsg: function () {

                var message = SDNodeChatConf.chatBox.val().trim();
                if (!message) return false;

                message = this.formatLink(message);

                this.addMsg(message, 'self');
                this.pushMsg(message);

                SDNodeChatConf.chatBox.val('');
                SDNodeChatConf.chatBox.focus();
            },

            /**
             * @param       message {Text}
             * @returns     message {Text}
             * @usage       This function will push a user message to server
             */
            formatLink: function (message) {
                return message.replace(SDNodeChatConf.pattern.URL, '<a target="_blank" href="' + SDNodeChatConf.pattern.URLPlaceholder + '">' + SDNodeChatConf.pattern.URLPlaceholder + '</a>');
            },
<commit_msg>Regular expression pattern added for URL. formatLink() function added to identify URLs inside message body and tranfer them to link. Fixes #5<commit_after>/**
 * @package      SD-NodeChat
 *
 * @author       <NAME> (SD) (http://saur.in)
 * @copyright    Copyright (C) 2014 <NAME>. All rights reserved.
 * @license      http://opensource.org/licenses/MIT, see LICENSE
 */

(function (window, document, $) {

    $.SDNodeChat = function (options) {

        var _defaults = {

            /**
             * @default     localhost
             * @type        Text
             * @value       server-IP address
             * @usage       This will be consider as default server for chat
             */
            server: "localhost",

            /**
             * @default     80
             * @type        Text
             * @value       Port number
             * @usage       This will be consider as default port for the chat server
             */
            port: "80",

            /**
             * @default     null
             * @type        [object Socket]
             * @value       [object Socket]
             * @usage       This socket object will be use to communicate to server.
             */
            socket: null,

            /**
             * @default     false
             * @type        boolean
             * @value       true/false
             * @usage       This can enable or disable log on server side.
             */
            debug: false,

            /**
             * @default     null
             * @type        Text
             * @value       username
             * @usage       This can enable or disable log on server side.
             */
            username: null,

            /**
             * @default     $('#messages')
             * @type        [object HTMLUListElement]
             * @value       [object HTMLUListElement]
             * @usage       This element will be consider as chat container
             */
            chatContainer: $('#messages'),

            /**
             * @default     $('#SendButtonID')
             * @type        [object HTMLButtonElement]
             * @value       [object HTMLButtonElement]
             * @usage       This element will be consider as an action to send chat
             */
            sendButton: $('#SendButtonID'),

            /**
             * @default     $('#chatTextBoxId')
             * @type        [object HTMLInputElement]
             * @value       [object HTMLInputElement]
             * @usage       This element will be consider as chat input it can also handle action to send chat
             */
            chatBox: $('#chatTextBox'),

            /**
             * @default     true
             * @type        boolean
             * @value       true/false
             * @usage       This can enable or disable enter key as sender on chatBox
             */
            enterToSend: true,

            /**
             * @default     $('#userContainer')
             * @type        [object HTMLUListElement]
             * @value       [object HTMLUListElement]
             * @usage       This element will be consider as a container of online users list.
             */
            usersContainer: $('#userContainer'),

            /**
             * @default     "Welcome to SD-NodeChat! For more info visit <a href="https://github.com/devsaurin/SD-NodeChat">SD-NodeChat@GitHub</a>"
             * @type        [text]
             * @value       [text]
             * @usage       This is to welcome a new user. It will be ignored if value not present.
             */
            welcomeNote: "Welcome to SD-NodeChat! For more info visit <a href=\"https://github.com/devsaurin/SD-NodeChat\">SD-NodeChat@GitHub</a>",
        }

        // extend default vaules
        var SDNodeChatConf = $.extend(_defaults, options);

        // remove trailing slash from URL using regular expression, if there any.
        SDNodeChatConf.server = SDNodeChatConf.server.replace(/\/$/, '');

        // Regualr expression for URL
        SDNodeChatConf.pattern = {};
        SDNodeChatConf.pattern.URL = /(https|http)(:\/\/)([\w\d.-]+)(:[\d]+)?([\/\w\d._-]+)?(\?[\w\d=&-_+!@%\+]+)?(#[\w\d!=%\+]+)?/ig;
        SDNodeChatConf.pattern.URLPlaceholder = '$1$2$3$4$5$6$7';

        return {
            /**
             *
             * @param       message {text}
             * @param       type    {text} ('self'/'other')
             * @returns     void
             * @usage       This function is use to display message.
             *              There are two ways to display messages
             *              1) type = 'self'    -> message from self
             *              2) type = 'other'   -> message from other users
             *              3) type = 'note'    -> Common notes to chat
             */
            addMsg : function (message, type) {
                var li = '<li class="' + type + '"><span>' + message + '</span></li>';
                $(SDNodeChatConf.chatContainer).append($(li));
                // scroll to new content
                this.scroll();
            },

            /**
             * @param       void
             * @returns     void
             * @usage       This function will be called when user send message. This function then add message
             *              to message container and will push message to server.
             */
            sendMsg: function () {

                var message = SDNodeChatConf.chatBox.val().trim();
                if (!message) return false;

                message = this.formatLink(message);

                this.addMsg(message, 'self');
                this.pushMsg(message);

                SDNodeChatConf.chatBox.val('');
                SDNodeChatConf.chatBox.focus();
            },

            /**
             * @param       message {Text}
             * @returns     message {Text}
             * @usage       This function will identify URLs inside message body and will transform them to links.
             */
            formatLink: function (message) {
                return message.replace(SDNodeChatConf.pattern.URL, '<a target="_blank" href="' + SDNodeChatConf.pattern.URLPlaceholder + '">' + SDNodeChatConf.pattern.URLPlaceholder + '</a>');
            },

{'fraction_non_alphanumeric': 0.11072, 'fraction_numerical': 0.00296, 'mean_word_length': 1.2403225806451612, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 33, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '68993', 'n_tokens_mistral': 3081, 'n_tokens_neox': 2986, 'n_words': 902}