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