This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+22
View File
@@ -0,0 +1,22 @@
/// <reference types="node" />
/**
Create a hash for file revving.
@param input - Data to create a hash from.
@example
```
import * as fs from 'fs';
import revisionHash = require('rev-hash');
revisionHash(fs.readFileSync('unicorn.png'));
//=> 'bb9d8fe615'
revisionHash('Lorem ipsum dolor sit amet');
//=> 'fea80f2db0'
```
*/
declare function revisionHash(input: Buffer | string): string;
export = revisionHash;
+10
View File
@@ -0,0 +1,10 @@
'use strict';
const crypto = require('crypto');
module.exports = input => {
if (typeof input !== 'string' && !Buffer.isBuffer(input)) {
throw new TypeError('Expected a Buffer or string');
}
return crypto.createHash('md5').update(input).digest('hex').slice(0, 10);
};
+9
View File
@@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+41
View File
@@ -0,0 +1,41 @@
{
"name": "rev-hash",
"version": "3.0.0",
"description": "Create a hash for file revving",
"license": "MIT",
"repository": "sindresorhus/rev-hash",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"hash",
"crypto",
"md5",
"rev",
"revving",
"web",
"buffer",
"string",
"file",
"cache",
"caching"
],
"devDependencies": {
"@types/node": "^11.13.7",
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
+44
View File
@@ -0,0 +1,44 @@
# rev-hash [![Build Status](https://travis-ci.org/sindresorhus/rev-hash.svg?branch=master)](https://travis-ci.org/sindresorhus/rev-hash)
> Create a hash for file revving
It will create an `md5` hash from an input buffer or string, and truncate it to 10 characters, which is unique enough for this purpose.
If you think you need a different hash algorithm or a longer hash, [you're wrong](http://blog.risingstack.com/automatic-cache-busting-for-your-css/).
## Install
```
$ npm install rev-hash
```
## Usage
```js
const fs = require('fs');
const revisionHash = require('rev-hash');
revisionHash(fs.readFileSync('unicorn.png'));
//=> 'bb9d8fe615'
revisionHash('Lorem ipsum dolor sit amet');
//=> 'fea80f2db0'
```
## API
### revisionHash(input)
#### input
Type: `Buffer | string`
Data to create a hash from.
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)