UNPKG

lunify.js

Version:

A basic api wrapper for the spotify api covering the oauth routes.

31 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.escapeMarkdown = exports.aristsToMarkdown = void 0; /** * 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(', '); } exports.aristsToMarkdown = aristsToMarkdown; /** * Escapes some common markdown characters in a string * @param input - The input string * @returns Markdown escaped string */ function escapeMarkdown(input) { const markdownCharacters = /\\|`|\*|_|{|}|\[|\]|\(|\)|#|\+|-|\.|!/g; const escapedInput = input.replace(markdownCharacters, '\\$&'); return escapedInput; } exports.escapeMarkdown = escapeMarkdown; //# sourceMappingURL=artistsToMarkdown.js.map