Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
angular-html5
Advanced tools
Change your ng-attributes to data-ng-attributes for HTML5 validation
Ever tried to run an Angular HTML page into w3c validator? Yeah it's a mess.
HTML5 has a preset definition of valid tag elements, and also allows data-attributes.
Angular, being as great as it is, allows you set set custom directives, that don't pass the
w3c validations. Angular default directives come with an option to be named data-something
.
If you are like me, it isn't fun using data-ng-include
or data-ng-switch
and prefer to use the shorter
versions. Using this module, you can easily convert the HTML attributes of Angular (and custom prefixes you want) to
valid HTML5 tags that start with data-something
.
Turn this:
<html ng-app="myApp">
...
<body ng-controller="MainCtrl">
</body>
</html>
Into this:
<html data-ng-app="myApp">
...
<body data-ng-controller="MainCtrl">
</body>
</html>
angular-html5 looks for ng-
directives by default and can handle the following cases:
<!-- attribute -->
<ANY ng-directive>
<!-- regular element -->
<ng-directive></ng-directive>
<!-- self closing element -->
<ng-directive />
<!-- custom directive prefix -->
<ui-router></ui-router>
<!-- your name prefix -->
<gilad-cool-loader></gilad-cool-loader>
You can add additional prefixes using the option customPrefixes
.
This plugin plays nice with type="text/ng-template"
and won't break it.
Install with npm
npm install --save-dev angular-html5
var htmlify = require('angular-html5')();
var str = fs.readFileSync('angular.html').toString();
var needsReplace = htmlify.test(str); //--> true if ng-attributes exist in file
if (needsReplace) {
str = htmlify.replace(str); //--> returns modified string with transofrmed attributes
}
??
??
var htmlify = require('angular-html5')(params);
Test whether a string containing HTML has ng-attributes
that can be transformed
to data-ng-attributes
.
Usage: htmlify.test(str)
Accepts: string
Returns: Boolean
Return a transformed string that contains data-ng-attributes
or relevant transformed attributes
for customPrefixes
.
Usage: htmlify.replace(str)
Accepts: string
Returns: string
params
is an object that contains the following settings:
An array to optionally add custom prefixes to the list of converted directives.
For example: ['ui-', 'gijo-']
By default only ng-
prefixes are are handled. Any items you add here will be handled as well.
Note: for this to work - you will need to make sure your directives can load with a data-
prefix.
Type: Array
Default: [ ]
Usage:
var str = require('angular-html5')({customPrefixes: ['ui-']}).replace(oldStr);
MIT ©2014 Gilad Peleg
FAQs
Change your ng-attributes to data-ng-attributes for html5 validation
The npm package angular-html5 receives a total of 641 weekly downloads. As such, angular-html5 popularity was classified as not popular.
We found that angular-html5 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.