Lint and format
This commit is contained in:
@@ -1,35 +1,55 @@
|
||||
const CDRAGON_BASE = "https://raw.communitydragon.org/latest/"
|
||||
const CDRAGON_BASE = 'https://raw.communitydragon.org/latest/'
|
||||
|
||||
/* Lanes */
|
||||
const POSITIONS = ["top", "jungle", "middle", "bottom", "utility"]
|
||||
const POSITIONS_STR = ["top", "jungle", "mid", "bot", "support"]
|
||||
const LANE_IMAGES = Array(5).fill("").map((_, index) => "/img/lanes/icon-position-" + POSITIONS[index] + ".png")
|
||||
const LANE_IMAGES_HOVER = Array(5).fill("").map((_, index) => "/img/lanes/icon-position-" + POSITIONS[index] + "-hover.png")
|
||||
const LANE_IMAGES_SELECTED = Array(5).fill("").map((_, index) => "/img/lanes/icon-position-" + POSITIONS[index] + "-blue.png")
|
||||
function laneIndexToPosition(index : number) {
|
||||
switch(index) {
|
||||
case 0: return "top"
|
||||
case 1: return "jungle"
|
||||
case 2: return "middle"
|
||||
case 3: return "bottom"
|
||||
case 4: return "utility"
|
||||
}
|
||||
return null
|
||||
const POSITIONS = ['top', 'jungle', 'middle', 'bottom', 'utility']
|
||||
const POSITIONS_STR = ['top', 'jungle', 'mid', 'bot', 'support']
|
||||
const LANE_IMAGES = Array(5)
|
||||
.fill('')
|
||||
.map((_, index) => '/img/lanes/icon-position-' + POSITIONS[index] + '.png')
|
||||
const LANE_IMAGES_HOVER = Array(5)
|
||||
.fill('')
|
||||
.map((_, index) => '/img/lanes/icon-position-' + POSITIONS[index] + '-hover.png')
|
||||
const LANE_IMAGES_SELECTED = Array(5)
|
||||
.fill('')
|
||||
.map((_, index) => '/img/lanes/icon-position-' + POSITIONS[index] + '-blue.png')
|
||||
function laneIndexToPosition(index: number) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return 'top'
|
||||
case 1:
|
||||
return 'jungle'
|
||||
case 2:
|
||||
return 'middle'
|
||||
case 3:
|
||||
return 'bottom'
|
||||
case 4:
|
||||
return 'utility'
|
||||
}
|
||||
return null
|
||||
}
|
||||
function lanePositionToIndex(position : string) {
|
||||
const p = position.toLowerCase()
|
||||
for(let i = 0; i < POSITIONS.length; i++) {
|
||||
if(p == POSITIONS[i]) return i;
|
||||
}
|
||||
return -1;
|
||||
function lanePositionToIndex(position: string) {
|
||||
const p = position.toLowerCase()
|
||||
for (let i = 0; i < POSITIONS.length; i++) {
|
||||
if (p == POSITIONS[i]) return i
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
function mapPath(assetPath : string) {
|
||||
if(assetPath === undefined || assetPath === null) return ""
|
||||
return assetPath.toLowerCase().replace("/lol-game-data/assets/", "plugins/rcp-be-lol-game-data/global/default/")
|
||||
function mapPath(assetPath: string) {
|
||||
if (assetPath === undefined || assetPath === null) return ''
|
||||
return assetPath
|
||||
.toLowerCase()
|
||||
.replace('/lol-game-data/assets/', 'plugins/rcp-be-lol-game-data/global/default/')
|
||||
}
|
||||
|
||||
export {
|
||||
mapPath, CDRAGON_BASE, laneIndexToPosition, lanePositionToIndex,
|
||||
POSITIONS, LANE_IMAGES, LANE_IMAGES_HOVER, LANE_IMAGES_SELECTED, POSITIONS_STR
|
||||
}
|
||||
export {
|
||||
mapPath,
|
||||
CDRAGON_BASE,
|
||||
laneIndexToPosition,
|
||||
lanePositionToIndex,
|
||||
POSITIONS,
|
||||
LANE_IMAGES,
|
||||
LANE_IMAGES_HOVER,
|
||||
LANE_IMAGES_SELECTED,
|
||||
POSITIONS_STR
|
||||
}
|
||||
|
||||
@@ -8,15 +8,18 @@
|
||||
* @param wait Time in milliseconds to wait before calling the function
|
||||
* @returns Debounced function
|
||||
*/
|
||||
export function debounce<T extends (...args: any[]) => any>(func: T, wait: number): (...args: Parameters<T>) => void {
|
||||
let timeout: ReturnType<typeof setTimeout> | null = null;
|
||||
export function debounce<T extends (...args: any[]) => any>(
|
||||
func: T,
|
||||
wait: number
|
||||
): (...args: Parameters<T>) => void {
|
||||
let timeout: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
return function(...args: Parameters<T>): void {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
timeout = setTimeout(() => func(...args), wait);
|
||||
};
|
||||
return function (...args: Parameters<T>): void {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout)
|
||||
}
|
||||
timeout = setTimeout(() => func(...args), wait)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,12 +29,12 @@ export function debounce<T extends (...args: any[]) => any>(func: T, wait: numbe
|
||||
* @returns Parsed JSON or default value
|
||||
*/
|
||||
export function safeJsonParse<T>(data: string, defaultValue: T): T {
|
||||
try {
|
||||
return JSON.parse(data) as T;
|
||||
} catch (error) {
|
||||
console.error('JSON parse error:', error);
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return JSON.parse(data) as T
|
||||
} catch (error) {
|
||||
console.error('JSON parse error:', error)
|
||||
return defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +44,7 @@ export function safeJsonParse<T>(data: string, defaultValue: T): T {
|
||||
* @returns Formatted percentage string
|
||||
*/
|
||||
export function formatPercentage(value: number, decimals: number = 0): string {
|
||||
return (value * 100).toFixed(decimals) + '%';
|
||||
return (value * 100).toFixed(decimals) + '%'
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,8 +53,8 @@ export function formatPercentage(value: number, decimals: number = 0): string {
|
||||
* @returns Capitalized string
|
||||
*/
|
||||
export function capitalize(str: string): string {
|
||||
if (!str) return '';
|
||||
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
||||
if (!str) return ''
|
||||
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,14 +63,14 @@ export function capitalize(str: string): string {
|
||||
* @returns Readable lane name
|
||||
*/
|
||||
export function getLaneName(position: string): string {
|
||||
const laneMap: Record<string, string> = {
|
||||
'top': 'Top',
|
||||
'jungle': 'Jungle',
|
||||
'middle': 'Middle',
|
||||
'bottom': 'Bottom',
|
||||
'utility': 'Support'
|
||||
};
|
||||
return laneMap[position.toLowerCase()] || position;
|
||||
const laneMap: Record<string, string> = {
|
||||
top: 'Top',
|
||||
jungle: 'Jungle',
|
||||
middle: 'Middle',
|
||||
bottom: 'Bottom',
|
||||
utility: 'Support'
|
||||
}
|
||||
return laneMap[position.toLowerCase()] || position
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +79,7 @@ export function getLaneName(position: string): string {
|
||||
* @returns Full image URL
|
||||
*/
|
||||
export function getChampionImageUrl(championAlias: string): string {
|
||||
return `/img/champions/${championAlias.toLowerCase()}.png`;
|
||||
return `/img/champions/${championAlias.toLowerCase()}.png`
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +88,7 @@ export function getChampionImageUrl(championAlias: string): string {
|
||||
* @returns Full item image URL
|
||||
*/
|
||||
export function getItemImageUrl(itemId: number): string {
|
||||
return `${CDRAGON_BASE}plugins/rcp-be-lol-game-data/global/default/v1/items/${itemId}.png`;
|
||||
return `${CDRAGON_BASE}plugins/rcp-be-lol-game-data/global/default/v1/items/${itemId}.png`
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +97,7 @@ export function getItemImageUrl(itemId: number): string {
|
||||
* @returns Full rune image URL
|
||||
*/
|
||||
export function getRuneImageUrl(runeId: number): string {
|
||||
return `${CDRAGON_BASE}plugins/rcp-be-lol-game-data/global/default/v1/perks/${runeId}.png`;
|
||||
return `${CDRAGON_BASE}plugins/rcp-be-lol-game-data/global/default/v1/perks/${runeId}.png`
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,12 +106,12 @@ export function getRuneImageUrl(runeId: number): string {
|
||||
* @returns Formatted string
|
||||
*/
|
||||
export function formatLargeNumber(num: number): string {
|
||||
if (num >= 1000000) {
|
||||
return (num / 1000000).toFixed(1) + 'M';
|
||||
} else if (num >= 1000) {
|
||||
return (num / 1000).toFixed(1) + 'K';
|
||||
}
|
||||
return num.toString();
|
||||
if (num >= 1000000) {
|
||||
return (num / 1000000).toFixed(1) + 'M'
|
||||
} else if (num >= 1000) {
|
||||
return (num / 1000).toFixed(1) + 'K'
|
||||
}
|
||||
return num.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +120,7 @@ export function formatLargeNumber(num: number): string {
|
||||
* @returns Cloned object
|
||||
*/
|
||||
export function deepClone<T>(obj: T): T {
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
return JSON.parse(JSON.stringify(obj))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,11 +129,11 @@ export function deepClone<T>(obj: T): T {
|
||||
* @returns True if value is empty
|
||||
*/
|
||||
export function isEmpty(value: any): boolean {
|
||||
if (value === null || value === undefined) return true;
|
||||
if (typeof value === 'string' && value.trim() === '') return true;
|
||||
if (Array.isArray(value) && value.length === 0) return true;
|
||||
if (typeof value === 'object' && Object.keys(value).length === 0) return true;
|
||||
return false;
|
||||
if (value === null || value === undefined) return true
|
||||
if (typeof value === 'string' && value.trim() === '') return true
|
||||
if (Array.isArray(value) && value.length === 0) return true
|
||||
if (typeof value === 'object' && Object.keys(value).length === 0) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,9 +142,9 @@ export function isEmpty(value: any): boolean {
|
||||
* @returns CSS color class
|
||||
*/
|
||||
export function getWinrateColor(winrate: number): string {
|
||||
if (winrate > 0.55) return 'text-green-500';
|
||||
if (winrate < 0.45) return 'text-red-500';
|
||||
return 'text-yellow-500';
|
||||
if (winrate > 0.55) return 'text-green-500'
|
||||
if (winrate < 0.45) return 'text-red-500'
|
||||
return 'text-yellow-500'
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,15 +153,15 @@ export function getWinrateColor(winrate: number): string {
|
||||
* @returns Formatted duration string
|
||||
*/
|
||||
export function formatDuration(ms: number): string {
|
||||
const seconds = Math.floor(ms / 1000);
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const seconds = Math.floor(ms / 1000)
|
||||
const minutes = Math.floor(seconds / 60)
|
||||
const hours = Math.floor(minutes / 60)
|
||||
|
||||
if (hours > 0) {
|
||||
return `${hours}h ${minutes % 60}m`;
|
||||
} else if (minutes > 0) {
|
||||
return `${minutes}m ${seconds % 60}s`;
|
||||
} else {
|
||||
return `${seconds}s`;
|
||||
}
|
||||
if (hours > 0) {
|
||||
return `${hours}h ${minutes % 60}m`
|
||||
} else if (minutes > 0) {
|
||||
return `${minutes}m ${seconds % 60}s`
|
||||
} else {
|
||||
return `${seconds}s`
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user