Skip to content

Commit

Permalink
Merge pull request #8 from Valkyr-JS/initial-build
Browse files Browse the repository at this point in the history
Initial build
  • Loading branch information
Valkyr-JS authored Jun 17, 2024
2 parents d950763 + 2f55c67 commit fbc0ed3
Show file tree
Hide file tree
Showing 28 changed files with 9,189 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# plugin-performer-popular-meta
Displays metadata about frequent scene partners, most prominent tags, etc., on performer pages in Stash.
# Performer Details Extended
A plugin for Stash. Displays metadata about frequent scene partners, most prominent tags, etc. in your library, on performer pages.
60 changes: 60 additions & 0 deletions helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/** Converts the given seconds into a uniform string showing an amount of time.
* */
export const createDuration = (seconds: number): string => {
const inMinutes = Math.floor(seconds / 60);
const inHours = Math.floor(inMinutes / 60);
const inDays = Math.floor(inHours / 24);

let output = "";

const totalHours = inHours % 60;
const totalMinutes = inMinutes % 60;
const totalSeconds = seconds % 60;

if (inDays > 0) output += inDays + " days ";
if (!!totalHours || !!output.length) output += totalHours + "h ";
if (!!totalMinutes || !!output.length) output += totalMinutes + "m ";

// Round down to match native
output += Math.floor(totalSeconds) + "s ";

return output;
};

/** Converts the given bytes into a uniform string showing a filesize, from
* bytes to terabytes. */
export const createFilesize = (bytes: number): string => {
const b = roundToTwo(bytes);
const kb = roundToTwo(bytes / 1024);
if (kb < 1) return b + "B";
const mb = roundToTwo(kb / 1024);
if (mb < 1) return kb + "KB";
const gb = roundToTwo(mb / 1024);
if (gb < 1) return mb + "MB";
const tb = roundToTwo(gb / 1024);
if (tb < 1) return gb + "GB";
return tb + "TB";
};

/** Returns the associated string GenderEnum as a human-readable value. */
export const getGenderFromEnum = (gender: GenderEnum): string | null => {
switch (gender) {
case "MALE":
return "Male";
case "FEMALE":
return "Female";
case "TRANSGENDER_MALE":
return "Transgender male";
case "TRANSGENDER_FEMALE":
return "Transgender female";
case "INTERSEX":
return "Intersex";
case "NON_BINARY":
return "Non-binary";
}
return null;
};

/** Round the provided number to two decimal places. */
const roundToTwo = (number: number): number =>
Math.round((number + Number.EPSILON) * 100) / 100;
Loading

0 comments on commit fbc0ed3

Please sign in to comment.