narou 0.5.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.d.ts +30 -0
- package/dist/index.browser.d.ts.map +1 -0
- package/dist/index.browser.js +119 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.common.d.ts +8 -0
- package/dist/index.common.d.ts.map +1 -0
- package/dist/index.common.js +17 -0
- package/dist/index.common.js.map +1 -0
- package/dist/index.d.ts +30 -31
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +120 -113
- package/dist/index.js.map +1 -1
- package/dist/narou-fetch.d.ts +13 -0
- package/dist/narou-fetch.d.ts.map +1 -0
- package/dist/narou-fetch.js +130 -0
- package/dist/narou-fetch.js.map +1 -0
- package/dist/narou-jsonp.d.ts +10 -0
- package/dist/narou-jsonp.d.ts.map +1 -0
- package/dist/narou-jsonp.js +102 -0
- package/dist/narou-jsonp.js.map +1 -0
- package/dist/narou-ranking-results.d.ts +8 -8
- package/dist/narou-ranking-results.js +2 -2
- package/dist/narou-search-results.d.ts +90 -89
- package/dist/narou-search-results.d.ts.map +1 -1
- package/dist/narou-search-results.js +51 -51
- package/dist/narou-search-results.js.map +1 -1
- package/dist/narou.d.ts +24 -25
- package/dist/narou.d.ts.map +1 -1
- package/dist/narou.js +104 -142
- package/dist/narou.js.map +1 -1
- package/dist/params.d.ts +230 -230
- package/dist/params.js +173 -173
- package/dist/ranking-history.d.ts +13 -13
- package/dist/ranking-history.js +13 -13
- package/dist/ranking-history.js.map +1 -1
- package/dist/ranking.d.ts +47 -45
- package/dist/ranking.d.ts.map +1 -1
- package/dist/ranking.js +167 -165
- package/dist/ranking.js.map +1 -1
- package/dist/search-builder-r18.d.ts +21 -21
- package/dist/search-builder-r18.d.ts.map +1 -1
- package/dist/search-builder-r18.js +64 -63
- package/dist/search-builder-r18.js.map +1 -1
- package/dist/search-builder.d.ts +228 -226
- package/dist/search-builder.d.ts.map +1 -1
- package/dist/search-builder.js +412 -412
- package/dist/search-builder.js.map +1 -1
- package/dist/util/jsonp.d.ts +14 -0
- package/dist/util/jsonp.d.ts.map +1 -0
- package/dist/util/jsonp.js +48 -0
- package/dist/util/jsonp.js.map +1 -0
- package/dist/util/unzipp.d.ts +3 -3
- package/dist/util/unzipp.js +56 -56
- package/dist/util/unzipp.js.map +1 -1
- package/dist/util/url.d.ts +10 -0
- package/dist/util/url.d.ts.map +1 -0
- package/dist/util/url.js +9 -0
- package/dist/util/url.js.map +1 -0
- package/dist.es2015/index.browser.js +50 -0
- package/dist.es2015/index.browser.js.map +1 -0
- package/dist.es2015/index.common.js +5 -0
- package/dist.es2015/index.common.js.map +1 -0
- package/dist.es2015/index.js +50 -49
- package/dist.es2015/index.js.map +1 -1
- package/dist.es2015/narou-fetch.js +44 -0
- package/dist.es2015/narou-fetch.js.map +1 -0
- package/dist.es2015/narou-jsonp.js +22 -0
- package/dist.es2015/narou-jsonp.js.map +1 -0
- package/dist.es2015/narou-ranking-results.js +1 -1
- package/dist.es2015/narou-search-results.js +46 -46
- package/dist.es2015/narou-search-results.js.map +1 -1
- package/dist.es2015/narou.js +23 -60
- package/dist.es2015/narou.js.map +1 -1
- package/dist.es2015/params.js +170 -170
- package/dist.es2015/ranking-history.js +9 -9
- package/dist.es2015/ranking.js +90 -90
- package/dist.es2015/ranking.js.map +1 -1
- package/dist.es2015/search-builder-r18.js +41 -42
- package/dist.es2015/search-builder-r18.js.map +1 -1
- package/dist.es2015/search-builder.js +383 -383
- package/dist.es2015/search-builder.js.map +1 -1
- package/dist.es2015/util/jsonp.js +43 -0
- package/dist.es2015/util/jsonp.js.map +1 -0
- package/dist.es2015/util/unzipp.js +7 -7
- package/dist.es2015/util/url.js +7 -0
- package/dist.es2015/util/url.js.map +1 -0
- package/dist.esm/index.browser.js +102 -0
- package/dist.esm/index.browser.js.map +1 -0
- package/dist.esm/index.common.js +5 -0
- package/dist.esm/index.common.js.map +1 -0
- package/dist.esm/index.js +102 -97
- package/dist.esm/index.js.map +1 -1
- package/dist.esm/narou-fetch.js +128 -0
- package/dist.esm/narou-fetch.js.map +1 -0
- package/dist.esm/narou-jsonp.js +100 -0
- package/dist.esm/narou-jsonp.js.map +1 -0
- package/dist.esm/narou-ranking-results.js +1 -1
- package/dist.esm/narou-search-results.js +49 -49
- package/dist.esm/narou-search-results.js.map +1 -1
- package/dist.esm/narou.js +102 -140
- package/dist.esm/narou.js.map +1 -1
- package/dist.esm/params.js +170 -170
- package/dist.esm/ranking-history.js +9 -9
- package/dist.esm/ranking.js +164 -162
- package/dist.esm/ranking.js.map +1 -1
- package/dist.esm/search-builder-r18.js +62 -61
- package/dist.esm/search-builder-r18.js.map +1 -1
- package/dist.esm/search-builder.js +410 -410
- package/dist.esm/search-builder.js.map +1 -1
- package/dist.esm/util/jsonp.js +44 -0
- package/dist.esm/util/jsonp.js.map +1 -0
- package/dist.esm/util/unzipp.js +52 -52
- package/dist.esm/util/url.js +7 -0
- package/dist.esm/util/url.js.map +1 -0
- package/package-lock.json +3328 -4289
- package/package.json +8 -9
- package/src/index.browser.ts +63 -0
- package/src/index.common.ts +17 -0
- package/src/index.ts +22 -23
- package/src/narou-fetch.ts +51 -0
- package/src/narou-jsonp.ts +29 -0
- package/src/narou-ranking-results.ts +9 -9
- package/src/narou-search-results.ts +11 -10
- package/src/narou.ts +21 -49
- package/src/params.ts +280 -280
- package/src/ranking.ts +111 -107
- package/src/search-builder-r18.ts +1 -2
- package/src/search-builder.ts +5 -3
- package/src/util/jsonp.ts +66 -0
- package/src/util/unzipp.ts +9 -9
- package/src/util/url.ts +7 -0
package/src/ranking.ts
CHANGED
|
@@ -1,107 +1,111 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
protected
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
*
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
builder.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
1
|
+
import { NarouRankingResult, RankingResult } from "./narou-ranking-results";
|
|
2
|
+
import { Fields } from "./index";
|
|
3
|
+
import SearchBuilder from "./search-builder";
|
|
4
|
+
import { addDays, format } from "date-fns";
|
|
5
|
+
import { RankingParams } from "./params";
|
|
6
|
+
import NarouNovel from "./narou";
|
|
7
|
+
import NarouNovelFetch from "./narou-fetch";
|
|
8
|
+
|
|
9
|
+
export enum RankingType {
|
|
10
|
+
Daily = "d",
|
|
11
|
+
Weekly = "w",
|
|
12
|
+
Monthly = "m",
|
|
13
|
+
Quarterly = "q",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const dateFormat = "yyyyMMdd";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* ランキングヘルパー
|
|
20
|
+
* @class Ranking
|
|
21
|
+
*/
|
|
22
|
+
export default class RankingBuilder {
|
|
23
|
+
protected date$: Date;
|
|
24
|
+
protected type$: RankingType;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* constructor
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
constructor(
|
|
31
|
+
protected params: Partial<RankingParams> = {},
|
|
32
|
+
protected api: NarouNovel
|
|
33
|
+
) {
|
|
34
|
+
/**
|
|
35
|
+
* クエリパラメータ
|
|
36
|
+
* @protected
|
|
37
|
+
*/
|
|
38
|
+
this.date$ = addDays(Date.now(), -1);
|
|
39
|
+
this.type$ = RankingType.Daily;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
date(date: Date) {
|
|
43
|
+
this.date$ = date;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type(type: RankingType) {
|
|
48
|
+
this.type$ = type;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* gzip圧縮する。
|
|
54
|
+
*
|
|
55
|
+
* 転送量上限を減らすためにも推奨
|
|
56
|
+
* @param {number} level gzip圧縮レベル(1~5)
|
|
57
|
+
* @return {RankingBuilder} this
|
|
58
|
+
*/
|
|
59
|
+
gzip(level: number) {
|
|
60
|
+
this.set({ gzip: level });
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* クエリパラメータをセットする
|
|
66
|
+
* @private
|
|
67
|
+
* @return {RankingBuilder} this
|
|
68
|
+
*/
|
|
69
|
+
protected set(obj: any) {
|
|
70
|
+
Object.assign(this.params, obj);
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* なろう小説APIへのリクエストを実行する
|
|
76
|
+
* @returns ランキング
|
|
77
|
+
*/
|
|
78
|
+
execute(): Promise<NarouRankingResult[]> {
|
|
79
|
+
const date = format(this.date$, dateFormat);
|
|
80
|
+
this.set({ rtype: `${date}-${this.type$}` });
|
|
81
|
+
return this.api.executeRanking(this.params as RankingParams);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async executeWithFields(
|
|
85
|
+
fields: Fields | Fields[] = [],
|
|
86
|
+
opt?: "weekly"
|
|
87
|
+
): Promise<RankingResult[]> {
|
|
88
|
+
const ranking = await this.execute();
|
|
89
|
+
const fields$: Fields[] = Array.isArray(fields)
|
|
90
|
+
? fields.length == 0
|
|
91
|
+
? []
|
|
92
|
+
: [...fields, Fields.ncode]
|
|
93
|
+
: [fields, Fields.ncode];
|
|
94
|
+
|
|
95
|
+
const rankingNcodes = ranking.map(({ ncode }) => ncode);
|
|
96
|
+
const builder = new SearchBuilder({}, this.api);
|
|
97
|
+
builder.fields(fields$);
|
|
98
|
+
if (opt) {
|
|
99
|
+
builder.opt(opt);
|
|
100
|
+
}
|
|
101
|
+
builder.ncode(rankingNcodes);
|
|
102
|
+
builder.limit(ranking.length);
|
|
103
|
+
const result = await builder.execute();
|
|
104
|
+
|
|
105
|
+
// TODO: 型的にはNull許容ではないが許容しているのでなんとかする(削除されている小説がある)
|
|
106
|
+
return ranking.map<RankingResult>((r) => ({
|
|
107
|
+
...r,
|
|
108
|
+
...(result.values.find((novel) => novel.ncode == r.ncode) ?? ({} as any)),
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import api from "./narou";
|
|
2
1
|
import SearchBuilder from "./search-builder";
|
|
3
2
|
import INarouSearchResults from "./narou-search-results";
|
|
4
3
|
import { R18Site } from "./params";
|
|
@@ -14,7 +13,7 @@ export default class SearchBuilderR18 extends SearchBuilder {
|
|
|
14
13
|
* @returns {Promise<INarouSearchResults>} 検索結果
|
|
15
14
|
*/
|
|
16
15
|
execute(): Promise<INarouSearchResults> {
|
|
17
|
-
return api.executeNovel18(this.params);
|
|
16
|
+
return this.api.executeNovel18(this.params);
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
r18Site(sites: R18Site | R18Site[]) {
|
package/src/search-builder.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { NarouNovel } from ".";
|
|
1
2
|
import api from "./narou";
|
|
3
|
+
import NarouNovelFetch from "./narou-fetch";
|
|
2
4
|
import INarouSearchResults from "./narou-search-results";
|
|
3
5
|
import { BigGenre, Genre } from "./params";
|
|
4
6
|
import {
|
|
@@ -7,7 +9,7 @@ import {
|
|
|
7
9
|
Order,
|
|
8
10
|
Buntai,
|
|
9
11
|
NovelType,
|
|
10
|
-
GzipLevel
|
|
12
|
+
GzipLevel,
|
|
11
13
|
} from "./params";
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -19,7 +21,7 @@ export default class SearchBuilder {
|
|
|
19
21
|
* constructor
|
|
20
22
|
* @private
|
|
21
23
|
*/
|
|
22
|
-
constructor(protected params: SearchParams = {}) {}
|
|
24
|
+
constructor(protected params: SearchParams = {}, protected api: NarouNovel) {}
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* a
|
|
@@ -423,7 +425,7 @@ export default class SearchBuilder {
|
|
|
423
425
|
* @returns {Promise<NarouSearchResults>} 検索結果
|
|
424
426
|
*/
|
|
425
427
|
execute(): Promise<INarouSearchResults> {
|
|
426
|
-
return api.executeNovel(this.params);
|
|
428
|
+
return this.api.executeNovel(this.params);
|
|
427
429
|
}
|
|
428
430
|
}
|
|
429
431
|
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT license
|
|
3
|
+
*/
|
|
4
|
+
import nodeURL from "./url";
|
|
5
|
+
|
|
6
|
+
// Callback index.
|
|
7
|
+
let count = 0;
|
|
8
|
+
|
|
9
|
+
type CallbackId<Prefix extends string = string> = `${Prefix}${number}`;
|
|
10
|
+
|
|
11
|
+
declare global {
|
|
12
|
+
interface Window {
|
|
13
|
+
[key: CallbackId]: (data: any) => void;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export type JsonpOption = {
|
|
17
|
+
prefix?: string;
|
|
18
|
+
param?: string;
|
|
19
|
+
timeout?: number;
|
|
20
|
+
};
|
|
21
|
+
const noop = function () {};
|
|
22
|
+
|
|
23
|
+
export function jsonp<T>(
|
|
24
|
+
url: string,
|
|
25
|
+
{ prefix = "__jp", param = "callback", timeout = 15000 }: JsonpOption = {}
|
|
26
|
+
): Promise<T> {
|
|
27
|
+
return new Promise(function (resolve, reject) {
|
|
28
|
+
const targetChild = document.getElementsByTagName("script").item(0);
|
|
29
|
+
const target = targetChild?.parentNode ?? document.head;
|
|
30
|
+
|
|
31
|
+
const id: CallbackId = `${prefix}${count++}`;
|
|
32
|
+
const cleanup = function () {
|
|
33
|
+
// Remove the script tag.
|
|
34
|
+
if (script && script.parentNode) {
|
|
35
|
+
script.parentNode.removeChild(script);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
window[id] = noop;
|
|
39
|
+
|
|
40
|
+
if (timer) {
|
|
41
|
+
clearTimeout(timer);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const timer =
|
|
46
|
+
timeout > 0
|
|
47
|
+
? setTimeout(() => {
|
|
48
|
+
cleanup();
|
|
49
|
+
reject(new Error("Timeout"));
|
|
50
|
+
}, timeout)
|
|
51
|
+
: undefined;
|
|
52
|
+
|
|
53
|
+
const callback = (data: T) => {
|
|
54
|
+
cleanup();
|
|
55
|
+
resolve(data);
|
|
56
|
+
};
|
|
57
|
+
window[id] = callback;
|
|
58
|
+
|
|
59
|
+
// Create script.
|
|
60
|
+
const script = document.createElement("script");
|
|
61
|
+
const urlObj = new nodeURL(url);
|
|
62
|
+
urlObj.searchParams.set(param, id);
|
|
63
|
+
script.setAttribute("src", urlObj.toString());
|
|
64
|
+
target.insertBefore(script, targetChild);
|
|
65
|
+
});
|
|
66
|
+
}
|
package/src/util/unzipp.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { gunzip, InputType } from "zlib";
|
|
2
|
-
import { promisify } from "util";
|
|
3
|
-
|
|
4
|
-
const gunzipAsync = promisify<InputType, Buffer>(gunzip);
|
|
5
|
-
|
|
6
|
-
export async function unzipp(data: InputType) {
|
|
7
|
-
const buffer = await gunzipAsync(data);
|
|
8
|
-
return JSON.parse(buffer.toString());
|
|
9
|
-
}
|
|
1
|
+
import { gunzip, InputType } from "zlib";
|
|
2
|
+
import { promisify } from "util";
|
|
3
|
+
|
|
4
|
+
const gunzipAsync = promisify<InputType, Buffer>(gunzip);
|
|
5
|
+
|
|
6
|
+
export async function unzipp(data: InputType) {
|
|
7
|
+
const buffer = await gunzipAsync(data);
|
|
8
|
+
return JSON.parse(buffer.toString());
|
|
9
|
+
}
|