diff --git a/CHANGELOG.md b/CHANGELOG.md index 05fb59e..07e972c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [3.0.0](https://github.com/microlinkhq/spotify-url-info/compare/v2.2.9...v3.0.0) (2022-03-20) + + +### ⚠ BREAKING CHANGES + +* The library will be shipped without a default fetch agent. + +### Features + +* pass fetch agent as necessary dependency ([649778b](https://github.com/microlinkhq/spotify-url-info/commit/649778be126d9ced15228f7c8c7f9ee85d7e9f7c)) + ### 2.2.9 (2022-03-20) ### 2.2.8 (2022-03-20) diff --git a/package.json b/package.json index 1536f9d..77d81c9 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "spotify-url-info", "description": "Get metadata from Spotify URLs", "homepage": "https://github.com/microlinkhq/spotify-url-info", - "version": "2.2.9", + "version": "3.0.0", "main": "src/index.js", "author": { "email": "kall@kall.ws", @@ -12,6 +12,22 @@ { "name": "Kiko Beats", "email": "josefrancisco.verdu@gmail.com" + }, + { + "name": "DaliborTrampota", + "email": "dalibor.trampota@gmail.com" + }, + { + "name": "crxts", + "email": "49580728+crxts@users.noreply.github.com" + }, + { + "name": "kaaax0815", + "email": "999999bst@gmail.com" + }, + { + "name": "KeepSOBP", + "email": "keepsobp@naver.com" } ], "repository": { @@ -30,7 +46,6 @@ "spotify-urls" ], "dependencies": { - "cross-fetch": "~3.1.4", "himalaya": "~1.1.0", "spotify-uri": "~2.2.0" }, @@ -41,6 +56,7 @@ "c8": "latest", "ci-publish": "latest", "conventional-github-releaser": "latest", + "cross-fetch": "latest", "finepack": "latest", "git-authors-cli": "latest", "nano-staged": "latest", diff --git a/src/index.js b/src/index.js index 30845f7..a581517 100644 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,12 @@ 'use strict' const spotifyURI = require('spotify-uri') -const { fetch } = require('cross-fetch') + const { parse } = require('himalaya') const SUPPORTED_TYPES = ['album', 'artist', 'episode', 'playlist', 'track'] -function getData (url, opts) { +const createGetData = fetch => (url, opts) => { let parsedURL = {} try { @@ -71,7 +71,7 @@ function getData (url, opts) { .then(sanityCheck) } -function parseIntoPreview (data) { +function toPreview (data) { const track = getFirstTrack(data) const images = data.type === 'track' ? data.album.images : data.images const date = data.album ? data.album.release_date : data.release_date @@ -98,7 +98,7 @@ function parseIntoPreview (data) { }) } -function parseIntoTrackArray (data) { +function getTracks (data) { if (!data.tracks) { // Is a track or a podcast episode return Promise.resolve([data]) @@ -154,10 +154,11 @@ function sanityCheck (data) { return Promise.resolve(data) } -module.exports.getData = getData - -module.exports.getPreview = (url, opts) => - getData(url, opts).then(parseIntoPreview) - -module.exports.getTracks = (url, opts) => - getData(url, opts).then(parseIntoTrackArray) +module.exports = fetch => { + const getData = createGetData(fetch) + return { + getData, + getPreview: (url, opts) => getData(url, opts).then(toPreview), + getTracks: (url, opts) => getData(url, opts).then(getTracks) + } +} diff --git a/test/get-data.js b/test/get-data.js index 80e7c9a..a2b5672 100644 --- a/test/get-data.js +++ b/test/get-data.js @@ -1,8 +1,9 @@ 'use strict' +const { fetch } = require('cross-fetch') const test = require('ava') -const { getData } = require('..') +const { getData } = require('..')(fetch) test('getting data for empty url should return rejection', async t => { const error = await t.throwsAsync(() => getData(''), { diff --git a/test/get-preview.js b/test/get-preview.js index 6788030..0e554f7 100644 --- a/test/get-preview.js +++ b/test/get-preview.js @@ -1,8 +1,9 @@ 'use strict' +const { fetch } = require('cross-fetch') const test = require('ava') -const { getPreview } = require('..') +const { getPreview } = require('..')(fetch) test('getting preview for empty url should return rejection', async t => { const error = await t.throwsAsync(() => getPreview(''), { diff --git a/test/get-tracks.js b/test/get-tracks.js index 6025aa8..85d9e66 100644 --- a/test/get-tracks.js +++ b/test/get-tracks.js @@ -1,8 +1,9 @@ 'use strict' +const { fetch } = require('cross-fetch') const test = require('ava') -const { getTracks } = require('..') +const { getTracks } = require('..')(fetch) test('getting data for empty url should return rejection', async t => { const error = await t.throwsAsync(() => getTracks(''), {