-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Replace crappy missing-cover cover with Hardcover-inspired Publ…
…ic Domain paintings Thank you @hardccoverapp!
- Loading branch information
1 parent
54f2609
commit 912731a
Showing
8 changed files
with
81 additions
and
15 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Selects an item from an array using a string as a key. | ||
* | ||
* @param options - Array of options to select from | ||
* @param key - String key used for selection | ||
* @returns Selected item from the array | ||
*/ | ||
export const selectByStringHash = <T>(options: T[], key: string): T => { | ||
if (!Array.isArray(options) || options.length === 0) { | ||
throw new Error("Options must be a non-empty array"); | ||
} | ||
if (typeof key !== "string") { | ||
throw new Error("Key must be a string"); | ||
} | ||
|
||
const hash = hashString(key); | ||
const index = hash % options.length; | ||
return options[index]; | ||
}; | ||
|
||
/** | ||
* Creates a simple hash from a string. | ||
* @param str - Input string to hash | ||
* @returns Hash value | ||
*/ | ||
const hashString = (str: string) => { | ||
let hash = 0; | ||
for (let i = 0; i < str.length; i++) { | ||
const char = str.charCodeAt(i); | ||
hash = (hash << 5) - hash + char; | ||
hash = hash & hash; // Convert to 32-bit integer | ||
} | ||
return Math.abs(hash); | ||
}; |