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

ng2-toggle-it

v0.1.8

Published

This library provides ready-to-use classes for adding **feature toggling capability** to your angular2 application - activating or deactivating specific parts of your UI without the need for deploying new application versions.

Downloads

20

Readme

ng2-toggle-it

This library provides ready-to-use classes for adding feature toggling capability to your angular2 application - activating or deactivating specific parts of your UI without the need for deploying new application versions.

You can use a directive in your template and an injectable service all over the application for managing the most common operations like enabling/disabling already defined features, adding new features or removing existing ones. The service stores data in the localStorage (property feature-toggle-list: always contains the most up to date version of the whole list of features).

This approach is meant for letting you immediately test the outcome of what changed in your local session, before sending the final list to the backend for permanently persisting it - and making it effective. Ideally the communication with the backend should occurr when the app is created (getting the whole list and initialising the service) and everytime the adminstrator of the features is happy with the changes applied (send back the whole list updated).

Demo

The angular-cli project awesome-demo is a FontEnd-Driven feature toggling example-app, showing the library capabilities (with a handy toggling admin dashboard).

  1. Download the full project from github

  2. Assuming that you already have node, npm and angular-cli installed:

$ cd awesome-demo
$ npm install
$ ng serve
  1. Access the application via browser at localhost:4200 and follow the link to the toggle dashboard for changing, adding, deleting features.

  2. See the outcome in the home page

Installation

To install this library, run:

$ npm install ng2-toggle-it --save

Consuming your library

You can import your library in any Angular application by running:

$ npm install ng2-toggle-it

and then from your Angular AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { ToggleItModule } from 'ng2-toggle-it';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpModule,
    ToggleItModule.forRoot(),
  ],
  providers: [
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Once your library is imported, you can use its service in your components, ie:

export class AppComponent implements OnInit {
  public features: Feature[];

  constructor(
    private toggleItService: ToggleItService
  ) { }

  ngOnInit() {
    // load features list from your backend (json, xml,...) and init the list of features using the service.
    let feature1 = new Feature('Feature-1', true, 'Awesome new look', new Date('2017-01-12'));
    let feature2 = new Feature('Feature-2', false, 'Awesome compliance change', new Date('2017-04-20'));
    this.features = [feature1, feature2];
    this.toggleItService.setFeatureList(this.features);
  }

This is an extract from the Feature model used:

export class Feature {

    key: string;
    enabled: boolean;
    description: string;
    creation: Date;

    constructor( key: string, enabled: boolean, description: string, creation: Date ) {
      this.key = key;
      this.enabled = enabled;
      this.description = description;
      this.creation = creation;
    }

And this is the directive you can use everywhere in your templates:

<pre>
  <div>
    <h1>use directive as follows:</h1>
    <div *toggleIt="feature.enabled">
      <foo-component></foo-component>
    </div>
    <div *toggleIt="!feature.enabled">
      <hello-component></hello-component>
    </div>
  </div>
</pre>

Here is the list of services exposed:

public setFeatureList(features: Feature[]);
public getAll(): Feature[];
public getFeature(key: string): any;
public toggleFeature(key: string, enabled: boolean): any;
public addFeature(feature: Feature): any;
public deleteFeature(feature: Feature): any;

Development

To generate all *.js, *.d.ts and *.metadata.json files:

$ npm run build

To lint all *.ts files:

$ npm run lint

License

MIT © Anna Amidani