Transform hexcode "& # x2b;" into "+" in JavaScript

0

I'm using a payment API that requires the phone numbers entered to be in the E.164 ( +[Código do país][código da cidade][numero de 8~9 dígitos] ) and string (as in the example below).

However, when you add the + sign, it is transformed into + . Is there any way to turn this code to + again?

{
    "object": "customer",
    "id": 233406,
    "external_id": "#123456789",
    "type": "individual",
    "country": "br",
    "document_number": null,
    "document_type": "cpf",
    "name": "João das Neves",
    "email": "[email protected]",
    "phone_numbers": [
        "+5511999999999",
        "+5511888888888"
    ],
    "born_at": null,
    "birthday": "1985-01-01",
    "gender": null,
    "date_created": "2017-08-14T23:28:36.296Z",
    "documents": [
        {
            "object": "document",
            "id": "doc_cj6csivuv05zj696dkzzjbfmq",
            "type": "cpf",
            "number": "11111111111"
        }
    ],
    "addresses": [],
    "phones": []
}
    
asked by anonymous 30.10.2018 / 18:15

1 answer

0

Try

function htmlDecode(input) {
  var e = document.createElement('div');
  e.innerHTML = input;
  return e.childNodes[0].nodeValue;
}

console.log(htmlDecode("+"));

The he lib (for "HTML entities") is a robust HTML entity encoder / decoder written in JavaScript. Project Here

    
30.10.2018 / 19:17