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

fingerprinting

v1.0.1

Published

Produce a unique string for any given resource, commonly used in cache busting practices.

Downloads

7,921

Readme

fingerprinting

Version npmBuild StatusDependenciesCoverage Status

Fingerprinting is a cache-busting technique which allows you to expire files when they actually change this is done by altering the filenames of the files. This way you can set far future expire headers without having to worry that your users might see stale or old files. Providing you with best of 2 worlds, cached assets for increased performance with sacrificing your ability to instantly modify files.

Installation

The module is released in the public npm registry and can be installed by running:

npm install --save fingerprinting

Usage

The fingerprinting module is exposed as a single function that generates the new filenames for your files. In all examples we assume that you've already required the module as followed;

'use strict';

var finger = require('fingerprinting');

The exported finger function accepts the following arguments:

  • file The path to the file or filename of the file where we're generating the file from. This is used to extract the file extension and read the file contents if no contents option is provided (please do note that reading is done using a sync fs method).
  • options Optional configuration for the fingerprint generation:
    • format: Template that specifies the format of the generated fingerprint. Defaults to {hash}.{suffix}.{ext}.
    • algorithm Hashing algorithm to be used to generate source hash. Defaults to md5.
    • map Also generate an unique id for source maps. Defaults to false.
    • env Environment that we're generating it for. It is used to generate the suffix in the filename format. For example production generates a min suffix while a mising or development generates a dev suffix. Defaults to NODE_ENV.
    • content The actual content of the filename. This eliminates the need to do a fs.readFileSync within the code. It can be either a string or Buffer.

The function returns an object with 2 keys:

  • file This is the new filename for the given file.
  • map If the map option was set to true this will contain the filename for your source map file.

Example

var fs = require('fs');

fs.readFile(__dirname + '/index.js', function (err, buffer) {
  if (err) throw err;

  var print = finger('index.js', {
    content: buffer
  });

  console.log('print:', print.file); // 167f581dd914ba9d3d2e6c8820a5caa6.dev.js
});

License

MIT