Skip to content

hughsk/md5ify

Repository files navigation

md5ify

Synchronously return the md5 hex hash of a file path through either Node or browserify.

Useful, for example, for keeping unique IDs of particular files based on their contents in order to cache external resources better.

Usage

NPM

md5ify(filename)

Returns a hash of the file's contents at filename.

const md5ify = require('md5ify')
const hash   = md5ify(__filename)

console.log(hash)

md5ify with browserify

The above works in Node, but you can easily make it work in browserify too by adding it as a transform. This works similarly to brfs and determines the file's hash at build time. Simply include it in your list of browserify.transforms in your project's package.json file:

{
  "name": "my-package",
  "version": "1.0.0",
  "browserify": {
    "transforms": [
      "md5ify/transform"
    ]
  }
}

Alternatively, you may specify the transform through browserify's command-line interface using the -t flag:

browserify index.js -t md5ify/transform

Or through browserify's Node API using the .transform method:

const browserify = require('browserify')
const bundler    = browserify('./index.js')

bundler.transform('md5ify/transform')
bundler.bundle(function(err, bundle) {
  if (err) throw err
  console.log(String(bundle))
})

License

MIT. See LICENSE.md for details.

About

Synchronously return the md5 hex hash of a file path through Node or browserify

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published