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

karma-transform-preprocessor

v1.0.1

Published

A Karma preprocessor to apply arbitrary transforms on served files

Downloads

22

Readme

karma-transform-preprocessor

A preprocessor plugin for karma to facilitate content transformations for any file served by the karma server

Why?

Because sometimes you just need to mangle a file before Karma should be allowed to get to it. My specific use case was working around a third-party Polymer component which attempted to define the translate function on itself. Apart from this conflicting with Polymer base, the bigger issue is that this conflicts with a property available on DOM elements. Some browsers, like Chrome (at time of writing) permit smashing DOM element properties. Others, like QtWebKit (ie, in PhantomJs) do not, resulting in esoteric errors.

This plugin allows me to rewrite the declaration all uses of translate to, for example, __translate, working around the issue of CI tests running through PhantomJS failing when they don't fail in Chrome.

But this preprocessor could be used for whatever you want -- perhaps rewriting urls in html or data in JSON structures. It's all up to you.

How to use?

  1. You will need to add karma-transform-preprocessor to your plugins declaration in karma.conf.js, if it exists (I prefer explicit declaration of plugins and if you declare one, you must declare all the ones you want to use).
  2. Add one or more preprocessors matchers, eg:
preprocessors: {
  "**/*.html": "transform"
}
  1. Add one or more transformers to deal with your matches. Any files which are not matched are simply passed through unscathed. Transformers may be synchronous or asynchronous and are used preferentially by the order in which they are defined:
transformConfig: {
  transforms: [
    { match: /template1.html$/, transform: s => {
        return "<p>this is the new template1.html</p>";
      }
    },
    { match: /template2.html$/, transform: s => {
        return new Promise((resolve, reject) => {
          resolve("<p>this is the new template2.html</p>");
        });
      } 
    },
    { match: /late2.html$/, transform: s => {
        return "this will not match template2.html as it has lower precedence";
      }
    },
}

Licensing

BSD 3 Clause. Basically, you can use it wherever you want for free. You can fork it, you can change it. You can even sell it. You just can't take credit for it.