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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ngx-webp-polyfill

v17.0.0

Published

A Webp polyfill for Angular, using `webp-hero`. This module applies to polyfill as Angular Pipes/Directives for: 1. Image elements 2. Elements with a `background-image` style

Readme

Angular Webp Polyfill

A Webp polyfill for Angular, using webp-hero. This module applies to polyfill as Angular Pipes/Directives for:

  1. Image elements
  2. Elements with a background-image style

You can view a demo here.

Installation

NPM

npm install --save ngx-webp-polyfill webp-hero p-queue

Yarn

yarn add ngx-webp-polyfill webp-hero p-queue

To allow the polyfill to be applied to images one-at-a-time (as enforced by webp-hero) we use p-queue to queue the decoding.

Usage

Standalone

Configure the default and/or override providers in your ApplicationConfig.

import { ApplicationConfig, Inject } from '@angular/core';
import { provideRouter } from '@angular/router';

import { externalPolyfillFactory, DEFAULT_WEBP_OPTIONS, polyfillServiceFactory, WEBP_POLYFILL, WEBP_POLYFILL_EXTERNAL, WEBP_POLYFILL_OPTIONS } from 'ngx-webp-polyfill';

export const appConfig: ApplicationConfig = {
  providers: [
    {
      provide: WEBP_POLYFILL_OPTIONS,
      useValue: DEFAULT_WEBP_OPTIONS
    },
    {
      provide: WEBP_POLYFILL,
      useFactory: polyfillServiceFactory,
      deps: [ [new Inject(WEBP_POLYFILL_OPTIONS)], [new Inject(WEBP_POLYFILL_EXTERNAL)]]
    },
    {
      provide: WEBP_POLYFILL_EXTERNAL,
      useFactory: externalPolyfillFactory
    }
  ]
};

NgxWebpPolyfillModule.forRoot(options?: WebpPolyfillOptions)

Import NgxWebpPolyfillModule.forRoot(options?: WebpPolyfillOptions) into AppModule.

WebpPolyfillOptions

  • applyPolyfill: (url: string) => boolean (defaults to true) to apply the polyfill conditionally i.e. for specific browsers
import { NgxWebpPolyfillModule } from 'ngx-webp-polyfill';

export function webpPolyfillOptions(url: string) {
  return true;
}

@NgModule({
  imports: [
    NgxWebpPolyfillModule.forRoot({
        applyPolyfill: webpPolyfillOptions
    })
  ]
})
export class AppModule { }

NgxWebpPolyfillModule.forChild()

Import NgxWebpPolyfillModule.forChild() into your application child modules, where needed.

import { NgxWebpPolyfillModule } from 'ngx-webp-polyfill';

@NgModule({
  imports: [
    NgxWebpPolyfillModule.forChild()
  ]
})
export class MyFeatureModule { }

Template example

Apply the polyfill directives in your template with the following options.

webpImage Pipe
  <img *ngIf="myImageUrl | webpImage | async as imagePipeTransform"
       [src]="imagePipeTransform"
       alt="My Image"
       class="thumbnail"/>

Note: The use of *ngIf is required here as the async pipe will emit null as an initial value.

webpBackground Pipe
  <div [style.background-image]="'url(' + myImageUrl + ')' | webpBackground | async"
       style="width: 200px; height: 200px"></div>

Contributing

Fork and send us a pull request. Consider discussing the change with us before committing the code. The library follows semantic versioning principles, which is automated using conventional commit messages.

Development

Running the demo and library locally using npm link

  1. npm run build:library to watch changes
  2. cd dist/ngx-webp-polyfill && npm link && cd ../../ && npm link ngx-webp-polyfill allows the demo application to develop against the locally built library
  3. npm start to start the demo application

Clean up

  1. cd dist/ngx-webp-polyfill && npm unlink && cd ../../ && npm unlink ngx-webp-polyfill reverts npm link

Committing

To use the interactive CLI when committing:

    $ git add <file/s to commit>
    $ npm run commit

Or use your IDE, commits messages are linted!

Release

These instructions are for maintainers of this library, to release a new version:

Package

  1. Generate new version and tag with npm run release && git push --follow-tags origin master
  2. Builds and package the library npm run package:library
  3. Publish the library to NPM cd dist/ngx-webp-polyfill && npm publish

Demo

  1. To build the demo run npm run build