npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-html5

v2.6.0

Published

Change your ng-attributes to data-ng-attributes for html5 validation

Downloads

2,980

Readme

angular-html5

Change your ng-attributes to data-ng-attributes for HTML5 validation

NPM Version NPM Downloads Build Status

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

Global

$ npm install --global angular-html5

Usage

❯ angular-html5 --help

  Usage: angular-html5 [options] <file>

  Options:

    -h, --help                      output usage information
    -V, --version                   output the version number
    -c, --custom-prefix [prefixes]  Optionally add custom prefixes to the list of converted directives.

  Examples:

    $ angular-html5 index.js
    $ angular-html5 --custom-prefix ui --custom-prefix gijo index.js > ./dist/index.js
    $ cat index.js | angular-html5 > ./dist/index.js

Programmatic

Install with npm

$ npm install --save-dev angular-html5

Usage

var htmlify = require('angular-html5')();

var str = fs.readFileSync('angular.html', 'utf8');

// test if contents need replacing (testing is quick, replacing is slower)
var needsReplace = htmlify.test(str);
if (needsReplace) {
    // get the transformed html string with data- attributes
    str = htmlify.replace(str);
}

Usage in build tools

Gulp - gulp-angular-htmlify

Grunt - grunt-angular-htmlify

API

var htmlify = require('angular-html5')(params);

API Methods

.test(str)

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

.replace(str)

Return a transformed string that contains data-ng-attributes or relevant transformed attributes for customPrefixes.

Usage: htmlify.replace(str)

Accepts: string

Returns: string

API Params

params is an object that contains the following settings:

customPrefixes

Type: Array

Default: [ ]

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.

Example Usage:

var str = require('angular-html5')({customPrefixes: ['ui-']}).replace(oldStr);

License

MIT © Gilad Peleg