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

@ctng/core

v5.0.2

Published

<section>

Downloads

13

Readme

Core Module

LoggerService

The LoggerService is the service, which should be used to log everything. It can be easily used by injecting it in a service or component. There is no configuration needed.

Console Logger Service

The ConsoleLoggerService is injected in the LoggerService and is used by default. It is not necessary to provide it in any module of the consuming application. This service can be configured by providing a ConsoleLoggerConfig with the CONSOLE_LOGGER_CONFIG injection token in the consuming module.

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, AppRoutingModule],
  providers: [{ provide: CONSOLE_LOGGER_CONFIG, useValue: { logLevel: LogLevel.debug } }],
  bootstrap: [AppComponent],
})
export class AppModule {}

Log Buffer Service

Environment Service

The EnvironmentService enables the possibility to provide a custom environment configuration and makes sure that the environment is available on app intialization through the service

There are 3 options to provide an environment to the EnvironmentService:

  1. Providing an environment from a .json file with initAppWithEnvFile(): This can be used, if the application runs on more than two environments and the application should not be rebuilded.

  2. Providing an environment with InjectionToken: The environment can be provided by the ENVIRONMENT InjectionToken to the service. This can be only used with static environments (e.g. Angular environment file)

  3. Last but not least, if you don't like the implementation at all, you can provide a custom EnvironmentService implementation

1. Loading .json file with initAppWithEnvFile()

To load a environment from a .json file, you have to provide the EnvironmentService with the correct Factory:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { EnvironmentService, EnvironmentFileFactory } from '@ctng/core';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  providers: [{ provide: EnvironmentService, useFactory: EnvironmentFileFactory }],
  bootstrap: [AppComponent],
})
export class AppModule {}

Now the EnvironmentService assumes the environment loaded from a .json file. Next the application bootstrap needs to be changed. Replace the bootstrap logic in main.ts with the function initAppWithEnvFile(). The main.ts should at least look like this:

import { enableProdMode } from '@angular/core';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import { initAppWithEnvFile } from '@ctng/core';

if (environment.production) {
  enableProdMode();
}

initAppWithEnvFile(AppModule);

initAppWithEnvFile()

  • appModule (required): This is the AppModule which should be bootstrapped
  • envFileLocation (optional): custom .json file location (Default: assets/env.json)
  • errorCallback (optional): custom errorCallback function (Default: ( any ) => void = (value) => console.error('bootstrap-fail', value))

2. Provide static environment with InjectionToken

You can provide a static environment with the ENVIRONMENT InjectionToken:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { environment } from 'src/environments/environment';
import { ENVIRONMENT } from '@ctng/core';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, AppRoutingModule],
  providers: [{ provide: ENVIRONMENT, useValue: environment }],
  bootstrap: [AppComponent],
})
export class AppModule {}

3. Providing own EnvironmentService

You can provide your own EnvironmentService:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { environment } from 'src/environments/environment';
import { EnvironmentService } from '@ctng/core';

export class CustomEnvironmentService {
  public getEnv() {
    return environment;
  }
}

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, AppRoutingModule],
  providers: [{ provide: EnvironmentService, useClass: CustomEnvironmentService }],
  bootstrap: [AppComponent],
})
export class AppModule {}