narou 1.1.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 (143) 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-CDOBNSCL.js → chunk-5UDKQCPJ.js} +1 -1
  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-K22KVNAH.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-XVH2CU2Q.js → chunk-IPDEGCWU.js} +1 -1
  16. package/dist/chunk-IPDEGCWU.js.map +1 -0
  17. package/dist/{chunk-AZT2OXBZ.js → chunk-LQLNWSWV.js} +3 -3
  18. package/dist/{chunk-SNPBEVCY.js → chunk-PLEM2AOH.js} +3 -3
  19. package/dist/chunk-RNHRR56W.js +25 -0
  20. package/dist/chunk-RNHRR56W.js.map +1 -0
  21. package/dist/{chunk-NVMUSXA5.js → chunk-VUZIISP2.js} +1 -1
  22. package/dist/chunk-VUZIISP2.js.map +1 -0
  23. package/dist/{chunk-XAUB42TO.js → chunk-VZVUANDN.js} +6 -4
  24. package/dist/chunk-VZVUANDN.js.map +1 -0
  25. package/dist/index.browser.cjs +214 -85
  26. package/dist/index.browser.cjs.map +1 -1
  27. package/dist/index.browser.d.cts +24 -9
  28. package/dist/index.browser.d.ts +24 -9
  29. package/dist/index.browser.js +11 -10
  30. package/dist/index.browser.js.map +1 -1
  31. package/dist/index.cjs +214 -85
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.common.cjs +214 -85
  34. package/dist/index.common.cjs.map +1 -1
  35. package/dist/index.common.d.cts +2 -2
  36. package/dist/index.common.d.ts +2 -2
  37. package/dist/index.common.js +9 -8
  38. package/dist/index.d.cts +15 -6
  39. package/dist/index.d.ts +15 -6
  40. package/dist/index.js +13 -12
  41. package/dist/index.js.map +1 -1
  42. package/dist/narou-DBa12V_l.d.ts +404 -0
  43. package/dist/narou-DCp4aGfA.d.cts +404 -0
  44. package/dist/narou-fetch.cjs +4 -1
  45. package/dist/narou-fetch.cjs.map +1 -1
  46. package/dist/narou-fetch.d.cts +2 -2
  47. package/dist/narou-fetch.d.ts +2 -2
  48. package/dist/narou-fetch.js +4 -4
  49. package/dist/narou-jsonp.cjs +4 -1
  50. package/dist/narou-jsonp.cjs.map +1 -1
  51. package/dist/narou-jsonp.d.cts +2 -2
  52. package/dist/narou-jsonp.d.ts +2 -2
  53. package/dist/narou-jsonp.js +4 -4
  54. package/dist/narou-ranking-results.d.cts +2 -2
  55. package/dist/narou-ranking-results.d.ts +2 -2
  56. package/dist/{narou-search-results-DWCJWTC5.d.cts → narou-search-results-C21hWrnL.d.cts} +2 -2
  57. package/dist/{narou-search-results-D5yqPRZ7.d.ts → narou-search-results-DT0YdaBn.d.ts} +2 -2
  58. package/dist/narou-search-results.cjs.map +1 -1
  59. package/dist/narou-search-results.d.cts +1 -1
  60. package/dist/narou-search-results.d.ts +1 -1
  61. package/dist/narou-search-results.js +1 -1
  62. package/dist/narou.cjs +4 -1
  63. package/dist/narou.cjs.map +1 -1
  64. package/dist/narou.d.cts +2 -2
  65. package/dist/narou.d.ts +2 -2
  66. package/dist/narou.js +2 -2
  67. package/dist/params.cjs.map +1 -1
  68. package/dist/params.d.cts +1 -1
  69. package/dist/params.d.ts +1 -1
  70. package/dist/params.js +1 -1
  71. package/dist/ranking-history.cjs +11 -3
  72. package/dist/ranking-history.cjs.map +1 -1
  73. package/dist/ranking-history.d.cts +12 -1
  74. package/dist/ranking-history.d.ts +12 -1
  75. package/dist/ranking-history.js +2 -1
  76. package/dist/ranking.cjs +186 -77
  77. package/dist/ranking.cjs.map +1 -1
  78. package/dist/ranking.d.cts +69 -8
  79. package/dist/ranking.d.ts +69 -8
  80. package/dist/ranking.js +4 -3
  81. package/dist/search-builder-r18.cjs +118 -59
  82. package/dist/search-builder-r18.cjs.map +1 -1
  83. package/dist/search-builder-r18.d.cts +19 -6
  84. package/dist/search-builder-r18.d.ts +19 -6
  85. package/dist/search-builder-r18.js +3 -3
  86. package/dist/search-builder.cjs +135 -69
  87. package/dist/search-builder.cjs.map +1 -1
  88. package/dist/search-builder.d.cts +2 -2
  89. package/dist/search-builder.d.ts +2 -2
  90. package/dist/search-builder.js +2 -2
  91. package/dist/user-search.cjs +37 -13
  92. package/dist/user-search.cjs.map +1 -1
  93. package/dist/user-search.d.cts +2 -2
  94. package/dist/user-search.d.ts +2 -2
  95. package/dist/user-search.js +3 -3
  96. package/dist/util/date.cjs +51 -0
  97. package/dist/util/date.cjs.map +1 -0
  98. package/dist/util/date.d.cts +21 -0
  99. package/dist/util/date.d.ts +21 -0
  100. package/dist/util/date.js +11 -0
  101. package/dist/util/date.js.map +1 -0
  102. package/dist/util/jsonp.cjs.map +1 -1
  103. package/dist/util/jsonp.d.cts +36 -0
  104. package/dist/util/jsonp.d.ts +36 -0
  105. package/dist/util/jsonp.js +1 -1
  106. package/dist/util/type.cjs.map +1 -1
  107. package/dist/util/type.d.cts +23 -0
  108. package/dist/util/type.d.ts +23 -0
  109. package/dist/util/unzipp.cjs.map +1 -1
  110. package/dist/util/unzipp.d.cts +9 -0
  111. package/dist/util/unzipp.d.ts +9 -0
  112. package/dist/util/unzipp.js +1 -1
  113. package/package.json +34 -36
  114. package/pnpm-lock.yaml +2114 -1991
  115. package/src/index.browser.ts +21 -5
  116. package/src/index.ts +11 -2
  117. package/src/narou-search-results.ts +2 -1
  118. package/src/narou.ts +4 -1
  119. package/src/params.ts +1 -1
  120. package/src/ranking-history.ts +13 -4
  121. package/src/ranking.ts +79 -15
  122. package/src/search-builder-r18.ts +17 -4
  123. package/src/search-builder.ts +176 -73
  124. package/src/util/date.ts +38 -0
  125. package/src/util/jsonp.ts +61 -6
  126. package/src/util/type.ts +23 -0
  127. package/src/util/unzipp.ts +9 -0
  128. package/dist/chunk-4VC3246A.js +0 -83
  129. package/dist/chunk-4VC3246A.js.map +0 -1
  130. package/dist/chunk-CDOBNSCL.js.map +0 -1
  131. package/dist/chunk-NVMUSXA5.js.map +0 -1
  132. package/dist/chunk-P7QOZBII.js +0 -386
  133. package/dist/chunk-P7QOZBII.js.map +0 -1
  134. package/dist/chunk-RITMMCZE.js.map +0 -1
  135. package/dist/chunk-WYSPGQ3S.js +0 -44
  136. package/dist/chunk-WYSPGQ3S.js.map +0 -1
  137. package/dist/chunk-XAUB42TO.js.map +0 -1
  138. package/dist/chunk-XVH2CU2Q.js.map +0 -1
  139. package/dist/narou-CatW_TC9.d.cts +0 -301
  140. package/dist/narou-fH9osIoh.d.ts +0 -301
  141. /package/dist/{chunk-K22KVNAH.js.map → chunk-DEQICAN3.js.map} +0 -0
  142. /package/dist/{chunk-AZT2OXBZ.js.map → chunk-LQLNWSWV.js.map} +0 -0
  143. /package/dist/{chunk-SNPBEVCY.js.map → chunk-PLEM2AOH.js.map} +0 -0
@@ -34,16 +34,32 @@ export abstract class SearchBuilderBase<
34
34
  /**
35
35
  * constructor
36
36
  * @private
37
+ * @param params クエリパラメータ
38
+ * @param api NarouNovel インスタンス
37
39
  */
38
40
  constructor(
39
41
  protected params: TParams = {} as TParams,
40
42
  protected api: NarouNovel
41
43
  ) {}
42
44
 
45
+ /**
46
+ * 配列から重複を除去する
47
+ * @protected
48
+ * @static
49
+ * @param array 配列
50
+ * @returns 重複を除去した配列
51
+ */
43
52
  protected static distinct<T>(array: readonly T[]): T[] {
44
53
  return Array.from(new Set(array));
45
54
  }
46
55
 
56
+ /**
57
+ * 配列をハイフン区切りの文字列に変換する
58
+ * @protected
59
+ * @static
60
+ * @param n 文字列または数値の配列、あるいは単一の文字列または数値
61
+ * @returns ハイフン区切りの文字列
62
+ */
47
63
  protected static array2string<T extends string | number>(
48
64
  n: T | readonly T[]
49
65
  ): Join<T> {
@@ -55,8 +71,9 @@ export abstract class SearchBuilderBase<
55
71
  }
56
72
 
57
73
  /**
58
- *
59
- * @return {SearchBuilder} this
74
+ * 取得件数を指定する (lim)
75
+ * @param num 取得件数 (1-500)
76
+ * @return {this}
60
77
  */
61
78
  limit(num: number): this {
62
79
  this.set({ lim: num } as TParams);
@@ -64,8 +81,9 @@ export abstract class SearchBuilderBase<
64
81
  }
65
82
 
66
83
  /**
67
- *
68
- * @return {SearchBuilder} this
84
+ * 取得開始位置を指定する (st)
85
+ * @param num 取得開始位置 (1-)
86
+ * @return {this}
69
87
  */
70
88
  start(num: number): this {
71
89
  this.set({ st: num } as TParams);
@@ -73,18 +91,20 @@ export abstract class SearchBuilderBase<
73
91
  }
74
92
 
75
93
  /**
76
- *
77
- * @return {SearchBuilder} this
94
+ * ページ番号と1ページあたりの件数で取得範囲を指定する
95
+ * @param no ページ番号 (0-)
96
+ * @param count 1ページあたりの件数 (デフォルト: 20)
97
+ * @return {this}
78
98
  */
79
99
  page(no: number, count = 20): this {
80
100
  return this.limit(count).start(no * count);
81
101
  }
82
102
 
83
103
  /**
84
- * 出力順序を指定する。指定しない場合は新着順となります。
85
- * old 古い順
104
+ * 出力順序を指定する (order)
105
+ * 指定しない場合は新着順となります。
86
106
  * @param {TOrder} order 出力順序
87
- * @return {SearchBuilder} this
107
+ * @return {this}
88
108
  */
89
109
  order(order: TOrder): this {
90
110
  this.set({ order: order } as TParams);
@@ -92,11 +112,11 @@ export abstract class SearchBuilderBase<
92
112
  }
93
113
 
94
114
  /**
95
- * gzip圧縮する。
115
+ * gzip圧縮レベルを指定する (gzip)
96
116
  *
97
117
  * 転送量上限を減らすためにも推奨
98
118
  * @param {GzipLevel} level gzip圧縮レベル(1~5)
99
- * @return {SearchBuilder} this
119
+ * @return {this}
100
120
  */
101
121
  gzip(level: GzipLevel): this {
102
122
  this.set({ gzip: level } as TParams);
@@ -105,8 +125,9 @@ export abstract class SearchBuilderBase<
105
125
 
106
126
  /**
107
127
  * クエリパラメータをセットする
108
- * @private
109
- * @return {SearchBuilder} this
128
+ * @protected
129
+ * @param obj セットするパラメータ
130
+ * @return {this}
110
131
  */
111
132
  protected set(obj: TParams): this {
112
133
  this.params = { ...this.params, ...obj };
@@ -115,6 +136,9 @@ export abstract class SearchBuilderBase<
115
136
 
116
137
  /**
117
138
  * クエリパラメータを削除する
139
+ * @protected
140
+ * @param key 削除するパラメータのキー
141
+ * @returns {this}
118
142
  */
119
143
  protected unset(key: keyof TParams): this {
120
144
  delete this.params[key];
@@ -126,8 +150,10 @@ export abstract class NovelSearchBuilderBase<
126
150
  T extends SearchResultFieldNames,
127
151
  > extends SearchBuilderBase<SearchParams, Order> {
128
152
  /**
129
- * a
130
- * @return {SearchBuilder} this
153
+ * 検索語を指定します (word)。
154
+ * 半角または全角スペースで区切るとAND抽出になります。部分一致でHITします。
155
+ * @param word 検索語
156
+ * @return {this}
131
157
  */
132
158
  word(word: string): this {
133
159
  this.set({ word: word });
@@ -135,8 +161,10 @@ export abstract class NovelSearchBuilderBase<
135
161
  }
136
162
 
137
163
  /**
138
- *
139
- * @return {SearchBuilder} this
164
+ * 除外したい単語を指定します (notword)。
165
+ * スペースで区切ることにより除外する単語を増やせます。部分一致で除外されます。
166
+ * @param word 除外語
167
+ * @return {this}
140
168
  */
141
169
  notWord(word: string): this {
142
170
  this.set({ notword: word });
@@ -144,8 +172,9 @@ export abstract class NovelSearchBuilderBase<
144
172
  }
145
173
 
146
174
  /**
147
- *
148
- * @return {SearchBuilder} this
175
+ * 検索対象を作品名に限定するかどうかを指定します (title)。
176
+ * @param bool trueの場合、作品名を検索対象とする (デフォルト: true)
177
+ * @return {this}
149
178
  */
150
179
  byTitle(bool = true): this {
151
180
  this.set({ title: bool ? BooleanNumber.True : BooleanNumber.False });
@@ -153,8 +182,9 @@ export abstract class NovelSearchBuilderBase<
153
182
  }
154
183
 
155
184
  /**
156
- *
157
- * @return {SearchBuilder} this
185
+ * 検索対象をあらすじに限定するかどうかを指定します (ex)。
186
+ * @param bool trueの場合、あらすじを検索対象とする (デフォルト: true)
187
+ * @return {this}
158
188
  */
159
189
  byOutline(bool = true): this {
160
190
  this.set({ ex: bool ? BooleanNumber.True : BooleanNumber.False });
@@ -162,8 +192,9 @@ export abstract class NovelSearchBuilderBase<
162
192
  }
163
193
 
164
194
  /**
165
- *
166
- * @return {SearchBuilder} this
195
+ * 検索対象をキーワードに限定するかどうかを指定します (keyword)。
196
+ * @param bool trueの場合、キーワードを検索対象とする (デフォルト: true)
197
+ * @return {this}
167
198
  */
168
199
  byKeyword(bool = true): this {
169
200
  this.set({ keyword: bool ? BooleanNumber.True : BooleanNumber.False });
@@ -171,8 +202,9 @@ export abstract class NovelSearchBuilderBase<
171
202
  }
172
203
 
173
204
  /**
174
- *
175
- * @return {SearchBuilder} this
205
+ * 検索対象を作者名に限定するかどうかを指定します (wname)。
206
+ * @param bool trueの場合、作者名を検索対象とする (デフォルト: true)
207
+ * @return {this}
176
208
  */
177
209
  byAuthor(bool = true): this {
178
210
  this.set({ wname: bool ? BooleanNumber.True : BooleanNumber.False });
@@ -180,8 +212,9 @@ export abstract class NovelSearchBuilderBase<
180
212
  }
181
213
 
182
214
  /**
183
- *
184
- * @return {SearchBuilder} this
215
+ * ボーイズラブ作品を抽出または除外します (isbl/notbl)。
216
+ * @param bool trueの場合、ボーイズラブ作品を抽出する (デフォルト: true)。falseの場合、除外する。
217
+ * @return {this}
185
218
  */
186
219
  isBL(bool = true): this {
187
220
  if (bool) {
@@ -193,8 +226,9 @@ export abstract class NovelSearchBuilderBase<
193
226
  }
194
227
 
195
228
  /**
196
- *
197
- * @return {SearchBuilder} this
229
+ * ガールズラブ作品を抽出または除外します (isgl/notgl)。
230
+ * @param bool trueの場合、ガールズラブ作品を抽出する (デフォルト: true)。falseの場合、除外する。
231
+ * @return {this}
198
232
  */
199
233
  isGL(bool = true): this {
200
234
  if (bool) {
@@ -206,8 +240,9 @@ export abstract class NovelSearchBuilderBase<
206
240
  }
207
241
 
208
242
  /**
209
- *
210
- * @return {SearchBuilder} this
243
+ * 残酷な描写あり作品を抽出または除外します (iszankoku/notzankoku)。
244
+ * @param bool trueの場合、残酷な描写あり作品を抽出する (デフォルト: true)。falseの場合、除外する。
245
+ * @return {this}
211
246
  */
212
247
  isZankoku(bool = true): this {
213
248
  if (bool) {
@@ -219,8 +254,9 @@ export abstract class NovelSearchBuilderBase<
219
254
  }
220
255
 
221
256
  /**
222
- *
223
- * @return {SearchBuilder} this
257
+ * 異世界転生作品を抽出または除外します (istensei/nottensei)。
258
+ * @param bool trueの場合、異世界転生作品を抽出する (デフォルト: true)。falseの場合、除外する。
259
+ * @return {this}
224
260
  */
225
261
  isTensei(bool = true): this {
226
262
  if (bool) {
@@ -232,8 +268,9 @@ export abstract class NovelSearchBuilderBase<
232
268
  }
233
269
 
234
270
  /**
235
- *
236
- * @return {SearchBuilder} this
271
+ * 異世界転移作品を抽出または除外します (istenni/nottenni)。
272
+ * @param bool trueの場合、異世界転移作品を抽出する (デフォルト: true)。falseの場合、除外する。
273
+ * @return {this}
237
274
  */
238
275
  isTenni(bool = true): this {
239
276
  if (bool) {
@@ -245,8 +282,8 @@ export abstract class NovelSearchBuilderBase<
245
282
  }
246
283
 
247
284
  /**
248
- *
249
- * @return {SearchBuilder} this
285
+ * 異世界転生または異世界転移作品を抽出します (istt)。
286
+ * @return {this}
250
287
  */
251
288
  isTT(): this {
252
289
  this.set({ istt: BooleanNumber.True });
@@ -254,8 +291,10 @@ export abstract class NovelSearchBuilderBase<
254
291
  }
255
292
 
256
293
  /**
257
- *
258
- * @return {SearchBuilder} this
294
+ * 抽出する作品の文字数を指定します (length)。
295
+ * 範囲指定する場合は、最小文字数と最大文字数をハイフン(-)記号で区切ってください。
296
+ * @param length 文字数、または[最小文字数, 最大文字数]
297
+ * @return {this}
259
298
  */
260
299
  length(length: number | readonly number[]): this {
261
300
  this.set({ length: NovelSearchBuilderBase.array2string(length) });
@@ -263,10 +302,17 @@ export abstract class NovelSearchBuilderBase<
263
302
  }
264
303
 
265
304
  /**
266
- *
267
- * @return {SearchBuilder} this
305
+ * 抽出する作品の会話率を%単位で指定します (kaiwaritu)。
306
+ * @param num 会話率(%)
307
+ * @return {this}
268
308
  */
269
309
  kaiwaritu(num: number): this;
310
+ /**
311
+ * 抽出する作品の会話率を%単位で範囲指定します (kaiwaritu)。
312
+ * @param min 最低会話率(%)
313
+ * @param max 最高会話率(%)
314
+ * @return {this}
315
+ */
270
316
  kaiwaritu(min: number, max: number): this;
271
317
 
272
318
  kaiwaritu(min: number, max?: number): this {
@@ -281,8 +327,9 @@ export abstract class NovelSearchBuilderBase<
281
327
  }
282
328
 
283
329
  /**
284
- *
285
- * @return {SearchBuilder} this
330
+ * 抽出する作品の挿絵数を指定します (sasie)。
331
+ * @param num 挿絵数、または[最小挿絵数, 最大挿絵数]
332
+ * @return {this}
286
333
  */
287
334
  sasie(num: number | readonly number[]): this {
288
335
  this.set({ sasie: NovelSearchBuilderBase.array2string(num) });
@@ -290,8 +337,9 @@ export abstract class NovelSearchBuilderBase<
290
337
  }
291
338
 
292
339
  /**
293
- *
294
- * @return {SearchBuilder} this
340
+ * 抽出する作品の予想読了時間を分単位で指定します (time)。
341
+ * @param num 読了時間(分)、または[最小読了時間, 最大読了時間]
342
+ * @return {this}
295
343
  */
296
344
  time(num: number | readonly number[]): this {
297
345
  this.set({ time: NovelSearchBuilderBase.array2string(num) });
@@ -299,8 +347,9 @@ export abstract class NovelSearchBuilderBase<
299
347
  }
300
348
 
301
349
  /**
302
- *
303
- * @return {SearchBuilder} this
350
+ * Nコードを指定して取得します (ncode)。
351
+ * @param ncodes Nコード、またはNコードの配列
352
+ * @return {this}
304
353
  */
305
354
  ncode(ncodes: string | readonly string[]): this {
306
355
  this.set({ ncode: NovelSearchBuilderBase.array2string(ncodes) });
@@ -308,8 +357,9 @@ export abstract class NovelSearchBuilderBase<
308
357
  }
309
358
 
310
359
  /**
311
- *
312
- * @return {SearchBuilder} this
360
+ * 抽出する小説タイプを指定します (type)。
361
+ * @param type 小説タイプ (t: 短編, r: 連載中, er: 完結済連載小説, ter: 短編と完結済連載小説, re: 連載中と完結済連載小説)
362
+ * @return {this}
313
363
  */
314
364
  type(type: NovelTypeParam): this {
315
365
  this.set({ type });
@@ -317,8 +367,10 @@ export abstract class NovelSearchBuilderBase<
317
367
  }
318
368
 
319
369
  /**
320
- *
321
- * @return {SearchBuilder} this
370
+ * 抽出する作品の文体を指定します (buntai)。
371
+ * 複数指定する場合はハイフン(-)で区切ってください。
372
+ * @param buntai 文体コード、または文体コードの配列
373
+ * @return {this}
322
374
  */
323
375
  buntai(buntai: BuntaiParam | readonly BuntaiParam[]): this {
324
376
  this.set({ buntai: NovelSearchBuilderBase.array2string(buntai) });
@@ -326,8 +378,9 @@ export abstract class NovelSearchBuilderBase<
326
378
  }
327
379
 
328
380
  /**
329
- *
330
- * @return {SearchBuilder} this
381
+ * 連載停止中作品に関する指定をします (stop)。
382
+ * @param bool trueの場合、長期連載停止中のみ取得する (デフォルト: true)。falseの場合、長期連載停止中を除外する。
383
+ * @return {this}
331
384
  */
332
385
  isStop(bool = true): this {
333
386
  this.set({ stop: bool ? StopParam.Stopping : StopParam.NoStopping });
@@ -335,20 +388,33 @@ export abstract class NovelSearchBuilderBase<
335
388
  }
336
389
 
337
390
  /**
338
- *
339
- * @return {SearchBuilder} this
391
+ * ピックアップ作品のみを取得します (ispickup)。
392
+ * @return {this}
340
393
  */
341
- isPickup(bool = true): this {
342
- this.set({ ispickup: bool ? BooleanNumber.True : BooleanNumber.False });
394
+ isPickup(): this {
395
+ this.set({ ispickup: BooleanNumber.True });
343
396
  return this;
344
397
  }
345
398
 
346
399
  /**
347
- *
348
- * @return {SearchBuilder} this
400
+ * 最終更新日時を指定します (lastup)。
401
+ * @param date 最終更新日時 (YYYYMMDDhhmmss形式またはUNIXタイムスタンプ)
402
+ * @return {this}
349
403
  */
350
404
  lastUpdate(date: DateParam): this;
405
+ /**
406
+ * 最終更新日時の範囲を指定します (lastup)。
407
+ * @param from 開始日時 (UNIXタイムスタンプ)
408
+ * @param to 終了日時 (UNIXタイムスタンプ)
409
+ * @return {this}
410
+ */
351
411
  lastUpdate(from: number, to: number): this;
412
+ /**
413
+ * 最終更新日時の範囲を指定します (lastup)。
414
+ * @param from 開始日時 (Dateオブジェクト)
415
+ * @param to 終了日時 (Dateオブジェクト)
416
+ * @return {this}
417
+ */
352
418
  lastUpdate(from: Date, to: Date): this;
353
419
 
354
420
  lastUpdate(x: string | number | Date, y?: number | Date): this {
@@ -367,8 +433,25 @@ export abstract class NovelSearchBuilderBase<
367
433
  return this;
368
434
  }
369
435
 
436
+ /**
437
+ * 作品の更新日時を指定します (lastupdate)。
438
+ * @param date 作品の更新日時 (YYYYMMDDhhmmss形式またはUNIXタイムスタンプ)
439
+ * @return {this}
440
+ */
370
441
  lastNovelUpdate(date: DateParam): this;
442
+ /**
443
+ * 作品の更新日時の範囲を指定します (lastupdate)。
444
+ * @param from 開始日時 (UNIXタイムスタンプ)
445
+ * @param to 終了日時 (UNIXタイムスタンプ)
446
+ * @return {this}
447
+ */
371
448
  lastNovelUpdate(from: number, to: number): this;
449
+ /**
450
+ * 作品の更新日時の範囲を指定します (lastupdate)。
451
+ * @param from 開始日時 (Dateオブジェクト)
452
+ * @param to 終了日時 (Dateオブジェクト)
453
+ * @return {this}
454
+ */
372
455
  lastNovelUpdate(from: Date, to: Date): this;
373
456
 
374
457
  lastNovelUpdate(x: string | number | Date, y?: number | Date): this {
@@ -405,8 +488,10 @@ export default class SearchBuilder<
405
488
  TOpt extends keyof NarouSearchResult = never,
406
489
  > extends NovelSearchBuilderBase<T | TOpt> {
407
490
  /**
408
- *
409
- * @return {SearchBuilder} this
491
+ * 大ジャンルを指定して取得します (biggenre)。
492
+ * 複数指定する場合はハイフン(-)で区切ってください。
493
+ * @param genre 大ジャンルコード、または大ジャンルコードの配列
494
+ * @return {this}
410
495
  */
411
496
  bigGenre(genre: BigGenre | readonly BigGenre[]): this {
412
497
  this.set({ biggenre: SearchBuilder.array2string(genre) });
@@ -414,8 +499,10 @@ export default class SearchBuilder<
414
499
  }
415
500
 
416
501
  /**
417
- *
418
- * @return {SearchBuilder} this
502
+ * 除外したい大ジャンルを指定します (notbiggenre)。
503
+ * 複数指定する場合はハイフン(-)で区切ってください。
504
+ * @param genre 除外する大ジャンルコード、または大ジャンルコードの配列
505
+ * @return {this}
419
506
  */
420
507
  notBigGenre(genre: BigGenre | readonly BigGenre[]): this {
421
508
  this.set({ notbiggenre: SearchBuilder.array2string(genre) });
@@ -423,8 +510,10 @@ export default class SearchBuilder<
423
510
  }
424
511
 
425
512
  /**
426
- *
427
- * @return {SearchBuilder} this
513
+ * ジャンルを指定して取得します (genre)。
514
+ * 複数指定する場合はハイフン(-)で区切ってください。
515
+ * @param genre ジャンルコード、またはジャンルコードの配列
516
+ * @return {this}
428
517
  */
429
518
  genre(genre: Genre | readonly Genre[]): this {
430
519
  this.set({ genre: SearchBuilder.array2string(genre) });
@@ -432,8 +521,10 @@ export default class SearchBuilder<
432
521
  }
433
522
 
434
523
  /**
435
- *
436
- * @return {SearchBuilder} this
524
+ * 除外したいジャンルを指定します (notgenre)。
525
+ * 複数指定する場合はハイフン(-)で区切ってください。
526
+ * @param genre 除外するジャンルコード、またはジャンルコードの配列
527
+ * @return {this}
437
528
  */
438
529
  notGenre(genre: Genre | readonly Genre[]): this {
439
530
  this.set({ notgenre: SearchBuilder.array2string(genre) });
@@ -441,8 +532,10 @@ export default class SearchBuilder<
441
532
  }
442
533
 
443
534
  /**
444
- *
445
- * @return {SearchBuilder} this
535
+ * ユーザIDを指定して取得します (userid)。
536
+ * 複数指定する場合はハイフン(-)で区切ってください。
537
+ * @param ids ユーザID、またはユーザIDの配列
538
+ * @return {this}
446
539
  */
447
540
  userId(ids: number | readonly number[]): this {
448
541
  this.set({ userid: SearchBuilder.array2string(ids) });
@@ -450,8 +543,9 @@ export default class SearchBuilder<
450
543
  }
451
544
 
452
545
  /**
453
- *
454
- * @return {SearchBuilder} this
546
+ * R15作品を抽出または除外します (isr15/notr15)。
547
+ * @param bool trueの場合、R15作品を抽出する (デフォルト: true)。falseの場合、除外する。
548
+ * @return {this}
455
549
  */
456
550
  isR15(bool = true): this {
457
551
  if (bool) {
@@ -463,8 +557,11 @@ export default class SearchBuilder<
463
557
  }
464
558
 
465
559
  /**
466
- *
467
- * @return {SearchBuilder} this
560
+ * 出力する項目を個別に指定します (of)。
561
+ * 未指定時は全項目出力されます。転送量軽減のため、このパラメータの使用が推奨されます。
562
+ * 複数項目を出力する場合はハイフン(-)記号で区切ってください。
563
+ * @param fields 出力するフィールド名、またはフィールド名の配列
564
+ * @return {SearchBuilder<SearchResultFields<TFields>, TOpt>} 型が更新されたビルダー
468
565
  */
469
566
  fields<TFields extends Fields>(
470
567
  fields: TFields | readonly TFields[]
@@ -474,6 +571,12 @@ export default class SearchBuilder<
474
571
  return this as any;
475
572
  }
476
573
 
574
+ /**
575
+ * 出力オプション項目を指定します (opt)。
576
+ * 複数項目を出力する場合はハイフン(-)記号で区切ってください。
577
+ * @param option 出力するオプションフィールド名、またはオプションフィールド名の配列
578
+ * @return {SearchBuilder<T, SearchResultOptionalFields<TFields>>} 型が更新されたビルダー
579
+ */
477
580
  opt<TFields extends OptionalFields>(
478
581
  option: TFields | readonly TFields[]
479
582
  ): SearchBuilder<T, SearchResultOptionalFields<TFields>> {
@@ -0,0 +1,38 @@
1
+ // 日付関連のユーティリティ関数
2
+
3
+ /**
4
+ * 文字列の日付(yyyyMMdd形式)をDateオブジェクトに変換する
5
+ * @param dateStr yyyyMMdd形式の日付文字列
6
+ * @returns Dateオブジェクト
7
+ */
8
+ export function parseDate(dateStr: string): Date {
9
+ const year = parseInt(dateStr.substring(0, 4), 10);
10
+ const month = parseInt(dateStr.substring(4, 6), 10) - 1; // JavaScriptの月は0から始まる
11
+ const day = parseInt(dateStr.substring(6, 8), 10);
12
+
13
+ return new Date(year, month, day, 0, 0, 0, 0);
14
+ }
15
+
16
+ /**
17
+ * 日付をyyyyMMdd形式の文字列に変換する
18
+ * @param date 日付
19
+ * @returns yyyyMMdd形式の文字列
20
+ */
21
+ export function formatDate(date: Date): string {
22
+ const year = date.getFullYear();
23
+ const month = String(date.getMonth() + 1).padStart(2, '0');
24
+ const day = String(date.getDate()).padStart(2, '0');
25
+ return `${year}${month}${day}`;
26
+ }
27
+
28
+ /**
29
+ * 指定された日数を加算した新しい日付を返す
30
+ * @param date 元の日付
31
+ * @param days 加算する日数
32
+ * @returns 新しい日付
33
+ */
34
+ export function addDays(date: Date, days: number): Date {
35
+ const result = new Date(date);
36
+ result.setDate(result.getDate() + days);
37
+ return result;
38
+ }
package/src/util/jsonp.ts CHANGED
@@ -13,30 +13,75 @@ declare global {
13
13
  [key: CallbackId]: (data: any) => void;
14
14
  }
15
15
  }
16
+
17
+ /**
18
+ * JSONP呼び出しのオプション設定
19
+ */
16
20
  export type JsonpOption = {
21
+ /**
22
+ * コールバック関数名のプレフィックス
23
+ * @default "__jp"
24
+ */
17
25
  prefix?: string;
26
+
27
+ /**
28
+ * コールバック関数名を指定するURLパラメータ名
29
+ * @default "callback"
30
+ */
18
31
  param?: string;
32
+
33
+ /**
34
+ * タイムアウト時間(ミリ秒)
35
+ * @default 15000
36
+ */
19
37
  timeout?: number;
20
38
  };
21
39
 
22
-
23
- const noop = function () {};
40
+ const noop = function () { };
24
41
 
42
+ /**
43
+ * JSONPリクエストを実行してデータを取得します。
44
+ *
45
+ * @param url - リクエスト先のURL
46
+ * @param options - JSONP呼び出しのオプション設定
47
+ * @returns JSONPリクエストの結果をPromiseで返します
48
+ * @throws {Error} タイムアウトが発生した場合、"Timeout"メッセージのエラーをスローします
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * // 基本的な使用方法
53
+ * const data = await jsonp<ResponseType>('https://example.com/api');
54
+ *
55
+ * // オプション指定
56
+ * const data = await jsonp<ResponseType>('https://example.com/api', {
57
+ * prefix: 'customPrefix',
58
+ * param: 'callbackParam',
59
+ * timeout: 10000
60
+ * });
61
+ * ```
62
+ */
25
63
  export function jsonp<T>(
26
64
  url: string,
27
65
  { prefix = "__jp", param = "callback", timeout = 15000 }: JsonpOption = {}
28
66
  ): Promise<T> {
29
67
  return new Promise(function (resolve, reject) {
68
+ // 最初のscriptタグを取得し、そのタグの直前に新しいscriptタグを挿入するための参照を取得
69
+ // これにより、ページの構造を大きく変えることなくscriptを追加できる
30
70
  const targetChild = document.getElementsByTagName("script").item(0);
31
71
  const target = targetChild?.parentNode ?? document.head;
32
72
 
73
+ // ユニークなコールバック関数名を生成
33
74
  const id: CallbackId = `${prefix}${count++}`;
75
+
76
+ // リソース解放用の関数を定義
77
+ // スクリプトタグの削除、コールバック関数のクリーンアップ、タイマーのクリアを行う
34
78
  const cleanup = function () {
35
79
  // Remove the script tag.
36
80
  if (script && script.parentNode) {
37
81
  script.parentNode.removeChild(script);
38
82
  }
39
83
 
84
+ // コールバック関数を空の関数に置き換えてメモリリークを防止
40
85
  window[id] = noop;
41
86
 
42
87
  if (timer) {
@@ -44,25 +89,35 @@ export function jsonp<T>(
44
89
  }
45
90
  };
46
91
 
92
+ // タイムアウト処理の設定
93
+ // 指定された時間内にレスポンスがない場合はエラーとして処理
47
94
  const timer =
48
95
  timeout > 0
49
96
  ? setTimeout(() => {
50
- cleanup();
51
- reject(new Error("Timeout"));
52
- }, timeout)
97
+ cleanup();
98
+ reject(new Error("Timeout"));
99
+ }, timeout)
53
100
  : undefined;
54
101
 
102
+ // サーバーからのレスポンスを処理するコールバック関数
55
103
  const callback = (data: T) => {
56
104
  cleanup();
57
105
  resolve(data);
58
106
  };
107
+
108
+ // グローバルスコープにコールバック関数を登録
109
+ // これによりJSONPのレスポンスから関数が呼び出せるようになる
59
110
  window[id] = callback;
60
111
 
61
- // Create script.
112
+ // JSONPリクエスト用のscriptタグを作成
62
113
  const script = document.createElement("script");
63
114
  const urlObj = new URL(url);
115
+
116
+ // URLにコールバック関数名をパラメータとして追加
64
117
  urlObj.searchParams.set(param, id);
65
118
  script.setAttribute("src", urlObj.toString());
119
+
120
+ // DOMにscriptタグを挿入し、リクエストを開始
66
121
  target.insertBefore(script, targetChild);
67
122
  });
68
123
  }