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 🙏

© 2026 – Pkg Stats / Ryan Hefner

theme-templater

v0.0.5

Published

Angular 4 library to allow the use of css templates including custom names as variables and replace them with actual values

Readme

theme-templater

Angular 4 library to allow the use of css templates including custom names as variables and replace them with actual values

NPM GitHub

Purpose

I found the need change the colors of an application on runtime depending on the authenticated user. The values for these colors are stored in datatbase and are returned via RestService.

The aim of this package is to use a local css file with dummy names for property values as a template and, using a list that relates those names to actual values, create a style tag to override existing styles or simply to create styles on the run.

Installation

npm install --save theme-templater

Once installed you need to import the main module:

import { TtStyleModule, TtStyleService } from 'theme-templater';

@NgModule({
  declarations: [AppComponent, ...],
  imports: [TtStyleModule, ...],  
  providers: [TtStyleService, ...],
  bootstrap: [AppComponent]
})
export class AppModule {
}

Usage Examples

Using Component

Having styles-template.css inside the assets folder:

.header{
    background: AppMainColorValue !important;
    color: AppTextColorValue !important;
}

app.component.ts:

import { TtStyleVar } from 'theme-templater';
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  template: string;
  vars: TtStyleVar[];

  constructor() {
    this.template = 'assets/styles-template.css';
    this.vars = [
      {
        VarName: 'AppMainColorValue',
        VarValue: '#222222'
      },
      {
        VarName: 'AppTextColorValue',
        VarValue: '#ffffff'
      }
    ];
  }
}

app.component.html:

<tt-style [templateFileSrc]="template" [templateVars]="vars"></tt-style>

<div class="header">
  This is but a test...
</div>

Using Service

Assuming the same styles-template.css from the previous example and RestService that returns a list of different styles to create.

this being my styles list in a json file:

[
  {
    "media": "only screen and (max-width:1024px)",
    "bgColor": "#222222",
    "textColor": "#ffffff"
  },
  {
    "media": "only screen and (min-width:1025px)",
    "bgColor": "#990000",
    "textColor": "#ffffff"
  }
]

app.component.ts:

import { TtStyleVar, TtStyleService } from 'theme-templater';
import { RestService } from './rest.service';
import { Subscription } from 'rxjs/Subscription';
import { Component, OnInit, OnDestroy } from '@angular/core';

@Component({
  selector: 'app-service-example',
  templateUrl: './service-example.component.html',
  styleUrls: ['./service-example.component.css']
})
export class AppComponent implements OnInit, OnDestroy {
  stylesSubscription: Subscription;

  template: string;

  constructor(
    private restService: RestService,
    private stylesService: TtStyleService
  ) {}

  ngOnInit() {
    this.stylesService.removeAddedStyles();

    this.template = 'assets/styles-template.css';

    this.stylesSubscription = this.restService.getStyles().subscribe((styles) => {
      for (const st of styles) {
        const vars = [
          {
            VarName: 'AppMainColorValue',
            VarValue: st.bgColor
          },
          {
            VarName: 'AppTextColorValue',
            VarValue: st.textColor
          }
        ];

        this.stylesService.start(this.template, vars, st.media);
      }
    });
  }

  ngOnDestroy() {
    this.stylesSubscription.unsubscribe();
  }
}

TODO

  • check if final result is valid css
  • opt between creating a tag or a css file