main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
922 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 | * @param {string | Buffer} content content
|
---|
12 | * @param {string} file file
|
---|
13 | * @returns {string} generated debug id
|
---|
14 | */
|
---|
15 | module.exports = (content, file) => {
|
---|
16 | // We need a uuid which is 128 bits so we need 2x 64 bit hashes.
|
---|
17 | // The first 64 bits is a hash of the source.
|
---|
18 | const sourceHash = createHash("xxhash64").update(content).digest("hex");
|
---|
19 | // The next 64 bits is a hash of the filename and sourceHash
|
---|
20 | const hash128 = `${sourceHash}${createHash("xxhash64")
|
---|
21 | .update(file)
|
---|
22 | .update(sourceHash)
|
---|
23 | .digest("hex")}`;
|
---|
24 |
|
---|
25 | return [
|
---|
26 | hash128.slice(0, 8),
|
---|
27 | hash128.slice(8, 12),
|
---|
28 | `4${hash128.slice(12, 15)}`,
|
---|
29 | ((Number.parseInt(hash128.slice(15, 16), 16) & 3) | 8).toString(16) +
|
---|
30 | hash128.slice(17, 20),
|
---|
31 | hash128.slice(20, 32)
|
---|
32 | ].join("-");
|
---|
33 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.