mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-17 10:27:03 -04:00
Settings: Calculate dependencies
This commit is contained in:
parent
78deb0ebad
commit
9951e0bcc5
2 changed files with 86 additions and 31 deletions
|
@ -69,4 +69,32 @@ export function mergeDefaults<T>(obj: T, defaults: T): T {
|
|||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Join an array of strings in a human readable way (1, 2 and 3)
|
||||
* @param elements Elements
|
||||
*/
|
||||
export function humanFriendlyJoin(elements: string[]): string;
|
||||
/**
|
||||
* Join an array of strings in a human readable way (1, 2 and 3)
|
||||
* @param elements Elements
|
||||
* @param mapper Function that converts elements to a string
|
||||
*/
|
||||
export function humanFriendlyJoin<T>(elements: T[], mapper: (e: T) => string): string;
|
||||
export function humanFriendlyJoin(elements: any[], mapper: (e: any) => string = s => s): string {
|
||||
const { length } = elements;
|
||||
if (length === 0) return "";
|
||||
if (length === 1) return mapper(elements[0]);
|
||||
|
||||
let s = "";
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
s += mapper(elements[i]);
|
||||
if (length - i > 2) s += ", ";
|
||||
else if (length - i > 1) s += " and ";
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue