angular-html5
Advanced tools
Comparing version 2.2.1 to 2.3.0
@@ -50,3 +50,2 @@ #!/usr/bin/env node | ||
function readFiles(files) { | ||
//TOOD: handle multiple files | ||
var file = files[0]; | ||
@@ -53,0 +52,0 @@ var _contents = fs.readFileSync(path.resolve(process.cwd(), file), 'utf8'); |
75
index.js
@@ -1,73 +0,2 @@ | ||
'use strict'; | ||
var cheerio = require('cheerio'); | ||
var defaultPrefix = 'ng-'; | ||
module.exports = function (params) { | ||
params = params || {}; | ||
//find ng-something by default | ||
var customPrefixes = params.customPrefixes || []; | ||
if (customPrefixes && !Array.isArray(customPrefixes)) { | ||
customPrefixes = [customPrefixes]; | ||
} | ||
var prefixes = [defaultPrefix].concat(customPrefixes); | ||
var rPrefix = new RegExp('^(' + prefixes.join('|') + ')', 'ig'); | ||
return { | ||
test: function (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) { | ||
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(); | ||
} | ||
}; | ||
}; | ||
var htmlify = require('./lib/angular-html5'); | ||
module.exports = exports = htmlify; |
{ | ||
"name": "angular-html5", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"description": "Change your ng-attributes to data-ng-attributes for html5 validation", | ||
@@ -35,12 +35,12 @@ "repository": "pgilad/angular-html5", | ||
"devDependencies": { | ||
"js-beautify": "^1.5.4", | ||
"mocha": "*", | ||
"should": "*" | ||
"js-beautify": "^1.5.5", | ||
"mocha": "^2.2.4", | ||
"should": "^6.0.1" | ||
}, | ||
"dependencies": { | ||
"cheerio": "^0.18.0", | ||
"commander": "^2.5.1", | ||
"get-stdin": "^3.0.2", | ||
"log-symbols": "^1.0.1" | ||
"cheerio": "^0.19.0", | ||
"commander": "^2.8.1", | ||
"get-stdin": "^4.0.1", | ||
"log-symbols": "^1.0.2" | ||
} | ||
} |
@@ -97,7 +97,9 @@ # angular-html5 | ||
var str = fs.readFileSync('angular.html').toString(); | ||
var str = fs.readFileSync('angular.html', 'utf8'); | ||
var needsReplace = htmlify.test(str); //--> true if ng-attributes exist in file | ||
// test if contents need replacing (testing is quick, replacing is slower) | ||
var needsReplace = htmlify.test(str); | ||
if (needsReplace) { | ||
str = htmlify.replace(str); //--> returns the modified string with transformed attributes | ||
// get the transformed html string with data- attributes | ||
str = htmlify.replace(str); | ||
} | ||
@@ -108,8 +110,6 @@ ``` | ||
#### [Gulp](https://github.com/gulpjs/gulp) - See [gulp-angular-htmlify](https://github.com/pgilad/gulp-angular-htmlify) | ||
#### [Gulp](https://github.com/gulpjs/gulp) - [gulp-angular-htmlify](https://github.com/pgilad/gulp-angular-htmlify) | ||
#### [Grunt](http://gruntjs.com/) - See [grunt-angular-htmlify](https://github.com/pgilad/grunt-angular-htmlify) | ||
#### [Grunt](http://gruntjs.com/) - [grunt-angular-htmlify](https://github.com/pgilad/grunt-angular-htmlify) | ||
#### [Broccoli](https://github.com/broccolijs/broccoli) - ?? | ||
## API | ||
@@ -116,0 +116,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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
8352
60
1
+ Addedboolbase@1.0.0(transitive)
+ Addedcheerio@0.19.0(transitive)
+ Addedcss-select@1.0.0(transitive)
+ Addedcss-what@1.0.0(transitive)
+ Addeddom-serializer@0.1.1(transitive)
+ Addeddomelementtype@1.3.1(transitive)
+ Addedget-stdin@4.0.1(transitive)
+ Addedlodash@3.10.1(transitive)
+ Addednth-check@1.0.2(transitive)
- RemovedCSSselect@0.4.1(transitive)
- RemovedCSSwhat@0.4.7(transitive)
- Removedcheerio@0.18.0(transitive)
- Removeddom-serializer@0.0.1(transitive)
- Removeddomelementtype@1.1.3(transitive)
- Removedget-stdin@3.0.2(transitive)
- Removedlodash@2.4.2(transitive)
Updatedcheerio@^0.19.0
Updatedcommander@^2.8.1
Updatedget-stdin@^4.0.1
Updatedlog-symbols@^1.0.2