2018-07-08 07:11:34 +02:00
|
|
|
/**
|
|
|
|
* Returns the input array as a comma separated string.
|
2019-02-09 03:46:30 +01:00
|
|
|
*
|
|
|
|
* Does several things that Array.toString() doesn't do
|
|
|
|
* - Adds brackets around the array
|
|
|
|
* - Adds quotation marks around strings
|
2018-07-08 07:11:34 +02:00
|
|
|
*/
|
2018-07-05 20:12:20 +02:00
|
|
|
export function arrayToString<T>(a: T[]) {
|
2019-02-09 03:46:30 +01:00
|
|
|
const vals: any[] = [];
|
|
|
|
for (let i = 0; i < a.length; ++i) {
|
|
|
|
let elem: any = a[i];
|
2019-05-02 00:20:14 +02:00
|
|
|
if (Array.isArray(elem)) {
|
|
|
|
elem = arrayToString(elem);
|
|
|
|
} else if (typeof elem === "string") {
|
2019-02-09 03:46:30 +01:00
|
|
|
elem = `"${elem}"`;
|
|
|
|
}
|
|
|
|
vals.push(elem);
|
|
|
|
}
|
2019-05-02 00:20:14 +02:00
|
|
|
|
2019-02-09 03:46:30 +01:00
|
|
|
return `[${vals.join(", ")}]`;
|
2018-07-05 20:12:20 +02:00
|
|
|
}
|