string-code.js 580 Bytes
'use strict';

const _ = require('lodash');

const utf8ToHex = (string) => {
    var buf = new Buffer(string, 'utf8');

    return _.toUpper(buf.toString('hex'));
};

const hexToUtf8 = (string) => {
    let buf = new Buffer(string, 'hex');

    return buf.toString('utf8');
};

const decodeURIComponentExt = (string) => {

    try {
        string = decodeURIComponent(string);
    } catch (e) {
        string = '';
        console.error(`${string}, err: ${e.message}`);
    }

    return string;
};

module.exports = {
    utf8ToHex,
    hexToUtf8,
    decodeURIComponentExt
};