👽 New API for generative icons, Re: #163

This commit is contained in:
Alicia Sykes
2021-09-29 19:46:04 +01:00
parent 66e4ada28f
commit 5ec2abcf81
4 changed files with 22 additions and 8 deletions

View File

@@ -3,4 +3,11 @@ import { hideFurnitureOn } from '@/utils/defaults';
/* Returns false if page furniture should be hidden on said route */
export const shouldBeVisible = (routeName) => !hideFurnitureOn.includes(routeName);
export const x = () => null;
/* Very rudimentary hash function for generative icons */
export const asciiHash = (input) => {
const str = (!input || input.length === 0) ? Math.random().toString() : input;
const reducer = (previousHash, char) => (previousHash || 0) + char.charCodeAt(0);
const asciiSum = str.split('').reduce(reducer).toString();
const shortened = asciiSum.slice(0, 30) + asciiSum.slice(asciiSum.length - 30);
return window.btoa(shortened);
};