@solely/simple-fm
Advanced tools
Comparing version 1.7.0 to 1.7.1
@@ -1,2 +0,2 @@ | ||
import { pkg } from './utils/package.js'; | ||
import { USER_AGENT } from './constants.js'; | ||
import { LastFMRequest } from './request.js'; | ||
@@ -6,5 +6,5 @@ export default class Base { | ||
userAgent; | ||
constructor(key, userAgent = `simple-fm v${pkg.version} - a simple Last.fm wrapper written in TypeScript (https://github.com/solelychloe/simple-fm)`) { | ||
constructor(key, userAgent) { | ||
this.key = key; | ||
this.userAgent = userAgent; | ||
this.userAgent = userAgent ?? USER_AGENT; | ||
} | ||
@@ -11,0 +11,0 @@ async sendRequest(params) { |
@@ -24,3 +24,3 @@ import { convertImageSizes, createLastFmURL } from '../utils/convert.js'; | ||
userStats: { | ||
userPlayCount: Number.isNaN(toInt(artist.stats.userplaycount)) ? undefined : toInt(artist.stats.userplaycount), | ||
userPlayCount: artist.stats.userplaycount ? toInt(artist.stats.userplaycount) : undefined, | ||
}, | ||
@@ -27,0 +27,0 @@ tags: toArray(artist.tags.tag).map((tag) => ({ |
@@ -164,3 +164,3 @@ import { convertImageSizes, createLastFmURL } from '../utils/convert.js'; | ||
user: attr.user, | ||
nowPlaying: toBool(trackMatches[0]['@attr']?.nowplaying), | ||
nowPlaying: !!toBool(trackMatches[0]['@attr']?.nowplaying), | ||
page: toInt(attr.page), | ||
@@ -167,0 +167,0 @@ itemsPerPage: toInt(attr.perPage), |
@@ -20,3 +20,2 @@ import Album from './classes/album.class.js'; | ||
userAgent?: string; | ||
versioning?: boolean; | ||
}); | ||
@@ -23,0 +22,0 @@ private createService; |
@@ -0,1 +1,2 @@ | ||
import { USER_AGENT } from './constants.js'; | ||
import Album from './classes/album.class.js'; | ||
@@ -9,3 +10,2 @@ import Artist from './classes/artist.class.js'; | ||
import LastFMError from './utils/error.js'; | ||
import { pkg } from './utils/package.js'; | ||
export default class SimpleFMClient { | ||
@@ -21,9 +21,7 @@ key; | ||
user; | ||
constructor(key, options = { | ||
versioning: true, | ||
}) { | ||
constructor(key, options = {}) { | ||
this.key = key; | ||
this.options = options; | ||
this.validateApiKey(); | ||
options.userAgent ??= `simple-fm${options.versioning ? ` v${pkg.version}` : ''} - a simple Last.fm wrapper written in TypeScript (https://github.com/solelychloe/simple-fm)`; | ||
options.userAgent ??= USER_AGENT; | ||
this.album = this.createService(Album); | ||
@@ -30,0 +28,0 @@ this.artist = this.createService(Artist); |
import { $fetch, FetchError } from 'ofetch'; | ||
import { BASE_URL } from './constants.js'; | ||
import LastFMError from './utils/error.js'; | ||
@@ -20,3 +21,2 @@ export class LastFMRequest { | ||
async get() { | ||
const baseURL = 'https://ws.audioscrobbler.com/2.0'; | ||
const params = { | ||
@@ -28,3 +28,3 @@ api_key: this.key, | ||
try { | ||
const data = await $fetch(baseURL, { | ||
const data = await $fetch(BASE_URL, { | ||
params, | ||
@@ -31,0 +31,0 @@ headers: { |
@@ -1,2 +0,2 @@ | ||
const imageSizes = ['extralarge', 'large', 'medium', 'small']; | ||
import { IMAGE_SIZES } from '../constants.js'; | ||
const convertURL = (url) => encodeURIComponent(url ?? '').replaceAll(/%20/g, '+'); | ||
@@ -7,3 +7,3 @@ export const convertImageSizes = (images) => { | ||
const data = images | ||
.filter((image) => image['#text'] && imageSizes.includes(image.size)) | ||
.filter((image) => image['#text'] && IMAGE_SIZES.includes(image.size)) | ||
.map((image) => ({ | ||
@@ -10,0 +10,0 @@ size: image.size, |
{ | ||
"name": "@solely/simple-fm", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"license": "Zlib", | ||
@@ -5,0 +5,0 @@ "author": "Chloe Arciniega <solely@riseup.net> (https://arciniega.one)", |
@@ -46,4 +46,7 @@ <div align="center"> | ||
import SimpleFM from '@solely/simple-fm'; // ESM | ||
import SimpleFM from 'https://esm.sh/@solely/simple-fm'; // Deno | ||
const SimpleFM = require('@solely/simple-fm'); // CommonJS | ||
``` | ||
```ts | ||
// Replace the token with your Last.fm API key. | ||
@@ -56,11 +59,4 @@ const client = new SimpleFM('Last.fm API key'); | ||
console.log(json); | ||
// => { search: { user: 'solelychloe', nowPlaying: true, ... }, tracks: [...] } | ||
``` | ||
If you're using [Deno][deno-repo], you can import `simple-fm` via a CDN: | ||
```ts | ||
import SimpleFM from 'https://esm.sh/@solely/simple-fm'; | ||
``` | ||
# License | ||
@@ -75,3 +71,2 @@ | ||
[actions-link]: https://github.com/solelychloe/simple-fm/actions/workflows/main.yml | ||
[deno-repo]: https://github.com/denoland/deno | ||
[docs]: https://simple.arciniega.one | ||
@@ -78,0 +73,0 @@ [logo]: /public/logo.svg 'The Twitter headphone emoji with musical notes in it.' |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
96337
2753
77