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

ng-di-annotate

v0.4.0

Published

add, remove and rebuild angularjs and ng-di dependency injection annotations

Downloads

49

Readme

ng-di-annotate

ng-annotate adds and removes AngularJS and NG-DI dependency injection annotations. It is non-intrusive so your source code stays exactly the same otherwise. No lost comments or moved lines.

This is a fork of and should be used in place of ng-annotate for support of NG-DI.

Without annotations:

angular.module("MyMod").controller("MyCtrl", function($scope, $timeout) {
});

With annotations:

angular.module("MyMod").controller("MyCtrl", ["$scope","$timeout", function($scope, $timeout) {
}]);

Annotations are useful because with them you're able to minify your source code using your favorite JS minifier.

Installation and usage

npm install -g ng-di-annotate

Then run it as ng-annotate OPTIONS file.js. The errors (if any) will go to stderr, the transpiled source to stdout, so redirect it like ng-annotate file.js > output.js.

Use the --add (-a) option to add annotations where non-existing, use --remove (-r) to remove all existing annotations, use --add --remove (-ar) to rebuild all annotations.

See description of the --regexp options further down.

There's also a Grunt plugin, see grunt-ng-annotate.

ng-annotate is written in ES6 constlet style and uses defs.js to transpile to ES5. Build instructions in BUILD.md.

License

MIT, see LICENSE file.

Changes

See CHANGES.md.

Why?

  • Keep your code base clutter free from annotations but add them in your build step prior to minimizing
  • De-clutter an existing code base by removing annotations, non-intrusively
  • If you must store annotations in the repo (for any reason) then checkout, remove them, code and refactor without annotations, add them back and commit. Alternatively checkout, code and refactor (ignoring annotations), rebuild them and commit.

Declaration forms

ng-annotate understands the two common declaration forms:

Long form:

angular.module("MyMod").controller("MyCtrl", function($scope, $timeout) {
});

Short form:

myMod.controller("MyCtrl", function($scope, $timeout) {
});

It's not limited to .controller of course. It understands .config, .factory, .directive, .filter, .run, .controller, .provider, .service and .animation.

For short forms it does not need to see the declaration of myMod so you can run it on your individual source files without concatenating. If ng-annotate detects a short form false positive then you can use the --regexp option to limit the module identifier. Examples: --regexp "^myMod$" (match only myMod) or --regexp "^$" (ignore short forms).

ng-annotate understands this.$get = function($scope) .. and {.., $get: function($scope) ..} inside a provider.

ng-annotate understands return {.., controller: function($scope) ..} inside a directive.

ng-annotate understands $provide.decorator("bar", function($scope) ..) and other methods on provide such as factory.

ng-annotate understands chaining.

Performance

ng-annotate is designed to be very fast (in general limited by parse speed). It traverses the AST exactly once and transforms it without the need for an AST -> source decompilation step.

Library (API)

ng-annotate can be used as a library. See ng-annotate.js for further info about options and return value.

var ngAnnotate = require("ng-di-annotate");
var transformedSource = ngAnnotate(src, {add: true}).src;