aboutsummaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authorPriyansh <[email protected]>2021-01-24 22:11:02 +0530
committerPriyansh <[email protected]>2021-01-24 22:11:02 +0530
commit4503265fbf9b2153f2c8786e850005e26a90f767 (patch)
treebb5d75d3d716a1eb0602594b8e20993c0c64474c /index.js
parentb1639decaa74cd2ae58505619dab2af4cff390ae (diff)
downloadrandomavatars-4503265fbf9b2153f2c8786e850005e26a90f767.tar.xz
randomavatars-4503265fbf9b2153f2c8786e850005e26a90f767.zip
removeExts function - if ignoreext is set to false
Diffstat (limited to 'index.js')
-rw-r--r--index.js29
1 files changed, 28 insertions, 1 deletions
diff --git a/index.js b/index.js
index d7b1bd4..e0ab620 100644
--- a/index.js
+++ b/index.js
@@ -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;
}