mirror of
https://github.com/lucide-icons/lucide.git
synced 2025-12-22 10:19:22 +01:00
29 lines
813 B
TypeScript
29 lines
813 B
TypeScript
|
|
/**
|
||
|
|
* djb2 hashing function
|
||
|
|
*
|
||
|
|
* @param {string} string
|
||
|
|
* @param {number} seed
|
||
|
|
* @returns {string} A hashed string of 6 characters
|
||
|
|
*/
|
||
|
|
export const hash = (string: string, seed = 5381) => {
|
||
|
|
let i = string.length;
|
||
|
|
|
||
|
|
while (i) {
|
||
|
|
// eslint-disable-next-line no-bitwise, no-plusplus
|
||
|
|
seed = (seed * 33) ^ string.charCodeAt(--i);
|
||
|
|
}
|
||
|
|
|
||
|
|
// eslint-disable-next-line no-bitwise
|
||
|
|
return (seed >>> 0).toString(36).substr(0, 6);
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Generate Hashed string based on name and attributes
|
||
|
|
*
|
||
|
|
* @param {object} seed
|
||
|
|
* @param {string} seed.name A name, for example an icon name
|
||
|
|
* @param {object} seed.attributes An object of SVGElement Attrbutes
|
||
|
|
* @returns {string} A hashed string of 6 characters
|
||
|
|
*/
|
||
|
|
export const generateHashedKey = ({ name, attributes }) => hash(JSON.stringify([name, attributes]));
|