diff options
| author | Priyansh <[email protected]> | 2021-01-24 22:11:02 +0530 |
|---|---|---|
| committer | Priyansh <[email protected]> | 2021-01-24 22:11:02 +0530 |
| commit | 4503265fbf9b2153f2c8786e850005e26a90f767 (patch) | |
| tree | bb5d75d3d716a1eb0602594b8e20993c0c64474c /index.js | |
| parent | b1639decaa74cd2ae58505619dab2af4cff390ae (diff) | |
| download | randomavatars-4503265fbf9b2153f2c8786e850005e26a90f767.tar.xz randomavatars-4503265fbf9b2153f2c8786e850005e26a90f767.zip | |
removeExts function - if ignoreext is set to false
Diffstat (limited to 'index.js')
| -rw-r--r-- | index.js | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -1,3 +1,30 @@ export default class RandomAvatars { - constructor() {} + constructor(string, hashcount=11, ignoreext=true) { + /** + * This creates our avatar. + * Takes in a string and makes an picture out of it. + */ + if (ignoreext) removeExts(this, string); + + this.format = 'png' + } +} + +function removeExts(currentClass, string) { + /** + * Sets the input string to create an avatar + */ + + // If the user hasn't disabled it, we will detect image extensions, such as .png, .jpg, etc. + // We'll remove them from the string before hashing. + // This ensures that /Bear.png and /Bear.bmp will send back the same image, in different formats. + + let input = (String(string)).toLowerCase(); + if (input.endsWith('.png') || input.endsWith('.gif') || input.endsWith('.jpg') || input.endsWith('.bmp') || input.endsWith('.jpeg') || input.endsWith('.ppm') || input.endsWith('.datauri')) { + let format = input.substr(input.lastIndexOf('.') + 1, input.length); + if (format.toLowerCase() === 'jpg') format = 'jpg'; + currentClass.format = format + input = input.substr(0, input.lastIndexOf('.')); + } + return input; } |
