narou 0.8.0 → 0.9.0

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.
Files changed (130) hide show
  1. package/dist/chunk-3UZPHZZH.js +43 -0
  2. package/dist/chunk-46WN4HIZ.js +25 -0
  3. package/dist/chunk-55V5YY6H.js +71 -0
  4. package/dist/chunk-5OZA6DNS.js +14 -0
  5. package/dist/chunk-67BSHN66.js +82 -0
  6. package/dist/chunk-6SHYBHWX.js +0 -0
  7. package/dist/chunk-AIRK7Y7G.js +0 -0
  8. package/dist/chunk-C54MSVRN.js +3064 -0
  9. package/dist/chunk-EQL67JCA.js +38 -0
  10. package/dist/chunk-IKR7OZGM.js +49 -0
  11. package/dist/chunk-IVQKYEQQ.js +371 -0
  12. package/dist/chunk-JFVJBECE.js +36 -0
  13. package/dist/chunk-JS5XPNGB.js +93 -0
  14. package/dist/chunk-OVGZ6RWT.js +23 -0
  15. package/dist/chunk-U3H4E2XZ.js +396 -0
  16. package/dist/index.browser.cjs +1221 -0
  17. package/dist/index.browser.d.cts +40 -0
  18. package/dist/index.browser.d.ts +40 -36
  19. package/dist/index.browser.js +127 -83
  20. package/dist/index.cjs +4305 -0
  21. package/dist/index.common.cjs +1032 -0
  22. package/dist/index.common.d.cts +6 -0
  23. package/dist/index.common.d.ts +6 -15
  24. package/dist/index.common.js +74 -35
  25. package/dist/index.d.cts +47 -0
  26. package/dist/index.d.ts +47 -43
  27. package/dist/index.js +132 -91
  28. package/dist/narou-61329eea.d.ts +298 -0
  29. package/dist/narou-98ededc8.d.ts +298 -0
  30. package/dist/narou-fetch.cjs +3190 -0
  31. package/dist/narou-fetch.d.cts +16 -0
  32. package/dist/narou-fetch.d.ts +16 -13
  33. package/dist/narou-fetch.js +10 -46
  34. package/dist/narou-jsonp.cjs +158 -0
  35. package/dist/narou-jsonp.d.cts +13 -0
  36. package/dist/narou-jsonp.d.ts +13 -10
  37. package/dist/narou-jsonp.js +10 -24
  38. package/dist/narou-ranking-results.cjs +18 -0
  39. package/dist/narou-ranking-results.d.cts +4 -0
  40. package/dist/narou-ranking-results.d.ts +4 -10
  41. package/dist/narou-ranking-results.js +1 -3
  42. package/dist/narou-search-results-6727b1ce.d.ts +716 -0
  43. package/dist/narou-search-results-b7c10db0.d.ts +716 -0
  44. package/dist/narou-search-results.cjs +61 -0
  45. package/dist/narou-search-results.d.cts +2 -0
  46. package/dist/narou-search-results.d.ts +2 -131
  47. package/dist/narou-search-results.js +11 -63
  48. package/dist/narou.cjs +108 -0
  49. package/dist/narou.d.cts +4 -0
  50. package/dist/narou.d.ts +4 -26
  51. package/dist/narou.js +8 -30
  52. package/dist/params.cjs +436 -0
  53. package/dist/params.d.cts +2 -0
  54. package/dist/params.d.ts +2 -324
  55. package/dist/params.js +39 -247
  56. package/dist/ranking-history.cjs +38 -0
  57. package/dist/ranking-history.d.cts +17 -0
  58. package/dist/ranking-history.d.ts +17 -14
  59. package/dist/ranking-history.js +7 -14
  60. package/dist/ranking.cjs +659 -0
  61. package/dist/ranking.d.cts +47 -0
  62. package/dist/ranking.d.ts +47 -46
  63. package/dist/ranking.js +9 -87
  64. package/dist/search-builder-r18.cjs +473 -0
  65. package/dist/search-builder-r18.d.cts +32 -0
  66. package/dist/search-builder-r18.d.ts +32 -29
  67. package/dist/search-builder-r18.js +9 -45
  68. package/dist/search-builder.cjs +510 -0
  69. package/dist/search-builder.d.cts +4 -0
  70. package/dist/search-builder.d.ts +4 -220
  71. package/dist/search-builder.js +12 -381
  72. package/dist/user-search.cjs +300 -0
  73. package/dist/user-search.d.cts +66 -0
  74. package/dist/user-search.d.ts +66 -63
  75. package/dist/user-search.js +9 -94
  76. package/dist/util/jsonp.cjs +62 -0
  77. package/dist/util/jsonp.d.cts +13 -0
  78. package/dist/util/jsonp.d.ts +13 -17
  79. package/dist/util/jsonp.js +7 -46
  80. package/dist/util/type.cjs +18 -0
  81. package/dist/util/type.d.cts +4 -0
  82. package/dist/util/type.d.ts +4 -4
  83. package/dist/util/type.js +0 -3
  84. package/dist/util/unzipp.cjs +47 -0
  85. package/dist/util/unzipp.d.cts +3 -0
  86. package/dist/util/unzipp.d.ts +3 -4
  87. package/dist/util/unzipp.js +7 -12
  88. package/package.json +35 -33
  89. package/src/narou-fetch.ts +6 -16
  90. package/src/narou-jsonp.ts +0 -2
  91. package/src/narou-ranking-results.ts +10 -0
  92. package/src/narou-search-results.ts +118 -63
  93. package/src/narou.ts +42 -3
  94. package/src/params.ts +220 -61
  95. package/src/user-search.ts +109 -109
  96. package/src/util/unzipp.ts +13 -3
  97. package/dist/index.browser.d.ts.map +0 -1
  98. package/dist/index.browser.js.map +0 -1
  99. package/dist/index.common.d.ts.map +0 -1
  100. package/dist/index.common.js.map +0 -1
  101. package/dist/index.d.ts.map +0 -1
  102. package/dist/index.js.map +0 -1
  103. package/dist/narou-fetch.d.ts.map +0 -1
  104. package/dist/narou-fetch.js.map +0 -1
  105. package/dist/narou-jsonp.d.ts.map +0 -1
  106. package/dist/narou-jsonp.js.map +0 -1
  107. package/dist/narou-ranking-results.d.ts.map +0 -1
  108. package/dist/narou-ranking-results.js.map +0 -1
  109. package/dist/narou-search-results.d.ts.map +0 -1
  110. package/dist/narou-search-results.js.map +0 -1
  111. package/dist/narou.d.ts.map +0 -1
  112. package/dist/narou.js.map +0 -1
  113. package/dist/params.d.ts.map +0 -1
  114. package/dist/params.js.map +0 -1
  115. package/dist/ranking-history.d.ts.map +0 -1
  116. package/dist/ranking-history.js.map +0 -1
  117. package/dist/ranking.d.ts.map +0 -1
  118. package/dist/ranking.js.map +0 -1
  119. package/dist/search-builder-r18.d.ts.map +0 -1
  120. package/dist/search-builder-r18.js.map +0 -1
  121. package/dist/search-builder.d.ts.map +0 -1
  122. package/dist/search-builder.js.map +0 -1
  123. package/dist/user-search.d.ts.map +0 -1
  124. package/dist/user-search.js.map +0 -1
  125. package/dist/util/jsonp.d.ts.map +0 -1
  126. package/dist/util/jsonp.js.map +0 -1
  127. package/dist/util/type.d.ts.map +0 -1
  128. package/dist/util/type.js.map +0 -1
  129. package/dist/util/unzipp.d.ts.map +0 -1
  130. package/dist/util/unzipp.js.map +0 -1
@@ -0,0 +1,43 @@
1
+ import {
2
+ NovelSearchBuilderBase
3
+ } from "./chunk-IVQKYEQQ.js";
4
+
5
+ // src/search-builder-r18.ts
6
+ var SearchBuilderR18 = class extends NovelSearchBuilderBase {
7
+ /**
8
+ * なろう小説APIへの検索リクエストを実行する
9
+ * @override
10
+ * @returns {Promise<NarouSearchResults>} 検索結果
11
+ */
12
+ execute() {
13
+ return this.api.executeNovel18(this.params);
14
+ }
15
+ r18Site(sites) {
16
+ this.set({ nocgenre: NovelSearchBuilderBase.array2string(sites) });
17
+ return this;
18
+ }
19
+ /**
20
+ *
21
+ * @return {SearchBuilder} this
22
+ */
23
+ xid(ids) {
24
+ this.set({ xid: NovelSearchBuilderBase.array2string(ids) });
25
+ return this;
26
+ }
27
+ /**
28
+ *
29
+ * @return {SearchBuilder} this
30
+ */
31
+ fields(fields) {
32
+ this.set({ of: NovelSearchBuilderBase.array2string(fields) });
33
+ return this;
34
+ }
35
+ opt(option) {
36
+ this.set({ opt: NovelSearchBuilderBase.array2string(option) });
37
+ return this;
38
+ }
39
+ };
40
+
41
+ export {
42
+ SearchBuilderR18
43
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ jsonp
3
+ } from "./chunk-EQL67JCA.js";
4
+ import {
5
+ NarouNovel
6
+ } from "./chunk-55V5YY6H.js";
7
+
8
+ // src/narou-jsonp.ts
9
+ var NarouNovelJsonp = class extends NarouNovel {
10
+ async execute(params, endpoint) {
11
+ const query = { ...params, out: "jsonp" };
12
+ query.gzip = 0;
13
+ const url = new URL(endpoint);
14
+ Object.entries(query).forEach(([key, value]) => {
15
+ if (value) {
16
+ url.searchParams.append(key, value.toString());
17
+ }
18
+ });
19
+ return await jsonp(url.toString());
20
+ }
21
+ };
22
+
23
+ export {
24
+ NarouNovelJsonp
25
+ };
@@ -0,0 +1,71 @@
1
+ import {
2
+ NarouSearchResults
3
+ } from "./chunk-JFVJBECE.js";
4
+
5
+ // src/narou.ts
6
+ var NarouNovel = class {
7
+ /**
8
+ * APIへの検索リクエストを実行する
9
+ * @param params クエリパラメータ
10
+ * @param endpoint APIエンドポイント
11
+ * @returns 検索結果
12
+ */
13
+ async executeSearch(params, endpoint = "https://api.syosetu.com/novelapi/api/") {
14
+ return new NarouSearchResults(await this.execute(params, endpoint), params);
15
+ }
16
+ /**
17
+ * 小説APIへの検索リクエストを実行する
18
+ * @param params クエリパラメータ
19
+ * @returns 検索結果
20
+ * @see https://dev.syosetu.com/man/api/
21
+ */
22
+ async executeNovel(params) {
23
+ return await this.executeSearch(
24
+ params,
25
+ "https://api.syosetu.com/novelapi/api/"
26
+ );
27
+ }
28
+ /**
29
+ * R18小説APIへの検索リクエストを実行する
30
+ * @param params クエリパラメータ
31
+ * @returns 検索結果
32
+ * @see https://dev.syosetu.com/xman/api/
33
+ */
34
+ async executeNovel18(params) {
35
+ return await this.executeSearch(
36
+ params,
37
+ "https://api.syosetu.com/novel18api/api/"
38
+ );
39
+ }
40
+ /**
41
+ * ランキングAPIへのリクエストを実行する
42
+ * @param params クエリパラメータ
43
+ * @returns ランキング結果
44
+ * @see https://dev.syosetu.com/man/rankapi/
45
+ */
46
+ async executeRanking(params) {
47
+ return await this.execute(params, "https://api.syosetu.com/rank/rankget/");
48
+ }
49
+ /**
50
+ * 殿堂入りAPiへのリクエストを実行する
51
+ * @param params クエリパラメータ
52
+ * @returns ランキング履歴結果
53
+ * @see https://dev.syosetu.com/man/rankinapi/
54
+ */
55
+ async executeRankingHistory(params) {
56
+ return await this.execute(params, "https://api.syosetu.com/rank/rankin/");
57
+ }
58
+ /**
59
+ * ユーザー検索APIへのリクエストを実行する
60
+ * @param params クエリパラメータ
61
+ * @returns 検索結果
62
+ * @see https://dev.syosetu.com/man/userapi/
63
+ */
64
+ async executeUserSearch(params) {
65
+ return await this.execute(params, "https://api.syosetu.com/userapi/api/");
66
+ }
67
+ };
68
+
69
+ export {
70
+ NarouNovel
71
+ };
@@ -0,0 +1,14 @@
1
+ // src/ranking-history.ts
2
+ import { parse } from "date-fns";
3
+ var dateFormat = "yyyyMMdd";
4
+ function formatRankingHistory(rankin) {
5
+ const { rtype, pt, rank } = rankin;
6
+ const [_date, _type] = rtype.split("-");
7
+ const date = parse(_date, dateFormat, /* @__PURE__ */ new Date());
8
+ const type = _type;
9
+ return { type, date, pt, rank };
10
+ }
11
+
12
+ export {
13
+ formatRankingHistory
14
+ };
@@ -0,0 +1,82 @@
1
+ import {
2
+ SearchBuilder
3
+ } from "./chunk-IVQKYEQQ.js";
4
+ import {
5
+ Fields,
6
+ RankingType
7
+ } from "./chunk-U3H4E2XZ.js";
8
+
9
+ // src/ranking.ts
10
+ import { addDays, format } from "date-fns";
11
+ var dateFormat = "yyyyMMdd";
12
+ var RankingBuilder = class {
13
+ /**
14
+ * constructor
15
+ * @private
16
+ */
17
+ constructor(params = {}, api) {
18
+ this.params = params;
19
+ this.api = api;
20
+ this.date$ = addDays(Date.now(), -1);
21
+ this.type$ = RankingType.Daily;
22
+ }
23
+ date(date) {
24
+ this.date$ = date;
25
+ return this;
26
+ }
27
+ type(type) {
28
+ this.type$ = type;
29
+ return this;
30
+ }
31
+ /**
32
+ * gzip圧縮する。
33
+ *
34
+ * 転送量上限を減らすためにも推奨
35
+ * @param {GzipLevel} level gzip圧縮レベル(1~5)
36
+ * @return {RankingBuilder} this
37
+ */
38
+ gzip(level) {
39
+ this.set({ gzip: level });
40
+ return this;
41
+ }
42
+ /**
43
+ * クエリパラメータをセットする
44
+ * @private
45
+ * @return {RankingBuilder} this
46
+ */
47
+ set(obj) {
48
+ Object.assign(this.params, obj);
49
+ return this;
50
+ }
51
+ /**
52
+ * なろう小説APIへのリクエストを実行する
53
+ * @returns ランキング
54
+ */
55
+ execute() {
56
+ const date = format(this.date$, dateFormat);
57
+ this.set({ rtype: `${date}-${this.type$}` });
58
+ return this.api.executeRanking(this.params);
59
+ }
60
+ async executeWithFields(fields = [], opt) {
61
+ const ranking = await this.execute();
62
+ const fields$ = Array.isArray(fields) ? fields.length == 0 ? [] : [...fields, Fields.ncode] : [fields, Fields.ncode];
63
+ const rankingNcodes = ranking.map(({ ncode }) => ncode);
64
+ const builder = new SearchBuilder({}, this.api);
65
+ builder.fields(fields$);
66
+ if (opt) {
67
+ builder.opt(opt);
68
+ }
69
+ builder.ncode(rankingNcodes);
70
+ builder.limit(ranking.length);
71
+ const result = await builder.execute();
72
+ return ranking.map((r) => ({
73
+ ...r,
74
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
+ ...result.values.find((novel) => novel.ncode == r.ncode)
76
+ }));
77
+ }
78
+ };
79
+
80
+ export {
81
+ RankingBuilder
82
+ };
File without changes
File without changes