Skip to main content
This release is 2 versions behind 0.1.10 — the latest version of @alator21/tay. Jump to latest

Built and signed on GitHub Actions

Generates a banner based on the last.fm top tracks

This package works with Node.js, Deno, Bun, BrowsersIt is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
70%
Published
4 months ago (0.1.8)
Package root>src>banner>text_banner_generator.ts
import { pluralize } from "../internal/pluralize.ts"; import type { GetTopTracksResponse, Period } from "../lastfm/user/getTopTracks.ts"; type Track = GetTopTracksResponse['toptracks']['track'][0]; type GenerateTextBannerRequest = { tracks: Array<Track>; period: Period; style: 'default' | 'experimental'; }; function constructHeader(period: Period): string { if (period === '7day') { return '## My top tracks last week!\n'; } throw new Error(`Not supported period ${period}`); }; /** * returns the top tracks of the week in markdown format */ export async function generateTextBanner(request: GenerateTextBannerRequest): Promise<string> { const { tracks: allTracks, period, style } = request; const tracks = allTracks.slice(0, 5); if (style === 'default') { return defaultStyle(tracks, period); } return experimentalStyle(tracks); } async function defaultStyle(tracks: Array<Track>, period: Period): Promise<string> { let formattedText = constructHeader(period); for (let i = 0; i < tracks.length; i++) { const track = tracks[i]; const index = i + 1; formattedText += `${index}. **${track.name}** by **${track.artist.name}** played **${track.playcount}** ${pluralize(track.playcount, 'time', 'times')}\n`; } return formattedText; } async function experimentalStyle(tracks: Array<Track>): Promise<string> { throw new Error(`not implemented yet`); }