lunify.js
Version:
A basic api wrapper for the spotify api covering the oauth routes.
30 lines • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.aristsToMarkdown = aristsToMarkdown;
exports.escapeMarkdown = escapeMarkdown;
const MARKDOWN_REGEX = /[!#()*+.[\\]_`{}-]/g;
/**
* Converts an array of artists to markdown
* @param artists - An array of partial artists to convert to markdown
* @param max - How many artists to show before showing the remaining count
* @returns Markdown string
*/
function aristsToMarkdown(artists, max) {
const arr = artists.map((artist) => `[${escapeMarkdown(artist.name)}](<https://open.spotify.com/artist/${artist.id}>)`);
if (max && arr.length > max) {
const shownArists = arr.slice(0, max).join(", ");
const remainingCount = Math.max(0, arr.length - max);
return `${shownArists} & ${remainingCount} more`;
}
return arr.join(", ");
}
/**
* Escapes some common markdown characters in a string
* @param input - The input string
* @returns Markdown escaped string
*/
function escapeMarkdown(input) {
const escapedInput = input.replace(MARKDOWN_REGEX, "\\$&");
return escapedInput;
}
//# sourceMappingURL=artists-to-markdown.js.map