@nextcloud/vue
Version:
Nextcloud vue components
31 lines (30 loc) • 1.12 kB
JavaScript
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const md5 = require("md5");
const GenColors = require("../chunks/GenColors-BVouTbTJ.cjs");
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
const md5__default = /* @__PURE__ */ _interopDefault(md5);
function usernameToColor(username) {
let hash = username.toLowerCase();
if (hash.match(/^([0-9a-f]{4}-?){8}$/) === null) {
hash = md5__default.default(hash);
}
hash = hash.replace(/[^0-9a-f]/g, "");
const steps = 6;
const finalPalette = GenColors.GenColors(steps);
function hashToInt(hash2, maximum) {
let finalInt = 0;
const result = [];
for (let i = 0; i < hash2.length; i++) {
result.push(parseInt(hash2.charAt(i), 16) % 16);
}
for (const j in result) {
finalInt += result[j];
}
return parseInt(parseInt(finalInt, 10) % maximum, 10);
}
return finalPalette[hashToInt(hash, steps * 3)];
}
exports.default = usernameToColor;
exports.usernameToColor = usernameToColor;
//# sourceMappingURL=usernameToColor.cjs.map
;