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

spotify-uri

Package Overview
Dependencies
Maintainers
2
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 2.2.2 to 3.0.0

dist/index.mjs

140

dist/index.d.ts

@@ -1,38 +0,104 @@

import _parse from './parse';
import _Search from './search';
import _Local from './local';
import _Playlist from './playlist';
import _Artist from './artist';
import _Album from './album';
import _Track from './track';
import _User from './user';
import _Episode from './episode';
import _SpotifyUri from './spotify-uri';
declare function parseSpotifyUri(uri: string | _SpotifyUri): parseSpotifyUri.ParsedSpotifyUri;
declare namespace parseSpotifyUri {
type SpotifyUri = _SpotifyUri;
const SpotifyUri: typeof _SpotifyUri;
type Local = _Local;
const Local: typeof _Local;
type Search = _Search;
const Search: typeof _Search;
type Playlist = _Playlist;
const Playlist: typeof _Playlist;
type Artist = _Artist;
const Artist: typeof _Artist;
type Album = _Album;
const Album: typeof _Album;
type Track = _Track;
const Track: typeof _Track;
type User = _User;
const User: typeof _User;
type Episode = _Episode;
const Episode: typeof _Episode;
type ParsedSpotifyUri = Search | Local | Playlist | Track | Artist | Album | User;
const parse: typeof _parse;
function formatURI(input: string | SpotifyUri): string;
function formatEmbedURL(input: string | SpotifyUri): string;
function formatOpenURL(input: string | SpotifyUri): string;
function formatPlayURL(input: string | SpotifyUri): string;
declare abstract class SpotifyUri {
uri: string;
abstract toURL(): string;
abstract toURI(): string;
constructor(uri: string);
static is(v: any): v is SpotifyUri;
toEmbedURL(): string;
toOpenURL(): string;
toPlayURL(): string;
}
export = parseSpotifyUri;
/**
* Parses a "Spotify URI".
*
* @param {String} uri
* @return {Object} parsed Spotify uri object
* @api public
*/
declare function parse(input: string | SpotifyUri): ParsedSpotifyUri;
declare class Search extends SpotifyUri {
type: string;
query: string;
constructor(uri: string, query: string);
static is(v: any): v is Search;
toURI(): string;
toURL(): string;
}
declare class Local extends SpotifyUri {
type: string;
artist: string;
album: string;
track: string;
seconds: number;
constructor(uri: string, artist: string, album: string, track: string, seconds: number);
static is(v: any): v is Local;
toURI(): string;
toURL(): string;
}
declare class Playlist extends SpotifyUri {
type: string;
id: string;
user?: string;
constructor(uri: string, id: string, user?: string);
static is(v: any): v is Playlist;
toURI(): string;
toURL(): string;
}
declare class Artist extends SpotifyUri {
type: string;
id: string;
constructor(uri: string, id: string);
static is(v: any): v is Artist;
toURI(): string;
toURL(): string;
}
declare class Album extends SpotifyUri {
type: string;
id: string;
constructor(uri: string, id: string);
static is(v: any): v is Album;
toURI(): string;
toURL(): string;
}
declare class Track extends SpotifyUri {
type: string;
id: string;
constructor(uri: string, id: string);
static is(v: any): v is Track;
toURI(): string;
toURL(): string;
}
declare class User extends SpotifyUri {
type: string;
user: string;
constructor(uri: string, user: string);
static is(v: any): v is User;
toURI(): string;
toURL(): string;
}
declare class Episode extends SpotifyUri {
type: string;
id: string;
constructor(uri: string, id: string);
static is(v: any): v is Episode;
toURI(): string;
toURL(): string;
}
declare type ParsedSpotifyUri = Search | Episode | Local | Playlist | Track | Artist | Album | User;
declare function formatURI(input: string | SpotifyUri): string;
declare function formatEmbedURL(input: string | SpotifyUri): string;
declare function formatOpenURL(input: string | SpotifyUri): string;
declare function formatPlayURL(input: string | SpotifyUri): string;
export { ParsedSpotifyUri, formatEmbedURL, formatOpenURL, formatPlayURL, formatURI, parse };

@@ -1,51 +0,329 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
const parse_1 = __importDefault(require("./parse"));
const search_1 = __importDefault(require("./search"));
const local_1 = __importDefault(require("./local"));
const playlist_1 = __importDefault(require("./playlist"));
const artist_1 = __importDefault(require("./artist"));
const album_1 = __importDefault(require("./album"));
const track_1 = __importDefault(require("./track"));
const user_1 = __importDefault(require("./user"));
const episode_1 = __importDefault(require("./episode"));
const spotify_uri_1 = __importDefault(require("./spotify-uri"));
function parseSpotifyUri(uri) {
return parse_1.default(uri);
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
formatEmbedURL: () => formatEmbedURL,
formatOpenURL: () => formatOpenURL,
formatPlayURL: () => formatPlayURL,
formatURI: () => formatURI,
parse: () => parse
});
module.exports = __toCommonJS(src_exports);
// src/parse.ts
var import_url = require("url");
// src/util.ts
function decode(str) {
return decodeURIComponent(str).replace(/\+/g, " ");
}
(function (parseSpotifyUri) {
parseSpotifyUri.SpotifyUri = spotify_uri_1.default;
parseSpotifyUri.Local = local_1.default;
parseSpotifyUri.Search = search_1.default;
parseSpotifyUri.Playlist = playlist_1.default;
parseSpotifyUri.Artist = artist_1.default;
parseSpotifyUri.Album = album_1.default;
parseSpotifyUri.Track = track_1.default;
parseSpotifyUri.User = user_1.default;
parseSpotifyUri.Episode = episode_1.default;
parseSpotifyUri.parse = parse_1.default;
function formatURI(input) {
const uri = typeof input === 'string' ? parseSpotifyUri.parse(input) : input;
return uri.toURI();
function encode(str) {
return escape(str.replace(/ /g, "+"));
}
// src/spotify-uri.ts
var SpotifyUri = class {
constructor(uri) {
this.uri = uri;
}
static is(v) {
return Boolean(typeof v === "object" && typeof v.uri === "string");
}
toEmbedURL() {
return `https://embed.spotify.com/?uri=${this.toURI()}`;
}
toOpenURL() {
return `http://open.spotify.com${this.toURL()}`;
}
toPlayURL() {
return `https://play.spotify.com${this.toURL()}`;
}
};
// src/local.ts
var Local = class extends SpotifyUri {
constructor(uri, artist, album, track, seconds) {
super(uri);
this.type = "local";
this.artist = artist;
this.album = album;
this.track = track;
this.seconds = seconds;
}
static is(v) {
return Boolean(typeof v === "object" && v.type === "local");
}
toURI() {
return `spotify:local:${encode(this.artist)}:${encode(this.album)}:${encode(this.track)}:${this.seconds}`;
}
toURL() {
return `/local/${encode(this.artist)}/${encode(this.album)}/${encode(this.track)}/${this.seconds}`;
}
};
// src/search.ts
var Search = class extends SpotifyUri {
constructor(uri, query) {
super(uri);
this.type = "search";
this.query = query;
}
static is(v) {
return Boolean(typeof v === "object" && v.type === "search");
}
toURI() {
return `spotify:search:${encode(this.query)}`;
}
toURL() {
return `/search/${encode(this.query)}`;
}
};
// src/playlist.ts
var Playlist = class extends SpotifyUri {
constructor(uri, id, user) {
super(uri);
this.type = "playlist";
this.id = id;
if (typeof user === "string") {
this.user = user;
}
parseSpotifyUri.formatURI = formatURI;
function formatEmbedURL(input) {
const uri = typeof input === 'string' ? parseSpotifyUri.parse(input) : input;
return uri.toEmbedURL();
}
static is(v) {
return Boolean(typeof v === "object" && v.type === "playlist");
}
toURI() {
if (this.user !== void 0) {
if (this.id === "starred") {
return `spotify:user:${encode(this.user)}:${encode(this.id)}`;
}
return `spotify:user:${encode(this.user)}:playlist:${encode(this.id)}`;
}
parseSpotifyUri.formatEmbedURL = formatEmbedURL;
function formatOpenURL(input) {
const uri = typeof input === 'string' ? parseSpotifyUri.parse(input) : input;
return uri.toOpenURL();
return `spotify:playlist:${encode(this.id)}`;
}
toURL() {
if (this.user !== void 0) {
if (this.id === "starred") {
return `/user/${encode(this.user)}/${encode(this.id)}`;
}
return `/user/${encode(this.user)}/playlist/${encode(this.id)}`;
}
parseSpotifyUri.formatOpenURL = formatOpenURL;
function formatPlayURL(input) {
const uri = typeof input === 'string' ? parseSpotifyUri.parse(input) : input;
return uri.toPlayURL();
return `/playlist/${encode(this.id)}`;
}
};
// src/artist.ts
var Artist = class extends SpotifyUri {
constructor(uri, id) {
super(uri);
this.type = "artist";
this.id = id;
}
static is(v) {
return Boolean(typeof v === "object" && v.type === "artist");
}
toURI() {
return `spotify:${this.type}:${encode(this.id)}`;
}
toURL() {
return `/${this.type}/${encode(this.id)}`;
}
};
// src/album.ts
var Album = class extends SpotifyUri {
constructor(uri, id) {
super(uri);
this.type = "album";
this.id = id;
}
static is(v) {
return Boolean(typeof v === "object" && v.type === "album");
}
toURI() {
return `spotify:${this.type}:${encode(this.id)}`;
}
toURL() {
return `/${this.type}/${encode(this.id)}`;
}
};
// src/track.ts
var Track = class extends SpotifyUri {
constructor(uri, id) {
super(uri);
this.type = "track";
this.id = id;
}
static is(v) {
return Boolean(typeof v === "object" && v.type === "track");
}
toURI() {
return `spotify:${this.type}:${encode(this.id)}`;
}
toURL() {
return `/${this.type}/${encode(this.id)}`;
}
};
// src/episode.ts
var Episode = class extends SpotifyUri {
constructor(uri, id) {
super(uri);
this.type = "episode";
this.id = id;
}
static is(v) {
return Boolean(typeof v === "object" && v.type === "episode");
}
toURI() {
return `spotify:${this.type}:${encode(this.id)}`;
}
toURL() {
return `/${this.type}/${encode(this.id)}`;
}
};
// src/show.ts
var Show = class extends SpotifyUri {
constructor(uri, id) {
super(uri);
this.type = "show";
this.id = id;
}
static is(v) {
return Boolean(typeof v === "object" && v.type === "show");
}
toURI() {
return `spotify:${this.type}:${encode(this.id)}`;
}
toURL() {
return `/${this.type}/${encode(this.id)}`;
}
};
// src/user.ts
var User = class extends SpotifyUri {
constructor(uri, user) {
super(uri);
this.type = "user";
this.user = user;
}
static is(v) {
return Boolean(typeof v === "object" && v.type === "user");
}
toURI() {
return `spotify:${this.type}:${encode(this.user)}`;
}
toURL() {
return `/${this.type}/${encode(this.user)}`;
}
};
// src/parse.ts
function parse(input) {
const uri = SpotifyUri.is(input) ? input.uri : input;
const { protocol, hostname, pathname = "/", searchParams } = new import_url.URL(uri);
if (hostname === "embed.spotify.com") {
const parsedQs = Object.fromEntries(searchParams);
if (typeof parsedQs.uri !== "string") {
throw new Error("fo");
}
parseSpotifyUri.formatPlayURL = formatPlayURL;
})(parseSpotifyUri || (parseSpotifyUri = {}));
module.exports = parseSpotifyUri;
//# sourceMappingURL=index.js.map
return parse(parsedQs.uri);
}
if (protocol === "spotify:") {
const parts2 = uri.split(":");
return parseParts(uri, parts2);
}
if (pathname === null) {
throw new TypeError("No pathname");
}
const parts = pathname.split("/");
return parseParts(uri, parts);
}
function parseParts(uri, parts) {
const len = parts.length;
if (parts[1] === "embed") {
parts = parts.slice(1);
}
if (parts[1] === "search") {
return new Search(uri, decode(parts.slice(2).join(":")));
}
if (len >= 3 && parts[1] === "local") {
return new Local(uri, decode(parts[2]), decode(parts[3]), decode(parts[4]), +parts[5]);
}
if (len === 3 && parts[1] === "playlist") {
return new Playlist(uri, decode(parts[2]));
}
if (len === 3 && parts[1] === "user") {
return new User(uri, decode(parts[2]));
}
if (len >= 5) {
return new Playlist(uri, decode(parts[4]), decode(parts[2]));
}
if (len >= 4 && parts[3] === "starred") {
return new Playlist(uri, "starred", decode(parts[2]));
}
if (parts[1] === "artist") {
return new Artist(uri, parts[2]);
}
if (parts[1] === "album") {
return new Album(uri, parts[2]);
}
if (parts[1] === "track") {
return new Track(uri, parts[2]);
}
if (parts[1] === "episode") {
return new Episode(uri, parts[2]);
}
if (parts[1] === "show") {
return new Show(uri, parts[2]);
}
if (parts[1] === "playlist") {
return new Playlist(uri, parts[2]);
}
throw new TypeError(`Could not determine type for: ${uri}`);
}
// src/index.ts
function formatURI(input) {
const uri = typeof input === "string" ? parse(input) : input;
return uri.toURI();
}
function formatEmbedURL(input) {
const uri = typeof input === "string" ? parse(input) : input;
return uri.toEmbedURL();
}
function formatOpenURL(input) {
const uri = typeof input === "string" ? parse(input) : input;
return uri.toOpenURL();
}
function formatPlayURL(input) {
const uri = typeof input === "string" ? parse(input) : input;
return uri.toPlayURL();
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
formatEmbedURL,
formatOpenURL,
formatPlayURL,
formatURI,
parse
});

@@ -5,4 +5,3 @@ {

"homepage": "https://github.com/TooTallNate/spotify-uri#readme",
"version": "2.2.2",
"main": "./dist/index.js",
"version": "3.0.0",
"author": {

@@ -15,4 +14,4 @@ "email": "nathan@tootallnate.net",

{
"name": "Nathan Rajlich",
"email": "nathan@tootallnate.net"
"name": "Kiko Beats",
"email": "josefrancisco.verdu@gmail.com"
},

@@ -28,12 +27,12 @@ {

{
"name": "Kiko Beats",
"email": "josefrancisco.verdu@gmail.com"
"name": "Shem Magnezi",
"email": "smagnezi8@gmail.com"
},
{
"name": "Marwan Zibaoui",
"email": "marwan.zibaoui@gmail.com"
},
{
"name": "Miraculous Owonubi",
"email": "omiraculous@gmail.com"
},
{
"name": "Shem Magnezi",
"email": "smagnezi8@gmail.com"
}

@@ -49,27 +48,24 @@ ],

"keywords": [
"http",
"link",
"object",
"album",
"artist",
"embed",
"episode",
"parse",
"playlist",
"search",
"spotify",
"track",
"uri",
"url"
"url",
"user"
],
"devDependencies": {
"@types/node": "^12.12.11",
"@typescript-eslint/eslint-plugin": "1.6.0",
"@typescript-eslint/parser": "1.1.0",
"eslint": "5.16.0",
"eslint-config-airbnb": "17.1.0",
"eslint-config-prettier": "4.1.0",
"eslint-import-resolver-typescript": "1.1.1",
"eslint-plugin-import": "2.16.0",
"eslint-plugin-jsx-a11y": "6.2.1",
"eslint-plugin-react": "7.12.4",
"mocha": "^6.2.2",
"rimraf": "^3.0.0",
"typescript": "^3.5.3"
"@types/node": "12",
"mocha": "latest",
"ts-standard": "latest",
"tsup": "latest",
"typescript": "latest"
},
"engines": {
"node": ">= 6"
"node": ">= 12"
},

@@ -80,10 +76,18 @@ "files": [

"license": "MIT",
"typings": "./dist/index.d.ts",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"prebuild": "rimraf dist",
"build": "tsup src/index.ts --format esm,cjs --dts",
"prebuild": "rm -rf dist",
"prerelease": "npm run test",
"pretest": "npm run build",
"release": "standard-version && git push --follow-tags origin next && npm publish && gh release create --generate-notes --help $(git describe --tags --abbrev=0)",
"test": "mocha",
"test-lint": "eslint src --ext .js,.ts"
"test-lint": "ts-standard"
},
"readme": "spotify-uri\n===========\n### Parse the various Spotify URI formats into Objects and back\n[![Build Status](https://github.com/TooTallNate/spotify-uri/workflows/Node%20CI/badge.svg)](https://github.com/TooTallNate/spotify-uri/actions?workflow=Node+CI)\n\nSpotify URIs get passed around in a variety of flavors. This module parses them\ninto a JavaScript object so you can work with them further. You can also convert\nthem back into Spotify URIs or HTTP URLs.\n\n\nInstallation\n------------\n\nInstall for node.js or browserify using `npm`:\n\n``` bash\n$ npm install spotify-uri\n```\n\n\nExample\n-------\n\n``` javascript\nvar spotifyUri = require('spotify-uri');\nvar parsed, uri;\n\n// parse Spotify URIs or HTTP URLs into JavaScipt metadata Objects:\n\nparsed = spotifyUri.parse('spotify:track:3GU4cxkfdc3lIp9pFEMMmw');\nconsole.log(parsed);\n// { uri: 'spotify:track:3GU4cxkfdc3lIp9pFEMMmw',\n// type: 'track',\n// id: '3GU4cxkfdc3lIp9pFEMMmw' }\n\nparsed = spotifyUri.parse('http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN');\nconsole.log(parsed);\n// { uri: 'http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN',\n// type: 'track',\n// id: '1pKYYY0dkg23sQQXi0Q5zN' }\n\n\n// you can also format the parsed objects back into a URI or HTTP URL:\n\nuri = spotifyUri.formatURI(parsed);\nconsole.log(uri);\n// 'spotify:track:1pKYYY0dkg23sQQXi0Q5zN'\n\nuri = spotifyUri.formatOpenURL(parsed);\nconsole.log(uri);\n// 'http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN'\n\nuri = spotifyUri.formatPlayURL(parsed);\nconsole.log(uri);\n// 'https://play.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN'\n\nuri = spotifyUri.formatEmbedURL(parsed);\nconsole.log(uri);\n// 'https://embed.spotify.com/?uri=spotify:track:1pKYYY0dkg23sQQXi0Q5zN'\n```\n\nSee the [test cases](./test) for some more examples of Spotify URIs.\n\n\n## API\n\n### .parse(String uri) → Object\n\nParses a Spotify URI or a Spotify HTTP(s) URL into an Object. The specific\nproperties set on the returned Object depend on the \"type\" of `uri` that gets\npassed in. The different \"types\" are listed below:\n\n### .formatURI(Object parsedUri) → String\n\nFormats a parsed URI Object back into a Spotify URI. For example:\n\n``` js\nvar parsed = spotifyUri.parse('https://play.spotify.com/track/3GU4cxkfdc3lIp9pFEMMmw');\nvar uri = spotifyUri.formatURI(parsed);\nconsole.log(uri);\n// 'spotify:track:3GU4cxkfdc3lIp9pFEMMmw'\n```\n\n### .formatOpenURL(Object parsedUri) → String\n\nFormats a parsed URI Object back into a Spotify HTTP \"open\" URL. For example:\n\n``` js\nvar parsed = spotifyUri.parse('spotify:track:3c1zC1Ma3987kQcHQfcG0Q');\nvar uri = spotifyUri.formatOpenURL(parsed);\nconsole.log(uri);\n// 'http://open.spotify.com/track/3c1zC1Ma3987kQcHQfcG0Q'\n```\n\n### .formatPlayURL(Object parsedUri) → String\n\nFormats a parsed URI Object back into a Spotify HTTPS \"play\" URL. For example:\n\n``` js\nvar parsed = spotifyUri.parse('spotify:track:4Jgp57InfWE4MxJLfheNVz');\nvar uri = spotifyUri.formatPlayURL(parsed);\nconsole.log(uri);\n// 'https://play.spotify.com/track/4Jgp57InfWE4MxJLfheNVz'\n```\n\n### .formatEmbedURL(Object parsedUri) → String\n\nFormats a parsed URI Object back into a Spotify HTTPS \"embed\" URL. For example:\n\n``` js\nvar parsed = spotifyUri.parse('spotify:track:6JmI8SpUHoQ4yveHLjTrko');\nvar uri = spotifyUri.formatEmbedURL(parsed);\nconsole.log(uri);\n// 'https://embed.spotify.com/?uri=spotify:track:6JmI8SpUHoQ4yveHLjTrko'\n```\n\n\n## License\n\nMIT\n"
"readme": "# spotify-uri\n\n> Parse and format the various Spotify URL/URI formats.\n\n**spotify-uri** get passed around in a variety of flavors. This module parses them\ninto a JavaScript object so you can work with them further. You can also convert\nthem back into Spotify URIs or HTTP URLs.\n\n## Install\n\n```bash\n$ npm install spotify-uri\n```\n\n## Usage\n\nJust call `parse` method:\n\n```js\nconst { parse } = require('spotify-uri')\n\nspotifyUri.parse('spotify:track:3GU4cxkfdc3lIp9pFEMMmw')\n// { \n// uri: 'spotify:track:3GU4cxkfdc3lIp9pFEMMmw',\n// type: 'track',\n// id: '3GU4cxkfdc3lIp9pFEMMmw' \n// }\n\nspotifyUri.parse('http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN')\n// { \n// uri: 'http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN',\n// type: 'track',\n// id: '1pKYYY0dkg23sQQXi0Q5zN' \n// }\n```\n\nYou can also format the parsed objects back into a URI or HTTP URL:\n\n```js\nconst { parse, formatURI, formatOpenURL, formatPlayURL, formatEmbedURL } = require('spotify-uri')\n\nconst parsed = parse('http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN')\n\nformatURI(parsed) // => 'spotify:track:1pKYYY0dkg23sQQXi0Q5zN'\nformatOpenURL(parsed) // => 'http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN'\nformatPlayURL(parsed) // => 'https://play.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN'\nformatEmbedURL(parsed) // => 'https://embed.spotify.com/?uri=spotify:track:1pKYYY0dkg23sQQXi0Q5zN'\n```\n\nSee the [test cases](./test) for some more examples of Spotify URIs.\n\n## API\n\n### .parse(String uri) → Object\n\nParses a Spotify URI or a Spotify HTTP(s) URL into an Object. The specific\nproperties set on the returned Object depend on the \"type\" of `uri` that gets\npassed in. The different \"types\" are listed below:\n\n### .formatURI(Object parsedUri) → String\n\nFormats a parsed URI Object back into a Spotify URI. For example:\n\n``` js\nconst { parse, formatURI } = require('spotify-uri')\nconst parsed = spotifyUri.parse('https://play.spotify.com/track/3GU4cxkfdc3lIp9pFEMMmw')\nformatURI(parsed) // => 'spotify:track:3GU4cxkfdc3lIp9pFEMMmw'\n```\n\n### .formatOpenURL(Object parsedUri) → String\n\nFormats a parsed URI Object back into a Spotify HTTP \"open\" URL. For example:\n\n``` js\nconst { parse, formatOpenURL } = require('spotify-uri')\nconst parsed = parse('spotify:track:3c1zC1Ma3987kQcHQfcG0Q')\nformatOpenURL(parsed) // => 'http://open.spotify.com/track/3c1zC1Ma3987kQcHQfcG0Q'\n```\n\n### .formatPlayURL(Object parsedUri) → String\n\nFormats a parsed URI Object back into a Spotify HTTPS \"play\" URL. For example:\n\n``` js\nconst { parse, formatPlayURL } = require('spotify-uri')\nconst parsed = parse('spotify:track:4Jgp57InfWE4MxJLfheNVz')\nformatPlayURL(parsed) // => 'https://play.spotify.com/track/4Jgp57InfWE4MxJLfheNVz'\n```\n\n### .formatEmbedURL(Object parsedUri) → String\n\nFormats a parsed URI Object back into a Spotify HTTPS \"embed\" URL. For example:\n\n``` js\nconst { parse, formatEmbedURL } = require('spotify-uri')\nconst parsed = parse('spotify:track:6JmI8SpUHoQ4yveHLjTrko')\nformatEmbedURL(parsed) // => 'https://embed.spotify.com/?uri=spotify:track:6JmI8SpUHoQ4yveHLjTrko'\n```\n\n## License\n\n**spotify-uri** © [Nathan Rajlich](http://n8.io), released under the [MIT](https://github.com/microlinkhq/spotify-url-info/blob/master/LICENSE.md) License.<br>\nAuthored by [Nathan Rajlich](http://n8.io) and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/microlinkhq/spotify-url-info/contributors).\n"
}

@@ -1,60 +0,48 @@

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)
# spotify-uri
Spotify URIs get passed around in a variety of flavors. This module parses them
> Parse and format the various Spotify URL/URI formats.
**spotify-uri** get passed around in a variety of flavors. This module parses them
into a JavaScript object so you can work with them further. You can also convert
them back into Spotify URIs or HTTP URLs.
## Install
Installation
------------
Install for node.js or browserify using `npm`:
``` bash
```bash
$ npm install spotify-uri
```
## Usage
Example
-------
Just call `parse` method:
``` javascript
var spotifyUri = require('spotify-uri');
var parsed, uri;
```js
const { parse } = require('spotify-uri')
// parse Spotify URIs or HTTP URLs into JavaScipt metadata Objects:
parsed = spotifyUri.parse('spotify:track:3GU4cxkfdc3lIp9pFEMMmw');
console.log(parsed);
// { uri: 'spotify:track:3GU4cxkfdc3lIp9pFEMMmw',
spotifyUri.parse('spotify:track:3GU4cxkfdc3lIp9pFEMMmw')
// {
// uri: 'spotify:track:3GU4cxkfdc3lIp9pFEMMmw',
// type: 'track',
// id: '3GU4cxkfdc3lIp9pFEMMmw' }
// id: '3GU4cxkfdc3lIp9pFEMMmw'
// }
parsed = spotifyUri.parse('http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN');
console.log(parsed);
// { uri: 'http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN',
spotifyUri.parse('http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN')
// {
// uri: 'http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN',
// type: 'track',
// id: '1pKYYY0dkg23sQQXi0Q5zN' }
// id: '1pKYYY0dkg23sQQXi0Q5zN'
// }
```
You can also format the parsed objects back into a URI or HTTP URL:
// you can also format the parsed objects back into a URI or HTTP URL:
```js
const { parse, formatURI, formatOpenURL, formatPlayURL, formatEmbedURL } = require('spotify-uri')
uri = spotifyUri.formatURI(parsed);
console.log(uri);
// 'spotify:track:1pKYYY0dkg23sQQXi0Q5zN'
const parsed = parse('http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN')
uri = spotifyUri.formatOpenURL(parsed);
console.log(uri);
// 'http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN'
uri = spotifyUri.formatPlayURL(parsed);
console.log(uri);
// 'https://play.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN'
uri = spotifyUri.formatEmbedURL(parsed);
console.log(uri);
// 'https://embed.spotify.com/?uri=spotify:track:1pKYYY0dkg23sQQXi0Q5zN'
formatURI(parsed) // => 'spotify:track:1pKYYY0dkg23sQQXi0Q5zN'
formatOpenURL(parsed) // => 'http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN'
formatPlayURL(parsed) // => 'https://play.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN'
formatEmbedURL(parsed) // => 'https://embed.spotify.com/?uri=spotify:track:1pKYYY0dkg23sQQXi0Q5zN'
```

@@ -64,3 +52,2 @@

## API

@@ -79,6 +66,5 @@

``` js
var parsed = spotifyUri.parse('https://play.spotify.com/track/3GU4cxkfdc3lIp9pFEMMmw');
var uri = spotifyUri.formatURI(parsed);
console.log(uri);
// 'spotify:track:3GU4cxkfdc3lIp9pFEMMmw'
const { parse, formatURI } = require('spotify-uri')
const parsed = spotifyUri.parse('https://play.spotify.com/track/3GU4cxkfdc3lIp9pFEMMmw')
formatURI(parsed) // => 'spotify:track:3GU4cxkfdc3lIp9pFEMMmw'
```

@@ -91,6 +77,5 @@

``` js
var parsed = spotifyUri.parse('spotify:track:3c1zC1Ma3987kQcHQfcG0Q');
var uri = spotifyUri.formatOpenURL(parsed);
console.log(uri);
// 'http://open.spotify.com/track/3c1zC1Ma3987kQcHQfcG0Q'
const { parse, formatOpenURL } = require('spotify-uri')
const parsed = parse('spotify:track:3c1zC1Ma3987kQcHQfcG0Q')
formatOpenURL(parsed) // => 'http://open.spotify.com/track/3c1zC1Ma3987kQcHQfcG0Q'
```

@@ -103,6 +88,5 @@

``` js
var parsed = spotifyUri.parse('spotify:track:4Jgp57InfWE4MxJLfheNVz');
var uri = spotifyUri.formatPlayURL(parsed);
console.log(uri);
// 'https://play.spotify.com/track/4Jgp57InfWE4MxJLfheNVz'
const { parse, formatPlayURL } = require('spotify-uri')
const parsed = parse('spotify:track:4Jgp57InfWE4MxJLfheNVz')
formatPlayURL(parsed) // => 'https://play.spotify.com/track/4Jgp57InfWE4MxJLfheNVz'
```

@@ -115,11 +99,10 @@

``` js
var parsed = spotifyUri.parse('spotify:track:6JmI8SpUHoQ4yveHLjTrko');
var uri = spotifyUri.formatEmbedURL(parsed);
console.log(uri);
// 'https://embed.spotify.com/?uri=spotify:track:6JmI8SpUHoQ4yveHLjTrko'
const { parse, formatEmbedURL } = require('spotify-uri')
const parsed = parse('spotify:track:6JmI8SpUHoQ4yveHLjTrko')
formatEmbedURL(parsed) // => 'https://embed.spotify.com/?uri=spotify:track:6JmI8SpUHoQ4yveHLjTrko'
```
## License
MIT
**spotify-uri** © [Nathan Rajlich](http://n8.io), released under the [MIT](https://github.com/microlinkhq/spotify-url-info/blob/master/LICENSE.md) License.<br>
Authored by [Nathan Rajlich](http://n8.io) and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/microlinkhq/spotify-url-info/contributors).
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