Socket
Book a DemoInstallSign in
Socket

hash-filename

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hash-filename

A command line tool that puts the hash of a file into its filename.

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

Build Status

Overview

hash-filename is a command line tool that puts the hash of a file into its filename.

Installation: npm install -g hash-filename

$ ls
app.css  app.js  vendor.js
$ hash-filename *.css *.js
{
  "app.css": "app-f1d2d2f924e.css",
  "app.js": "app-e242ed3bffc.js",
  "vendor.js": "vendor-6eadeac2dad.js"
}
$ ls
app-e242ed3bffc.js  app-f1d2d2f924e.css  app.css  app.js  vendor-6eadeac2dad.js  vendor.js
$ hash-filename --help

  Usage: hash-filename [options] <files>

  Options:

    -h, --help              output usage information
    -V, --version           output the version number
    -a, --algorithm <name>  Hash algorithm [sha1]
    -l, --length <n>        Hash length [11]

Copies the given files with a hash of their contents put into to their filenames.
Writes a JSON map of original filenames to hashed filenames to stdout.

It is useful for cache busting. The outputted JSON map can be used to update references to the unhashed filenames.

For example, you could create a function such as the following, expose it to templates and wrap file paths in it.

var map = production ? require("./map") : {} // You can even require .json files!
function file(path) {
  return map[path] || path
}

The above function uses the original paths during development and the hashed ones during production. And if for some reason a path would be missing from the map during production, it falls back to the original path.

You could also feed the map directly to a replacement tool such as map-replace to update static files:

hash-filename *.css *.js | map-replace -m "<[^>]+>" *.html

License

GPLv3.

Keywords

cli

FAQs

Package last updated on 01 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts