Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

decode-html

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decode-html - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

33

index.js

@@ -0,14 +1,23 @@

// Store markers outside of the function scope,
// not to recreate them on every call
var entities = {
'amp': '&',
'apos': '\'',
'lt': '<',
'gt': '>',
'quot': '"',
'nbsp': '\xa0'
};
var entityPattern = /&([a-z]+);/ig;
module.exports = function decodeHTMLEntities(text) {
var replacements = [
['amp', '&'],
['apos', '\''],
['lt', '<'],
['gt', '>']
];
replacements.forEach(function(replace){
text = text.replace(new RegExp('&'+replace[0]+';', 'g'), replace[1]);
// A single replace pass with a static RegExp is faster than a loop
return text.replace(entityPattern, function(match, entity) {
entity = entity.toLowerCase();
if (entities.hasOwnProperty(entity)) {
return entities[entity];
}
// return original string if there is no matching entity (no replace)
return match;
});
return text;
};
};
{
"name": "decode-html",
"version": "1.0.2",
"version": "2.0.0",
"description": "decode html entities",
"main": "index.js",
"dependencies": {},
"devDependencies": {},
"devDependencies": {
"tape": "^4.5.1"
},
"scripts": {

@@ -9,0 +11,0 @@ "test": "node test.js"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc