1 | /*
|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
3 | Author Ivan Kopeykin @vankop
|
4 | */
|
5 |
|
6 | ;
|
7 |
|
8 | const A_CODE = "a".charCodeAt(0);
|
9 |
|
10 | /**
|
11 | * @param {string} hash hash
|
12 | * @param {number} hashLength hash length
|
13 | * @returns {string} returns hash that has at least one non numeric char
|
14 | */
|
15 | module.exports = (hash, hashLength) => {
|
16 | if (hashLength < 1) return "";
|
17 | const slice = hash.slice(0, hashLength);
|
18 | if (slice.match(/[^\d]/)) return slice;
|
19 | return `${String.fromCharCode(
|
20 | A_CODE + (parseInt(hash[0], 10) % 6)
|
21 | )}${slice.slice(1)}`;
|
22 | };
|