Skip to content

Commit

Permalink
refactor: Add ESM & CJS bundle
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The library exports an object
  • Loading branch information
Kikobeats committed Apr 7, 2022
1 parent d5d523e commit af66e4f
Show file tree
Hide file tree
Showing 18 changed files with 563 additions and 686 deletions.
89 changes: 0 additions & 89 deletions .eslintrc.js

This file was deleted.

19 changes: 19 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
103 changes: 43 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,54 @@
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' }


// you can also format the parsed objects back into a URI or HTTP URL:
// id: '1pKYYY0dkg23sQQXi0Q5zN'
// }
```

uri = spotifyUri.formatURI(parsed);
console.log(uri);
// 'spotify:track:1pKYYY0dkg23sQQXi0Q5zN'
You can also format the parsed objects back into a URI or HTTP URL:

uri = spotifyUri.formatOpenURL(parsed);
console.log(uri);
// 'http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN'
```js
const { parse, formatURI, formatOpenURL, formatPlayURL, formatEmbedURL } = require('spotify-uri')

uri = spotifyUri.formatPlayURL(parsed);
console.log(uri);
// 'https://play.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN'
const parsed = parse('http://open.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'
```

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


## API

### .parse(String uri) → Object
Expand All @@ -75,46 +62,42 @@ passed in. The different "types" are listed below:
Formats a parsed URI Object back into a Spotify URI. For example:

``` 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'
```

### .formatOpenURL(Object parsedUri) → String

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

``` 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'
```

### .formatPlayURL(Object parsedUri) → String

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

``` 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'
```

### .formatEmbedURL(Object parsedUri) → String

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

``` 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).
68 changes: 36 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
"name": "spotify-uri",
"description": "Parse the various Spotify URI formats into Objects and back",
"homepage": "https://github.com/TooTallNate/spotify-uri#readme",
"version": "2.2.2",
"main": "./dist/index.js",
"version": "2.2.1",
"author": {
"email": "[email protected]",
"name": "Nathan Rajlich",
"url": "http://n8.io/"
},
"contributors": [
{
"name": "Nathan Rajlich",
"email": "[email protected]"
"name": "Kiko Beats",
"email": "[email protected]"
},
{
"name": "Stefan Duberg",
Expand All @@ -23,16 +22,16 @@
"email": "[email protected]"
},
{
"name": "Kiko Beats",
"email": "josefrancisco.verdu@gmail.com"
"name": "Shem Magnezi",
"email": "smagnezi8@gmail.com"
},
{
"name": "Miraculous Owonubi",
"email": "omiraculous@gmail.com"
"name": "Marwan Zibaoui",
"email": "marwan.zibaoui@gmail.com"
},
{
"name": "Shem Magnezi",
"email": "smagnezi8@gmail.com"
"name": "Miraculous Owonubi",
"email": "omiraculous@gmail.com"
}
],
"repository": {
Expand All @@ -43,42 +42,47 @@
"url": "https://github.com/TooTallNate/spotify-uri/issues"
},
"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"
},
"files": [
"dist"
],
"scripts": {
"build": "tsc",
"prebuild": "rimraf dist",
"build": "tsup src/index.ts --format esm,cjs --dts",
"prebuild": "rm -rf dist",
"prepublishOnly": "npm run build",
"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"
},
"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"
}
Loading

0 comments on commit af66e4f

Please sign in to comment.