angular-html5
Advanced tools
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" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8123
68
1
3
+ Addedcheerio@^0.18.0
+ AddedCSSselect@0.4.1(transitive)
+ AddedCSSwhat@0.4.7(transitive)
+ Addedcheerio@0.18.0(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddom-serializer@0.0.1(transitive)
+ Addeddomelementtype@1.1.3(transitive)
+ Addeddomhandler@2.3.0(transitive)
+ Addeddomutils@1.4.31.5.1(transitive)
+ Addedentities@1.0.01.1.2(transitive)
+ Addedhtmlparser2@3.8.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedlodash@2.4.2(transitive)
+ Addedreadable-stream@1.1.14(transitive)
+ Addedstring_decoder@0.10.31(transitive)