• Stars
    star
    4,984
  • Rank 8,384 (Top 0.2 %)
  • Language
  • License
    MIT License
  • Created about 11 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📚 Community-driven set of best practices for AngularJS application development

Join the chat at https://gitter.im/mgechev/angularjs-style-guide

Introduction

The goal of this style guide is to present a set of best practices and style guidelines for one AngularJS application. These best practices are collected from:

  1. AngularJS source code
  2. Source code or articles I've read
  3. My own experience

Note 1: this is still a draft of the style guide, its main goal is to be community-driven so filling the gaps will be greatly appreciated by the whole community.

Note 2: before following any of the guidelines in the translations of the English document, make sure they are up-to date. The latest version of the AngularJS style guide is in the current document.

In this style guide you won't find common guidelines for JavaScript development. Such can be found at:

  1. Google's JavaScript style guide
  2. Mozilla's JavaScript style guide
  3. Douglas Crockford's JavaScript style guide
  4. Airbnb JavaScript style guide
  5. Idiomatic JavaScript style guide

For AngularJS development recommended is the Google's JavaScript style guide.

In AngularJS's GitHub wiki there is a similar section by ProLoser, you can check it here.

Translations

Table of content

General

Directory structure

Since a large AngularJS application has many components it's best to structure it in a directory hierarchy. There are two main approaches:

  • Creating high-level divisions by component types and lower-level divisions by functionality.

In this way the directory structure will look like:

.
├── app
│   ├── app.js
│   ├── controllers
│   │   ├── home
│   │   │   ├── FirstCtrl.js
│   │   │   └── FirstCtrl.spec.js
│   │   │   └── SecondCtrl.js
│   │   │   └── SecondCtrl.spec.js
│   │   └── about
│   │       └── ThirdCtrl.js
│   │       └── ThirdCtrl.spec.js
│   ├── directives
│   │   ├── home
│   │   │   └── directive1.js
│   │   │   └── directive1.spec.js
│   │   └── about
│   │       ├── directive2.js
│   │       ├── directive2.spec.js
│   │       └── directive3.js
│   │       └── directive3.spec.js
│   ├── filters
│   │   ├── home
│   │   └── about
│   └── services
│       ├── CommonService.js
│       ├── CommonService.spec.js
│       ├── cache
│       │   ├── Cache1.js
│       │   ├── Cache1.spec.js
│       │   └── Cache2.js
│       │   └── Cache2.spec.js
│       └── models
│           ├── Model1.spec.js
│           ├── Model1.js
│           └── Model2.spec.js
│           └── Model2.js
├── partials
├── lib
└── e2e-tests
  • Creating high-level divisions by functionality and lower-level divisions by component types.

Here is its layout:

.
├── app
│   ├── app.js
│   ├── common
│   │   ├── controllers
│   │   ├── directives
│   │   ├── filters
│   │   └── services
│   ├── home
│   │   ├── controllers
│   │   │   ├── FirstCtrl.js
│   │   │   ├── FirstCtrl.spec.js
│   │   │   └── SecondCtrl.js
│   │   │   └── SecondCtrl.spec.js
│   │   ├── directives
│   │   │   └── directive1.js
│   │   │   └── directive1.spec.js
│   │   ├── filters
│   │   │   ├── filter1.js
│   │   │   ├── filter1.spec.js
│   │   │   └── filter2.js
│   │   │   └── filter2.spec.js
│   │   └── services
│   │       ├── service1.js
│   │       ├── service1.spec.js
│   │       └── service2.js
│   │       └── service2.spec.js
│   └── about
│       ├── controllers
│       │   └── ThirdCtrl.js
│       │   └── ThirdCtrl.spec.js
│       ├── directives
│       │   ├── directive2.js
│       │   ├── directive2.spec.js
│       │   └── directive3.js
│       │   └── directive3.spec.js
│       ├── filters
│       │   └── filter3.js
│       │   └── filter3.spec.js
│       └── services
│           └── service3.js
│           └── service3.spec.js
├── partials
├── lib
└── e2e-tests
  • In case the directory name contains multiple words, use lisp-case syntax:
app
 ├── app.js
 └── my-complex-module
     ├── controllers
     ├── directives
     ├── filters
     └── services
  • Put all the files associated with the given directive (i.e. templates, CSS/SASS files, JavaScript) in a single folder. If you choose to use this style be consistent and use it everywhere along your project.
app
└── directives
    ├── directive1
    │   ├── directive1.html
    │   ├── directive1.js
    │   ├── directive1.spec.js
    │   └── directive1.sass
    └── directive2
        ├── directive2.html
        ├── directive2.js
        ├── directive2.spec.js
        └── directive2.sass

This approach can be combined with both directory structures above.

  • The unit tests for a given component (*.spec.js) should be located in the directory where the component is. This way when you make changes to a given component finding its test is easy. The tests also act as documentation and show use cases.
services
├── cache
│   ├── cache1.js
│   └── cache1.spec.js
└── models
    ├── model1.js
    └── model1.spec.js
  • The app.js file should contain route definitions, configuration and/or manual bootstrap (if required).
  • Each JavaScript file should only hold a single component. The file should be named with the component's name.
  • Use AngularJS project structure template like Yeoman, ng-boilerplate.

Conventions about component naming can be found in each component section.

Markup

TLDR; Put the scripts at the bottom.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>MyApp</title>
</head>
<body>
  <div ng-app="myApp">
    <div ng-view></div>
  </div>
  <script src="angular.js"></script>
  <script src="app.js"></script>
</body>
</html>

Keep things simple and put AngularJS specific directives after standard attributes. This will make it easier to skim your code and will make it easier to maintain because your attributes are consistently grouped and positioned.

<form class="frm" ng-submit="login.authenticate()">
  <div>
    <input class="ipt" type="text" placeholder="name" require ng-model="user.name">
  </div>
</form>

Other HTML attributes should follow the Code Guide's recommendation

Naming conventions

The following table is shown the naming conventions for every element:

Element Naming style Example usage
Modules lowerCamelCase angularApp
Controllers Functionality + 'Ctrl' AdminCtrl
Directives lowerCamelCase userInfo
Filters lowerCamelCase userFilter
Services UpperCamelCase User constructor
Factories lowerCamelCase dataFactory others

Others

  • Use:
    • $timeout instead of setTimeout
    • $interval instead of setInterval
    • $window instead of window
    • $document instead of document
    • $http instead of $.ajax
    • $location instead of window.location or $window.location
    • $cookies instead of document.cookie

This will make your testing easier and in some cases prevent unexpected behaviour (for example, if you missed $scope.$apply in setTimeout).

  • Automate your workflow using tools like:

  • Use promises ($q) instead of callbacks. It will make your code look more elegant and clean, and save you from callback hell.

  • Use $resource instead of $http when possible. The higher level of abstraction will save you from redundancy.

  • Use an AngularJS pre-minifier (ng-annotate) for preventing problems after minification.

  • Don't use globals. Resolve all dependencies using Dependency Injection, this will prevent bugs and monkey patching when testing.

  • Avoid globals by using Grunt/Gulp to wrap your code in Immediately Invoked Function Expression (IIFE). You can use plugins like grunt-wrap or gulp-wrap for this purpose. Example (using Gulp)

     gulp.src("./src/*.js")
     .pipe(wrap('(function(){\n"use strict";\n<%= contents %>\n})();'))
     .pipe(gulp.dest("./dist"));
  • Do not pollute your $scope. Only add functions and variables that are being used in the templates.

  • Prefer the usage of controllers instead of ngInit. There are only a few appropriate uses of ngInit, such as for aliasing special properties of ngRepeat, and for injecting data via server side scripting. Besides these few cases, you should use controllers rather than ngInit to initialize values on a scope. The expression passed to ngInit should go through lexing, parsing and evaluation by the Angular interpreter implemented inside the $parse service. This leads to:

    • Performance impact, because the interpreter is implemented in JavaScript
    • The caching of the parsed expressions inside the $parse service doesn't make a lot of sense in most cases, since ngInit expressions are often evaluated only once
    • Is error-prone, since you're writing strings inside your templates, there's no syntax highlighting and further support by your editor
    • No run-time errors are thrown
  • Do not use $ prefix for the names of variables, properties and methods. This prefix is reserved for AngularJS usage.

  • Do not use JQUERY inside your app, If you must, use JQLite instead with angular.element.

  • When resolving dependencies through the DI mechanism of AngularJS, sort the dependencies by their type - the built-in AngularJS dependencies should be first, followed by your custom ones:

module.factory('Service', function ($rootScope, $timeout, MyCustomDependency1, MyCustomDependency2) {
  return {
    //Something
  };
});

Modules

  • Modules should be named with lowerCamelCase. For indicating that module b is submodule of module a you can nest them by using namespacing like: a.b.

    There are two common ways for structuring the modules:

    1. By functionality
    2. By component type

    Currently there's not a big difference, but the first way looks cleaner. Also, if lazy-loading modules is implemented (currently not in the AngularJS roadmap), it will improve the app's performance.

Controllers

  • Do not manipulate DOM in your controllers, this will make your controllers harder for testing and will violate the Separation of Concerns principle. Use directives instead.

  • The naming of the controller is done using the controller's functionality (for example shopping cart, homepage, admin panel) and the substring Ctrl in the end.

  • Controllers are plain javascript constructors, so they will be named UpperCamelCase (HomePageCtrl, ShoppingCartCtrl, AdminPanelCtrl, etc.).

  • The controllers should not be defined as globals (even though AngularJS allows this, it is a bad practice to pollute the global namespace).

  • Use the following syntax for defining controllers:

    function MyCtrl(dependency1, dependency2, ..., dependencyn) {
      // ...
    }
    module.controller('MyCtrl', MyCtrl);

    In order to prevent problems with minification, you can automatically generate the array definition syntax from the standard one using tools like ng-annotate (and grunt task grunt-ng-annotate).

    Another alternative will be to use $inject like:

    angular
     .module('app')
     .controller('HomepageCtrl', HomepageCtrl);
    
    HomepageCtrl.$inject = ['$log', '$http', 'ngRoute'];
    
    function HomepageCtrl($log, $http, ngRoute) {
     // ...
    }
  • Avoid use of $scope service to define functions and properties as part of controllers. Use $scope only if It's really needed: 0. For publish and subscribe to events: $scope.$emit, $scope.$broadcast, and $scope.$on. 0. For watch values or collections: $scope.$watch, $scope.$watchCollection

  • Prefer using controller as syntax and capture this using a variable:

    <div ng-controller="MainCtrl as main">
       {{ main.things }}
    </div>
    app.controller('MainCtrl', MainCtrl);
    MainCtrl.$inject = ['$http'];
    
    function MainCtrl ($http) {
      var vm = this;
      //a clearer visual connection on how is defined on the view
      vm.title = 'Some title';
      vm.description = 'Some description';
    
      $http.get('/api/main/things').then(function (response) {
          vm.things = response.data.things; // Adding 'things' as a property of the controller
      });
    }

    Avoid using this keyword repeatedly inside a controller:

      app.controller('MainCtrl', MainCtrl);
      MainCtrl.$inject = ['$http'];
    
      // Avoid
      function MainCtrl ($http) {
        this.title = 'Some title';
        this.description = 'Some description';
    
        $http.get('/api/main/things').then(function (response) {
            // Warning! 'this' is in a different context here.
            // The property will not be added as part of the controller context
            this.things = response.data.things;
        });
      }

    Using a consistent and short variable name is preferred, for example vm.

    The main benefits of using this syntax:

    • Creates an 'isolated' component - binded properties are not part of $scope prototype chain. This is good practice since $scope prototype inheritance has some major drawbacks (this is probably the reason it was removed on Angular 2):
      • It is hard to track where data is coming from.
      • Scope's value changes can affect places you did not intend to affect.
      • Harder to refactor.
      • The 'dot rule'.
    • Removes the use of $scope when no need for special operations (as mentioned above). This is a good preparation for AngularJS V2.
    • Syntax is closer to that of a 'vanilla' JavaScript constructor

    Digging more into controller as: digging-into-angulars-controller-as-syntax

  • If using array definition syntax, use the original names of the controller's dependencies. This will help you produce more readable code:

    function MyCtrl(l, h) {
      // ...
    }
    
    module.controller('MyCtrl', ['$log', '$http', MyCtrl]);

    which is less readable than:

    function MyCtrl($log, $http) {
      // ...
    }
    
    module.controller('MyCtrl', ['$log', '$http', MyCtrl]);

    This especially applies to a file that has so much code that you'd need to scroll through. This would possibly cause you to forget which variable is tied to which dependency.

  • Make the controllers as lean as possible. Abstract commonly used functions into a service.

  • Avoid writing business logic inside controllers. Delegate business logic to a model, using a service. For example:

    //This is a common behaviour (bad example) of using business logic inside a controller.
    angular.module('Store', [])
    .controller('OrderCtrl', function () {
      var vm = this;
    
      vm.items = [];
    
      vm.addToOrder = function (item) {
        vm.items.push(item);//-->Business logic inside controller
      };
    
      vm.removeFromOrder = function (item) {
        vm.items.splice(vm.items.indexOf(item), 1);//-->Business logic inside controller
      };
    
      vm.totalPrice = function () {
        return vm.items.reduce(function (memo, item) {
          return memo + (item.qty * item.price);//-->Business logic inside controller
        }, 0);
      };
    });

    When delegating business logic into a 'model' service, controller will look like this (see 'use services as your Model' for service-model implementation):

    // order is used as a 'model'
    angular.module('Store', [])
    .controller('OrderCtrl', function (order) {
      var vm = this;
    
      vm.items = order.items;
    
      vm.addToOrder = function (item) {
        order.addToOrder(item);
      };
    
      vm.removeFromOrder = function (item) {
        order.removeFromOrder(item);
      };
    
      vm.totalPrice = function () {
        return order.total();
      };
    });

    Why business logic / app state inside controllers is bad?

    • Controllers instantiated for each view and dies when the view unloads
    • Controllers are not reusable - they are coupled with the view
    • Controllers are not meant to be injected
  • Communicate within different controllers using method invocation (possible when a child wants to communicate with its parent) or $emit, $broadcast and $on methods. The emitted and broadcasted messages should be kept to a minimum.

  • Make a list of all messages which are passed using $emit, $broadcast and manage it carefully because of name collisions and possible bugs.

    Example:

    // app.js
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    Custom events:
      - 'authorization-message' - description of the message
        - { user, role, action } - data format
          - user - a string, which contains the username
          - role - an ID of the role the user has
          - action - specific action the user tries to perform
    * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  • When you need to format data encapsulate the formatting logic into a filter and declare it as dependency:

    function myFormat() {
      return function () {
        // ...
      };
    }
    module.filter('myFormat', myFormat);
    
    function MyCtrl($scope, myFormatFilter) {
      // ...
    }
    
    module.controller('MyCtrl', MyCtrl);
  • In case of nested controllers use "nested scoping" (the controllerAs syntax):

    app.js

    module.config(function ($routeProvider) {
      $routeProvider
        .when('/route', {
          templateUrl: 'partials/template.html',
          controller: 'HomeCtrl',
          controllerAs: 'home'
        });
    });

    HomeCtrl

    function HomeCtrl() {
      var vm = this;
    
      vm.bindingValue = 42;
    }

    template.html

    <div ng-bind="home.bindingValue"></div>

Directives

  • Name your directives with lowerCamelCase.
  • Use scope instead of $scope in your link function. In the compile, post/pre link functions you have already defined arguments which will be passed when the function is invoked, you won't be able to change them using DI. This style is also used in AngularJS's source code.
  • Use custom prefixes for your directives to prevent name collisions with third-party libraries.
  • Do not use ng or ui prefixes since they are reserved for AngularJS and AngularJS UI usage.
  • DOM manipulations must be done only through directives.
  • Create an isolated scope when you develop reusable components.
  • Use directives as attributes or elements instead of comments or classes, this will make your code more readable.
  • Use scope.$on('$destroy', fn) for cleaning up. This is especially useful when you're wrapping third-party plugins as directives.
  • Do not forget to use $sce when you should deal with untrusted content.

Filters

  • Name your filters with lowerCamelCase.
  • Make your filters as light as possible. They are called often during the $digest loop so creating a slow filter will slow down your app.
  • Do a single thing in your filters, keep them coherent. More complex manipulations can be achieved by piping existing filters.

Services

This section includes information about the service component in AngularJS. It is not dependent of the way of definition (i.e. as provider, .factory, .service), except if explicitly mentioned.

  • Use camelCase to name your services.

    • UpperCamelCase (PascalCase) for naming your services, used as constructor functions i.e.:

      function MainCtrl(User) {
          var vm = this;
          vm.user = new User('foo', 42);
      }
      
      module.controller('MainCtrl', MainCtrl);
      
      function User(name, age) {
        this.name = name;
        this.age = age;
      }
      
      module.factory('User', function () {
        return User;
      });
    • lowerCamelCase for all other services.

  • Encapsulate all the business logic in services. Prefer using it as your model. For example:

    // order is the 'model'
    angular.module('Store')
    .factory('order', function () {
        var add = function (item) {
          this.items.push (item);
        };
    
        var remove = function (item) {
          if (this.items.indexOf(item) > -1) {
            this.items.splice(this.items.indexOf(item), 1);
          }
        };
    
        var total = function () {
          return this.items.reduce(function (memo, item) {
            return memo + (item.qty * item.price);
          }, 0);
        };
    
        return {
          items: [],
          addToOrder: add,
          removeFromOrder: remove,
          totalPrice: total
        };
    });

    See 'Avoid writing business logic inside controllers' for an example of a controller consuming this service.

  • Services representing the domain preferably a service instead of a factory. In this way we can take advantage of the "klassical" inheritance easier:

     function Human() {
       //body
     }
     Human.prototype.talk = function () {
       return "I'm talking";
     };
    
     function Developer() {
       //body
     }
     Developer.prototype = Object.create(Human.prototype);
     Developer.prototype.code = function () {
       return "I'm coding";
     };
    
     myModule.service('human', Human);
     myModule.service('developer', Developer);
  • For session-level cache you can use $cacheFactory. This should be used to cache results from requests or heavy computations.

  • If given service requires configuration define the service as provider and configure it in the config callback like:

     angular.module('demo', [])
     .config(function ($provide) {
       $provide.provider('sample', function () {
         var foo = 42;
         return {
           setFoo: function (f) {
             foo = f;
           },
           $get: function () {
             return {
               foo: foo
             };
           }
         };
       });
     });
    
     var demo = angular.module('demo');
    
     demo.config(function (sampleProvider) {
       sampleProvider.setFoo(41);
     });

Templates

  • Use ng-bind or ng-cloak instead of simple {{ }} to prevent flashing content.
  • Avoid writing complex expressions in the templates.
  • When you need to set the src of an image dynamically use ng-src instead of src with {{ }} template.
  • When you need to set the href of an anchor tag dynamically use ng-href instead of href with {{ }} template.
  • Instead of using scope variable as string and using it with style attribute with {{ }}, use the directive ng-style with object-like parameters and scope variables as values:
    <div ng-controller="MainCtrl as main">
        <div ng-style="main.divStyle">my beautifully styled div which will work in IE</div>;
    </div>
  angular
    .module('app')
    .controller('MainCtrl', MainCtrl);

  MainCtrl.$inject = [];

  function MainCtrl() {
    var vm = this;
    vm.divStyle = {
        width: 200,
        position: 'relative'
    };
  }

Routing

  • Use resolve to resolve dependencies before the view is shown.
  • Do not place explicit RESTful calls inside the resolve callback. Isolate all the requests inside appropriate services. This way you can enable caching and follow the separation of concerns principle.

E2E Testing

E2E tests are the next common sense step after unit tests, that will allow you to trace bugs and errors in the behaviour of your system. They are great for providing a sanity check that most common scenarios of using your application works. This way you can automate the process and run it each time before you deploy your application.

Ideally, Angular End-to-End tests are written in Jasmine. These tests are run using the Protractor E2E test runner which uses native events and has special features for Angular applications.

File structure:

.
├── app
│   ├── app.js
│   ├── home
│   │   ├── home.html
│   │   ├── controllers
│   │   │   ├── FirstCtrl.js
│   │   │   ├── FirstCtrl.spec.js
│   │   ├── directives
│   │   │   └── directive1.js
│   │   │   └── directive1.spec.js
│   │   ├── filters
│   │   │   ├── filter1.js
│   │   │   └── filter1.spec.js
│   │   └── services
│   │       ├── service1.js
│   │       └── service1.spec.js
│   └── about
│       ├── about.html
│       ├── controllers
│       │   └── ThirdCtrl.js
│       │   └── ThirdCtrl.spec.js
│       └── directives
│           ├── directive2.js
│           └── directive2.spec.js
├── partials
├── lib
└── e2e-tests
    ├── protractor.conf.js
    └── specs
        ├── home.js
        └── about.js

i18n

  • For newer versions of the framework (>=1.4.0) use the built-in i18n tools, when using older versions (<1.4.0) use angular-translate.

Performance

  • Optimize the digest cycle

    • Watch only the most vital variables. When required to invoke the $digest loop explicitly (it should happen only in exceptional cases), invoke it only when required (for example: when using real-time communication, don't cause a $digest loop in each received message).
    • For content that is initialized only once and then never changed, use single-time watchers like bindonce for older versions of AngularJS or one-time bindings in AngularJS >=1.3.0.
       <div>
         {{ ::main.things }}
       </div>
      or
         <div ng-bind="::main.things"></div>
      After that, no watchers will be created for main.things and any changes of main.things will not update the view.
    • Make the computations in $watch as simple as possible. Making heavy and slow computations in a single $watch will slow down the whole application (the $digest loop is done in a single thread because of the single-threaded nature of JavaScript).
    • When watching collections, do not watch them deeply when not strongly required. Better use $watchCollection, which performs a shallow check for equality of the result of the watched expression and the previous value of the expression's evaluation.
    • Set third parameter in $timeout function to false to skip the $digest loop when no watched variables are impacted by the invocation of the $timeout callback function.
    • When dealing with big collections, which change rarely, use immutable data structures.
  • Consider decreasing number of network requests by bundling/caching html template files into your main javascript file, using grunt-html2js / gulp-html2js. See here and here for details. This is particularly useful when the project has a lot of small html templates that can be a part of the main (minified and gzipped) javascript file.

Contribution

Since the goal of this style guide is to be community-driven, contributions are greatly appreciated. For example, you can contribute by extending the Testing section or by translating the style guide to your language.

Contributors

mgechev morizotter chatii2412 pascalockert yanivefraim ericguirbal
mgechev morizotter chatii2412 pascalockert yanivefraim ericguirbal
agnislav ray7551 mainyaa LeonardCModoran elfinxx tiagobarreto
agnislav ray7551 mainyaa LeonardCModoran elfinxx tiagobarreto
Xuefeng-Zhu SullyP giacomocusinato rubystream lukaszklis Spuffynism
Xuefeng-Zhu SullyP giacomocusinato rubystream lukaszklis Spuffynism
susieyy cironunes cavarzan guiltry MSafter mingchen
susieyy cironunes cavarzan guiltry MSafter mingchen
jmblog luixaviles andreasonny83 kuzzmi jabhishek adambabik
jmblog luixaviles andreasonny83 kuzzmi jabhishek adambabik
astalker clbn atodorov apetro valgreens bitdeli-chef
astalker clbn atodorov apetro valgreens bitdeli-chef
meetbryce unseen1980 cminhho dwmkerr kuzmeig1 dominickolbe
meetbryce unseen1980 cminhho dwmkerr kuzmeig1 dominickolbe
gsamokovarov grvcoelho yassirh bargaorobalo hermankan jesselpalmer
gsamokovarov grvcoelho yassirh bargaorobalo hermankan jesselpalmer
capaj johnnyghost jordanyee whoan nacyot mariolamacchia
capaj johnnyghost jordanyee whoan nacyot mariolamacchia
mischkl michaelmov kirstein mo-gr mortonfox cryptojuice
mischkl michaelmov kirstein mo-gr mortonfox cryptojuice
nktssh olafahn olov vorktanamobay QuietHeartThinkingFar raphaelfruneaux
nktssh olafahn olov vorktanamobay QuietHeartThinkingFar raphaelfruneaux
sahat ganchiku kaneshin imaimiami dooart thomastuts
sahat ganchiku kaneshin imaimiami dooart thomastuts
UrielMiranda vkarampinis grapswiz coderhaoxin giantray ntaoo
UrielMiranda vkarampinis grapswiz coderhaoxin giantray ntaoo
seyyah dchest
seyyah dchest

More Repositories

1

javascript-algorithms

💻 JavaScript implementations of computer science algorithms
JavaScript
7,836
star
2

revive

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint
Go
4,764
star
3

angular-seed

🌱 [Deprecated] Extensible, reliable, modular, PWA ready starter project for Angular (2 and beyond) with statically typed build and AoT compilation
TypeScript
4,572
star
4

angular-performance-checklist

⚡ Cheatsheet for developing lightning fast progressive Angular applications
4,027
star
5

google-interview-preparation-problems

leetcode problems I solved to prepare for my Google interview.
JavaScript
3,124
star
6

codelyzer

Static analysis for Angular projects.
TypeScript
2,446
star
7

angularjs-in-patterns

AngularJS in patterns - this repository provides different look into AngularJS. It contains information where different design patterns are used inside the framework or any Angular application.
JavaScript
1,956
star
8

ngrev

Tool for reverse engineering of Angular applications
TypeScript
1,553
star
9

mk.js

Canvas implementation of basic fighting game which allows multiplayer over the network.
JavaScript
1,504
star
10

angular2-style-guide

[Deprecated] Community-driven set of best practices and style guidelines for Angular 2 application development
1,203
star
11

injection-js

Dependency injection library for JavaScript and TypeScript in 5.1K. It is an extraction of the Angular's ReflectiveInjector which means that it's well designed, feature complete, fast, reliable and well tested.
TypeScript
1,149
star
12

jscapture

Screen recording and capturing with pure client-side JavaScript.
JavaScript
797
star
13

tiny-compiler

A tiny evaluator and compiler of arithmetic expressions.
JavaScript
768
star
14

ngx-quicklink

Quicklink prefetching strategy for the Angular router
TypeScript
749
star
15

guess-next

🔮 Demo application showing the integration of Guess.js with Next.js
JavaScript
526
star
16

aspect.js

JavaScript library for aspect-oriented programming using modern syntax.
TypeScript
474
star
17

angular-webrtc

Demo for my blog post at http://goo.gl/LCOSsI
ApacheConf
307
star
18

switching-to-angular2

TypeScript
285
star
19

memo-decorator

Decorator which applies memoization to a method of a class.
TypeScript
256
star
20

js-vnc-demo-project

Demo project for the class Advanced JavaScript at the department mathematics and informatics in Sofia University.
JavaScript
186
star
21

is-esm

🌳 CLI tool which checks if a package is distributed in ECMAScript module format. Helps you reason if the package is tree-shakable.
JavaScript
184
star
22

angular-immutable

Simple directive, which allows binding to Immutable.js collections.
JavaScript
166
star
23

ngast

Parser for Angular projects.
TypeScript
164
star
24

angular-aop

Library for aspect-oriented programming with AngularJS.
JavaScript
161
star
25

tslint-angular

Recommended tslint configuration for Angular applications.
161
star
26

ngx-hover-preload

🖱 Preload Angular lazy-loaded routes on mouse over
TypeScript
160
star
27

mk-tfjs

Play MK.js with TensorFlow.js
JavaScript
156
star
28

ReactChat

WebRTC chat with ReactJS
JavaScript
153
star
29

ngworld

Generate a Minecraft/Christmas-like world out of an Angular application.
TypeScript
142
star
30

scalable-architecture-demo

TypeScript
134
star
31

github-contributors-list

Node.js script, which outputs all the contributors for given open GitHub project
JavaScript
133
star
32

ngresizable

Simple, tree-shakable, AoT, Universal and Web Worker friendly resizable component for Angular (2 and beyond).
TypeScript
117
star
33

angular2-hot-loader

[NOT MAINTAINED] Angular 2 hot loader
TypeScript
115
star
34

light-angularjs

Light AngularJS implementation for my slides "Lightweight AngularJS"
JavaScript
110
star
35

movement.js

Gesture recognition with JavaScript and HTML5.
JavaScript
106
star
36

angular-vnc

VNC client implemented with AngularJS and Yeoman
JavaScript
99
star
37

ngx-tfjs

🤖 TensorFlow.js bindings for Angular
TypeScript
95
star
38

real-world-bazel

The real world Angular example app moved to Bazel
TypeScript
90
star
39

angular-transitions

Pre-defined set of CSS3 transformation which can be used with ng-view, ui-view, ng-repeat, ng-show, ng-hide. Both the 1.1.5 and 1.2.0 APIs are supported.
CSS
90
star
40

angular-tfjs-demo

A demo application with TensorFlow.js bindings for Angular.
TypeScript
85
star
41

angular2-ngc-rollup-build

Simple build for "Hello world!" Angular 2 application with ngc and rollup.
HTML
81
star
42

angular2-github-app-bootstrap

Exercise for building simple Angular 2 apps
JavaScript
79
star
43

blog.mgechev.com

My personal blog.
JavaScript
70
star
44

dotfiles

My dot files.
Shell
67
star
45

react-reorderable

Simple react sortable component (for more advanced cases use react-dnd).
JavaScript
63
star
46

devtools-vnc

VNC client for Chrome Devtools
JavaScript
61
star
47

cli-builders-demo

Demo showing how to develop a builder using the Angular CLI Architect API.
TypeScript
59
star
48

ngx-flamegraph

Flame graph for stack trace visualization written in Angular
TypeScript
57
star
49

electron-typescript-boilerplate

Electron TypeScript starter (intended mostly for personal projects). Fork of https://github.com/szwacz/electron-boilerplate.
JavaScript
54
star
50

angular-ivy-demo

Demo repository showing how ivy allows significant API simplification.
TypeScript
53
star
51

mlx

Data-driven bundling
TypeScript
48
star
52

optimizing-an-angular-application

Code for my ngconf talk "Optimizing an Angular Application".
TypeScript
48
star
53

ngx-gh

Automatic deployments to GitHub pages directly from the Angular CLI 🚀
TypeScript
45
star
54

data-adapter

Data adapter useful in data serialization when talking with external services.
TypeScript
45
star
55

react-pstate

Persistence of the state of ReactJS component
JavaScript
43
star
56

hybrid-rendering

TypeScript
42
star
57

playground

Initial experience with different programming languages
JavaScript
40
star
58

bazel-demo

Simple demo for building a TypeScript project with Bazel.
TypeScript
40
star
59

angular-hybrid-rendering

TypeScript
39
star
60

plainvm

plainvm allows you to control multiple virtual machines which are distributed among many hosts through your browser.
JavaScript
38
star
61

gemini-angular-drawing-demo

TypeScript
38
star
62

angular2-simple-build

Simple build for "Hello world!" Angular 2 application.
TypeScript
37
star
63

versionable-collections

Collection optimized for AngularJS 1.x one-way bindings
JavaScript
33
star
64

typed-calc

Interpreter for simply typed lambda calculus implemented in JavaScript λ
JavaScript
33
star
65

ngx-circular-player

Circular player for Angular
TypeScript
32
star
66

swagger-typescript-fetch-api

Swagger codegen for TypeScript Fetch API.
HTML
32
star
67

angular2-stripe-demo

TypeScript
30
star
68

blobreader

Simple interface for reading blobs sequentially
JavaScript
28
star
69

ts-rpc

RPC protocol with services defined via TypeScript interfaces.
TypeScript
27
star
70

performance-patterns

TypeScript
27
star
71

podcast

Website of the Programming Podcast
TypeScript
26
star
72

dots

Implements the wildcard file matching in Go used by golint, go test etc.
Go
25
star
73

ng-tutorial

Platform for AngularJS interactive tutorials
JavaScript
25
star
74

purely-fast

TypeScript
25
star
75

ELang

Simple programming language created for educational purpose
Java
24
star
76

gently-js

Module which returns the offensive words in a string. A soft reminder to be nicer to each other ❤️.
JavaScript
23
star
77

angular-realworld-example-app-qucklink

TypeScript
22
star
78

optimizing-apps-angular-demo

Demo application for my talk on optimizing Angular apps
TypeScript
21
star
79

ngmigrate

Automated migration of <template> to <ng-template> for Angular 4+
JavaScript
20
star
80

dynamic-route-creator

[DEPRECATED] Demo for dynamically defining routes in Angular 2
TypeScript
19
star
81

guess-js-angular-demo

TypeScript
18
star
82

lazy-loading-routes-angular2

WARNING: Uses deprecated APIs.
JavaScript
18
star
83

angular2-hot-loader-demo

Demo of the Angular 2 hot loader prototype
TypeScript
18
star
84

guess-js-react-demo

JavaScript
17
star
85

angular2-rollup-build

Simple build for "Hello world!" Angular 2 application with rollup.
HTML
17
star
86

getting-started-with-angular

Code for the second edition of the book "Switching to Angular 2", with title "Getting started with Angular".
TypeScript
17
star
87

svg-design-patterns

This repository contains UML class diagrams of some design and architectural patterns.
17
star
88

kitty-cinema

HTML
16
star
89

programming-podcast-samples

TypeScript
16
star
90

react-di-demo

Demo for my blog post "Implementing Angular's Dependency Injection in React. Understanding Element Injectors."
JavaScript
16
star
91

code-splitting-web-dev

TypeScript
15
star
92

react-drag

JavaScript
15
star
93

ivy-library-distribution-demo

TypeScript
14
star
94

angular-bazel-hello-world

Simple Angular app with Bazel configuration
HTML
13
star
95

viewchildren-contentchildren-demo

TypeScript
12
star
96

photos.mgechev.com

Website for my personal photography.
TypeScript
12
star
97

top-packages

TypeScript
12
star
98

v8-sorting-test

Testing the sorting performance of Google's V8 JavaScript engine.
Perl
12
star
99

immutable-differ

Work in progress.
TypeScript
11
star
100

guess-angular

TypeScript
11
star