How to use the encode function from he

Find comprehensive JavaScript he.encode code examples handpicked from public code repositorys.

672
673
674
675
676
677
678
679
680
681
  indentBy: "  ",
  supressEmptyNode: format === 'xccdf',
  tagValueProcessor: a => {
    return a ? he.encode(a.toString(), { useNamedReferences: false}) : a 
  },
  attrValueProcessor: a => he.encode(a, {isAttributeValue: true, useNamedReferences: true})
})
const zip = Archiver('zip', {zlib: {level: 9}})
res.attachment(`${parsedRequest.collection.name}-${format.startsWith('ckl-') ? 'CKL' : 'XCCDF'}.zip`)
zip.pipe(res)
fork icon19
star icon50
watch icon8

747
748
749
750
751
752
753
754
755
756
757
        ret = ret.replace(/&/g, '&');
        ret = ret.replace(/>/g, '>');
        ret = ret.replace(/</g, '&lt;');
        ret = ret.replace(/"/g, '&quot;');
        ret = ret.replace(/'/g, "&apos;");*/
    return he.encode(content, {'useNamedReferences': true});
}


/**
 * Helper function for server API tokens. You should likely use authenticatedFetch()
fork icon8
star icon11
watch icon6

122
123
124
125
126
127
128
129
130
131
    img.loading = 'eager';
  }
};

function safe(input) {
  if (input) return he.encode(input, { 'useNamedReferences': true });
  return '';
}

async function handler(request, response) {
fork icon8
star icon11
watch icon6

+ 2 other calls in file

37
38
39
40
41
42
43
44
45
46
// usually mark has entities like &rarr; but when copying dumps from the
// browser, they come as unicode.
var arr = mark.split(";");
var core = arr.shift();
var termsArr = JSON.parse(arr.join(";"));
termsArr = termsArr.map(x => x.match(/&/) ? x : He.encode(x, {useNamedReferences:true}));
termsArr = termsArr.map(x => ENTITY_MAP.hasOwnProperty(x) ? ENTITY_MAP[x] : x);
termsArr = termsArr.slice(0, 1 + maxTermOfCore(JSON.parse(core)));
mark = core + ";" + JSON.stringify(termsArr);
var fact = state.factsByMark[mark];
fork icon1
star icon1
watch icon3

+ 2 other calls in file

1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
    password = he.decode(parsed.password);
    parsed.password = '';
}

if (username || password) {
    headers.Authorization = `Basic ${Buffer.from(he.encode(username || '') + ':' + he.encode(password || '')).toString('base64')}`;
}

let customHeaders = request.payload.customHeaders
    .split(/[\r\n]+/)
fork icon113
star icon0
watch icon16

36
37
38
39
40
41
42
43
44
45
46
 * @private
 * @param  {string} html
 * @return {string}
 */
exports.escape = function(html) {
  return he.encode(String(html), {useNamedReferences: false});
};


/**
 * Test if the given obj is type of string.
fork icon1
star icon0
watch icon1

204
205
206
207
208
209
210
211
212
213
}
var infoHashes = JSON.parse(he.decode(req.body.infoHashes));
for (var i = 0; i < infoHashes.length; i++) {
 console.log(infoHashes[i]);
 infoHashes[i] = infoHashes.length > 0 ? infoHashes[i].trim() : ""
 infoHashes[i] = infoHashes.length > 0 ? he.encode(infoHashes[i]) : "";
}
st_george.recommendTorrent(driver, infoHashes, function(data){
  if(data.records[0]){
    console.log("FOUND TAB RECO!")
fork icon0
star icon0
watch icon1

1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
delete req.body.uuid;
//console.log(req.body);
if(!req.body.ad) req.body.ad = [];
// req.body.timestamp_modified = new Date().getTime();
req.body.gallery = he.encode(req.body.gallery);
req.body.detail = he.encode(req.body.detail);
req.body.id = req.body.id_letter + req.body.id_number;
console.log(req.body.area_use);
if(req.body.area_use[0] === ''){
	req.body.area_use = req.body.area_use[1];
fork icon0
star icon0
watch icon1

+ 3 other calls in file