itunes-search-client
Advanced tools
Comparing version 0.0.1 to 1.0.0
@@ -24,8 +24,7 @@ export declare type Media = 'movie' | 'music' | 'podcast' | 'musicVideo' | 'audiobook' | 'shortFilm' | 'tvShow' | 'software' | 'ebook' | 'all'; | ||
all: 'actorTerm' | 'languageTerm' | 'allArtistTerm' | 'tvEpisodeTerm' | 'shortFilmTerm' | 'directorTerm' | 'releaseYearTerm' | 'titleTerm' | 'featureFilmTerm' | 'ratingIndex' | 'keywordsTerm' | 'descriptionTerm' | 'authorTerm' | 'genreIndex' | 'mixTerm' | 'allTrackTerm' | 'artistTerm' | 'composerTerm' | 'tvSeasonTerm' | 'producerTerm' | 'ratingTerm' | 'songTerm' | 'movieArtistTerm' | 'showTerm' | 'movieTerm' | 'albumTerm'; | ||
ebook: never; | ||
}; | ||
export declare type ReturnEntity<MediaType> = MediaType extends 'movie' ? Entity['movie'] : MediaType extends 'podcast' ? Entity['podcast'] : MediaType extends 'music' ? Entity['music'] : MediaType extends 'musicVideo' ? Entity['musicVideo'] : MediaType extends 'audiobook' ? Entity['audiobook'] : MediaType extends 'shortFilm' ? Entity['shortFilm'] : MediaType extends 'tvShow' ? Entity['tvShow'] : MediaType extends 'software' ? Entity['software'] : MediaType extends 'ebook' ? Entity['ebook'] : MediaType extends 'all' ? Entity['all'] : never; | ||
export declare type ReturnAttribute<MediaType> = MediaType extends 'movie' ? Attribute['movie'] : MediaType extends 'podcast' ? Attribute['podcast'] : MediaType extends 'music' ? Attribute['music'] : MediaType extends 'musicVideo' ? Attribute['musicVideo'] : MediaType extends 'audiobook' ? Attribute['audiobook'] : MediaType extends 'shortFilm' ? Attribute['shortFilm'] : MediaType extends 'tvShow' ? Attribute['tvShow'] : MediaType extends 'software' ? Attribute['software'] : MediaType extends 'all' ? Attribute['all'] : never; | ||
export declare type Params<MediaType> = { | ||
entity?: ReturnEntity<MediaType>; | ||
attribute?: ReturnAttribute<MediaType>; | ||
export declare type Params<MediaType extends Media> = { | ||
entity?: Entity[MediaType]; | ||
attribute?: Attribute[MediaType]; | ||
media: Media; | ||
@@ -37,7 +36,7 @@ limit: number; | ||
}; | ||
export declare type ItunesSearchClient<MediaType> = { | ||
export declare type ItunesSearchClient<MediaType extends Media> = { | ||
getParams(): Params<MediaType>; | ||
getUrl(): string; | ||
entity(value: ReturnEntity<MediaType>): ItunesSearchClient<MediaType>; | ||
attribute(value: ReturnAttribute<MediaType>): ItunesSearchClient<MediaType>; | ||
entity(value: Entity[MediaType]): ItunesSearchClient<MediaType>; | ||
attribute(value: Attribute[MediaType]): ItunesSearchClient<MediaType>; | ||
limit(value: number): ItunesSearchClient<MediaType>; | ||
@@ -51,5 +50,9 @@ send(options?: Request): Promise<Response>; | ||
}; | ||
export default function itunesSearch(term: string, options?: Options): { | ||
media<M extends Media>(value: M): ItunesSearchClient<M>; | ||
}; | ||
export {}; | ||
declare class ItunesSearch { | ||
private term; | ||
private options; | ||
constructor(term: string, options?: Options); | ||
media: <M extends Media>(value: M) => ItunesSearchClient<M>; | ||
} | ||
export default function itunesSearch(term: string, options?: Options): ItunesSearch; | ||
export { itunesSearch as isc }; |
@@ -39,7 +39,7 @@ "use strict"; | ||
this.send = function (options) { | ||
return fetch(_this.getUrl(), __assign({}, options, { method: 'GET' })); | ||
return fetch(_this.getUrl(), __assign(__assign({}, options), { method: 'GET' })); | ||
}; | ||
this.create = function (key, value) { | ||
var _a; | ||
return new Client(__assign({}, _this.params, (_a = {}, _a[key] = value, _a))); | ||
return new Client(__assign(__assign({}, _this.params), (_a = {}, _a[key] = value, _a))); | ||
}; | ||
@@ -46,0 +46,0 @@ this.params = params; |
{ | ||
"name": "itunes-search-client", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "client for itunse search api.", | ||
"main": "lib/index.js", | ||
"main": "lib/bundle.common.js", | ||
"module": "lib/bundle.module.js", | ||
"author": "highhi", | ||
@@ -11,2 +12,3 @@ "license": "MIT", | ||
"types": "lib/index.d.ts", | ||
"sideEffects": false, | ||
"keywords": [ | ||
@@ -19,3 +21,3 @@ "itunes search api", | ||
"start": "tsc -w", | ||
"build": "tsc", | ||
"build": "rollup -c", | ||
"prepublish": "npm run --if-present build", | ||
@@ -26,20 +28,23 @@ "test": "jest", | ||
"devDependencies": { | ||
"@types/jest": "^24.0.6", | ||
"@types/node": "^11.9.4", | ||
"@types/qs": "^6.5.1", | ||
"@typescript-eslint/eslint-plugin": "^1.4.0", | ||
"@typescript-eslint/parser": "^1.4.0", | ||
"@rollup/plugin-commonjs": "^13.0.0", | ||
"@rollup/plugin-node-resolve": "^8.0.1", | ||
"@types/jest": "^26.0.0", | ||
"@types/node": "^14.0.13", | ||
"@typescript-eslint/eslint-plugin": "^3.3.0", | ||
"@typescript-eslint/parser": "^3.3.0", | ||
"conditional-type-checks": "^1.0.0", | ||
"eslint": "^5.14.1", | ||
"eslint-config-prettier": "^4.0.0", | ||
"eslint": "^7.3.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-prettier": "^3.0.1", | ||
"isomorphic-unfetch": "^3.0.0", | ||
"jest": "^24.1.0", | ||
"prettier": "^1.16.4", | ||
"ts-jest": "^24.0.0", | ||
"jest": "^26.0.1", | ||
"jest-fetch-mock": "^3.0.3", | ||
"prettier": "^2.0.5", | ||
"rollup": "^2.17.1", | ||
"rollup-plugin-terser": "^6.1.0", | ||
"rollup-plugin-typescript2": "^0.27.1", | ||
"ts-jest": "^26.1.0", | ||
"typescript": "^3.3.3" | ||
}, | ||
"dependencies": { | ||
"qs": "^6.6.0" | ||
} | ||
"dependencies": {} | ||
} |
@@ -1,3 +0,1 @@ | ||
import qs from 'qs' | ||
const BASE_PATH = 'https://itunes.apple.com/search' | ||
@@ -69,34 +67,8 @@ | ||
| 'albumTerm' | ||
ebook: never | ||
} | ||
/* eslint-disable */ | ||
export type ReturnEntity<MediaType> = | ||
MediaType extends 'movie' ? Entity['movie'] : | ||
MediaType extends 'podcast' ? Entity['podcast'] : | ||
MediaType extends 'music' ? Entity['music'] : | ||
MediaType extends 'musicVideo' ? Entity['musicVideo'] : | ||
MediaType extends 'audiobook' ? Entity['audiobook'] : | ||
MediaType extends 'shortFilm' ? Entity['shortFilm'] : | ||
MediaType extends 'tvShow' ? Entity['tvShow'] : | ||
MediaType extends 'software' ? Entity['software'] : | ||
MediaType extends 'ebook' ? Entity['ebook'] : | ||
MediaType extends 'all' ? Entity['all'] : | ||
never | ||
export type ReturnAttribute<MediaType> = | ||
MediaType extends 'movie' ? Attribute['movie'] : | ||
MediaType extends 'podcast' ? Attribute['podcast'] : | ||
MediaType extends 'music' ? Attribute['music'] : | ||
MediaType extends 'musicVideo' ? Attribute['musicVideo'] : | ||
MediaType extends 'audiobook' ? Attribute['audiobook'] : | ||
MediaType extends 'shortFilm' ? Attribute['shortFilm'] : | ||
MediaType extends 'tvShow' ? Attribute['tvShow'] : | ||
MediaType extends 'software' ? Attribute['software'] : | ||
MediaType extends 'all' ? Attribute['all'] : | ||
never | ||
/* eslint-enable */ | ||
export type Params<MediaType> = { | ||
entity?: ReturnEntity<MediaType> | ||
attribute?: ReturnAttribute<MediaType> | ||
export type Params<MediaType extends Media> = { | ||
entity?: Entity[MediaType] | ||
attribute?: Attribute[MediaType] | ||
media: Media | ||
@@ -109,7 +81,17 @@ limit: number | ||
export type ItunesSearchClient<MediaType> = { | ||
function qs(params: { [key: string]: any }): string { | ||
return Object.keys(params) | ||
.map((key) => { | ||
const enkey = encodeURIComponent(key) | ||
const envalue = encodeURIComponent(params[key]) | ||
return `${enkey}=${envalue}` | ||
}) | ||
.join('&') | ||
} | ||
export type ItunesSearchClient<MediaType extends Media> = { | ||
getParams(): Params<MediaType> | ||
getUrl(): string | ||
entity(value: ReturnEntity<MediaType>): ItunesSearchClient<MediaType> | ||
attribute(value: ReturnAttribute<MediaType>): ItunesSearchClient<MediaType> | ||
entity(value: Entity[MediaType]): ItunesSearchClient<MediaType> | ||
attribute(value: Attribute[MediaType]): ItunesSearchClient<MediaType> | ||
limit(value: number): ItunesSearchClient<MediaType> | ||
@@ -119,3 +101,3 @@ send(options?: Request): Promise<Response> | ||
class Client<MediaType> implements ItunesSearchClient<MediaType> { | ||
class Client<MediaType extends Media> implements ItunesSearchClient<MediaType> { | ||
private params: Params<MediaType> | ||
@@ -132,11 +114,11 @@ | ||
getUrl = () => { | ||
const queries = qs.stringify(this.params) | ||
const queries = qs(this.params) | ||
return `${BASE_PATH}?${queries}` | ||
} | ||
entity = (value: ReturnEntity<MediaType>) => { | ||
entity = (value: Entity[MediaType]) => { | ||
return this.create('entity', value) | ||
} | ||
attribute = (value: ReturnAttribute<MediaType>) => { | ||
attribute = (value: Attribute[MediaType]) => { | ||
return this.create('attribute', value) | ||
@@ -164,15 +146,27 @@ } | ||
export default function itunesSearch(term: string, options: Options = {}) { | ||
return { | ||
media<M extends Media>(value: M): ItunesSearchClient<M> { | ||
const params: Params<M> = Object.create(null) | ||
params['term'] = term | ||
params['media'] = value | ||
params['limit'] = options.limit || 10 | ||
params['lang'] = options.lang || 'en_us' | ||
params['country'] = options.country || 'us' | ||
class ItunesSearch { | ||
private term = '' | ||
private options: Options = {} | ||
return new Client(params) | ||
}, | ||
constructor(term: string, options: Options = {}) { | ||
this.term = term | ||
this.options = options | ||
} | ||
media = <M extends Media>(value: M): ItunesSearchClient<M> => { | ||
const params: Params<M> = Object.create(null) | ||
params['term'] = this.term | ||
params['media'] = value | ||
params['limit'] = this.options.limit || 10 | ||
params['lang'] = this.options.lang || 'en_us' | ||
params['country'] = this.options.country || 'us' | ||
return new Client(params) | ||
} | ||
} | ||
export default function itunesSearch(term: string, options: Options = {}): ItunesSearch { | ||
return new ItunesSearch(term, options) | ||
} | ||
export { itunesSearch as isc } |
@@ -1,7 +0,6 @@ | ||
import 'isomorphic-unfetch' | ||
import { enableFetchMocks } from 'jest-fetch-mock' | ||
import { assert, IsExact } from 'conditional-type-checks' | ||
import isc, { Entity, Attribute } from '../src' | ||
import { Entity, Attribute, isc } from '../src' | ||
// @ts-ignore | ||
global.fetch = jest.fn() | ||
enableFetchMocks() | ||
@@ -28,3 +27,3 @@ describe('itunes-search-client', () => { | ||
describe('#getParams', () => { | ||
let base: {} | ||
let base: Record<string, unknown> = {} | ||
@@ -80,4 +79,4 @@ beforeEach(() => { | ||
type A = (value: Attribute['movie']) => any | ||
assert<IsExact<typeof client.entity, E>>(true); | ||
assert<IsExact<typeof client.attribute, A>>(true); | ||
assert<IsExact<typeof client.entity, E>>(true) | ||
assert<IsExact<typeof client.attribute, A>>(true) | ||
}) | ||
@@ -89,4 +88,4 @@ | ||
type A = (value: Attribute['music']) => any | ||
assert<IsExact<typeof client.entity, E>>(true); | ||
assert<IsExact<typeof client.attribute, A>>(true); | ||
assert<IsExact<typeof client.entity, E>>(true) | ||
assert<IsExact<typeof client.attribute, A>>(true) | ||
}) | ||
@@ -98,4 +97,4 @@ | ||
type A = (value: Attribute['music']) => any | ||
assert<IsExact<typeof client.entity, E>>(true); | ||
assert<IsExact<typeof client.attribute, A>>(true); | ||
assert<IsExact<typeof client.entity, E>>(true) | ||
assert<IsExact<typeof client.attribute, A>>(true) | ||
}) | ||
@@ -107,4 +106,4 @@ | ||
type A = (value: Attribute['podcast']) => any | ||
assert<IsExact<typeof client.entity, E>>(true); | ||
assert<IsExact<typeof client.attribute, A>>(true); | ||
assert<IsExact<typeof client.entity, E>>(true) | ||
assert<IsExact<typeof client.attribute, A>>(true) | ||
}) | ||
@@ -116,4 +115,4 @@ | ||
type A = (value: Attribute['musicVideo']) => any | ||
assert<IsExact<typeof client.entity, E>>(true); | ||
assert<IsExact<typeof client.attribute, A>>(true); | ||
assert<IsExact<typeof client.entity, E>>(true) | ||
assert<IsExact<typeof client.attribute, A>>(true) | ||
}) | ||
@@ -125,4 +124,4 @@ | ||
type A = (value: Attribute['audiobook']) => any | ||
assert<IsExact<typeof client.entity, E>>(true); | ||
assert<IsExact<typeof client.attribute, A>>(true); | ||
assert<IsExact<typeof client.entity, E>>(true) | ||
assert<IsExact<typeof client.attribute, A>>(true) | ||
}) | ||
@@ -134,4 +133,4 @@ | ||
type A = (value: Attribute['shortFilm']) => any | ||
assert<IsExact<typeof client.entity, E>>(true); | ||
assert<IsExact<typeof client.attribute, A>>(true); | ||
assert<IsExact<typeof client.entity, E>>(true) | ||
assert<IsExact<typeof client.attribute, A>>(true) | ||
}) | ||
@@ -143,4 +142,4 @@ | ||
type A = (value: Attribute['tvShow']) => any | ||
assert<IsExact<typeof client.entity, E>>(true); | ||
assert<IsExact<typeof client.attribute, A>>(true); | ||
assert<IsExact<typeof client.entity, E>>(true) | ||
assert<IsExact<typeof client.attribute, A>>(true) | ||
}) | ||
@@ -152,4 +151,4 @@ | ||
type A = (value: Attribute['software']) => any | ||
assert<IsExact<typeof client.entity, E>>(true); | ||
assert<IsExact<typeof client.attribute, A>>(true); | ||
assert<IsExact<typeof client.entity, E>>(true) | ||
assert<IsExact<typeof client.attribute, A>>(true) | ||
}) | ||
@@ -160,4 +159,5 @@ | ||
type E = (value: Entity['ebook']) => any | ||
assert<IsExact<typeof client.entity, E>>(true); | ||
// ebook attribute does not exist | ||
type A = (value: never) => any | ||
assert<IsExact<typeof client.entity, E>>(true) | ||
assert<IsExact<typeof client.attribute, A>>(true) | ||
}) | ||
@@ -169,6 +169,6 @@ | ||
type A = (value: Attribute['all']) => any | ||
assert<IsExact<typeof client.entity, E>>(true); | ||
assert<IsExact<typeof client.attribute, A>>(true); | ||
assert<IsExact<typeof client.entity, E>>(true) | ||
assert<IsExact<typeof client.attribute, A>>(true) | ||
}) | ||
}) | ||
}) |
@@ -5,3 +5,3 @@ { | ||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ | ||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | ||
"module": "esnext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | ||
// "lib": [], /* Specify library files to be included in the compilation. */ | ||
@@ -11,7 +11,6 @@ // "allowJs": true, /* Allow javascript files to be compiled. */ | ||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ | ||
"declaration": true, /* Generates corresponding '.d.ts' file. */ | ||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ | ||
"declaration": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ | ||
// "sourceMap": true, /* Generates corresponding '.map' file. */ | ||
// "outFile": "./", /* Concatenate and emit output to single file. */ | ||
"outDir": "./lib", /* Redirect output structure to the directory. */ | ||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ | ||
@@ -65,5 +64,3 @@ // "composite": true, /* Enable project compilation */ | ||
"node_modules", | ||
"**/__tests__", | ||
"**/*.test.ts" | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
32392
0
17
524
0
19
3
- Removedqs@^6.6.0
- Removedcall-bind@1.0.7(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedqs@6.13.1(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedside-channel@1.0.6(transitive)