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

ng4-configure

v0.1.7

Published

loads a general config object from json file before app initialization

Downloads

30

Readme

ng4-configure

angular 4 library to easily load a configuration file prior to application initialization and use it anywhere in your app. Screenshot of demo app: image

Usage

  1. Use NPM to install ng4-configure into your project

    npm install ng4-configure --save

  2. Create a JSON config file for your project and store it somewhere accessible by the browser

    {
      "name": "Paul",
      "favoriteColor": "green",
      "google": "https://google.com",
      "ng4_configure_repo": "https://github.com/mcdonaldp2/ng4-configure"
    }

    a) In the demo this is stored in demo/src/assets/config.json

  3. Create a custom options class that extends ConfigureOptions:

       
       import { ConfigureOptions } from 'ng4-configure/ng4-configure';
    
       export class MyOptions extends ConfigureOptions {
         ConfigurationURL: string = 'assets/config.json';
         AppVersion: string = '0.0.0';
         BustCache: boolean = false
       }
  4. Add NgConfigureModule, ConfigureOptions, and your custom ConfigureOptions into your AppModule. Make sure to provide your custom ConfigureOptions. app.module.ts should look something like this:

           
        import { MyOptions }  from './my-options'
        import { BrowserModule } from '@angular/platform-browser';
        import { NgModule } from '@angular/core';
        import { NgConfigureModule, ConfigureOptions } from 'ng4-configure/ng4-configure'
        import { AppComponent } from './app.component';
    
           
        @NgModule({
          imports: [
            BrowserModule, 
            NgConfigureModule.forRoot()
            ],
          declarations: [AppComponent],
          providers: [
            { provide: ConfigureOptions, useClass: MyOptions} 
          ],
          bootstrap: [AppComponent],
        })
        export class AppModule { }
  5. Inject ConfigureService into any place in your project to access the config object in your code: app.component.ts

      import { Component } from '@angular/core';
      import { ConfigureService } from 'ng4-configure/ng4-configure';
      @Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
        styleUrls: ['./app.component.css']
      })
      export class AppComponent {
        title = 'app';
    
        constructor(public configService: ConfigureService) {
          console.log("Here is the config loaded by ng4-configure:")
          console.log(configService.config);
        }
      }
    

    app.component.html

    <div style="text-align:center">
    <h1>
      Welcome to the ng4-configure demo app!
    </h1>
    <div style="padding: 15px">
      <p> 
        Hi! My name is {{this.configService.config.name}}.
      </p>
      <p>
        The url of this repo is <b>{{this.configService.config.ng4_configure_repo}}</b>
      </p>
      <p>
        Here is a link to <a [href]="this.configService.config.google">Google</a>
      </p>
    </div>

ConfigureOptions Attributes

ConfigurationURL

Specifies the location of the configuration file. By default this location is set to 'assets/config.json'

AppVersion

Specifies the version of the application. To ensure that client browsers are getting the latest version of your config file after a release and not just a version that is cached in the browser, change this value when doing releases. The version will be appended to the url like so: http://localhost:1495/assets/config.json?v=<AppVersion> By default this is blank and will not append anything to the ConfigurationURL.

BustCache

If set to true, will generate a random value to end of the ConfigurationURL to ensure that the config file is never cached: http://localhost:1495/assets/config.json?t=<random value> By default this is set to false.