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

Parse the various Spotify URI formats into Objects and back

  • 4.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
decreased by-1.5%
Maintainers
2
Weekly downloads
 
Created
Source

spotify-uri

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

$ npm install spotify-uri

Usage

Just call parse method:

const { parse } = require('spotify-uri')

spotifyUri.parse('spotify:track:3GU4cxkfdc3lIp9pFEMMmw')
// { 
//   uri: 'spotify:track:3GU4cxkfdc3lIp9pFEMMmw',
//   type: 'track',
//   id: '3GU4cxkfdc3lIp9pFEMMmw' 
// }

spotifyUri.parse('http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN')
// { 
//   uri: 'http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN',
//   type: 'track',
//   id: '1pKYYY0dkg23sQQXi0Q5zN' 
// }

You can also format the parsed objects back into a URI or HTTP URL:

const { parse, formatURI, formatOpenURL, formatPlayURL, formatEmbedURL } = require('spotify-uri')

const parsed = parse('http://open.spotify.com/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'

See the test cases for some more examples of Spotify URIs.

API

.parse(String uri) → Object

Parses a Spotify URI or a Spotify HTTP(s) URL into an Object. The specific properties set on the returned Object depend on the "type" of uri that gets passed in. The different "types" are listed below:

.formatURI(Object parsedUri) → String

Formats a parsed URI Object back into a Spotify URI. For example:

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

.formatOpenURL(Object parsedUri) → String

Formats a parsed URI Object back into a Spotify HTTP "open" URL. For example:

const { parse, formatOpenURL } = require('spotify-uri')
const parsed = parse('spotify:track:3c1zC1Ma3987kQcHQfcG0Q')
formatOpenURL(parsed) // => 'http://open.spotify.com/track/3c1zC1Ma3987kQcHQfcG0Q'

.formatPlayURL(Object parsedUri) → String

Formats a parsed URI Object back into a Spotify HTTPS "play" URL. For example:

const { parse, formatPlayURL } = require('spotify-uri')
const parsed = parse('spotify:track:4Jgp57InfWE4MxJLfheNVz')
formatPlayURL(parsed) // => 'https://play.spotify.com/track/4Jgp57InfWE4MxJLfheNVz'

.formatEmbedURL(Object parsedUri) → String

Formats a parsed URI Object back into a Spotify HTTPS "embed" URL. For example:

const { parse, formatEmbedURL } = require('spotify-uri')
const parsed = parse('spotify:track:6JmI8SpUHoQ4yveHLjTrko')
formatEmbedURL(parsed) // => 'https://embed.spotify.com/?uri=spotify:track:6JmI8SpUHoQ4yveHLjTrko'

License

spotify-uri © Nathan Rajlich, released under the MIT License.
Authored by Nathan Rajlich and maintained by Kiko Beats with help from contributors.

Keywords

FAQs

Package last updated on 23 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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