searchitunes
Advanced tools
Comparing version 2.5.4 to 2.5.5
// Load module | ||
const itunes = require ('searchitunes'); | ||
const itunes = require( 'searchitunes' ); | ||
// Find an app | ||
itunes ({ | ||
itunes( { | ||
entity: 'software', | ||
@@ -12,9 +12,9 @@ country: 'NL', | ||
}) | ||
.then (data => console.dir (data, { | ||
} ) | ||
.then( data => console.dir( data, { | ||
depth: null, | ||
colors: true, | ||
})) | ||
.catch (console.error) | ||
} ) ) | ||
.catch( console.error ) | ||
; | ||
@@ -9,3 +9,3 @@ { | ||
"description": "Search the Apple iTunes Store and App Store with this lightweight module", | ||
"version": "2.5.4", | ||
"version": "2.5.5", | ||
"repository": { | ||
@@ -26,6 +26,6 @@ "type": "git", | ||
"devDependencies": { | ||
"dotest": "^2.9.0" | ||
"dotest": "^2.12.2" | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=14" | ||
}, | ||
@@ -32,0 +32,0 @@ "keywords": [ |
@@ -13,20 +13,20 @@ # searchitunes | ||
```js | ||
const searchitunes = require ('searchitunes'); | ||
const searchitunes = require( 'searchitunes' ); | ||
// Find free Github app for iPhone in Dutch App Store | ||
searchitunes ({ | ||
entity: 'software', | ||
searchitunes( { | ||
entity: 'software', | ||
country: 'NL', | ||
term: 'github', | ||
limit: 1, | ||
price: 0, | ||
}) | ||
.then (console.log) | ||
.catch (console.error) | ||
term: 'github', | ||
limit: 1, | ||
price: 0, | ||
} ) | ||
.then( console.log ) | ||
.catch( console.error ) | ||
; | ||
// Get one specific item by ID | ||
searchitunes ({ id: 512939461 }) | ||
.then (console.log) | ||
.catch (console.error) | ||
searchitunes( { id: 512939461 } ) | ||
.then( console.log ) | ||
.catch( console.error ) | ||
; | ||
@@ -60,7 +60,7 @@ ``` | ||
```js | ||
itunes ({ | ||
itunes( { | ||
timeout: 8000, | ||
entity: 'software', | ||
term: 'github', | ||
}) | ||
entity: 'software', | ||
term: 'github', | ||
} ) | ||
``` | ||
@@ -75,3 +75,3 @@ | ||
- [Search-API docs](https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/#overview) | ||
- [Search API docs](https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/iTuneSearchAPI/) | ||
- [Live demo](https://npm.runkit.com/searchitunes) | ||
@@ -86,3 +86,3 @@ | ||
- [Lookup-API docs](https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/#lookup) | ||
- [Lookup API docs](https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/iTuneSearchAPI/LookupExamples.html) | ||
@@ -105,5 +105,5 @@ | ||
```js | ||
searchitunes ({ id: 123456 }) | ||
.then (console.log) | ||
.catch (console.error) | ||
searchitunes( { id: 123456 } ) | ||
.then( console.log ) | ||
.catch( console.error ) | ||
; | ||
@@ -145,1 +145,2 @@ ``` | ||
| [buy me a coffee](https://fvdm.com/donating) | ||
@@ -9,3 +9,3 @@ /* | ||
const { doRequest } = require ('httpreq'); | ||
const { doRequest } = require( 'httpreq' ); | ||
@@ -21,3 +21,4 @@ | ||
async function keysInObject (obj) { | ||
async function keysInObject ( obj ) { | ||
const objKeys = Object.keys( obj ); | ||
const keys = [ | ||
@@ -32,9 +33,3 @@ 'amgAlbumId', | ||
for (let i = 0; i < keys.length; i++) { | ||
if (obj[keys[i]]) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
return objKeys.some( key => keys.includes( key ) ); | ||
} | ||
@@ -52,13 +47,13 @@ | ||
async function httpResponse ({ | ||
async function httpResponse ( { | ||
res, | ||
first = false, | ||
}) { | ||
const data = JSON.parse (res.body); | ||
} ) { | ||
const data = JSON.parse( res.body ); | ||
if (!data.results || !data.results.length) { | ||
throw new Error ('no results'); | ||
if ( ! data.results || ! data.results.length ) { | ||
throw new Error( 'no results' ); | ||
} | ||
if (first) { | ||
if ( first ) { | ||
return data.results[0]; | ||
@@ -81,7 +76,7 @@ } | ||
module.exports = async function SearchItunes ({ | ||
module.exports = async function SearchItunes ( { | ||
timeout = 5000, | ||
userAgent = 'searchitunes.js', | ||
trackId, | ||
}) { | ||
} ) { | ||
let first; | ||
@@ -100,3 +95,3 @@ let options = { | ||
// Convert trackId from a search response | ||
if (trackId) { | ||
if ( trackId ) { | ||
options.parameters.id = trackId; | ||
@@ -107,5 +102,5 @@ delete options.parameters.trackId; | ||
// Search or lookup | ||
const hasKeys = await keysInObject (options.parameters); | ||
const hasKeys = await keysInObject( options.parameters ); | ||
if (hasKeys) { | ||
if ( hasKeys ) { | ||
options.url = 'https://itunes.apple.com/lookup'; | ||
@@ -119,6 +114,5 @@ first = true; | ||
const res = await doRequest (options); | ||
const res = await doRequest( options ); | ||
return httpResponse ({ res, first }); | ||
return httpResponse( { res, first } ); | ||
}; | ||
8583
141
106