narou 1.0.0 → 1.2.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 (148) hide show
  1. package/README.md +7 -0
  2. package/dist/{chunk-RITMMCZE.js → chunk-3A5MHPWL.js} +1 -1
  3. package/dist/chunk-3A5MHPWL.js.map +1 -0
  4. package/dist/{chunk-6RIDVTFQ.js → chunk-5UDKQCPJ.js} +12 -2
  5. package/dist/chunk-5UDKQCPJ.js.map +1 -0
  6. package/dist/{chunk-UN3W2CT3.js → chunk-6BZWV4ZC.js} +6 -3
  7. package/dist/{chunk-UN3W2CT3.js.map → chunk-6BZWV4ZC.js.map} +1 -1
  8. package/dist/chunk-BQLSW236.js +117 -0
  9. package/dist/chunk-BQLSW236.js.map +1 -0
  10. package/dist/{chunk-DBCAWGIX.js → chunk-DEQICAN3.js} +2 -2
  11. package/dist/chunk-E2H3AJSQ.js +57 -0
  12. package/dist/chunk-E2H3AJSQ.js.map +1 -0
  13. package/dist/chunk-HOBLKBZ6.js +452 -0
  14. package/dist/chunk-HOBLKBZ6.js.map +1 -0
  15. package/dist/{chunk-TNDGN3EF.js → chunk-IPDEGCWU.js} +1 -1
  16. package/dist/chunk-IPDEGCWU.js.map +1 -0
  17. package/dist/{chunk-GAEL5UWA.js → chunk-LQLNWSWV.js} +4 -4
  18. package/dist/{chunk-GAEL5UWA.js.map → chunk-LQLNWSWV.js.map} +1 -1
  19. package/dist/{chunk-NP5NZV5Q.js → chunk-PLEM2AOH.js} +8 -5
  20. package/dist/chunk-PLEM2AOH.js.map +1 -0
  21. package/dist/chunk-RNHRR56W.js +25 -0
  22. package/dist/chunk-RNHRR56W.js.map +1 -0
  23. package/dist/{chunk-JMTNQTNC.js → chunk-VUZIISP2.js} +2 -3
  24. package/dist/chunk-VUZIISP2.js.map +1 -0
  25. package/dist/{chunk-XAUB42TO.js → chunk-VZVUANDN.js} +6 -4
  26. package/dist/chunk-VZVUANDN.js.map +1 -0
  27. package/dist/index.browser.cjs +245 -94
  28. package/dist/index.browser.cjs.map +1 -1
  29. package/dist/index.browser.d.cts +24 -9
  30. package/dist/index.browser.d.ts +24 -9
  31. package/dist/index.browser.js +16 -16
  32. package/dist/index.browser.js.map +1 -1
  33. package/dist/index.cjs +256 -103
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.common.cjs +241 -87
  36. package/dist/index.common.cjs.map +1 -1
  37. package/dist/index.common.d.cts +2 -2
  38. package/dist/index.common.d.ts +2 -2
  39. package/dist/index.common.js +11 -8
  40. package/dist/index.d.cts +15 -6
  41. package/dist/index.d.ts +15 -6
  42. package/dist/index.js +20 -20
  43. package/dist/index.js.map +1 -1
  44. package/dist/narou-DBa12V_l.d.ts +404 -0
  45. package/dist/narou-DCp4aGfA.d.cts +404 -0
  46. package/dist/narou-fetch.cjs +10 -5
  47. package/dist/narou-fetch.cjs.map +1 -1
  48. package/dist/narou-fetch.d.cts +4 -3
  49. package/dist/narou-fetch.d.ts +4 -3
  50. package/dist/narou-fetch.js +4 -4
  51. package/dist/narou-jsonp.cjs +5 -2
  52. package/dist/narou-jsonp.cjs.map +1 -1
  53. package/dist/narou-jsonp.d.cts +2 -2
  54. package/dist/narou-jsonp.d.ts +2 -2
  55. package/dist/narou-jsonp.js +4 -4
  56. package/dist/narou-ranking-results.d.cts +2 -2
  57. package/dist/narou-ranking-results.d.ts +2 -2
  58. package/dist/{narou-search-results-D_vbjc_I.d.cts → narou-search-results-C21hWrnL.d.cts} +30 -19
  59. package/dist/{narou-search-results-CvMcnYqe.d.ts → narou-search-results-DT0YdaBn.d.ts} +30 -19
  60. package/dist/narou-search-results.cjs.map +1 -1
  61. package/dist/narou-search-results.d.cts +1 -1
  62. package/dist/narou-search-results.d.ts +1 -1
  63. package/dist/narou-search-results.js +1 -1
  64. package/dist/narou.cjs +4 -1
  65. package/dist/narou.cjs.map +1 -1
  66. package/dist/narou.d.cts +2 -2
  67. package/dist/narou.d.ts +2 -2
  68. package/dist/narou.js +2 -2
  69. package/dist/params.cjs +12 -1
  70. package/dist/params.cjs.map +1 -1
  71. package/dist/params.d.cts +1 -1
  72. package/dist/params.d.ts +1 -1
  73. package/dist/params.js +3 -1
  74. package/dist/ranking-history.cjs +11 -3
  75. package/dist/ranking-history.cjs.map +1 -1
  76. package/dist/ranking-history.d.cts +12 -1
  77. package/dist/ranking-history.d.ts +12 -1
  78. package/dist/ranking-history.js +2 -1
  79. package/dist/ranking.cjs +201 -78
  80. package/dist/ranking.cjs.map +1 -1
  81. package/dist/ranking.d.cts +70 -9
  82. package/dist/ranking.d.ts +70 -9
  83. package/dist/ranking.js +4 -3
  84. package/dist/search-builder-r18.cjs +133 -60
  85. package/dist/search-builder-r18.cjs.map +1 -1
  86. package/dist/search-builder-r18.d.cts +19 -6
  87. package/dist/search-builder-r18.d.ts +19 -6
  88. package/dist/search-builder-r18.js +3 -3
  89. package/dist/search-builder.cjs +150 -70
  90. package/dist/search-builder.cjs.map +1 -1
  91. package/dist/search-builder.d.cts +2 -2
  92. package/dist/search-builder.d.ts +2 -2
  93. package/dist/search-builder.js +2 -2
  94. package/dist/user-search.cjs +37 -13
  95. package/dist/user-search.cjs.map +1 -1
  96. package/dist/user-search.d.cts +2 -2
  97. package/dist/user-search.d.ts +2 -2
  98. package/dist/user-search.js +3 -3
  99. package/dist/util/date.cjs +51 -0
  100. package/dist/util/date.cjs.map +1 -0
  101. package/dist/util/date.d.cts +21 -0
  102. package/dist/util/date.d.ts +21 -0
  103. package/dist/util/date.js +11 -0
  104. package/dist/util/date.js.map +1 -0
  105. package/dist/util/jsonp.cjs.map +1 -1
  106. package/dist/util/jsonp.d.cts +36 -0
  107. package/dist/util/jsonp.d.ts +36 -0
  108. package/dist/util/jsonp.js +1 -1
  109. package/dist/util/type.cjs.map +1 -1
  110. package/dist/util/type.d.cts +23 -0
  111. package/dist/util/type.d.ts +23 -0
  112. package/dist/util/unzipp.cjs +1 -2
  113. package/dist/util/unzipp.cjs.map +1 -1
  114. package/dist/util/unzipp.d.cts +9 -0
  115. package/dist/util/unzipp.d.ts +9 -0
  116. package/dist/util/unzipp.js +1 -1
  117. package/package.json +47 -46
  118. package/pnpm-lock.yaml +3041 -0
  119. package/src/index.browser.ts +21 -5
  120. package/src/index.ts +11 -2
  121. package/src/narou-fetch.ts +5 -2
  122. package/src/narou-jsonp.ts +1 -1
  123. package/src/narou-search-results.ts +2 -1
  124. package/src/narou.ts +4 -1
  125. package/src/params.ts +34 -18
  126. package/src/ranking-history.ts +13 -4
  127. package/src/ranking.ts +79 -15
  128. package/src/search-builder-r18.ts +17 -4
  129. package/src/search-builder.ts +203 -79
  130. package/src/util/date.ts +38 -0
  131. package/src/util/jsonp.ts +61 -6
  132. package/src/util/type.ts +23 -0
  133. package/src/util/unzipp.ts +9 -0
  134. package/dist/chunk-6RIDVTFQ.js.map +0 -1
  135. package/dist/chunk-JMTNQTNC.js.map +0 -1
  136. package/dist/chunk-NP5NZV5Q.js.map +0 -1
  137. package/dist/chunk-OJGRUQEQ.js +0 -372
  138. package/dist/chunk-OJGRUQEQ.js.map +0 -1
  139. package/dist/chunk-QQYQ4GQF.js +0 -83
  140. package/dist/chunk-QQYQ4GQF.js.map +0 -1
  141. package/dist/chunk-RITMMCZE.js.map +0 -1
  142. package/dist/chunk-TNDGN3EF.js.map +0 -1
  143. package/dist/chunk-XAUB42TO.js.map +0 -1
  144. package/dist/chunk-YJQXIVFD.js +0 -44
  145. package/dist/chunk-YJQXIVFD.js.map +0 -1
  146. package/dist/narou-CosGR0J9.d.cts +0 -298
  147. package/dist/narou-CutsOEgk.d.ts +0 -298
  148. /package/dist/{chunk-DBCAWGIX.js.map → chunk-DEQICAN3.js.map} +0 -0
@@ -12,9 +12,10 @@ export { NarouNovelJsonp };
12
12
  const narouNovelJsonp = new NarouNovelJsonp();
13
13
 
14
14
  /**
15
- * 検索
16
- * @param {string} [word] - 検索ワード
15
+ * なろう小説 API で小説を検索する
16
+ * @param {string} [word] 検索ワード
17
17
  * @returns {SearchBuilder}
18
+ * @see https://dev.syosetu.com/man/api/
18
19
  */
19
20
  export function search(
20
21
  word = "",
@@ -26,9 +27,10 @@ export function search(
26
27
  }
27
28
 
28
29
  /**
29
- * 検索
30
- * @param {string} [word] - 検索ワード
30
+ * 18禁小説 API で小説を検索する
31
+ * @param {string} [word] 検索ワード
31
32
  * @returns {SearchBuilder}
33
+ * @see https://dev.syosetu.com/xman/api/
32
34
  */
33
35
  export function searchR18(
34
36
  word = "",
@@ -40,7 +42,10 @@ export function searchR18(
40
42
  }
41
43
 
42
44
  /**
43
- * ユーザ検索
45
+ * なろうユーザ検索 API でユーザを検索する
46
+ * @param {string} [word] - 検索ワード
47
+ * @returns {UserSearchBuilder}
48
+ * @see https://dev.syosetu.com/man/userapi/
44
49
  */
45
50
  export function searchUser(word = "", api: NarouNovel = narouNovelJsonp) {
46
51
  const builder = new UserSearchBuilder({}, api);
@@ -48,11 +53,22 @@ export function searchUser(word = "", api: NarouNovel = narouNovelJsonp) {
48
53
  return builder;
49
54
  }
50
55
 
56
+
57
+ /**
58
+ * なろう小説ランキング API でランキングを取得する
59
+ * @returns {RankingBuilder}
60
+ * @see https://dev.syosetu.com/man/rankapi/
61
+ */
51
62
  export function ranking(api: NarouNovel = narouNovelJsonp): RankingBuilder {
52
63
  const builder = new RankingBuilder({}, api);
53
64
  return builder;
54
65
  }
55
66
 
67
+ /**
68
+ * なろう殿堂入り API でランキング履歴を取得する
69
+ * @param {string} ncode 小説のNコード
70
+ * @see https://dev.syosetu.com/man/rankinapi/
71
+ */
56
72
  export async function rankingHistory(
57
73
  ncode: string,
58
74
  api: NarouNovel = narouNovelJsonp
package/src/index.ts CHANGED
@@ -14,8 +14,9 @@ const narouNovelFetch = new NarouNovelFetch();
14
14
 
15
15
  /**
16
16
  * なろう小説 API で小説を検索する
17
- * @param {string} [word] - 検索ワード
17
+ * @param {string} [word] 検索ワード
18
18
  * @returns {SearchBuilder}
19
+ * @see https://dev.syosetu.com/man/api/
19
20
  */
20
21
  export function search(
21
22
  word = "",
@@ -28,8 +29,9 @@ export function search(
28
29
 
29
30
  /**
30
31
  * 18禁小説 API で小説を検索する
31
- * @param {string} [word] - 検索ワード
32
+ * @param {string} [word] 検索ワード
32
33
  * @returns {SearchBuilder}
34
+ * @see https://dev.syosetu.com/xman/api/
33
35
  */
34
36
  export function searchR18(
35
37
  word = "",
@@ -42,6 +44,9 @@ export function searchR18(
42
44
 
43
45
  /**
44
46
  * なろうユーザ検索 API でユーザを検索する
47
+ * @param {string} [word] - 検索ワード
48
+ * @returns {UserSearchBuilder}
49
+ * @see https://dev.syosetu.com/man/userapi/
45
50
  */
46
51
  export function searchUser(word = "", api: NarouNovel = narouNovelFetch) {
47
52
  const builder = new UserSearchBuilder({}, api);
@@ -51,6 +56,8 @@ export function searchUser(word = "", api: NarouNovel = narouNovelFetch) {
51
56
 
52
57
  /**
53
58
  * なろう小説ランキング API でランキングを取得する
59
+ * @returns {RankingBuilder}
60
+ * @see https://dev.syosetu.com/man/rankapi/
54
61
  */
55
62
  export function ranking(api: NarouNovel = narouNovelFetch): RankingBuilder {
56
63
  const builder = new RankingBuilder({}, api);
@@ -59,6 +66,8 @@ export function ranking(api: NarouNovel = narouNovelFetch): RankingBuilder {
59
66
 
60
67
  /**
61
68
  * なろう殿堂入り API でランキング履歴を取得する
69
+ * @param {string} ncode 小説のNコード
70
+ * @see https://dev.syosetu.com/man/rankinapi/
62
71
  */
63
72
  export async function rankingHistory(
64
73
  ncode: string,
@@ -25,17 +25,20 @@ export default class NarouNovelFetch extends NarouNovel {
25
25
  if (query.gzip === undefined) {
26
26
  query.gzip = 5;
27
27
  }
28
+ if (query.gzip === 0) {
29
+ delete query.gzip;
30
+ }
28
31
  const url = new URL(endpoint);
29
32
 
30
33
  Object.entries(query).forEach(([key, value]) => {
31
- if (value) {
34
+ if (value !== undefined) {
32
35
  url.searchParams.append(key, value.toString());
33
36
  }
34
37
  });
35
38
 
36
39
  const res = await (this.fetch ?? fetch)(url);
37
40
 
38
- if (query.gzip === 0) {
41
+ if (!query.gzip) {
39
42
  return (await res.json()) as T;
40
43
  }
41
44
 
@@ -16,7 +16,7 @@ export default class NarouNovelJsonp extends NarouNovel {
16
16
  const url = new URL(endpoint);
17
17
 
18
18
  Object.entries(query).forEach(([key, value]) => {
19
- if (value) {
19
+ if (value !== undefined) {
20
20
  url.searchParams.append(key, value.toString());
21
21
  }
22
22
  });
@@ -8,6 +8,7 @@ import type {
8
8
  R18Fields,
9
9
  OptionalFields,
10
10
  UserFields,
11
+ UserSearchParams,
11
12
  } from "./params.js";
12
13
 
13
14
  /**
@@ -45,7 +46,7 @@ export default class NarouSearchResults<T, TKey extends keyof T> {
45
46
  */
46
47
  constructor(
47
48
  [header, ...result]: [{ allcount: number }, ...Pick<T, TKey>[]],
48
- params: SearchParams
49
+ params: SearchParams | UserSearchParams
49
50
  ) {
50
51
  const count = header.allcount;
51
52
  const limit = params.lim ?? 20;
package/src/narou.ts CHANGED
@@ -112,6 +112,9 @@ export default abstract class NarouNovel {
112
112
  async executeUserSearch<T extends keyof UserSearchResult>(
113
113
  params: UserSearchParams
114
114
  ): Promise<NarouSearchResults<UserSearchResult, T>> {
115
- return await this.execute(params, "https://api.syosetu.com/userapi/api/");
115
+ return new NarouSearchResults<UserSearchResult, T>(
116
+ await this.execute(params, "https://api.syosetu.com/userapi/api/"),
117
+ params
118
+ );
116
119
  }
117
120
  }
package/src/params.ts CHANGED
@@ -1,4 +1,7 @@
1
- import type { NarouSearchResult, UserSearchResult } from "./narou-search-results.js";
1
+ import type {
2
+ NarouSearchResult,
3
+ UserSearchResult,
4
+ } from "./narou-search-results.js";
2
5
  import type { Join } from "./util/type.js";
3
6
 
4
7
  export const RankingType = {
@@ -7,7 +10,7 @@ export const RankingType = {
7
10
  Monthly: "m",
8
11
  Quarterly: "q",
9
12
  } as const;
10
- export type RankingType = typeof RankingType[keyof typeof RankingType];
13
+ export type RankingType = (typeof RankingType)[keyof typeof RankingType];
11
14
 
12
15
  /**
13
16
  * すべてのAPIで共通のクエリパラメータ
@@ -82,11 +85,10 @@ export interface SearchParams extends ParamsBaseWithOrder<Order> {
82
85
  notzankoku?: BooleanNumber;
83
86
  nottensei?: BooleanNumber;
84
87
  nottenni?: BooleanNumber;
85
- nottt?: BooleanNumber;
86
88
 
87
89
  minlen?: number;
88
90
  maxlen?: number;
89
- length?: number | Join<number>;
91
+ length?: number | Join<number | "">;
90
92
 
91
93
  kaiwaritu?: number | string;
92
94
  sasie?: number | string;
@@ -103,8 +105,9 @@ export interface SearchParams extends ParamsBaseWithOrder<Order> {
103
105
 
104
106
  stop?: StopParam;
105
107
 
106
- ispickup?: BooleanNumber;
108
+ ispickup?: typeof BooleanNumber.True;
107
109
  lastup?: string;
110
+ lastupdate?: string;
108
111
 
109
112
  opt?: Join<OptionalFields>;
110
113
  }
@@ -143,7 +146,7 @@ export const BooleanNumber = {
143
146
  True: 1,
144
147
  False: 0,
145
148
  } as const;
146
- export type BooleanNumber = typeof BooleanNumber[keyof typeof BooleanNumber];
149
+ export type BooleanNumber = (typeof BooleanNumber)[keyof typeof BooleanNumber];
147
150
 
148
151
  export type SearchResultFieldNames = keyof NarouSearchResult;
149
152
 
@@ -231,7 +234,7 @@ export const Fields = {
231
234
  updated_at: "ua",
232
235
  } as const;
233
236
 
234
- export type Fields = typeof Fields[keyof Omit<
237
+ export type Fields = (typeof Fields)[keyof Omit<
235
238
  NarouSearchResult,
236
239
  "novel_type" | "weekly_unique" | "nocgenre"
237
240
  >];
@@ -316,7 +319,7 @@ export const R18Fields = {
316
319
  updated_at: "ua",
317
320
  } as const;
318
321
 
319
- export type R18Fields = typeof R18Fields[keyof Omit<
322
+ export type R18Fields = (typeof R18Fields)[keyof Omit<
320
323
  NarouSearchResult,
321
324
  "novel_type" | "weekly_unique" | "biggenre" | "genre" | "isr15"
322
325
  >];
@@ -333,7 +336,7 @@ export const OptionalFields = {
333
336
  weekly_unique: "weekly",
334
337
  } as const;
335
338
 
336
- export type OptionalFields = typeof OptionalFields[keyof Pick<
339
+ export type OptionalFields = (typeof OptionalFields)[keyof Pick<
337
340
  NarouSearchResult,
338
341
  "weekly_unique"
339
342
  >];
@@ -360,7 +363,7 @@ export const UserFields = {
360
363
  /** 総合評価ポイントの合計 */
361
364
  sum_global_point: "sg",
362
365
  } as const;
363
- export type UserFields = typeof UserFields[keyof UserSearchResult];
366
+ export type UserFields = (typeof UserFields)[keyof UserSearchResult];
364
367
 
365
368
  /**
366
369
  * 出力順序
@@ -402,9 +405,11 @@ export const Order = {
402
405
  QuarterPoint: "quarterpoint",
403
406
  /** 年間ポイントの高い順 */
404
407
  YearlyPoint: "yearlypoint",
408
+ /** 初回掲載順 */
409
+ GeneralFirstUp: "generalfirstup",
405
410
  } as const;
406
411
 
407
- export type Order = typeof Order[keyof typeof Order];
412
+ export type Order = (typeof Order)[keyof typeof Order];
408
413
 
409
414
  /** R18掲載サイト */
410
415
  export const R18Site = {
@@ -418,7 +423,7 @@ export const R18Site = {
418
423
  Midnight: 4,
419
424
  } as const;
420
425
 
421
- export type R18Site = typeof R18Site[keyof typeof R18Site];
426
+ export type R18Site = (typeof R18Site)[keyof typeof R18Site];
422
427
 
423
428
  /** R18掲載サイト表記ヘルパー */
424
429
  export const R18SiteNotation: { readonly [K in R18Site]: string } = {
@@ -444,7 +449,7 @@ export const BigGenre = {
444
449
  NonGenre: 98,
445
450
  } as const;
446
451
 
447
- export type BigGenre = typeof BigGenre[keyof typeof BigGenre];
452
+ export type BigGenre = (typeof BigGenre)[keyof typeof BigGenre];
448
453
 
449
454
  /** 大ジャンル表記ヘルパー */
450
455
  export const BigGenreNotation: { readonly [K in BigGenre]: string } = {
@@ -501,7 +506,7 @@ export const Genre = {
501
506
  /** ノンジャンル〔ノンジャンル〕*/
502
507
  NonGenre: 9801,
503
508
  } as const;
504
- export type Genre = typeof Genre[keyof typeof Genre];
509
+ export type Genre = (typeof Genre)[keyof typeof Genre];
505
510
 
506
511
  /** ジャンル表記ヘルパー */
507
512
  export const GenreNotation: { readonly [K in Genre]: string } = {
@@ -540,7 +545,7 @@ export const BuntaiParam = {
540
545
  JisageKaigyoHutsuu: 6,
541
546
  } as const;
542
547
 
543
- export type BuntaiParam = typeof BuntaiParam[keyof typeof BuntaiParam];
548
+ export type BuntaiParam = (typeof BuntaiParam)[keyof typeof BuntaiParam];
544
549
 
545
550
  /** 連載停止中指定 */
546
551
  export const StopParam = {
@@ -550,7 +555,7 @@ export const StopParam = {
550
555
  Stopping: 2,
551
556
  } as const;
552
557
 
553
- export type StopParam = typeof StopParam[keyof typeof StopParam];
558
+ export type StopParam = (typeof StopParam)[keyof typeof StopParam];
554
559
 
555
560
  /** 小説タイプ指定 */
556
561
  export const NovelTypeParam = {
@@ -565,7 +570,18 @@ export const NovelTypeParam = {
565
570
  /** 短編と完結済連載小説 */
566
571
  ShortAndRensai: "ter",
567
572
  } as const;
568
- export type NovelTypeParam = typeof NovelTypeParam[keyof typeof NovelTypeParam];
573
+ export type NovelTypeParam =
574
+ (typeof NovelTypeParam)[keyof typeof NovelTypeParam];
575
+
576
+ /** 日付指定パラメータ */
577
+ export const DateParam = {
578
+ ThisWeek: "thisweek",
579
+ LastWeek: "lastweek",
580
+ SevenDays: "sevenday",
581
+ ThisMonth: "thismonth",
582
+ LastMonth: "lastmonth",
583
+ };
584
+ export type DateParam = (typeof DateParam)[keyof typeof DateParam];
569
585
 
570
586
  export const UserOrder = {
571
587
  /** ユーザIDの新しい順 */
@@ -581,6 +597,6 @@ export const UserOrder = {
581
597
  /** ユーザIDの古い順 */
582
598
  Old: "old",
583
599
  } as const;
584
- export type UserOrder = typeof UserOrder[keyof typeof UserOrder];
600
+ export type UserOrder = (typeof UserOrder)[keyof typeof UserOrder];
585
601
 
586
602
  export type GzipLevel = 0 | 1 | 2 | 3 | 4 | 5;
@@ -1,7 +1,5 @@
1
- import { parse } from "date-fns";
2
1
  import type { RankingType } from "./params.js";
3
-
4
- const dateFormat = "yyyyMMdd";
2
+ import { parseDate } from "./util/date.js";
5
3
 
6
4
  export interface RankingHistoryRawResult {
7
5
  rtype: `${string}-${RankingType}`;
@@ -16,12 +14,23 @@ export interface RankingHistoryResult {
16
14
  rank: number;
17
15
  }
18
16
 
17
+ /**
18
+ * 生のランキング履歴エントリを構造化された形式にフォーマットします。
19
+ *
20
+ * @param rankin - フォーマットする生のランキング履歴データ
21
+ * @returns 日付とタイプが解析されたフォーマット済みランキング履歴
22
+ *
23
+ * @example
24
+ * const rawData = { rtype: "20230101-daily", pt: 500, rank: 10 };
25
+ * const formattedData = formatRankingHistory(rawData);
26
+ * // 返り値: { type: "daily", date: [Dateオブジェクト], pt: 500, rank: 10 }
27
+ */
19
28
  export function formatRankingHistory(
20
29
  rankin: RankingHistoryRawResult
21
30
  ): RankingHistoryResult {
22
31
  const { rtype, pt, rank } = rankin;
23
32
  const [_date, _type] = rtype.split("-");
24
- const date = parse(_date, dateFormat, new Date());
33
+ const date = parseDate(_date);
25
34
  const type = _type as RankingType;
26
35
 
27
36
  return { type, date, pt, rank };
package/src/ranking.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type { NarouRankingResult, RankingResult } from "./narou-ranking-results.js";
2
2
  import SearchBuilder from "./search-builder.js";
3
3
  import type { DefaultSearchResultFields } from "./search-builder.js";
4
- import { addDays, format } from "date-fns";
5
4
  import type {
6
5
  GzipLevel,
7
6
  OptionalFields,
@@ -13,19 +12,34 @@ import {
13
12
  } from "./params.js";
14
13
  import type NarouNovel from "./narou.js";
15
14
  import type { SearchResultFields } from "./narou-search-results.js";
16
-
17
- const dateFormat = "yyyyMMdd";
15
+ import { addDays, formatDate } from "./util/date.js";
18
16
 
19
17
  /**
20
- * ランキングヘルパー
21
- * @class Ranking
18
+ * なろう小説ランキングAPIのヘルパークラス。
19
+ *
20
+ * ランキング種別や日付を指定してランキングデータを取得します。
21
+ * また、取得したランキングデータに含まれるNコードを元に、
22
+ * なろう小説APIを利用して詳細な小説情報を取得することも可能です。
23
+ *
24
+ * @class RankingBuilder
25
+ * @see https://dev.syosetu.com/man/rankapi/ なろう小説ランキングAPI仕様
22
26
  */
23
27
  export default class RankingBuilder {
28
+ /**
29
+ * ランキング集計対象の日付
30
+ * @protected
31
+ */
24
32
  protected date$: Date;
33
+ /**
34
+ * ランキング種別
35
+ * @protected
36
+ */
25
37
  protected type$: RankingType;
26
38
 
27
39
  /**
28
40
  * constructor
41
+ * @param params - 初期クエリパラメータ
42
+ * @param api - API実行クラスのインスタンス
29
43
  * @private
30
44
  */
31
45
  constructor(
@@ -36,15 +50,32 @@ export default class RankingBuilder {
36
50
  * クエリパラメータ
37
51
  * @protected
38
52
  */
39
- this.date$ = addDays(Date.now(), -1);
53
+ this.date$ = addDays(new Date(), -1);
40
54
  this.type$ = RankingType.Daily;
41
55
  }
42
56
 
57
+ /**
58
+ * ランキング集計対象の日付を指定します。
59
+ *
60
+ * - 日間: 任意の日付
61
+ * - 週間: 火曜日の日付
62
+ * - 月間・四半期: 1日の日付
63
+ *
64
+ * @param date 集計対象の日付
65
+ * @returns {RankingBuilder} this
66
+ * @see https://dev.syosetu.com/man/rankapi/
67
+ */
43
68
  date(date: Date) {
44
69
  this.date$ = date;
45
70
  return this;
46
71
  }
47
72
 
73
+ /**
74
+ * ランキング種別を指定します。
75
+ * @param type ランキング種別
76
+ * @returns {RankingBuilder} this
77
+ * @see https://dev.syosetu.com/man/rankapi/
78
+ */
48
79
  type(type: RankingType) {
49
80
  this.type$ = type;
50
81
  return this;
@@ -63,9 +94,10 @@ export default class RankingBuilder {
63
94
  }
64
95
 
65
96
  /**
66
- * クエリパラメータをセットする
97
+ * クエリパラメータを内部的にセットします。
98
+ * @param obj - セットするパラメータオブジェクト
99
+ * @returns {RankingBuilder} this
67
100
  * @private
68
- * @return {RankingBuilder} this
69
101
  */
70
102
  protected set(obj: Partial<RankingParams>) {
71
103
  Object.assign(this.params, obj);
@@ -73,33 +105,65 @@ export default class RankingBuilder {
73
105
  }
74
106
 
75
107
  /**
76
- * なろう小説APIへのリクエストを実行する
77
- * @returns ランキング
108
+ * 設定されたパラメータに基づき、なろう小説ランキングAPIへのリクエストを実行します。
109
+ *
110
+ * 返される結果には、Nコード、ポイント、順位が含まれます。
111
+ * @returns {Promise<NarouRankingResult[]>} ランキング結果の配列
112
+ * @see https://dev.syosetu.com/man/rankapi/#output
78
113
  */
79
114
  execute(): Promise<NarouRankingResult[]> {
80
- const date = format(this.date$, dateFormat);
115
+ const date = formatDate(this.date$);
81
116
  this.set({ rtype: `${date}-${this.type$}` });
82
117
  return this.api.executeRanking(this.params as RankingParams);
83
118
  }
84
119
 
120
+ /**
121
+ * ランキングAPIを実行し、取得したNコードを元になろう小説APIで詳細情報を取得して結合します。
122
+ */
85
123
  async executeWithFields(): Promise<
86
124
  RankingResult<DefaultSearchResultFields>[]
87
125
  >;
88
-
126
+ /**
127
+ * ランキングAPIを実行し、取得したNコードを元になろう小説APIで詳細情報を取得して結合します。
128
+ *
129
+ * @template TFields - 取得する小説情報のフィールド型
130
+ * @param fields - 取得するフィールドの配列
131
+ * @returns {Promise<RankingResult<SearchResultFields<TFields>>[]>} 詳細情報を含むランキング結果の配列
132
+ */
89
133
  async executeWithFields<TFields extends Fields>(
90
134
  fields: TFields | TFields[]
91
135
  ): Promise<RankingResult<SearchResultFields<TFields>>[]>;
92
-
136
+ /**
137
+ * ランキングAPIを実行し、取得したNコードを元になろう小説APIで詳細情報を取得して結合します。
138
+ *
139
+ * @param opt - オプショナルな取得フィールド (`weekly` など)
140
+ * @returns {Promise<RankingResult<DefaultSearchResultFields | "weekly_unique">[]>} 詳細情報を含むランキング結果の配列
141
+ */
93
142
  async executeWithFields(
94
143
  fields: never[],
95
144
  opt: OptionalFields | OptionalFields[]
96
145
  ): Promise<RankingResult<DefaultSearchResultFields | "weekly_unique">[]>;
97
-
146
+ /**
147
+ * ランキングAPIを実行し、取得したNコードを元になろう小説APIで詳細情報を取得して結合します。
148
+ *
149
+ * @template TFields - 取得する小説情報のフィールド型
150
+ * @param fields - 取得するフィールドの配列
151
+ * @param opt - オプショナルな取得フィールド (`weekly` など)
152
+ * @returns {Promise<RankingResult<SearchResultFields<TFields> | "weekly_unique">[]>} 詳細情報を含むランキング結果の配列
153
+ */
98
154
  async executeWithFields<TFields extends Fields>(
99
155
  fields: TFields | TFields[],
100
156
  opt: OptionalFields | OptionalFields[]
101
157
  ): Promise<RankingResult<SearchResultFields<TFields> | "weekly_unique">[]>;
102
-
158
+ /**
159
+ * ランキングAPIを実行し、取得したNコードを元になろう小説APIで詳細情報を取得して結合します。
160
+ *
161
+ * @template TFields - 取得する小説情報のフィールド型
162
+ * @template TOpt - オプショナルな取得フィールドの型
163
+ * @param fields - 取得するフィールドの配列 (省略時はデフォルトフィールド)
164
+ * @param opt - オプショナルな取得フィールド (`weekly` など)
165
+ * @returns {Promise<RankingResult<SearchResultFields<TFields>>[]>} 詳細情報を含むランキング結果の配列
166
+ */
103
167
  async executeWithFields<
104
168
  TFields extends Fields,
105
169
  TOpt extends OptionalFields | undefined = undefined
@@ -34,14 +34,20 @@ export default class SearchBuilderR18<
34
34
  return this.api.executeNovel18(this.params);
35
35
  }
36
36
 
37
+ /**
38
+ * 抽出するR18サイトを指定します (nocgenre)。
39
+ * @param sites R18サイトコード、またはR18サイトコードの配列 (1: ノクターンノベルズ, 2: ムーンライトノベルズ(男性向け), 3: ムーンライトノベルズ(BL), 4: ミッドナイトノベルズ)
40
+ * @return {this}
41
+ */
37
42
  r18Site(sites: R18Site | readonly R18Site[]) {
38
43
  this.set({ nocgenre: NovelSearchBuilderBase.array2string(sites) });
39
44
  return this;
40
45
  }
41
46
 
42
47
  /**
43
- *
44
- * @return {SearchBuilder} this
48
+ * X-IDを指定して取得します (xid)。
49
+ * @param ids X-ID、またはX-IDの配列
50
+ * @return {this}
45
51
  */
46
52
  xid(ids: number | readonly number[]) {
47
53
  this.set({ xid: NovelSearchBuilderBase.array2string(ids) });
@@ -49,8 +55,10 @@ export default class SearchBuilderR18<
49
55
  }
50
56
 
51
57
  /**
52
- *
53
- * @return {SearchBuilder} this
58
+ * 出力する項目を個別に指定します (of)。
59
+ * 未指定時は全項目出力されます。転送量軽減のため、このパラメータの使用が推奨されます。
60
+ * @param fields 出力するR18フィールド名、またはR18フィールド名の配列
61
+ * @return {SearchBuilderR18<SearchResultR18Fields<R18Fields>>} 型が更新されたビルダー
54
62
  */
55
63
  fields<TFields extends R18Fields>(
56
64
  fields: TFields | readonly TFields[]
@@ -60,6 +68,11 @@ export default class SearchBuilderR18<
60
68
  return this as any;
61
69
  }
62
70
 
71
+ /**
72
+ * 出力オプション項目を指定します (opt)。
73
+ * @param option 出力するオプションフィールド名、またはオプションフィールド名の配列
74
+ * @return {SearchBuilderR18<T, SearchResultOptionalFields<TFields>>} 型が更新されたビルダー
75
+ */
63
76
  opt<TFields extends OptionalFields>(
64
77
  option: TFields | readonly TFields[]
65
78
  ): SearchBuilderR18<T, SearchResultOptionalFields<TFields>> {