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-js-proxy

v1.3.0

Published

Angular Javascript ES6 proxy

Downloads

6

Readme

Angular Javascript Proxy

An Angular ES6 proxy. If you don't want to use TypeScript. Work with Angular 5.

⚠️ Every example, in this documentation, works with Babel


Installation

$ npm install --save angular-js-proxy

What is contained in this module

import {
    Component,       // Component decorator proxy
    NgModule,        // NgModule decorator proxy
    Injectable       // Injectable decorator proxy
    compiler,        // Angular compiler namespace
    common,          // Angular common namespace
    core,            // Angular core namespace
    router,          // Angular router namespace
    forms,           // Angular forms namespace
    platformBrowserDynamic, // Angular platformBrowserDynamic namespace
    platformBrowser         // Angular platformBrowser namespace
} from 'angular-js-proxy';

Usage with decorators

You can use Angular decorators (Component, NgModule ...), with transform-decorators-legacy babel plugin, as Javascript decorator.

// index.js

import { Component, NgModule, platformBrowserDynamic, platformBrowser } from 'angular-js-proxy';

@Component({
    selector: 'home-component',
    template: `
        <h1>Hello</h1>
    `
})
class HomeComponent {
    constructor() {}
}

@NgModule({
    imports: [platformBrowser.BrowserModule],
    declarations: [HomeComponent],
    bootstrap: [HomeComponent]
})
class Module {
    constructor() {}
}

platformBrowserDynamic.platformBrowserDynamic().bootstrapModule(Module);

With this package.json

{
  "name": "angular-es6-demo",
  "scripts": {
    "build": "browserify index.js -o dist/app.js -t [ babelify ]"
  },
  "babel": {
    "presets": [
      "env"
    ],
    "plugins": [
      "transform-decorators-legacy"
    ]
  },
  "dependencies": {
    "angular-js-proxy": "^0.1"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-preset-env": "^1.6.1",
    "babelify": "^8.0.0",
    "browserify": "^16.2.0"
  }
}

Run npm run build to transpilate your code.

Usage with functions

You can also use Angular decorators (Component, NgModule ...) as function

// index.js

import { Component, NgModule, platformBrowserDynamic, platformBrowser } from 'angular-js-proxy';

class HomeComponent {
    constructor() {}
}

Component({
    selector: 'home-component',
    template: `
        <h1>Hello</h1>
    `
})(HomeComponent);

class Module {
    constructor() {}
}

NgModule({
    imports: [platformBrowser.BrowserModule],
    declarations: [HomeComponent],
    bootstrap: [HomeComponent]
})(Module);


platformBrowserDynamic.platformBrowserDynamic().bootstrapModule(Module);

With this package.json

{
  "name": "angular-es6-demo",
  "scripts": {
    "build": "browserify index.js -o dist/app.js -t [ babelify ]"
  },
  "babel": {
    "presets": [
      "env"
    ]
  },
  "dependencies": {
    "angular-js-proxy": "^0.1"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "babelify": "^8.0.0",
    "browserify": "^16.2.0"
  }
}

Run npm run build to transpilate your code.

Examples

Create an injectable service.

import { Injectable } from 'angular-js-proxy';

// as decorator

@Injectable()
class Utils {
    toUpperCase(string) {
        return String(string).toUpperCase();
    }
}

// as function

class Utils {
    toUpperCase(string) {
        return String(string).toUpperCase();
    }
}

Injectable()(Utils);

Usage

import { Component, NgModule, Injectable, platformBrowserDynamic, platformBrowser } from 'angular-js-proxy';

@Injectable()
class Utils {
    toUpperCase(string) {
        return String(string).toUpperCase();
    }
}

@Component({
    selector: 'home-component',
    template: `
        <h1>{{ message }}</h1>
    `,
    inject: [Utils] // TypeScript use type for DI, so in javascript need to define what inject
})
class HomeComponent {
    constructor(utils) {
        this.message = utils.toUpperCase('hello');
    }
}

@NgModule({
    imports: [platformBrowser.BrowserModule],
    providers: [Utils],
    declarations: [HomeComponent],
    bootstrap: [HomeComponent]
})
class Module {
    constructor() {}
}

platformBrowserDynamic.platformBrowserDynamic().bootstrapModule(Module);

A injectable service can be inject to another injectable service.

@Injectable()
class Configurator {
    getAPIConfig() {
        ...
    }
}

@Injectable({
    inject: [Configurator] // You can use "providers" instead of "inject" if you want a new instance of Configurator
})
class API {
    constructor(configurator) {
        this.config = configurator.getAPIConfig();
    }

    callAPI() {
        ...
    }
}

Create an exportable module

// index.js

import { Component, NgModule, common } from 'angular-js-proxy';

@Component({
    selector: 'another-component',
    template: '<h2>Another hello</h2>'
})
class AnotherComponent {}

@NgModule({
    imports: [common.CommonModule],
    declarations: [AnotherComponent],
    exports: [AnotherComponent]
})
export class AnotherModule {}

With this package.json

{
  "name": "another-angular-es6-module",
  "main": "index.js",
  "dependencies": {
    "angular-js-proxy": "^0.1"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "babelify": "^8.0.0",
    "browserify": "^16.1.1"
  },
  "browserify": {
    "transform": [
      [
        "babelify",
        {
          "presets": [
            "env"
          ],
          "plugins": [
            "transform-decorators-legacy"
          ]
        }
      ]
    ]
  }
}

Usage

import { Component, NgModule, platformBrowserDynamic, platformBrowser } from 'angular-js-proxy';
import { AnotherModule } from 'another-angular-es6-module';

@Component({
    selector: 'home-component',
    template: `
        <h1>Hello</h1>
        <another-component></another-component>
    `
})
class HomeComponent {}

@NgModule({
    imports: [platformBrowser.BrowserModule, AnotherModule],
    declarations: [HomeComponent],
    bootstrap: [HomeComponent]
})
class Module {
    constructor() {}
}

platformBrowserDynamic.platformBrowserDynamic().bootstrapModule(Module);

Use Angular service

Example with Angular Router service

import { Component, NgModule, Injectable, router, platformBrowserDynamic, platformBrowser } from 'angular-js-proxy';

@Injectable()
class MyService {}

@Component({
    selector: 'home-component',
    template: `
        <h1>Hello</h1>
        <router-outlet></router-outlet>
    `,
    inject: [MyService, router.ActivatedRoute]
})
class HomeComponent {
    constructor(myService, ActivatedRoute) {
        this.service = myService;
        this.route = ActivatedRoute;
    }
}

@NgModule({
    imports: [
        platformBrowser.BrowserModule,
        router.RouterModule.forRoot([...])
    ],
    declarations: [HomeComponent],
    bootstrap: [HomeComponent],
    providers: [MyService]
})
class Module {
    constructor() {}
}

platformBrowserDynamic.platformBrowserDynamic().bootstrapModule(Module);

Uglify

angular-js-proxy use function name to inject Angular service, so if you use Uglify.js, you have to use --keep-fnames options.

$ uglifyjs source.js --keep-fnames -o ouput.js