UNPKG

556 BJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Ivan Kopeykin @vankop
4*/
5
6"use strict";
7
8const 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 */
15module.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};