Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hughsk/md5ify
Synchronously return the md5 hex hash of a file path through Node or browserify
https://github.com/hughsk/md5ify
Last synced: 12 days ago
JSON representation
Synchronously return the md5 hex hash of a file path through Node or browserify
- Host: GitHub
- URL: https://github.com/hughsk/md5ify
- Owner: hughsk
- License: other
- Created: 2015-06-16T16:25:01.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-06-16T16:25:02.000Z (over 9 years ago)
- Last Synced: 2024-10-17T16:41:17.350Z (22 days ago)
- Language: JavaScript
- Size: 97.7 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# md5ify
![](http://img.shields.io/badge/stability-stable-orange.svg?style=flat)
![](http://img.shields.io/npm/v/md5ify.svg?style=flat)
![](http://img.shields.io/npm/dm/md5ify.svg?style=flat)
![](http://img.shields.io/npm/l/md5ify.svg?style=flat)Synchronously return the md5 hex hash of a file path through
either [Node](http://github.com/nodejs/node) or
[browserify](http://browserify.org).Useful, for example, for keeping unique IDs of particular
files based on their contents in order to cache external
resources better.## Usage
[![NPM](https://nodei.co/npm/md5ify.png)](https://nodei.co/npm/md5ify/)
### `md5ify(filename)`
Returns a hash of the file's contents at `filename`.
``` javascript
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](http://github.com/substack/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:``` json
{
"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:``` bash
browserify index.js -t md5ify/transform
```Or through browserify's Node API using the `.transform`
method:``` javascript
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](http://github.com/hughsk/md5ify/blob/master/LICENSE.md) for details.