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

spotify-uri

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spotify-uri - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

.editorconfig

5

formatEmbedURL.js

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

/**

@@ -23,4 +22,4 @@ * Module dependencies.

function formatEmbedURI (parsed) {
return 'https://embed.spotify.com/?uri=' + formatURI(parsed);
function formatEmbedURI(parsed) {
return 'https://embed.spotify.com/?uri=' + formatURI(parsed);
}

56

formatOpenURL.js

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

/**

@@ -23,24 +22,31 @@ * Module dependencies.

function formatOpenURL (parsed, base) {
if ('string' == typeof parsed) parsed = parse(parsed);
if ('string' != typeof base) base = 'http://open.spotify.com';
if (parsed.starred) {
// user's "starred" playlist
return base + '/user/' + encode(parsed.user) + '/starred';
} else if ('playlist' == parsed.type) {
// user "playlist"
return base + '/user/' + encode(parsed.user) + '/playlist/' + parsed.id;
} else if ('local' == parsed.type) {
// "local" file
return base + '/local/' + encode(parsed.artist) +
'/' + encode(parsed.album) +
'/' + encode(parsed.track) +
'/' + parsed.seconds;
} else if ('search' == parsed.type) {
// "search" query
return base + '/search/' + encode(parsed.query);
} else {
// artist, album, track
return base + '/' + parsed.type + '/' + parsed.id;
}
function formatOpenURL(parsed, base) {
if ('string' == typeof parsed) parsed = parse(parsed);
if ('string' != typeof base) base = 'http://open.spotify.com';
if (parsed.starred) {
// user's "starred" playlist
return base + '/user/' + encode(parsed.user) + '/starred';
} else if ('playlist' == parsed.type) {
// user "playlist"
return base + (parsed.user ? '/user/' + encode(parsed.user) : '') + '/playlist/' + parsed.id;
} else if ('local' == parsed.type) {
// "local" file
return (
base +
'/local/' +
encode(parsed.artist) +
'/' +
encode(parsed.album) +
'/' +
encode(parsed.track) +
'/' +
parsed.seconds
);
} else if ('search' == parsed.type) {
// "search" query
return base + '/search/' + encode(parsed.query);
} else {
// artist, album, track
return base + '/' + parsed.type + '/' + parsed.id;
}
}

@@ -55,4 +61,4 @@

function encode (str) {
return escape(str.replace(/ /g, '+'));
function encode(str) {
return escape(str.replace(/ /g, '+'));
}

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

/**

@@ -23,4 +22,4 @@ * Module dependencies.

function formatPlayURL (parsed) {
return formatOpenURL(parsed, 'https://play.spotify.com');
function formatPlayURL(parsed) {
return formatOpenURL(parsed, 'https://play.spotify.com');
}

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

/**

@@ -22,23 +21,29 @@ * Module dependencies.

function formatURI (parsed) {
if ('string' == typeof parsed) parsed = parse(parsed);
if (parsed.starred) {
// user's "starred" playlist
return 'spotify:user:' + encode(parsed.user) + ':starred';
} else if ('playlist' == parsed.type) {
// user "playlist"
return 'spotify:user:' + encode(parsed.user) + ':playlist:' + parsed.id;
} else if ('local' == parsed.type) {
// "local" file
return 'spotify:local:' + encode(parsed.artist) +
':' + encode(parsed.album) +
':' + encode(parsed.track) +
':' + parsed.seconds;
} else if ('search' == parsed.type) {
// "search" query
return 'spotify:search:' + encode(parsed.query);
} else {
// artist, album, track
return 'spotify:' + parsed.type + ':' + parsed.id;
}
function formatURI(parsed) {
if ('string' == typeof parsed) parsed = parse(parsed);
if (parsed.starred) {
// user's "starred" playlist
return 'spotify:user:' + encode(parsed.user) + ':starred';
} else if ('playlist' == parsed.type) {
// user or non-user "playlist"
return 'spotify' + (parsed.user ? ':user:' + encode(parsed.user) : '') + ':playlist:' + parsed.id;
} else if ('local' == parsed.type) {
// "local" file
return (
'spotify:local:' +
encode(parsed.artist) +
':' +
encode(parsed.album) +
':' +
encode(parsed.track) +
':' +
parsed.seconds
);
} else if ('search' == parsed.type) {
// "search" query
return 'spotify:search:' + encode(parsed.query);
} else {
// artist, album, track
return 'spotify:' + parsed.type + ':' + parsed.id;
}
}

@@ -53,4 +58,4 @@

function encode (str) {
return escape(str.replace(/ /g, '+'));
function encode(str) {
return escape(str.replace(/ /g, '+'));
}

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

/**

@@ -3,0 +2,0 @@ * Module dependencies.

{
"name": "spotify-uri",
"version": "1.0.0",
"version": "1.1.0",
"description": "Parse the various Spotify URI formats into Objects and back",
"main": "index.js",
"scripts": {
"test": "make test"
"test": "mocha --reporter spec"
},

@@ -28,5 +28,4 @@ "repository": {

"devDependencies": {
"mocha": "~1.10.0",
"zuul": "~1.13.0"
"mocha": "6"
}
}

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

/**

@@ -23,52 +22,56 @@ * Module dependencies.

function parse (uri) {
var rtn;
var parts;
if ('object' == typeof uri) {
// re-use the `uri` Object if one is passed in
rtn = uri;
uri = rtn.uri;
} else {
rtn = { uri: uri };
}
var parsed = url.parse(uri);
if ('spotify:' == parsed.protocol) {
parts = uri.split(':');
parseParts(parts, rtn);
} else if ('embed.spotify.com' == parsed.hostname) {
return parse(qs.parse(parsed.query).uri);
} else { // http: or https:
parts = parsed.pathname.split('/');
parseParts(parts, rtn);
}
return rtn;
function parse(uri) {
var rtn;
var parts;
if ('object' == typeof uri) {
// re-use the `uri` Object if one is passed in
rtn = uri;
uri = rtn.uri;
} else {
rtn = { uri: uri };
}
var parsed = url.parse(uri);
if ('spotify:' == parsed.protocol) {
parts = uri.split(':');
parseParts(parts, rtn);
} else if ('embed.spotify.com' == parsed.hostname) {
return parse(qs.parse(parsed.query).uri);
} else {
// http: or https:
parts = parsed.pathname.split('/');
parseParts(parts, rtn);
}
return rtn;
}
function parseParts (parts, obj) {
var len = parts.length;
if ('search' == parts[1]) {
obj.type = 'search';
obj.query = decode(parts.slice(2).join(':'));
} else if (len >= 3 && 'local' == parts[1]) {
// local
obj.type = 'local';
obj.artist = decode(parts[2]);
obj.album = decode(parts[3]);
obj.track = decode(parts[4]);
obj.seconds = +parts[5];
} else if (len >= 5) {
// playlist
obj.user = decode(parts[2]);
obj.type = parts[3];
obj.id = parts[4];
} else if (len >= 4 && 'starred' == parts[3]) {
// starred
obj.type = 'playlist';
obj.starred = true;
obj.user = decode(parts[2]);
} else if (len >= 3) {
// track, artist, album
obj.type = parts[1];
obj.id = parts[2];
}
function parseParts(parts, obj) {
var len = parts.length;
if ('embed' == parts[1]) {
parts = parts.slice(1, len);
}
if ('search' == parts[1]) {
obj.type = 'search';
obj.query = decode(parts.slice(2).join(':'));
} else if (len >= 3 && 'local' == parts[1]) {
// local
obj.type = 'local';
obj.artist = decode(parts[2]);
obj.album = decode(parts[3]);
obj.track = decode(parts[4]);
obj.seconds = +parts[5];
} else if (len >= 5) {
// playlist
obj.user = decode(parts[2]);
obj.type = parts[3];
obj.id = parts[4];
} else if (len >= 4 && 'starred' == parts[3]) {
// starred
obj.type = 'playlist';
obj.starred = true;
obj.user = decode(parts[2]);
} else if (len >= 3) {
// track, artist, album
obj.type = parts[1];
obj.id = parts[2];
}
}

@@ -83,4 +86,4 @@

function decode (str) {
return decodeURIComponent(str).replace(/\+/g, ' ');
function decode(str) {
return decodeURIComponent(str).replace(/\+/g, ' ');
}
spotify-uri
===========
### Parse the various Spotify URI formats into Objects and back
[![Build Status](https://github.com/TooTallNate/spotify-uri/workflows/Node%20CI/badge.svg)](https://github.com/TooTallNate/spotify-uri/actions?workflow=Node+CI)
[![Sauce Test Status](https://saucelabs.com/browser-matrix/spotify-uri.svg)](https://saucelabs.com/u/spotify-uri)
[![Build Status](https://travis-ci.org/TooTallNate/spotify-uri.svg?branch=master)](https://travis-ci.org/TooTallNate/spotify-uri)
Spotify URIs get passed around in a variety of flavors. This module parses them
into a JavaScript object so you can work with the further. You can also convert
into a JavaScript object so you can work with them further. You can also convert
them back into Spotify URIs or HTTP URLs.
Installation

@@ -22,13 +20,6 @@ ------------

Install for component(1) using `component`:
``` bash
$ component install TooTallNate/spotify-uri
```
Example
-------
``` javascript

@@ -72,4 +63,5 @@ var spotifyUri = require('spotify-uri');

See the [test cases][tests] for some more examples of Spotify URIs.
See the [test cases](./test) for some more examples of Spotify URIs.
## API

@@ -127,6 +119,5 @@

## License
MIT
[tests]: http://tootallnate.github.io/spotify-uri/

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

/**

@@ -14,267 +13,315 @@ * Module dependencies.

describe('parse()', function () {
describe('"open.spotify.com" URLs', function () {
it('should parse "track" URLs', function () {
var url = 'http://open.spotify.com/track/10M2REwwztVxgr0szw7UwD';
var obj = parse(url);
assert('track' == obj.type);
assert('10M2REwwztVxgr0szw7UwD' == obj.id);
});
it('should parse "playlist" URLs', function () {
var url = 'http://open.spotify.com/user/tootallnate/playlist/0Lt5S4hGarhtZmtz7BNTeX';
var obj = parse(url);
assert('playlist' == obj.type);
assert('tootallnate' == obj.user);
assert('0Lt5S4hGarhtZmtz7BNTeX' == obj.id);
});
it('should parse "local" URLs', function () {
var url = 'http://open.spotify.com/local/Yasunori+Mitsuda/Chrono+Trigger+OST/A+Shot+of+Crisis/161';
var obj = parse(url);
assert('local' == obj.type);
assert('Yasunori Mitsuda' == obj.artist);
assert('Chrono Trigger OST' == obj.album);
assert('A Shot of Crisis' == obj.track);
assert(161 == obj.seconds);
});
it('should parse "search" URLs', function () {
var url = 'http://open.spotify.com/search/artist%3ah%c3%a4xor';
var obj = parse(url);
assert('search' == obj.type);
assert('artist:häxor' == obj.query);
});
it('should parse "encoded special characters" in URLs', function () {
var url = 'http://open.spotify.com/user/hitradio%c3%b63';
var obj = parse(url);
assert('user', obj.type);
assert('hitradioö3', obj.user);
});
it('should parse "special characters" in URLs', function () {
var url = 'http://open.spotify.com/user/hitradioö63';
var obj = parse(url);
assert('user', obj.type);
assert('hitradioö3', obj.user);
});
it('should parse "user" URLs', function () {
var url = 'http://open.spotify.com/user/tootallnate';
var obj = parse(url);
assert('user' == obj.type);
assert('tootallnate' == obj.id);
});
});
describe('parse()', function() {
describe('"open.spotify.com" URLs', function() {
it('should parse "track" URLs', function() {
var url = 'http://open.spotify.com/track/10M2REwwztVxgr0szw7UwD';
var obj = parse(url);
assert('track' == obj.type);
assert('10M2REwwztVxgr0szw7UwD' == obj.id);
});
it('should parse user "playlist" URLs', function() {
var url =
'http://open.spotify.com/user/tootallnate/playlist/0Lt5S4hGarhtZmtz7BNTeX';
var obj = parse(url);
assert('playlist' == obj.type);
assert('tootallnate' == obj.user);
assert('0Lt5S4hGarhtZmtz7BNTeX' == obj.id);
});
it('should parse public "playlist" URLs', function() {
var url =
'https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M';
var obj = parse(url);
assert('playlist' == obj.type);
assert('37i9dQZF1DXcBWIGoYBM5M' == obj.id);
});
it('should parse "local" URLs', function() {
var url =
'http://open.spotify.com/local/Yasunori+Mitsuda/Chrono+Trigger+OST/A+Shot+of+Crisis/161';
var obj = parse(url);
assert('local' == obj.type);
assert('Yasunori Mitsuda' == obj.artist);
assert('Chrono Trigger OST' == obj.album);
assert('A Shot of Crisis' == obj.track);
assert(161 == obj.seconds);
});
it('should parse "search" URLs', function() {
var url = 'http://open.spotify.com/search/artist%3ah%c3%a4xor';
var obj = parse(url);
assert('search' == obj.type);
assert('artist:häxor' == obj.query);
});
it('should parse "encoded special characters" in URLs', function() {
var url = 'http://open.spotify.com/user/hitradio%c3%b63';
var obj = parse(url);
assert('user', obj.type);
assert('hitradioö3', obj.user);
});
it('should parse "special characters" in URLs', function() {
var url = 'http://open.spotify.com/user/hitradioö63';
var obj = parse(url);
assert('user', obj.type);
assert('hitradioö3', obj.user);
});
it('should parse "user" URLs', function() {
var url = 'http://open.spotify.com/user/tootallnate';
var obj = parse(url);
assert('user' == obj.type);
assert('tootallnate' == obj.id);
});
});
describe('"play.spotify.com" URLs', function () {
it('should parse "track" URLs', function () {
var url = 'https://play.spotify.com/track/5W3cjX2J3tjhG8zb6u0qHn';
var obj = parse(url);
assert('track' == obj.type);
assert('5W3cjX2J3tjhG8zb6u0qHn' == obj.id);
});
});
describe('"play.spotify.com" URLs', function() {
it('should parse "track" URLs', function() {
var url = 'https://play.spotify.com/track/5W3cjX2J3tjhG8zb6u0qHn';
var obj = parse(url);
assert('track' == obj.type);
assert('5W3cjX2J3tjhG8zb6u0qHn' == obj.id);
});
});
describe('"embed.spotify.com" URLs', function () {
it('should parse "track" URLs', function () {
var url = 'https://embed.spotify.com/?uri=spotify:track:5oscsdDQ0NpjsTgpG4bI8S';
var obj = parse(url);
assert('track' == obj.type);
assert('5oscsdDQ0NpjsTgpG4bI8S' == obj.id);
});
});
describe('"embed.spotify.com" URLs', function() {
it('should parse "track" URLs', function() {
var url =
'https://embed.spotify.com/?uri=spotify:track:5oscsdDQ0NpjsTgpG4bI8S';
var obj = parse(url);
assert('track' == obj.type);
assert('5oscsdDQ0NpjsTgpG4bI8S' == obj.id);
});
});
describe('Spotify URIs', function () {
it('should parse "ablum" URIs', function () {
var uri = 'spotify:album:4m2880jivSbbyEGAKfITCa';
var obj = parse(uri);
assert('album' == obj.type);
assert('4m2880jivSbbyEGAKfITCa' == obj.id);
});
it('should parse "artist" URIs', function () {
var uri = 'spotify:artist:4tZwfgrHOc3mvqYlEYSvVi';
var obj = parse(uri);
assert('artist' == obj.type);
assert('4tZwfgrHOc3mvqYlEYSvVi' == obj.id);
});
it('should parse "track" URIs', function () {
var uri = 'spotify:track:5CMjjywI0eZMixPeqNd75R';
var obj = parse(uri);
assert('track' == obj.type);
assert('5CMjjywI0eZMixPeqNd75R' == obj.id);
});
it('should parse "playlist" URIs', function () {
var uri = 'spotify:user:daftpunkofficial:playlist:6jP6EcvAwqNksccDkIe6hX';
var obj = parse(uri);
assert('playlist' == obj.type);
assert('daftpunkofficial' == obj.user);
assert('6jP6EcvAwqNksccDkIe6hX' == obj.id);
});
it('should parse "local" track URIs', function () {
var uri = 'spotify:local:Yasunori+Mitsuda:Chrono+Trigger+OST:A+Shot+of+Crisis:161';
var obj = parse(uri);
assert('local' == obj.type);
assert('Yasunori Mitsuda' == obj.artist);
assert('Chrono Trigger OST' == obj.album);
assert('A Shot of Crisis' == obj.track);
assert(161 === obj.seconds);
});
it('should parse "local" track URIs 2', function () {
var uri = 'spotify:local:::a:6';
var obj = parse(uri);
assert('local' == obj.type);
assert('' === obj.artist);
assert('' === obj.album);
assert('a' === obj.track);
assert(6 === obj.seconds);
});
it('should parse "starred" playlist URIs', function () {
var uri = 'spotify:user:tootallnate:starred';
var obj = parse(uri);
assert('playlist' == obj.type);
assert('tootallnate' == obj.user);
assert(true == obj.starred);
});
it('should parse "search" URIs', function () {
var uri = 'spotify:search:artist:h%C3%A4xor';
var obj = parse(uri);
assert('search' == obj.type);
assert('artist:häxor' == obj.query);
});
it('should parse "encoded special characters" in URIs', function () {
var url = 'spotify:user:hitradio%c3%b63';
var obj = parse(url);
assert('user', obj.type);
assert('hitradioö3', obj.user);
});
it('should parse "special characters" in URIs', function () {
var url = 'spotify:user:hitradioö63';
var obj = parse(url);
assert('user', obj.type);
assert('hitradioö3', obj.user);
});
it('should parse combined "search"', function () {
var uri = 'spotify:search:genre:hip-hop+year:1980-1989';
var obj = parse(uri);
assert('search' == obj.type);
assert('genre:hip-hop year:1980-1989' == obj.query);
});
});
describe('"open.spotify.com/embed" URLs (e.g. twitter embed)', function() {
it('should parse "track" URLs', function() {
var url =
'https://open.spotify.com/embed/track/5oscsdDQ0NpjsTgpG4bI8S';
var obj = parse(url);
assert('track' == obj.type);
assert('5oscsdDQ0NpjsTgpG4bI8S' == obj.id);
});
});
describe('Spotify URIs', function() {
it('should parse "ablum" URIs', function() {
var uri = 'spotify:album:4m2880jivSbbyEGAKfITCa';
var obj = parse(uri);
assert('album' == obj.type);
assert('4m2880jivSbbyEGAKfITCa' == obj.id);
});
it('should parse "artist" URIs', function() {
var uri = 'spotify:artist:4tZwfgrHOc3mvqYlEYSvVi';
var obj = parse(uri);
assert('artist' == obj.type);
assert('4tZwfgrHOc3mvqYlEYSvVi' == obj.id);
});
it('should parse "track" URIs', function() {
var uri = 'spotify:track:5CMjjywI0eZMixPeqNd75R';
var obj = parse(uri);
assert('track' == obj.type);
assert('5CMjjywI0eZMixPeqNd75R' == obj.id);
});
it('should parse user "playlist" URIs', function() {
var uri =
'spotify:user:daftpunkofficial:playlist:6jP6EcvAwqNksccDkIe6hX';
var obj = parse(uri);
assert('playlist' == obj.type);
assert('daftpunkofficial' == obj.user);
assert('6jP6EcvAwqNksccDkIe6hX' == obj.id);
});
it('should parse public "playlist" URIs', function() {
var uri =
'spotify:playlist:37i9dQZF1DX4JAvHpjipBk';
var obj = parse(uri);
assert('playlist' == obj.type);
assert('37i9dQZF1DX4JAvHpjipBk' == obj.id);
});
it('should parse "local" track URIs', function() {
var uri =
'spotify:local:Yasunori+Mitsuda:Chrono+Trigger+OST:A+Shot+of+Crisis:161';
var obj = parse(uri);
assert('local' == obj.type);
assert('Yasunori Mitsuda' == obj.artist);
assert('Chrono Trigger OST' == obj.album);
assert('A Shot of Crisis' == obj.track);
assert(161 === obj.seconds);
});
it('should parse "local" track URIs 2', function() {
var uri = 'spotify:local:::a:6';
var obj = parse(uri);
assert('local' == obj.type);
assert('' === obj.artist);
assert('' === obj.album);
assert('a' === obj.track);
assert(6 === obj.seconds);
});
it('should parse "starred" playlist URIs', function() {
var uri = 'spotify:user:tootallnate:starred';
var obj = parse(uri);
assert('playlist' == obj.type);
assert('tootallnate' == obj.user);
assert(true == obj.starred);
});
it('should parse "search" URIs', function() {
var uri = 'spotify:search:artist:h%C3%A4xor';
var obj = parse(uri);
assert('search' == obj.type);
assert('artist:häxor' == obj.query);
});
it('should parse "encoded special characters" in URIs', function() {
var url = 'spotify:user:hitradio%c3%b63';
var obj = parse(url);
assert('user', obj.type);
assert('hitradioö3', obj.user);
});
it('should parse "special characters" in URIs', function() {
var url = 'spotify:user:hitradioö63';
var obj = parse(url);
assert('user', obj.type);
assert('hitradioö3', obj.user);
});
it('should parse combined "search"', function() {
var uri = 'spotify:search:genre:hip-hop+year:1980-1989';
var obj = parse(uri);
assert('search' == obj.type);
assert('genre:hip-hop year:1980-1989' == obj.query);
});
});
});
describe('formatURI()', function () {
it('should format "artist" open URLs', function () {
var url = 'http://open.spotify.com/artist/1gR0gsQYfi6joyO1dlp76N';
var obj = parse(url);
var expected = 'spotify:artist:1gR0gsQYfi6joyO1dlp76N';
var actual = formatURI(obj);
assert(actual == expected);
});
it('should format "search" query URIs', function () {
var url = 'spotify:search:artist%3aDaft+Punk';
var obj = parse(url);
var expected = 'spotify:search:artist%3ADaft+Punk';
var actual = formatURI(obj);
assert(actual == expected);
});
it('should format "starred" playlist open URLs', function () {
var url = 'http://open.spotify.com/user/syknyk/starred';
var obj = parse(url);
var expected = 'spotify:user:syknyk:starred';
var actual = formatURI(obj);
assert(actual == expected);
});
it('should parse "playlist" URIs', function () {
var url = 'spotify:user:syknyk:playlist:0Idyatn0m08Y48tiOovNd9';
var obj = parse(url);
var expected = 'spotify:user:syknyk:playlist:0Idyatn0m08Y48tiOovNd9';
var actual = formatURI(obj);
assert(actual == expected);
});
it('should parse "local" file URIs', function () {
var url = 'spotify:local:Flite%2c+Medium+Minus:YouTube:Find+What+You+Love:399';
var obj = parse(url);
var expected = 'spotify:local:Flite%2C+Medium+Minus:YouTube:Find+What+You+Love:399';
var actual = formatURI(obj);
assert(actual == expected);
});
describe('formatURI()', function() {
it('should format "artist" open URLs', function() {
var url = 'http://open.spotify.com/artist/1gR0gsQYfi6joyO1dlp76N';
var obj = parse(url);
var expected = 'spotify:artist:1gR0gsQYfi6joyO1dlp76N';
var actual = formatURI(obj);
assert(actual == expected);
});
it('should format "search" query URIs', function() {
var url = 'spotify:search:artist%3aDaft+Punk';
var obj = parse(url);
var expected = 'spotify:search:artist%3ADaft+Punk';
var actual = formatURI(obj);
assert(actual == expected);
});
it('should format "starred" playlist open URLs', function() {
var url = 'http://open.spotify.com/user/syknyk/starred';
var obj = parse(url);
var expected = 'spotify:user:syknyk:starred';
var actual = formatURI(obj);
assert(actual == expected);
});
it('should parse user "playlist" URIs', function() {
var url = 'spotify:user:syknyk:playlist:0Idyatn0m08Y48tiOovNd9';
var obj = parse(url);
var expected = 'spotify:user:syknyk:playlist:0Idyatn0m08Y48tiOovNd9';
var actual = formatURI(obj);
assert(actual == expected);
});
it('should parse public "playlist" URIs', function() {
var url = 'spotify:playlist:37i9dQZF1DWUa8ZRTfalHk';
var obj = parse(url);
var expected = 'spotify:playlist:37i9dQZF1DWUa8ZRTfalHk';
var actual = formatURI(obj);
assert(actual == expected);
});
it('should parse "local" file URIs', function() {
var url =
'spotify:local:Flite%2c+Medium+Minus:YouTube:Find+What+You+Love:399';
var obj = parse(url);
var expected =
'spotify:local:Flite%2C+Medium+Minus:YouTube:Find+What+You+Love:399';
var actual = formatURI(obj);
assert(actual == expected);
});
});
describe('formatOpenURL()', function () {
it('should format "artist" URIs', function () {
var uri = 'spotify:artist:1gR0gsQYfi6joyO1dlp76N';
var obj = parse(uri);
var expected = 'http://open.spotify.com/artist/1gR0gsQYfi6joyO1dlp76N';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "album" URIs', function () {
var uri = 'spotify:album:7CjakTZxwIF8oixONe6Bpb';
var obj = parse(uri);
var expected = 'http://open.spotify.com/album/7CjakTZxwIF8oixONe6Bpb';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "track" URIs', function () {
var uri = 'spotify:track:4XfokvilxHAOQXfnWD9p0Q';
var obj = parse(uri);
var expected = 'http://open.spotify.com/track/4XfokvilxHAOQXfnWD9p0Q';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "playlist" URIs', function () {
var uri = 'spotify:user:daftpunkofficial:playlist:6jP6EcvAwqNksccDkIe6hX';
var obj = parse(uri);
var expected = 'http://open.spotify.com/user/daftpunkofficial/playlist/6jP6EcvAwqNksccDkIe6hX';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "starred" playlist URIs', function () {
var uri = 'spotify:user:tootallnate:starred';
var obj = parse(uri);
var expected = 'http://open.spotify.com/user/tootallnate/starred';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "local" URIs', function () {
var uri = 'spotify:local:Yasunori+Mitsuda:Chrono+Trigger+OST+Disc+2:Ayla%27s+Theme:84';
var obj = parse(uri);
var expected = 'http://open.spotify.com/local/Yasunori+Mitsuda/Chrono+Trigger+OST+Disc+2/Ayla%27s+Theme/84';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "local" URIs 2', function () {
var uri = 'spotify:local:::a:6';
var obj = parse(uri);
var expected = 'http://open.spotify.com/local///a/6';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "search" URIs', function () {
var uri = 'spotify:search:artist%3aDaft+Punk';
var obj = parse(uri);
var expected = 'http://open.spotify.com/search/artist%3ADaft+Punk';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
describe('formatOpenURL()', function() {
it('should format "artist" URIs', function() {
var uri = 'spotify:artist:1gR0gsQYfi6joyO1dlp76N';
var obj = parse(uri);
var expected = 'http://open.spotify.com/artist/1gR0gsQYfi6joyO1dlp76N';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "album" URIs', function() {
var uri = 'spotify:album:7CjakTZxwIF8oixONe6Bpb';
var obj = parse(uri);
var expected = 'http://open.spotify.com/album/7CjakTZxwIF8oixONe6Bpb';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "track" URIs', function() {
var uri = 'spotify:track:4XfokvilxHAOQXfnWD9p0Q';
var obj = parse(uri);
var expected = 'http://open.spotify.com/track/4XfokvilxHAOQXfnWD9p0Q';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format user "playlist" URIs', function() {
var uri =
'spotify:user:daftpunkofficial:playlist:6jP6EcvAwqNksccDkIe6hX';
var obj = parse(uri);
var expected =
'http://open.spotify.com/user/daftpunkofficial/playlist/6jP6EcvAwqNksccDkIe6hX';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format public "playlist" URIs', function() {
var uri =
'spotify:playlist:37i9dQZF1DXaPCIWxzZwR1';
var obj = parse(uri);
var expected =
'http://open.spotify.com/playlist/37i9dQZF1DXaPCIWxzZwR1';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "starred" playlist URIs', function() {
var uri = 'spotify:user:tootallnate:starred';
var obj = parse(uri);
var expected = 'http://open.spotify.com/user/tootallnate/starred';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "local" URIs', function() {
var uri =
'spotify:local:Yasunori+Mitsuda:Chrono+Trigger+OST+Disc+2:Ayla%27s+Theme:84';
var obj = parse(uri);
var expected =
'http://open.spotify.com/local/Yasunori+Mitsuda/Chrono+Trigger+OST+Disc+2/Ayla%27s+Theme/84';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "local" URIs 2', function() {
var uri = 'spotify:local:::a:6';
var obj = parse(uri);
var expected = 'http://open.spotify.com/local///a/6';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "search" URIs', function() {
var uri = 'spotify:search:artist%3aDaft+Punk';
var obj = parse(uri);
var expected = 'http://open.spotify.com/search/artist%3ADaft+Punk';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
});
describe('formatPlayURL()', function () {
it('should format "track" URIs', function () {
var uri = 'spotify:track:4XfokvilxHAOQXfnWD9p0Q';
var obj = parse(uri);
var expected = 'https://play.spotify.com/track/4XfokvilxHAOQXfnWD9p0Q';
var actual = formatPlayURL(obj);
assert(actual == expected);
});
describe('formatPlayURL()', function() {
it('should format "track" URIs', function() {
var uri = 'spotify:track:4XfokvilxHAOQXfnWD9p0Q';
var obj = parse(uri);
var expected = 'https://play.spotify.com/track/4XfokvilxHAOQXfnWD9p0Q';
var actual = formatPlayURL(obj);
assert(actual == expected);
});
});
describe('formatEmbedURL()', function () {
it('should format "track" URIs', function () {
var uri = 'spotify:track:4XfokvilxHAOQXfnWD9p0Q';
var obj = parse(uri);
var expected = 'https://embed.spotify.com/?uri=spotify:track:4XfokvilxHAOQXfnWD9p0Q';
var actual = formatEmbedURL(obj);
assert(actual == expected);
});
describe('formatEmbedURL()', function() {
it('should format "track" URIs', function() {
var uri = 'spotify:track:4XfokvilxHAOQXfnWD9p0Q';
var obj = parse(uri);
var expected =
'https://embed.spotify.com/?uri=spotify:track:4XfokvilxHAOQXfnWD9p0Q';
var actual = formatEmbedURL(obj);
assert(actual == expected);
});
});
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