|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
953 bytes
|
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
|---|
| 3 | Author Alexander Akait @alexander-akait
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | "use strict";
|
|---|
| 7 |
|
|---|
| 8 | const createHash = require("./createHash");
|
|---|
| 9 |
|
|---|
| 10 | /**
|
|---|
| 11 | * Returns generated debug id.
|
|---|
| 12 | * @param {string | Buffer} content content
|
|---|
| 13 | * @param {string} file file
|
|---|
| 14 | * @returns {string} generated debug id
|
|---|
| 15 | */
|
|---|
| 16 | module.exports = (content, file) => {
|
|---|
| 17 | // We need a uuid which is 128 bits so we need 2x 64 bit hashes.
|
|---|
| 18 | // The first 64 bits is a hash of the source.
|
|---|
| 19 | const sourceHash = createHash("xxhash64").update(content).digest("hex");
|
|---|
| 20 | // The next 64 bits is a hash of the filename and sourceHash
|
|---|
| 21 | const hash128 = `${sourceHash}${createHash("xxhash64")
|
|---|
| 22 | .update(file)
|
|---|
| 23 | .update(sourceHash)
|
|---|
| 24 | .digest("hex")}`;
|
|---|
| 25 |
|
|---|
| 26 | return [
|
|---|
| 27 | hash128.slice(0, 8),
|
|---|
| 28 | hash128.slice(8, 12),
|
|---|
| 29 | `4${hash128.slice(12, 15)}`,
|
|---|
| 30 | ((Number.parseInt(hash128.slice(15, 16), 16) & 3) | 8).toString(16) +
|
|---|
| 31 | hash128.slice(17, 20),
|
|---|
| 32 | hash128.slice(20, 32)
|
|---|
| 33 | ].join("-");
|
|---|
| 34 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.