Function to escape special charecter

/**

        * Function to escape from special characters in the data

        * @param textvalue data from PPA account

        * @returns {*} data after replacing special characters

        */

        const escapeSpecialChar = (textvalue) => {

            try {

                if(textvalue){

                textvalue = textvalue.replaceAll(/&/g, ‘&’);

                textvalue = textvalue.replaceAll(/”/g, ‘"’);

                textvalue = textvalue.replaceAll(/’/g, ‘'’);

                textvalue = textvalue.replace(/</g, ‘&lt;’);

                textvalue = textvalue.replace(/>/g, ‘&gt;’);

            }

                return textvalue;

            } catch (e) {

                log.error({

                    title: e.name,

                    details: e

                });

                return textvalue;

            }

        }

Leave a comment

Your email address will not be published. Required fields are marked *