source: node_modules/parse-entities/decode-entity.browser.js@ 65b6638

main
Last change on this file since 65b6638 was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 867 bytes
Line 
1'use strict'
2
3/* eslint-env browser */
4
5var el
6
7var semicolon = 59 // ';'
8
9module.exports = decodeEntity
10
11function decodeEntity(characters) {
12 var entity = '&' + characters + ';'
13 var char
14
15 el = el || document.createElement('i')
16 el.innerHTML = entity
17 char = el.textContent
18
19 // Some entities do not require the closing semicolon (`&not` - for instance),
20 // which leads to situations where parsing the assumed entity of &notit; will
21 // result in the string `¬it;`. When we encounter a trailing semicolon after
22 // parsing and the entity to decode was not a semicolon (`&semi;`), we can
23 // assume that the matching was incomplete
24 if (char.charCodeAt(char.length - 1) === semicolon && characters !== 'semi') {
25 return false
26 }
27
28 // If the decoded string is equal to the input, the entity was not valid
29 return char === entity ? false : char
30}
Note: See TracBrowser for help on using the repository browser.