# spotify-uri

> Parse the various Spotify URI formats into Objects and back

Latest version **4.1.0** (published 2024-05-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install spotify-uri
pnpm add spotify-uri
yarn add spotify-uri
bun add spotify-uri
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2024-05-23 |
| First published | 2013-05-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 16 |
| Dependencies | 0 |
| Unpacked size | 25.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 73 |
| Author | Nathan Rajlich |
| Maintainers | tootallnate, kikobeats |
| Keywords | album, artist, embed, episode, parse, playlist, search, spotify, track, uri, url, user |

## Links

- npm: https://www.npmjs.com/package/spotify-uri
- Repository: https://github.com/TooTallNate/spotify-uri
- Homepage: https://github.com/TooTallNate/spotify-uri#readme
- Issues: https://github.com/TooTallNate/spotify-uri/issues
- npm.io page: https://npm.io/package/spotify-uri

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 4.1.0 (latest) — 2024-05-23
- 4.0.1 — 2023-12-23
- 4.0.0 — 2023-07-25
- 3.0.4 — 2023-05-15
- 3.0.3 — 2022-09-02
- 3.0.2 — 2022-04-10
- 3.0.1 — 2022-04-07
- 3.0.0 — 2022-04-07
- 2.2.2 — 2022-04-07
- 2.2.1 — 2022-04-07
- 2.2.0 — 2021-03-28
- 2.1.0 — 2020-07-30
- 2.0.0 — 2020-02-25
- 1.1.0 — 2020-02-23
- 1.0.0 — 2014-11-05
- … 3 more at https://npm.io/package/spotify-uri/versions

## README

# 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

```bash
$ npm install spotify-uri
```

## Usage

Just call `parse` method:

```js
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:

```js
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](./test) 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:

``` js
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:

``` js
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:

``` js
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:

``` js
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](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).

---
_Source: https://npm.io/package/spotify-uri · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
