Search code examples
mysqlnode.jsexpressfarsi

Wrong string format when i use persian and english together in Node Js


I have a node js project with MySql database. I have to use Persian data in my DB like:

UserModel = {id: 1200, firstName: 'صابر', lastName: 'سجادی' , nationalCode:'4640147800', displayName: 'saber-sajadi', status: 1, createDateTime: null };

so for run stored procedure i need to convert object to string with this Code:

let objectToString = (object) => {
    let _string = "";
    let i = 1;
    for (let key in object) {
        var val = object[key];
        _string += (val == undefined || val == null) ? `null` : `'` + val + `' `;
        if (i < Object.keys(object).length) {
            _string += " , ";
            i++;
        }
    }
    return _string;
}



I expect the output of the function to be as follows:
enter image description here
but it return:
1200,'صابر','سجادی','4640147800','saber-sajadi','1',''

Please help me to solve this problem


Solution

  • we can use this function to solve problem:
    function wrap(str){ return '\u202B' + str + '\u202C'; }