From 8d692cdfa7a834ed3d98bb5e7fe479074817001d Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 18 Jan 2024 19:59:47 +0100 Subject: [PATCH] add `utils.artistsToMarkdown` --- package.json | 2 +- src/lib/index.ts | 3 ++- src/lib/utils/artistsToMarkdown.ts | 14 ++++++++++++++ src/lib/utils/index.ts | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/lib/utils/artistsToMarkdown.ts create mode 100644 src/lib/utils/index.ts diff --git a/package.json b/package.json index f325cf1..17f1d14 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "oauth2", "music" ], - "version": "0.1.8", + "version": "0.1.9", "main": "dist/src/lib/index.js", "types": "dist/src/lib/index.d.js", "files": [ diff --git a/src/lib/index.ts b/src/lib/index.ts index a184d14..98242c1 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -57,4 +57,5 @@ export class Lunify { export * from './managers'; export * from './structures'; -export * from './Constants'; \ No newline at end of file +export * from './Constants'; +export * as utils from './utils'; \ No newline at end of file diff --git a/src/lib/utils/artistsToMarkdown.ts b/src/lib/utils/artistsToMarkdown.ts new file mode 100644 index 0000000..6c9c958 --- /dev/null +++ b/src/lib/utils/artistsToMarkdown.ts @@ -0,0 +1,14 @@ +import { PartialArtist } from '../structures'; + +export const aristsToMarkdown = (artists: PartialArtist[], max?: number) => { + const arr = artists.map((artist) => `[${artist.name}]()`); + + 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(', '); +}; \ No newline at end of file diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts new file mode 100644 index 0000000..5f554ee --- /dev/null +++ b/src/lib/utils/index.ts @@ -0,0 +1 @@ +export * from './artistsToMarkdown'; \ No newline at end of file