1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.cache = void 0;
|
4 | exports.sha1 = sha1;
|
5 | var crypto_1 = require("crypto");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | exports.cache = Object.create(null);
|
11 |
|
12 |
|
13 |
|
14 | function sha1() {
|
15 | var data = [];
|
16 | for (var _i = 0; _i < arguments.length; _i++) {
|
17 | data[_i] = arguments[_i];
|
18 | }
|
19 | var canCache = data.length === 1 && typeof data[0] === 'string';
|
20 |
|
21 | var cacheKey;
|
22 | if (canCache) {
|
23 | cacheKey = data[0];
|
24 | if (cacheKey in exports.cache) {
|
25 | return exports.cache[cacheKey];
|
26 | }
|
27 | }
|
28 |
|
29 |
|
30 | var hash = (0, crypto_1.createHash)('sha1');
|
31 | data.forEach(function (item) {
|
32 | if (typeof item === 'string')
|
33 | hash.update(item, 'utf8');
|
34 | else
|
35 | hash.update(item);
|
36 | });
|
37 | var res = hash.digest('hex').toString();
|
38 | if (canCache) {
|
39 | exports.cache[cacheKey] = res;
|
40 | }
|
41 | return res;
|
42 | }
|