Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@solely/simple-fm

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solely/simple-fm - npm Package Compare versions

Comparing version 1.6.4 to 1.7.0

dist/utils/caster.d.ts

44

dist/classes/album.class.js
import { convertImageSizes, createLastFmURL } from '../utils/convert.js';
import Base from '../base.js';
import { toInt, toArray, convertSearch } from '../utils/caster.js';
export default class Album extends Base {

@@ -15,18 +16,12 @@ /**

});
const createTrackObject = (track) => ({
rank: Number(track['@attr'].rank),
name: track.name,
duration: Number(track.duration),
url: track.url,
});
return {
name: album.name,
mbid: album.mbid,
mbid: album.mbid === '' ? undefined : album.mbid,
artist: {
name: album.artist,
url: createLastFmURL('artist', album.artist),
url: createLastFmURL({ type: 'artist', value: album.artist }),
},
stats: {
scrobbles: Number(album.playcount),
listeners: Number(album.listeners),
scrobbles: toInt(album.playcount),
listeners: toInt(album.listeners),
},

@@ -36,6 +31,12 @@ userStats: {

},
tags: tagMatches.map((tag) => ({ name: tag.name, url: tag.url })),
tracks: Array.isArray(trackMatches)
? trackMatches.map((track) => createTrackObject(track))
: createTrackObject(trackMatches),
tags: toArray(tagMatches).map((tag) => ({
name: tag.name,
url: tag.url,
})),
tracks: toArray(trackMatches).map((track) => ({
rank: toInt(track['@attr'].rank),
name: track.name,
duration: toInt(track.duration),
url: track.url,
})),
url: album.url,

@@ -59,5 +60,5 @@ image: convertImageSizes(album.image),

name: attr.artist,
url: createLastFmURL('artist', attr.artist),
url: createLastFmURL({ type: 'artist', value: attr.artist }),
},
tags: tagMatches.map((tag) => ({
tags: toArray(tagMatches).map((tag) => ({
count: tag.count,

@@ -83,9 +84,4 @@ name: tag.name,

return {
search: {
query: results['opensearch:Query'].searchTerms,
page: Number(results['opensearch:Query'].startPage),
itemsPerPage: Number(results['opensearch:itemsPerPage']),
totalResults: Number(results['opensearch:totalResults']),
},
albums: albumMatches.map((album) => ({
search: convertSearch(results),
albums: toArray(albumMatches).map((album) => ({
name: album.name,

@@ -95,3 +91,3 @@ mbid: album.mbid === '' ? undefined : album.mbid,

name: album.artist,
url: createLastFmURL('artist', album.artist),
url: createLastFmURL({ type: 'artist', value: album.artist }),
},

@@ -98,0 +94,0 @@ url: album.url,

import { convertImageSizes, createLastFmURL } from '../utils/convert.js';
import Base from '../base.js';
import { convertSearch, sanitizeBio, toArray, toBool, toFloat, toInt } from '../utils/caster.js';
export default class Artist extends Base {

@@ -16,12 +17,26 @@ /**

name: artist.name,
mbid: artist.mbid,
description: artist.bio.summary,
onTour: Boolean(Number(artist.ontour)).valueOf(),
mbid: artist.mbid === '' ? undefined : artist.mbid,
onTour: toBool(artist.ontour),
stats: {
scrobbles: Number(artist.stats.playcount),
listeners: Number(artist.stats.listeners),
scrobbles: toInt(artist.stats.playcount),
listeners: toInt(artist.stats.listeners),
},
userStats: {
userPlayCount: Number(artist.stats.userplaycount),
userPlayCount: Number.isNaN(toInt(artist.stats.userplaycount)) ? undefined : toInt(artist.stats.userplaycount),
},
tags: toArray(artist.tags.tag).map((tag) => ({
name: tag.name,
url: tag.url,
})),
bio: {
summary: sanitizeBio(artist.bio.summary),
extended: sanitizeBio(artist.bio.content),
published: new Date(`${artist.bio.published} UTC`),
url: artist.bio.links.link.href,
},
similarArtists: toArray(artist.similar.artist).map((artist) => ({
name: artist.name,
image: convertImageSizes(artist.image),
url: artist.url,
})),
url: artist.url,

@@ -45,9 +60,9 @@ };

name: attr.artist,
url: createLastFmURL('artist', attr.artist),
url: createLastFmURL({ type: 'artist', value: attr.artist }),
},
},
artists: artistMatches.map((artist) => ({
match: Number(artist.match),
artists: toArray(artistMatches).map((artist) => ({
match: toFloat(artist.match),
name: artist.name,
mbid: artist.mbid,
mbid: artist.mbid === '' ? undefined : artist.mbid,
url: artist.url,

@@ -74,12 +89,12 @@ })),

name: attr.artist,
url: createLastFmURL('artist', attr.artist),
url: createLastFmURL({ type: 'artist', value: attr.artist }),
},
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
albums: albumMatches.map((album) => ({
albums: toArray(albumMatches).map((album) => ({
name: album.name,
scrobbles: Number(album.playcount),
scrobbles: toInt(album.playcount),
artist: {

@@ -104,7 +119,9 @@ name: album.artist.name,

return {
artist: {
name: attr.artist,
url: createLastFmURL('artist', attr.artist),
search: {
artist: {
name: attr.artist,
url: createLastFmURL({ type: 'artist', value: attr.artist }),
},
},
tags: tagMatches.map((tag) => ({
tags: toArray(tagMatches).map((tag) => ({
count: tag.count,

@@ -133,13 +150,13 @@ name: tag.name,

name: attr.artist,
url: createLastFmURL('artist', attr.artist),
url: createLastFmURL({ type: 'artist', value: attr.artist }),
},
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
tracks: trackMatches.map((track) => ({
rank: Number(track['@attr'].rank),
rank: toInt(track['@attr'].rank),
name: track.name,
mbid: track.mbid,
mbid: track.mbid === '' ? undefined : track.mbid,
artist: {

@@ -150,4 +167,4 @@ name: track.artist.name,

stats: {
scrobbles: Number(track.playcount),
listeners: Number(track.listeners),
scrobbles: toInt(track.playcount),
listeners: toInt(track.listeners),
},

@@ -172,12 +189,7 @@ url: track.url,

return {
search: {
query: results['opensearch:Query'].searchTerms,
page: Number(results['opensearch:Query'].startPage),
itemsPerPage: Number(results['opensearch:itemsPerPage']),
totalResults: Number(results['opensearch:totalResults']),
},
artists: artistMatches.map((artist) => ({
search: convertSearch(results),
artists: toArray(artistMatches).map((artist) => ({
name: artist.name,
mbid: artist.mbid,
listeners: Number(artist.listeners),
mbid: artist.mbid === '' ? undefined : artist.mbid,
listeners: toInt(artist.listeners),
url: artist.url,

@@ -184,0 +196,0 @@ })),

import Base from '../base.js';
import { toArray, toInt } from '../utils/caster.js';
export default class Chart extends Base {

@@ -16,13 +17,13 @@ /**

search: {
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
artists: artistMatches.map((artist) => ({
artists: toArray(artistMatches).map((artist) => ({
name: artist.name,
mbid: artist.mbid,
mbid: artist.mbid === '' ? undefined : artist.mbid,
stats: {
scrobbles: Number(artist.playcount),
listeners: Number(artist.listeners),
scrobbles: toInt(artist.playcount),
listeners: toInt(artist.listeners),
},

@@ -46,12 +47,12 @@ url: artist.url,

search: {
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
tags: tagMatches.map((tag) => ({
tags: toArray(tagMatches).map((tag) => ({
name: tag.name,
stats: {
count: Number(tag.taggings),
reach: Number(tag.reach),
count: toInt(tag.taggings),
reach: toInt(tag.reach),
},

@@ -75,19 +76,19 @@ url: tag.url,

search: {
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
tracks: trackMatches.map((tag) => ({
name: tag.name,
mbid: tag.mbid,
tracks: toArray(trackMatches).map((track) => ({
name: track.name,
mbid: track.mbid === '' ? undefined : track.mbid,
stats: {
scrobbles: Number(tag.playcount),
listeners: Number(tag.listeners),
scrobbles: toInt(track.playcount),
listeners: toInt(track.listeners),
},
artist: {
name: tag.artist.name,
url: tag.artist.url,
name: track.artist.name,
url: track.artist.url,
},
url: tag.url,
url: track.url,
})),

@@ -94,0 +95,0 @@ };

import Base from '../base.js';
import { toArray, toInt } from '../utils/caster.js';
export default class Geo extends Base {

@@ -19,11 +20,11 @@ /**

country: attr.country,
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
artists: artistMatches.map((artist) => ({
name: artist.name,
mbid: artist.mbid,
listeners: Number(artist.listeners),
mbid: artist.mbid === '' ? undefined : artist.mbid,
listeners: toInt(artist.listeners),
url: artist.url,

@@ -49,16 +50,16 @@ })),

country: attr.country,
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
tracks: trackMatches.map((track) => ({
rank: Number(track['@attr'].rank),
tracks: toArray(trackMatches).map((track) => ({
rank: toInt(track['@attr'].rank),
name: track.name,
mbid: track.mbid,
duration: Number(track.duration),
listeners: Number(track.listeners),
mbid: track.mbid === '' ? undefined : track.mbid,
duration: toInt(track.duration),
listeners: toInt(track.listeners),
artist: {
name: track.artist.name,
mbid: track.artist.mbid,
mbid: track.artist.mbid === '' ? undefined : track.artist.mbid,
url: track.artist.url,

@@ -65,0 +66,0 @@ },

import { convertImageSizes, createLastFmURL } from '../utils/convert.js';
import Base from '../base.js';
import { toArray, toInt } from '../utils/caster.js';
export default class Tag extends Base {

@@ -20,3 +21,3 @@ /**

},
url: createLastFmURL('tag', tag.name),
url: createLastFmURL({ type: 'tag', value: tag.name }),
};

@@ -40,17 +41,17 @@ }

tag: attr.tag,
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
albums: albumMatches.map((album) => ({
rank: Number(album['@attr'].rank),
albums: toArray(albumMatches).map((album) => ({
rank: toInt(album['@attr'].rank),
name: album.name,
mbid: album.mbid,
mbid: album.mbid === '' ? undefined : album.mbid,
artist: {
name: album.artist.name,
mbid: album.artist.mbid,
mbid: album.artist.mbid === '' ? undefined : album.artist.mbid,
url: album.artist.url,
},
url: createLastFmURL('album', album.artist.name, album.name),
url: createLastFmURL({ type: 'album', value: album.artist.name, album: album.name }),
image: convertImageSizes(album.image),

@@ -76,11 +77,11 @@ })),

tag: attr.tag,
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
artists: artistMatches.map((artist) => ({
artists: toArray(artistMatches).map((artist) => ({
rank: Number(artist['@attr'].rank),
name: artist.name,
mbid: artist.mbid,
mbid: artist.mbid === '' ? undefined : artist.mbid,
url: artist.url,

@@ -106,15 +107,15 @@ })),

tag: attr.tag,
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
tracks: trackMatches.map((track) => ({
rank: Number(track['@attr'].rank),
tracks: toArray(trackMatches).map((track) => ({
rank: toInt(track['@attr'].rank),
name: track.name,
mbid: track.mbid,
duration: Number(track.duration),
mbid: track.mbid === '' ? undefined : track.mbid,
duration: toInt(track.duration),
artist: {
name: track.artist.name,
mbid: track.artist.mbid,
mbid: track.artist.mbid === '' ? undefined : track.artist.mbid,
url: track.artist.url,

@@ -139,5 +140,5 @@ },

},
positions: chartMatches.map((chart) => ({
from: new Date(Number(chart.from) * 1000),
to: new Date(Number(chart.to) * 1000),
positions: toArray(chartMatches).map((chart) => ({
from: new Date(toInt(chart.from) * 1000),
to: new Date(toInt(chart.to) * 1000),
})),

@@ -144,0 +145,0 @@ };

import { convertImageSizes, createLastFmURL } from '../utils/convert.js';
import Base from '../base.js';
import { convertSearch, toArray, toBool, toInt } from '../utils/caster.js';
export default class Track extends Base {

@@ -17,25 +18,27 @@ /**

name: track.name,
mbid: track.mbid,
duration: Number(track.duration),
mbid: track.mbid === '' ? undefined : track.mbid,
duration: toInt(track.duration),
stats: {
scrobbles: Number(track.playcount),
listeners: Number(track.listeners),
scrobbles: toInt(track.playcount),
listeners: toInt(track.listeners),
},
userStats: {
userLoved: Boolean(Number(track.userloved)).valueOf(),
userPlayCount: Number(track.userplaycount),
userLoved: toBool(track.userloved),
userPlayCount: track.userplaycount ? toInt(track.userplaycount) : undefined,
},
artist: {
name: track.artist.name,
mbid: track.artist.mbid,
mbid: track.artist.mbid === '' ? undefined : track.artist.mbid,
url: track.artist.url,
},
album: {
position: Number(album?.['@attr']?.position),
name: album?.title,
mbid: album?.mbid,
image: convertImageSizes(album?.image),
url: album?.url,
},
tags: tagMatches.map((tag) => ({
album: album === undefined
? undefined
: {
position: album['@attr'] ? toInt(album['@attr'].position) : undefined,
name: album.title,
mbid: album.mbid === '' ? undefined : album.mbid,
image: convertImageSizes(album.image),
url: album.url,
},
tags: toArray(tagMatches).map((tag) => ({
name: tag.name,

@@ -63,10 +66,11 @@ url: tag.url,

name: attr.artist,
url: createLastFmURL('artist', attr.artist),
url: createLastFmURL({ type: 'artist', value: attr.artist }),
},
url: createLastFmURL('track', attr.artist, params.track),
tracks: trackMatches.map((track) => ({
match: Number(track.match),
url: createLastFmURL({ type: 'track', value: attr.artist, track: params.track }),
tracks: toArray(trackMatches).map((track) => ({
match: toInt(track.match),
name: track.name,
duration: Number(track.duration),
scrobbles: Number(track.playcount),
mbid: track.mbid === '' ? undefined : track.mbid,
duration: toInt(track.duration),
scrobbles: toInt(track.playcount),
artist: {

@@ -95,7 +99,7 @@ name: track.artist.name,

name: attr.artist,
url: createLastFmURL('artist', attr.artist),
url: createLastFmURL({ type: 'artist', value: attr.artist }),
},
url: createLastFmURL('track', attr.artist, attr.track),
tags: tagMatches.map((tag) => ({
count: Number(tag.count),
url: createLastFmURL({ type: 'track', value: attr.artist, track: attr.track }),
tags: toArray(tagMatches).map((tag) => ({
count: toInt(tag.count),
name: tag.name,

@@ -121,14 +125,12 @@ url: tag.url,

search: {
...convertSearch(results),
query: params.track,
page: Number(results['opensearch:Query'].startPage),
itemsPerPage: Number(results['opensearch:itemsPerPage']),
totalResults: Number(results['opensearch:totalResults']),
},
tracks: trackMatches.map((track) => ({
tracks: toArray(trackMatches).map((track) => ({
name: track.name,
mbid: track.mbid,
listeners: Number(track.listeners),
mbid: track.mbid === '' ? undefined : track.mbid,
listeners: toInt(track.listeners),
artist: {
name: track.artist,
url: createLastFmURL('artist', track.artist),
url: createLastFmURL({ type: 'artist', value: track.artist }),
},

@@ -135,0 +137,0 @@ url: track.url,

import { convertImageSizes, createLastFmURL } from '../utils/convert.js';
import Base from '../base.js';
import { toArray, toBool, toInt } from '../utils/caster.js';
export default class User extends Base {

@@ -20,12 +21,14 @@ /**

user: attr.user,
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
friends: userMatches.map((user) => ({
friends: toArray(userMatches).map((user) => ({
name: user.name,
realName: user.realname === '' ? undefined : user.realname,
country: user.country === 'None' ? undefined : user.country,
registered: new Date(Number(user.registered.unixtime) * 1000),
type: user.type,
subscriber: toBool(user.subscriber),
registered: new Date(toInt(user.registered.unixtime) * 1000),
url: user.url,

@@ -49,8 +52,10 @@ image: convertImageSizes(user.image),

country: user.country === 'None' ? undefined : user.country,
type: user.type,
subscriber: toBool(user.subscriber),
registered: new Date(user.registered['#text'] * 1000),
stats: {
albumCount: Number(user.album_count),
artistCount: Number(user.artist_count),
playCount: Number(user.playcount),
trackCount: Number(user.track_count),
albumCount: toInt(user.album_count),
artistCount: toInt(user.artist_count),
playCount: toInt(user.playcount),
trackCount: toInt(user.track_count),
},

@@ -77,14 +82,14 @@ url: user.url,

user: attr.user,
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
tracks: trackMatches.map((track) => ({
tracks: toArray(trackMatches).map((track) => ({
name: track.name,
mbid: track.mbid,
date: new Date(Number(track.date.uts) * 1000),
mbid: track.mbid === '' ? undefined : track.mbid,
date: new Date(toInt(track.date.uts) * 1000),
artist: {
name: track.artist.name,
mbid: track.artist.mbid,
mbid: track.artist.mbid === '' ? undefined : track.artist.mbid,
url: track.artist.url,

@@ -103,3 +108,3 @@ },

async getPersonalTags(params) {
const { taggings: { albums, artists, tracks, '@attr': attr }, } = await this.sendRequest({
const { taggings: { albums: { album: albumMatches } = { album: undefined }, artists: { artist: artistMatches } = { artist: undefined }, tracks: { track: trackMatches } = { track: undefined }, '@attr': attr, }, } = await this.sendRequest({
method: 'user.getPersonalTags',

@@ -109,21 +114,26 @@ ...params,

const responseTypes = {
album: albums?.album.map((album) => ({
name: album.name,
album: toArray(albumMatches).map((album) => ({
name: album?.name,
mbid: album?.mbid === '' ? undefined : album?.mbid,
artist: {
name: album.artist.name,
url: album.artist.url,
name: album?.artist.name,
mbid: album?.artist.mbid === '' ? undefined : album?.artist.mbid,
url: album?.artist.url,
},
url: album.url,
url: album?.url,
})),
artist: artists?.artist.map((artist) => ({
name: artist.name,
url: artist.url,
artist: toArray(artistMatches).map((artist) => ({
name: artist?.name,
mbid: artist?.mbid === '' ? undefined : artist?.mbid,
url: artist?.url,
})),
track: tracks?.track.map((track) => ({
name: track.name,
track: toArray(trackMatches).map((track) => ({
name: track?.name,
mbid: track?.mbid === '' ? undefined : track?.mbid,
artist: {
name: track.artist.name,
url: track.artist.url,
name: track?.artist.name,
mbid: track?.artist.mbid === '' ? undefined : track?.artist.mbid,
url: track?.artist.url,
},
url: track.url,
url: track?.url,
})),

@@ -135,8 +145,8 @@ };

tag: attr.tag,
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
response: responseTypes[params.taggingtype] || undefined,
response: responseTypes[params.taggingtype],
};

@@ -160,10 +170,10 @@ }

user: attr.user,
nowPlaying: trackMatches[0]['@attr']?.nowplaying === 'true',
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
nowPlaying: toBool(trackMatches[0]['@attr']?.nowplaying),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
tracks: trackMatches.map((track) => ({
dateAdded: track.date ? new Date(Number(track.date.uts) * 1000) : undefined,
tracks: toArray(trackMatches).map((track) => ({
dateAdded: track.date ? new Date(toInt(track.date.uts) * 1000) : undefined,
name: track.name,

@@ -173,7 +183,8 @@ mbid: track.mbid === '' ? undefined : track.mbid,

name: track.artist['#text'],
url: createLastFmURL('artist', track.artist['#text']),
mbid: track.artist.mbid === '' ? undefined : track.artist.mbid,
url: createLastFmURL({ type: 'artist', value: track.artist['#text'] }),
},
album: {
name: track.album['#text'],
mbid: track.album.mbid,
mbid: track.album.mbid === '' ? undefined : track.album.mbid,
},

@@ -201,15 +212,15 @@ url: track.url,

user: attr.user,
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
albums: albumMatches.map((album) => ({
rank: Number(album['@attr'].rank),
albums: toArray(albumMatches).map((album) => ({
rank: toInt(album['@attr'].rank),
name: album.name,
mbid: album.mbid,
playCount: Number(album.playcount),
mbid: album.mbid === '' ? undefined : album.mbid,
playCount: toInt(album.playcount),
artist: {
name: album.artist.name,
mbid: album.artist.mbid,
mbid: album.artist.mbid === '' ? undefined : album.artist.mbid,
url: album.artist.url,

@@ -238,12 +249,12 @@ },

user: attr.user,
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
artists: artistMatches.map((artist) => ({
rank: Number(artist['@attr'].rank),
artists: toArray(artistMatches).map((artist) => ({
rank: toInt(artist['@attr'].rank),
name: artist.name,
mbid: artist.mbid,
scrobbles: Number(artist.playcount),
mbid: artist.mbid === '' ? undefined : artist.mbid,
scrobbles: toInt(artist.playcount),
url: artist.url,

@@ -268,4 +279,4 @@ })),

},
tags: tagMatches.map((tag) => ({
count: Number(tag.count),
tags: toArray(tagMatches).map((tag) => ({
count: toInt(tag.count),
name: tag.name,

@@ -292,18 +303,18 @@ url: tag.url,

user: attr.user,
page: Number(attr.page),
itemsPerPage: Number(attr.perPage),
totalPages: Number(attr.totalPages),
totalResults: Number(attr.total),
page: toInt(attr.page),
itemsPerPage: toInt(attr.perPage),
totalPages: toInt(attr.totalPages),
totalResults: toInt(attr.total),
},
tracks: trackMatches.map((track) => ({
rank: Number(track['@attr'].rank),
tracks: toArray(trackMatches).map((track) => ({
rank: toInt(track['@attr'].rank),
name: track.name,
mbid: track.mbid,
mbid: track.mbid === '' ? undefined : track.mbid,
stats: {
duration: Number(track.duration),
userPlayCount: Number(track.playcount),
duration: toInt(track.duration),
userPlayCount: toInt(track.playcount),
},
artist: {
name: track.artist.name,
mbid: track.artist.mbid,
mbid: track.artist.mbid === '' ? undefined : track.artist.mbid,
url: track.artist.url,

@@ -310,0 +321,0 @@ },

@@ -20,2 +20,3 @@ import Album from './classes/album.class.js';

userAgent?: string;
versioning?: boolean;
});

@@ -22,0 +23,0 @@ private createService;

@@ -20,7 +20,9 @@ import Album from './classes/album.class.js';

user;
constructor(key, options = {}) {
constructor(key, options = {
versioning: true,
}) {
this.key = key;
this.options = options;
this.validateApiKey();
options.userAgent ??= `simple-fm v${pkg.version} - a simple Last.fm wrapper written in TypeScript (https://github.com/solelychloe/simple-fm)`;
options.userAgent ??= `simple-fm${options.versioning ? ` v${pkg.version}` : ''} - a simple Last.fm wrapper written in TypeScript (https://github.com/solelychloe/simple-fm)`;
this.album = this.createService(Album);

@@ -27,0 +29,0 @@ this.artist = this.createService(Artist);

@@ -40,6 +40,5 @@ import { $fetch, FetchError } from 'ofetch';

throw new LastFMError(err.data);
else if (err instanceof LastFMError)
if (err instanceof LastFMError)
throw new LastFMError(err.response);
else
console.error(err);
console.error(err);
}

@@ -50,5 +49,4 @@ }

return this.post();
else
return this.get();
return this.get();
}
}

@@ -5,3 +5,3 @@ import type { AlbumResponse, ArtistResponse, ImageResponse, ObjectArray, OpenSearchResponse, TagResponse, TrackResponse } from './index.js';

tags: {
tag: Array<TagResponse & {
tag: ObjectArray<TagResponse & {
url: string;

@@ -8,0 +8,0 @@ }>;

@@ -5,2 +5,3 @@ import type { AlbumResponse, ArtistResponse, AttrResponse, OpenSearchResponse, TagResponse, TrackResponse } from './index.js';

mbid: string;
ontour: string;
stats: {

@@ -11,6 +12,20 @@ listeners: string;

};
ontour: string;
tags: {
tag: TagResponse[];
};
bio: {
links: {
link: {
'#text': string;
rel: string;
href: string;
};
};
published: string;
summary: string;
content: string;
};
similar: {
artist: ArtistResponse[];
};
};

@@ -17,0 +32,0 @@ }

@@ -39,5 +39,5 @@ export type ObjectArray<T> = T | T[];

url?: string;
count?: number;
total?: number;
reach?: number;
count: number;
total: number;
reach: number;
}

@@ -55,2 +55,4 @@ export interface TrackResponse {

country?: string;
type: string;
subscriber?: string;
registered: Registered;

@@ -57,0 +59,0 @@ url: string;

@@ -10,8 +10,8 @@ import type { ArtistResponse, AlbumResponse, OpenSearchResponse, TagResponse, TrackResponse } from './index.js';

};
album?: AlbumResponse & {
title: string;
'@attr'?: {
album?: (AlbumResponse & {
title?: string;
'@attr': {
position: string;
};
};
}) | undefined;
toptags: {

@@ -18,0 +18,0 @@ tag: Array<TagResponse & {

@@ -1,2 +0,2 @@

import type { ArtistResponse, AlbumResponse, AttrResponse, ImageResponse, TagResponse, TrackResponse, UserResponse } from './index.js';
import type { ArtistResponse, AlbumResponse, AttrResponse, TagResponse, TrackResponse, UserResponse } from './index.js';
export declare interface UserGetFriendsResponse {

@@ -37,21 +37,12 @@ friends: {

albums?: {
album: Array<{
name: string;
artist: ArtistResponse & {
mbid: string;
};
url: string;
image: ImageResponse[];
album: Array<AlbumResponse & {
artist: ArtistResponse;
}>;
};
artists?: {
artist: Array<ArtistResponse & {
mbid: string;
}>;
artist: ArtistResponse[];
};
tracks?: {
track: Array<TrackResponse & {
artist: ArtistResponse & {
mbid: string;
};
artist: ArtistResponse;
}>;

@@ -58,0 +49,0 @@ };

import type { ObjectArray } from '../responses/index.js';
import type { AlbumType, ImageType, SearchMeta, TagType, TrackType } from './index.js';
export declare interface AlbumGetInfoType extends AlbumType {
mbid?: string;
export declare interface AlbumGetInfoType {
name: string;
artist: {
name: string;
url: string | undefined;
};
mbid: string | undefined;
stats: {

@@ -9,14 +14,18 @@ scrobbles: number;

};
userStats?: {
userPlayCount?: number;
userStats: {
userPlayCount: number | undefined;
};
tags: TagType[];
tracks: ObjectArray<TrackType & {
tags: ObjectArray<TagType>;
tracks: ObjectArray<Omit<TrackType, 'artist' | 'mbid'> & {
rank: number;
duration?: number;
duration: number;
}>;
url: string;
image?: ImageType[];
image: ImageType[] | undefined;
}
export declare interface AlbumGetTopTagsType extends AlbumType {
export declare interface AlbumGetTopTagsType extends Omit<AlbumType, 'image' | 'url'> {
artist: {
name: string;
url: string | undefined;
};
tags: Array<TagType & {

@@ -31,6 +40,4 @@ count: number;

albums: Array<AlbumType & {
mbid?: string;
url: string;
image?: ImageType[];
mbid: string | undefined;
}>;
}
import type { ArtistType, AlbumType, ImageType, SearchMeta, TagType, TrackType } from './index.js';
export declare interface ArtistGetInfoType extends ArtistType {
mbid: string;
description?: string;
export declare interface ArtistGetInfoType {
name: string;
mbid: string | undefined;
onTour: boolean;

@@ -11,12 +11,31 @@ stats: {

userStats: {
userPlayCount?: number;
userPlayCount: number | undefined;
};
tags: Array<{
name: string;
url: string | undefined;
}>;
bio: {
summary: string;
extended: string;
published: Date;
url: string;
};
similarArtists: Array<{
name: string;
image: ImageType[] | undefined;
url: string;
}>;
url: string;
}
export declare interface ArtistGetSimilarType {
search: {
artist: ArtistType;
artist: {
name: string;
url: string | undefined;
};
};
artists: Array<ArtistType & {
match: number;
mbid: string;
mbid: string | undefined;
}>;

@@ -30,7 +49,8 @@ }

scrobbles: number;
image?: ImageType[];
}>;
}
export declare interface ArtistGetTopTagsType {
artist: ArtistType;
search: {
artist: ArtistType;
};
tags: Array<TagType & {

@@ -46,3 +66,2 @@ count: number;

rank: number;
mbid: string;
stats: {

@@ -59,5 +78,5 @@ scrobbles: number;

artists: Array<ArtistType & {
mbid: string;
mbid: string | undefined;
listeners: number;
}>;
}

@@ -5,3 +5,3 @@ import type { ArtistType, TagType, TrackType, SearchMeta } from './index.js';

artists: Array<ArtistType & {
mbid: string;
mbid: string | undefined;
stats: {

@@ -25,3 +25,3 @@ scrobbles: number;

tracks: Array<TrackType & {
mbid: string;
mbid: string | undefined;
stats: {

@@ -28,0 +28,0 @@ scrobbles: number;

@@ -7,3 +7,3 @@ import type { ArtistType, TrackType, SearchMeta } from './index.js';

artists: Array<ArtistType & {
mbid: string;
mbid: string | undefined;
listeners: number;

@@ -18,9 +18,9 @@ }>;

rank: number;
mbid: string;
duration?: number;
mbid: string | undefined;
duration: number;
listeners: number;
artist: {
mbid: string;
mbid: string | undefined;
};
}>;
}

@@ -6,3 +6,3 @@ import type { TrackResponse } from '../responses/index.js';

itemsPerPage: number;
totalPages?: number;
totalPages: number;
totalResults: number;

@@ -15,7 +15,5 @@ }

export interface PersonalTag {
name: string;
artist?: ArtistType & {
mbid: string;
};
url: string;
name?: string;
artist?: Partial<ArtistType>;
url?: string;
image?: ImageType[];

@@ -25,7 +23,7 @@ }

position?: number;
name?: string;
name: string;
mbid?: string;
artist?: ArtistType;
url?: string;
image?: ImageType[];
artist: ArtistType;
url: string | undefined;
image: ImageType[] | undefined;
}

@@ -35,22 +33,24 @@ export interface ArtistType {

mbid?: string;
url?: string;
url: string | undefined;
}
export interface TagType {
name: string;
url?: string;
url: string | undefined;
}
export interface TrackType {
name: string;
mbid?: string;
artist?: ArtistType;
mbid: string | undefined;
artist: ArtistType | undefined;
album?: AlbumType;
url: string;
url: string | undefined;
}
export interface UserType {
name: string;
realName?: string;
country?: string;
realName: string | undefined;
country: string | undefined;
subscriber: boolean;
type: string;
registered: Date;
url: string;
image?: ImageType[];
url: string | undefined;
image: ImageType[] | undefined;
}

@@ -57,0 +57,0 @@ export interface TrackReturnType extends TrackResponse {

@@ -1,7 +0,7 @@

import type { AlbumType, ArtistType, ImageType, SearchMeta, TagType, TrackType } from './index.js';
import type { AlbumType, ArtistType, SearchMeta, TagType, TrackType } from './index.js';
export declare interface TagGetInfoType extends TagType {
description?: string;
description: string;
stats: {
count?: number;
reach?: number;
count: number;
reach: number;
};

@@ -15,7 +15,6 @@ }

rank: number;
mbid?: string;
mbid: string | undefined;
artist: {
mbid: string;
mbid: string | undefined;
};
image?: ImageType[];
}>;

@@ -29,3 +28,2 @@ }

rank: number;
mbid: string;
}>;

@@ -39,7 +37,3 @@ }

rank: number;
mbid: string;
duration?: number;
artist: {
mbid: string;
};
duration: number;
}>;

@@ -46,0 +40,0 @@ }

@@ -1,4 +0,5 @@

import type { AlbumType, ImageType, SearchMeta, TagType, TrackType } from './index.js';
export declare interface TrackGetInfoType extends TrackType {
mbid: string;
import type { AlbumType, SearchMeta, TagType, TrackType } from './index.js';
export declare interface TrackGetInfoType {
name: string;
mbid: string | undefined;
duration?: number;

@@ -15,13 +16,11 @@ stats: {

name: string;
mbid: string;
mbid: string | undefined;
url: string;
};
album: AlbumType & {
album: Partial<Omit<AlbumType, 'artist'> & {
position: number;
name?: string;
mbid?: string;
image?: ImageType[];
url?: string;
};
mbid: string | undefined;
}> | undefined;
tags?: object[];
url: string;
}

@@ -37,5 +36,4 @@ export declare interface TrackGetSimilarType {

match: number;
duration?: number;
duration: number;
scrobbles: number;
image?: ImageType[];
}>;

@@ -47,5 +45,5 @@ }

name: string;
url?: string;
url: string | undefined;
};
url?: string;
url: string | undefined;
tags: Array<TagType & {

@@ -60,5 +58,5 @@ count: number;

tracks: Array<TrackType & {
mbid: string;
mbid: string | undefined;
listeners: number;
}>;
}

@@ -1,2 +0,2 @@

import type { AlbumType, ArtistType, ImageType, PersonalTag, SearchMeta, TagType, TrackType, UserType } from './index.js';
import type { AlbumType, ArtistType, PersonalTag, SearchMeta, TagType, TrackType, UserType } from './index.js';
export declare interface UserGetFriendsType {

@@ -6,11 +6,5 @@ search: SearchMeta & {

};
friends: Array<UserType & {
realName?: string;
country?: string;
image?: ImageType[];
}>;
friends: UserType[];
}
export declare interface UserGetInfoType extends UserType {
realName?: string;
country?: string;
stats: {

@@ -22,3 +16,2 @@ albumCount: number;

};
image?: ImageType[];
}

@@ -30,7 +23,3 @@ export declare interface UserGetLovedTracksType {

tracks: Array<TrackType & {
mbid: string;
date: Date;
artist: {
mbid: string;
};
}>;

@@ -50,9 +39,8 @@ }

};
tracks: Array<TrackType & {
tracks: Array<Omit<TrackType, 'album'> & {
dateAdded: Date | undefined;
mbid?: string;
mbid: string | undefined;
album: {
mbid: string;
mbid: string | undefined;
};
image?: ImageType[];
}>;

@@ -66,8 +54,7 @@ }

rank: number;
mbid?: string;
mbid: string | undefined;
playCount: number;
artist: {
mbid: string;
mbid: string | undefined;
};
image?: ImageType[];
}>;

@@ -81,3 +68,3 @@ }

rank: number;
mbid: string;
mbid: string | undefined;
scrobbles: number;

@@ -92,3 +79,2 @@ }>;

count: number;
url: string;
}>;

@@ -102,3 +88,3 @@ }

rank: number;
mbid: string;
mbid: string | undefined;
stats: {

@@ -109,6 +95,5 @@ duration?: number;

artist: {
mbid: string;
mbid: string | undefined;
};
image?: ImageType[];
}>;
}
import type { ImageResponse } from '../responses/index.js';
import type { ImageType } from '../typings/index.js';
type LastFmURLType = 'album' | 'artist' | 'tag' | 'track';
interface LastFmURLParams<T> {
type: T;
value: string;
track?: T extends 'track' ? string : never;
album?: T extends 'album' ? string : never;
}
export declare const convertImageSizes: (images?: ImageResponse[]) => ImageType[] | undefined;
type LastFmURLType = 'album' | 'artist' | 'tag' | 'track';
export declare const createLastFmURL: <T extends LastFmURLType>(type: T, value: string, track?: (T extends "track" | "album" ? string : never) | undefined) => string | undefined;
export declare const createLastFmURL: <T extends LastFmURLType>(params: LastFmURLParams<T>) => string | undefined;
export {};

@@ -1,2 +0,3 @@

const ImageSize = ['extralarge', 'large', 'medium', 'small'];
const imageSizes = ['extralarge', 'large', 'medium', 'small'];
const convertURL = (url) => encodeURIComponent(url ?? '').replaceAll(/%20/g, '+');
export const convertImageSizes = (images) => {

@@ -6,3 +7,3 @@ if (!images)

const data = images
.filter((image) => image['#text'] && ImageSize.includes(image.size))
.filter((image) => image['#text'] && imageSizes.includes(image.size))
.map((image) => ({

@@ -14,12 +15,12 @@ size: image.size,

};
const convertURL = (url) => encodeURIComponent(url ?? '').replaceAll(/%20/g, '+');
export const createLastFmURL = (type, value, track) => {
switch (type) {
export const createLastFmURL = (params) => {
switch (params.type) {
case 'album':
return `https://www.last.fm/music/${convertURL(params.value)}/_/${convertURL(params.album)}`;
case 'artist':
return `https://www.last.fm/music/${convertURL(params.value)}`;
case 'track':
return `https://www.last.fm/music/${convertURL(value)}/_/${convertURL(track)}`;
case 'artist':
return `https://www.last.fm/music/${convertURL(value)}`;
return `https://www.last.fm/music/${convertURL(params.value)}/_/${convertURL(params.track)}`;
case 'tag':
return `https://www.last.fm/tag/${convertURL(value)}`;
return `https://www.last.fm/tag/${convertURL(params.value)}`;
default:

@@ -26,0 +27,0 @@ return undefined;

{
"name": "@solely/simple-fm",
"version": "1.6.4",
"version": "1.7.0",
"license": "Zlib",

@@ -16,3 +16,3 @@ "author": "Chloe Arciniega <solely@riseup.net> (https://arciniega.one)",

"engines": {
"node": ">=20"
"node": ">=18"
},

@@ -19,0 +19,0 @@ "exports": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc