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

gulp-hash-filename

v4.1.0

Published

gulp-hash-filename is a gulp plug-in that adds a hash to the filename based on the content of that file, size of that file, or the file's atime, ctime and mtime.

Downloads

35,842

Readme

gulp-hash-filename

NPM version Downloads Build Status Coverage Status


gulp-hash-filename is a gulp plug-in that renames each file using a generated hash value based on the contents of the source file.

Using hashed filenames based on content allows for filenames that only change as the content changes. This helps improve caching of your files. If the content does not change then the filename does not change and that file can still be pulled from the browser's cache.


Always reference the documents on the git repo since they are updated more often then the NPM package website. I update NPM when there is a code change. I might change documentation without a code change and, at that time, I would not update the version number or NPM release.


Install

npm install -g gulp-hash-filename

or

npm install --save-dev gulp-hash-filename

Pull Requests and Issues

Please submit pull requests and issues. I will do my best to review and take care of PRs and issues quickly. If you have suggestions, I would love to hear them.


Usage of gulp-hash-filename

Example of the hash() function

Here is an example of how to use the hash() function in your gulpfile.js file:

const gulp = require('gulp');
const hash = require('gulp-hash-filename');

gulp.task('assemble', function() {
  return gulp.src('./assembly.json')
    .pipe(hash())
    .pipe(gulp.dest('./dist'))
});

The example below includes minification and saving the file with both the hashed filename "{name}-{hash}{ext}" and the hashed and minimized filename "{name}-{hash}-min{ext}" format.

const gulp = require('gulp');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const hash = require('gulp-hash-filename');

gulp.task('assemble', function() {
  return gulp.src('./*.js')
    .pipe(hash())
    .pipe(gulp.dest('./dist'))
    .pipe(uglify())
    .pipe(rename(function (path) {path.basename += "-min";}))
    .pipe(gulp.dest('./dist'))
});

You can change how the filename is formatted by passing in a format option in the hash() function.

const gulp = require('gulp');
const hash = require('gulp-hash-filename');

gulp.task('assemble', function() {
  return gulp.src('./assembly.json')
    .pipe(hash({
    	"format": "{name}.{hash}.{size}{ext}"
    }))
    .pipe(gulp.dest('./dist'))
});

Options used in the hash() function

There is only one option that is allowed in the hash() function. That is the format option.

format is used to control the output filename format. The default value for format is "{name}-{hash}{ext}".

example: Assuming the incoming filename was "sample.js" and the hash value was "a8c23bc812abef98" and that the format value is the default then the hashed filename would be "sample-a8c23bc812abef98.js"

format paramaters

| Parameter | Description | | --- | --- | | {name} | The base portion of the filename. For sample.js the {name} is sample. For sample.test.js the {name} is sample.test. | | {ext} | The file extention of the filename. For sample.js the {ext} is .js. For testfile.json the {ext} is .json | | {size} | The size of the file in bytes. This number is base 10 without commas, periods or a leading '0' | | {hash} | The hase based on the content of the file. | | {atime} | The file access time. | | {ctime} | The inode or file change time. | | {mtime} | The file modify time. |

atime, ctime and mtime

For more information about what the time formats mean go here

The output format used by atime, ctime and mtime is a format that includes the Year, Month, Date, Hours, Minutes, Seconds and Milliseconds.

example: "2015-01-31T11-34-13.1234Z"

As of version 1.2.0 if a file is added through the gulp system that does not support the file.stat object the values for atime, ctime and mtime will be an empty string.

Limiting the length of the output

You can limit the number of characters for the value of each parameter by adding :value to the parameter.

For example if you only want to use the first 8 characters of the hash value you would use the parameter {hash:8}.

More examples

Below are some other examples of the output filename based on the following values:

| parameter | value | | --- | --- | | filename | "sample.js" | | file size | 12,234 bytes | | ctime | Dec 19, 2014 at 3:15:33am and 235 milliseconds | | hash | ABCDEF0000FEDCBA |

Example output file name:

| format string | output file name | | --- | --- | | {name}-{size}.test{ext} | sample-12234.test.js | | {name}.{hash}.js1 | sample.ABCDEF0000FEDCBA.js1 | | {name}{ext} | Leaves the filename as it was. (sample.js) | | proj-{name}-{ctime}{ext} | proj-sample-2014-12-19T03-15-33.235Z.js | | {name}.{hash:5}{ext} | sample.ABCDE.js | | {name}.{hash:8}{ext} | sample.ABCDEF00.js |


License

MIT - License File


Update History

Update History File