Socket
Socket
Sign inDemoInstall

angular-html5

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-html5 - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

86

index.js
'use strict';
var cheerio = require('cheerio');
var defaultPrefix = 'ng-';

@@ -7,38 +8,67 @@

//find ng-something by default
var prefix = defaultPrefix;
var customPrefixes = params.customPrefixes;
//optionally add custom prefixes
if (Array.isArray(customPrefixes) && customPrefixes.length) {
prefix += '|' + customPrefixes.join('|');
var customPrefixes = params.customPrefixes || [];
if (customPrefixes && !Array.isArray(customPrefixes)) {
customPrefixes = [customPrefixes];
}
var prefixes = [defaultPrefix].concat(customPrefixes);
var rPrefix = new RegExp('^(' + prefixes.join('|') + ')', 'ig');
//wrap around to insert into replace str later
prefix = '(' + prefix + '){1}';
//handle the following:
//1. ' ng-'
//2. '<ng-'
//3. '</ng-'
var allowedPreChars = '(\\s|<|<\/|["\']){1}';
//build find/replace regex
//$1 -> allowable pre-chars
//$2 -> prefix match
//$3 -> actual directive (partially)
var replaceRegex = new RegExp(allowedPreChars + prefix + '(\\w+)', 'ig');
//replace with data-ng-something
var replaceStr = '$1data-$2$3';
return {
test: function (str) {
//see http://stackoverflow.com/questions/2141974/javascript-regex-literal-with-g-used-multiple-times
replaceRegex.lastIndex = 0;
return replaceRegex.test(str);
var $ = cheerio.load(str, {
recognizeSelfClosing: true
});
var foundPrefix = false;
$('*').each(function (i, el) {
// check tagName
rPrefix.lastIndex = 0;
foundPrefix = rPrefix.test(el.tagName);
// early exit
if (foundPrefix) {
return false;
}
// check attributes
var attrs = Object.keys($(el).attr()).filter(function (attr) {
rPrefix.lastIndex = 0;
return rPrefix.test(attr);
});
foundPrefix = attrs.length > 0;
// early exit
if (foundPrefix) {
return false;
}
});
return foundPrefix;
},
replace: function (str) {
//see http://stackoverflow.com/questions/2141974/javascript-regex-literal-with-g-used-multiple-times
replaceRegex.lastIndex = 0;
return str.replace(replaceRegex, replaceStr);
var $ = cheerio.load(str, {
xmlMode: false,
decodeEntities: false,
normalizeWhitespace: false,
recognizeSelfClosing: true
});
$('*').each(function (i, el) {
var $el = $(el);
Object.keys($el.attr()).forEach(function (attr) {
rPrefix.lastIndex = 0;
if (!rPrefix.test(attr)) {
return;
}
$el.attr('data-' + attr, $el.attr(attr));
$el.removeAttr(attr);
});
// check tagName
rPrefix.lastIndex = 0;
if (rPrefix.test(el.tagName)) {
$el.replaceWith(function () {
return $('<data-' + el.tagName + '/>').attr($el.attr()).append($el.html());
});
}
});
return $.html();
}
};
};
{
"name": "angular-html5",
"version": "1.2.0",
"version": "2.0.0",
"description": "Change your ng-attributes to data-ng-attributes for html5 validation",

@@ -33,5 +33,9 @@ "repository": "pgilad/angular-html5",

"devDependencies": {
"js-beautify": "^1.5.4",
"mocha": "*",
"should": "*"
},
"dependencies": {
"cheerio": "^0.18.0"
}
}
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