@rmdes/indiekit-endpoint-lastfm 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/utils.js +30 -9
  2. package/package.json +1 -1
package/lib/utils.js CHANGED
@@ -302,12 +302,18 @@ export function formatLovedTrack(track) {
302
302
  * @returns {object} - Formatted artist
303
303
  */
304
304
  export function formatTopArtist(artist, rank) {
305
+ // Handle edge cases where artist data might be malformed
306
+ let name = artist?.name;
307
+ if (typeof name !== "string") {
308
+ name = name?.["#text"] || String(name || "Unknown Artist");
309
+ }
310
+
305
311
  return {
306
312
  rank,
307
- name: artist.name,
308
- playCount: parseInt(artist.playcount) || 0,
309
- url: artist.url,
310
- mbid: artist.mbid || null,
313
+ name,
314
+ playCount: parseInt(artist?.playcount) || 0,
315
+ url: artist?.url || null,
316
+ mbid: artist?.mbid || null,
311
317
  imageUrl: getCoverUrl(artist),
312
318
  };
313
319
  }
@@ -319,13 +325,28 @@ export function formatTopArtist(artist, rank) {
319
325
  * @returns {object} - Formatted album
320
326
  */
321
327
  export function formatTopAlbum(album, rank) {
328
+ // Handle edge cases where album data might be malformed
329
+ let title = album?.name;
330
+ if (typeof title !== "string") {
331
+ title = title?.["#text"] || String(title || "Unknown Album");
332
+ }
333
+
334
+ // Extract artist name from various possible formats
335
+ let artist = album?.artist;
336
+ if (typeof artist === "object" && artist !== null) {
337
+ artist = artist.name || artist["#text"] || "Unknown Artist";
338
+ }
339
+ if (typeof artist !== "string") {
340
+ artist = String(artist || "Unknown Artist");
341
+ }
342
+
322
343
  return {
323
344
  rank,
324
- title: album.name,
325
- artist: album.artist?.name || album.artist?.["#text"] || album.artist,
326
- playCount: parseInt(album.playcount) || 0,
327
- url: album.url,
328
- mbid: album.mbid || null,
345
+ title,
346
+ artist,
347
+ playCount: parseInt(album?.playcount) || 0,
348
+ url: album?.url || null,
349
+ mbid: album?.mbid || null,
329
350
  coverUrl: getCoverUrl(album),
330
351
  };
331
352
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-lastfm",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Last.fm scrobble and listening activity endpoint for Indiekit. Display listening history, loved tracks, and statistics.",
5
5
  "keywords": [
6
6
  "indiekit",