# rewrite-to-spotify-uri

> Rewrites Spotify URIs and HTTP links to Spotify application URIs

Latest version **1.0.0** (published 2018-06-28) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-06-28 |
| First published | 2018-06-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 1 |
| Unpacked size | 15.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Mark Cicoria |
| Maintainers | mcicoria |
| Keywords | spotify, uri |

## Links

- npm: https://www.npmjs.com/package/rewrite-to-spotify-uri
- Repository: https://github.com/mcicoria/rewrite-to-spotify-uri
- Issues: https://github.com/mcicoria/rewrite-to-spotify-uri/issues
- npm.io page: https://npm.io/package/rewrite-to-spotify-uri

## Dependencies (1)

- [url-regex](https://npm.io/package/url-regex.md) ^4.1.1

## Recent versions

- 1.0.0 (latest) — 2018-06-28

## README

# rewrite-to-spotify-uri [![Build Status](http://img.shields.io/travis/mcicoria/rewrite-to-spotify-uri.svg?style=flat)](https://travis-ci.org/mcicoria/rewrite-to-spotify-uri)

Rewrites all Spotify links and uris like:  
```
https://open.spotify.com/user/markcicoria/playlist/2Wz5C4qI9cpOV0xWurixU0?si=9VHvI4znToSovfHHUSdEpw   
spotify:user:markcicoria:playlist:2Wz5C4qI9cpOV0xWurixU0  
```
To Spotify application links like:  
```spotify://user:markcicoria:playlist:2Wz5C4qI9cpOV0xWurixU0```  


## Install

```
$ npm install --save rewrite-to-spotify-uri
```

## Test

```
$ npm test
```
Or watch with:
```
$ npm test -- --watch
```

## Usage

```js
const rewriteSpotifyUri = require('rewrite-to-spotify-uri');

rewriteSpotifyUri.rewrite('spotify:user:markcicoria:playlist:2Wz5C4qI9cpOV0xWurixU0 foo bar');
//=> spotify://user:markcicoria:playlist:2Wz5C4qI9cpOV0xWurixU0 foo bar

rewriteSpotifyUri.rewrite('https://open.spotify.com/user/markcicoria/playlist/2Wz5C4qI9cpOV0xWurixU0?si=9VHvI4znToSovfHHUSdEpw foo bar spotify:track:6JD5hXgXe7z5edGKpQK0AE');
//=> spotify://user/markcicoria/playlist/2Wz5C4qI9cpOV0xWurixU0?si=9VHvI4znToSovfHHUSdEpw foo bar spotify://track:6JD5hXgXe7z5edGKpQK0AE

rewriteSpotifyUri.isSpotifyUri('http://github.com');
//=> false

rewriteSpotifyUri.isSpotifyUri('spotify:user:markcicoria:playlist:2Wz5C4qI9cpOV0xWurixU0');
//=> true

rewriteSpotifyUri.isSpotifyUri('https://open.spotify.com/user/markcicoria/playlist/2Wz5C4qI9cpOV0xWurixU0?si=9VHvI4znToSovfHHUSdEpw');
//=> false

rewriteSpotifyUri.isSpotifyLink('https://open.spotify.com/user/markcicoria/playlist/2Wz5C4qI9cpOV0xWurixU0?si=9VHvI4znToSovfHHUSdEpw');
//=> true

rewriteSpotifyUri.extractUris('https://open.spotify.com/user/markcicoria/playlist/2Wz5C4qI9cpOV0xWurixU0?si=9VHvI4znToSovfHHUSdEpw foo bar spotify:track:6JD5hXgXe7z5edGKpQK0AE');
//=> ['https://open.spotify.com/user/markcicoria/playlist/2Wz5C4qI9cpOV0xWurixU0?si=9VHvI4znToSovfHHUSdEpw', 'spotify:track:6JD5hXgXe7z5edGKpQK0AE']

rewriteSpotifyUri.extractSpotifyUris('https://open.spotify.com/user/markcicoria/playlist/2Wz5C4qI9cpOV0xWurixU0?si=9VHvI4znToSovfHHUSdEpw foo bar spotify:track:6JD5hXgXe7z5edGKpQK0AE');
//=> ['spotify:track:6JD5hXgXe7z5edGKpQK0AE']
```


## API

### rewrite(string)

Returns a string with all Spotify links and uris replaced with the spotify:// version.

### isSpotifyUri(string)

Returns a boolean. True if the string is a Spotify uri like `spotify:track:id`, false otherwise.

### isSpotifyLink(string)

Returns a boolean. True if the string is a Spotify uri like `open.spotify://track/id`, false otherwise.

### extractUris(string)

Returns an array of matched Spotify links and uris.

### extractSpotifyUris(string)

Returns an array of matched Spotify uris only.


## Related

- [get-urls](https://github.com/sindresorhus/get-urls) - Get all URLs in text
- [linkify-urls](https://github.com/sindresorhus/linkify-urls) - Linkify URLs in text


## License

MIT © [Mark Cicoria](https://github.com/mcicoria), [Kevin Mårtensson](https://github.com/kevva), and [Diego Perini](https://github.com/dperini)

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