narou 0.7.6 → 0.8.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 (139) hide show
  1. package/README.md +97 -4
  2. package/dist/index.browser.d.ts +7 -1
  3. package/dist/index.browser.d.ts.map +1 -1
  4. package/dist/index.browser.js +37 -77
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.common.d.ts +12 -7
  7. package/dist/index.common.d.ts.map +1 -1
  8. package/dist/index.common.js +30 -20
  9. package/dist/index.common.js.map +1 -1
  10. package/dist/index.d.ts +15 -3
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +46 -80
  13. package/dist/index.js.map +1 -1
  14. package/dist/narou-fetch.d.ts.map +1 -1
  15. package/dist/narou-fetch.js +35 -119
  16. package/dist/narou-fetch.js.map +1 -1
  17. package/dist/narou-jsonp.d.ts.map +1 -1
  18. package/dist/narou-jsonp.js +14 -92
  19. package/dist/narou-jsonp.js.map +1 -1
  20. package/dist/narou-search-results.d.ts +20 -10
  21. package/dist/narou-search-results.d.ts.map +1 -1
  22. package/dist/narou-search-results.js +6 -9
  23. package/dist/narou-search-results.js.map +1 -1
  24. package/dist/narou.d.ts +7 -6
  25. package/dist/narou.d.ts.map +1 -1
  26. package/dist/narou.js +20 -95
  27. package/dist/narou.js.map +1 -1
  28. package/dist/params.d.ts +55 -14
  29. package/dist/params.d.ts.map +1 -1
  30. package/dist/params.js +56 -39
  31. package/dist/params.js.map +1 -1
  32. package/dist/ranking-history.js +7 -7
  33. package/dist/ranking-history.js.map +1 -1
  34. package/dist/ranking.js +41 -110
  35. package/dist/ranking.js.map +1 -1
  36. package/dist/search-builder-r18.d.ts +5 -5
  37. package/dist/search-builder-r18.d.ts.map +1 -1
  38. package/dist/search-builder-r18.js +17 -37
  39. package/dist/search-builder-r18.js.map +1 -1
  40. package/dist/search-builder.d.ts +50 -65
  41. package/dist/search-builder.d.ts.map +1 -1
  42. package/dist/search-builder.js +155 -215
  43. package/dist/search-builder.js.map +1 -1
  44. package/dist/user-search.d.ts +63 -0
  45. package/dist/user-search.d.ts.map +1 -0
  46. package/dist/user-search.js +94 -0
  47. package/dist/user-search.js.map +1 -0
  48. package/dist/util/jsonp.d.ts +3 -0
  49. package/dist/util/jsonp.d.ts.map +1 -1
  50. package/dist/util/jsonp.js +14 -17
  51. package/dist/util/jsonp.js.map +1 -1
  52. package/dist/util/unzipp.js +6 -51
  53. package/dist/util/unzipp.js.map +1 -1
  54. package/package.json +18 -8
  55. package/src/index.browser.ts +12 -1
  56. package/src/index.common.ts +18 -29
  57. package/src/index.ts +20 -3
  58. package/src/narou-fetch.ts +1 -2
  59. package/src/narou-jsonp.ts +1 -3
  60. package/src/narou-search-results.ts +20 -7
  61. package/src/narou.ts +26 -11
  62. package/src/params.ts +60 -15
  63. package/src/search-builder-r18.ts +9 -9
  64. package/src/search-builder.ts +96 -102
  65. package/src/user-search.ts +109 -0
  66. package/src/util/jsonp.ts +1 -2
  67. package/dist/util/url.d.ts +0 -10
  68. package/dist/util/url.d.ts.map +0 -1
  69. package/dist/util/url.js +0 -9
  70. package/dist/util/url.js.map +0 -1
  71. package/dist.es2015/index.browser.js +0 -50
  72. package/dist.es2015/index.browser.js.map +0 -1
  73. package/dist.es2015/index.common.js +0 -6
  74. package/dist.es2015/index.common.js.map +0 -1
  75. package/dist.es2015/index.js +0 -51
  76. package/dist.es2015/index.js.map +0 -1
  77. package/dist.es2015/narou-fetch.js +0 -44
  78. package/dist.es2015/narou-fetch.js.map +0 -1
  79. package/dist.es2015/narou-jsonp.js +0 -22
  80. package/dist.es2015/narou-jsonp.js.map +0 -1
  81. package/dist.es2015/narou-ranking-results.js +0 -2
  82. package/dist.es2015/narou-ranking-results.js.map +0 -1
  83. package/dist.es2015/narou-search-results.js +0 -60
  84. package/dist.es2015/narou-search-results.js.map +0 -1
  85. package/dist.es2015/narou.js +0 -24
  86. package/dist.es2015/narou.js.map +0 -1
  87. package/dist.es2015/params.js +0 -226
  88. package/dist.es2015/params.js.map +0 -1
  89. package/dist.es2015/ranking-history.js +0 -10
  90. package/dist.es2015/ranking-history.js.map +0 -1
  91. package/dist.es2015/ranking.js +0 -80
  92. package/dist.es2015/ranking.js.map +0 -1
  93. package/dist.es2015/search-builder-r18.js +0 -42
  94. package/dist.es2015/search-builder-r18.js.map +0 -1
  95. package/dist.es2015/search-builder.js +0 -390
  96. package/dist.es2015/search-builder.js.map +0 -1
  97. package/dist.es2015/util/jsonp.js +0 -44
  98. package/dist.es2015/util/jsonp.js.map +0 -1
  99. package/dist.es2015/util/type.js +0 -2
  100. package/dist.es2015/util/type.js.map +0 -1
  101. package/dist.es2015/util/unzipp.js +0 -8
  102. package/dist.es2015/util/unzipp.js.map +0 -1
  103. package/dist.es2015/util/url.js +0 -7
  104. package/dist.es2015/util/url.js.map +0 -1
  105. package/dist.esm/index.browser.js +0 -102
  106. package/dist.esm/index.browser.js.map +0 -1
  107. package/dist.esm/index.common.js +0 -6
  108. package/dist.esm/index.common.js.map +0 -1
  109. package/dist.esm/index.js +0 -103
  110. package/dist.esm/index.js.map +0 -1
  111. package/dist.esm/narou-fetch.js +0 -128
  112. package/dist.esm/narou-fetch.js.map +0 -1
  113. package/dist.esm/narou-jsonp.js +0 -100
  114. package/dist.esm/narou-jsonp.js.map +0 -1
  115. package/dist.esm/narou-ranking-results.js +0 -2
  116. package/dist.esm/narou-ranking-results.js.map +0 -1
  117. package/dist.esm/narou-search-results.js +0 -63
  118. package/dist.esm/narou-search-results.js.map +0 -1
  119. package/dist.esm/narou.js +0 -103
  120. package/dist.esm/narou.js.map +0 -1
  121. package/dist.esm/params.js +0 -227
  122. package/dist.esm/params.js.map +0 -1
  123. package/dist.esm/ranking-history.js +0 -10
  124. package/dist.esm/ranking-history.js.map +0 -1
  125. package/dist.esm/ranking.js +0 -154
  126. package/dist.esm/ranking.js.map +0 -1
  127. package/dist.esm/search-builder-r18.js +0 -63
  128. package/dist.esm/search-builder-r18.js.map +0 -1
  129. package/dist.esm/search-builder.js +0 -438
  130. package/dist.esm/search-builder.js.map +0 -1
  131. package/dist.esm/util/jsonp.js +0 -45
  132. package/dist.esm/util/jsonp.js.map +0 -1
  133. package/dist.esm/util/type.js +0 -2
  134. package/dist.esm/util/type.js.map +0 -1
  135. package/dist.esm/util/unzipp.js +0 -53
  136. package/dist.esm/util/unzipp.js.map +0 -1
  137. package/dist.esm/util/url.js +0 -7
  138. package/dist.esm/util/url.js.map +0 -1
  139. package/src/util/url.ts +0 -7
package/src/narou.ts CHANGED
@@ -1,9 +1,21 @@
1
1
  import { NarouRankingResult } from "./narou-ranking-results";
2
- import NarouSearchResults, { NarouSearchResult } from "./narou-search-results";
3
- import { RankingHistoryParams, RankingParams, SearchParams } from "./params";
2
+ import NarouSearchResults, {
3
+ NarouSearchResult,
4
+ UserSearchResult,
5
+ } from "./narou-search-results";
6
+ import {
7
+ RankingHistoryParams,
8
+ RankingParams,
9
+ SearchParams,
10
+ UserSearchParams,
11
+ } from "./params";
4
12
  import { RankingHistoryRawResult } from "./ranking-history";
5
13
 
6
- export type NarouParams = SearchParams | RankingParams | RankingHistoryParams;
14
+ export type NarouParams =
15
+ | SearchParams
16
+ | RankingParams
17
+ | RankingHistoryParams
18
+ | UserSearchParams;
7
19
 
8
20
  /**
9
21
  * なろう小説APIへのリクエストを実行する
@@ -23,18 +35,15 @@ export default abstract class NarouNovel {
23
35
  ): Promise<T>;
24
36
 
25
37
  async executeSearch<T extends keyof NarouSearchResult>(
26
- params: NarouParams,
38
+ params: SearchParams,
27
39
  endpoint = "https://api.syosetu.com/novelapi/api/"
28
- ): Promise<NarouSearchResults<T>> {
29
- return new NarouSearchResults<T>(
30
- await this.execute(params, endpoint),
31
- params
32
- );
40
+ ): Promise<NarouSearchResults<NarouSearchResult, T>> {
41
+ return new NarouSearchResults(await this.execute(params, endpoint), params);
33
42
  }
34
43
 
35
44
  async executeNovel<T extends keyof NarouSearchResult>(
36
45
  params: SearchParams
37
- ): Promise<NarouSearchResults<T>> {
46
+ ): Promise<NarouSearchResults<NarouSearchResult, T>> {
38
47
  return await this.executeSearch(
39
48
  params,
40
49
  "https://api.syosetu.com/novelapi/api/"
@@ -43,7 +52,7 @@ export default abstract class NarouNovel {
43
52
 
44
53
  async executeNovel18<T extends keyof NarouSearchResult>(
45
54
  params: SearchParams
46
- ): Promise<NarouSearchResults<T>> {
55
+ ): Promise<NarouSearchResults<NarouSearchResult, T>> {
47
56
  return await this.executeSearch(
48
57
  params,
49
58
  "https://api.syosetu.com/novel18api/api/"
@@ -59,4 +68,10 @@ export default abstract class NarouNovel {
59
68
  ): Promise<RankingHistoryRawResult[]> {
60
69
  return await this.execute(params, "https://api.syosetu.com/rank/rankin/");
61
70
  }
71
+
72
+ async executeUserSearch<T extends keyof UserSearchResult>(
73
+ params: UserSearchParams
74
+ ): Promise<NarouSearchResults<UserSearchResult, T>> {
75
+ return await this.execute(params, "https://api.syosetu.com/userapi/api/");
76
+ }
62
77
  }
package/src/params.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NarouSearchResult } from "./narou-search-results";
1
+ import { NarouSearchResult, UserSearchResult } from "./narou-search-results";
2
2
  import { Join } from "./util/type";
3
3
 
4
4
  export const RankingType = {
@@ -9,6 +9,18 @@ export const RankingType = {
9
9
  } as const;
10
10
  export type RankingType = typeof RankingType[keyof typeof RankingType];
11
11
 
12
+ export interface ParamsBase {
13
+ gzip?: GzipLevel;
14
+ out?: "json" | "jsonp";
15
+ }
16
+
17
+ export interface ParamsBaseWithOrder<TOrder extends string> extends ParamsBase {
18
+ of?: string;
19
+ lim?: number;
20
+ st?: number;
21
+ order?: TOrder;
22
+ }
23
+
12
24
  /**
13
25
  * {@link SearchBuilder#Fields}メソッドにパラメータを指定する際のヘルパー。
14
26
  * @typedef {Object} Fields
@@ -38,14 +50,7 @@ export type RankingType = typeof RankingType[keyof typeof RankingType];
38
50
  * @property {string} novelupdated_at 小説の更新日時
39
51
  * @property {string} updated_at 最終更新日時(注意:システム用で小説更新時とは関係ありません)
40
52
  */
41
- export interface SearchParams {
42
- gzip?: GzipLevel;
43
- out?: "json";
44
- of?: string;
45
- lim?: number;
46
- st?: number;
47
- order?: Order;
48
-
53
+ export interface SearchParams extends ParamsBaseWithOrder<Order> {
49
54
  word?: string;
50
55
  notword?: string;
51
56
  title?: BooleanNumber;
@@ -104,16 +109,34 @@ export interface SearchParams {
104
109
  opt?: Join<OptionalFields>;
105
110
  }
106
111
 
107
- export interface RankingParams {
112
+ export interface RankingParams extends ParamsBase {
108
113
  rtype: `${string}-${RankingType}`;
109
- gzip?: GzipLevel;
110
- out?: "json";
111
114
  }
112
115
 
113
- export interface RankingHistoryParams {
116
+ export interface RankingHistoryParams extends ParamsBase {
114
117
  ncode: string;
115
- gzip?: GzipLevel;
116
- out?: "json";
118
+ }
119
+
120
+ /**
121
+ * ユーザー検索パラメータ
122
+ */
123
+ export interface UserSearchParams extends ParamsBaseWithOrder<UserOrder> {
124
+ /** 単語を指定できます。半角または全角スペースで区切るとAND抽出になります。部分一致でHITします。検索の対象はユーザ名とユーザ名のフリガナです。 */
125
+ word?: string;
126
+ /** 含みたくない単語を指定できます。スペースで区切ることにより含ませない単語を増やせます。部分一致で除外されます。除外の対象はユーザ名とユーザ名のフリガナです。 */
127
+ notword?: string;
128
+ /** ユーザIDで抽出可能。 */
129
+ userid?: number;
130
+ /** 抽出するユーザのユーザ名のフリガナの頭文字を指定できます。頭文字はユーザ名のフリガナをひらがなに変換し、最初の1文字が「ぁ」~「ん」の場合に対象となります。 */
131
+ name1st?: string;
132
+ /** 抽出するユーザの小説投稿数の下限を指定できます。小説投稿件数が指定された数値以上のユーザを抽出します。 */
133
+ minnovel?: number;
134
+ /** 抽出するユーザの小説投稿数の上限を指定できます。小説投稿件数が指定された数値以下のユーザを抽出します。 */
135
+ maxnovel?: number;
136
+ /** 抽出するユーザのレビュー投稿数の下限を指定できます。レビュー投稿件数が指定された数値以上のユーザを抽出します。 */
137
+ minreview?: number;
138
+ /** 抽出するユーザのレビュー投稿数の上限を指定できます。レビュー投稿件数が指定された数値以下のユーザを抽出します。 */
139
+ maxreview?: number;
117
140
  }
118
141
 
119
142
  export const BooleanNumber = {
@@ -216,6 +239,18 @@ export type R18Fields = typeof R18Fields[keyof Omit<
216
239
  "novel_type" | "weekly_unique" | "biggenre" | "genre"
217
240
  >];
218
241
 
242
+ export const UserFields = {
243
+ userid: "u",
244
+ name: "n",
245
+ yomikata: "y",
246
+ name1st: "1",
247
+ novel_cnt: "nc",
248
+ review_cnt: "rc",
249
+ novel_length: "nl",
250
+ sum_global_point: "sg",
251
+ } as const;
252
+ export type UserFields = typeof UserFields[keyof UserSearchResult];
253
+
219
254
  export const OptionalFields = {
220
255
  weekly_unique: "weekly",
221
256
  } as const;
@@ -379,4 +414,14 @@ export const NovelTypeParam = {
379
414
  } as const;
380
415
  export type NovelTypeParam = typeof NovelTypeParam[keyof typeof NovelTypeParam];
381
416
 
417
+ export const UserOrder = {
418
+ New: "new",
419
+ NovelCount: "novelcnt",
420
+ ReviewCount: "reviewcnt",
421
+ NovelLength: "novellength",
422
+ SumGlobalPoint: "sumglobalpoint",
423
+ Old: "old",
424
+ } as const;
425
+ export type UserOrder = typeof UserOrder[keyof typeof UserOrder];
426
+
382
427
  export type GzipLevel = 0 | 1 | 2 | 3 | 4 | 5;
@@ -1,8 +1,8 @@
1
- import { SearchBuilderBase } from "./search-builder";
1
+ import { NovelSearchBuilderBase } from "./search-builder";
2
2
  import NarouSearchResults, {
3
3
  NarouSearchResult,
4
4
  SearchResultR18Fields,
5
- SerachResultOptionalFields,
5
+ SearchResultOptionalFields,
6
6
  } from "./narou-search-results";
7
7
  import {
8
8
  R18Site,
@@ -23,18 +23,18 @@ export type DefaultR18SearchResultFields = keyof Omit<
23
23
  export default class SearchBuilderR18<
24
24
  T extends SearchResultFieldNames = DefaultR18SearchResultFields,
25
25
  TOpt extends keyof NarouSearchResult = never
26
- > extends SearchBuilderBase<T | TOpt> {
26
+ > extends NovelSearchBuilderBase<T | TOpt> {
27
27
  /**
28
28
  * なろう小説APIへの検索リクエストを実行する
29
29
  * @override
30
30
  * @returns {Promise<NarouSearchResults>} 検索結果
31
31
  */
32
- execute(): Promise<NarouSearchResults<T | TOpt>> {
32
+ execute(): Promise<NarouSearchResults<NarouSearchResult, T | TOpt>> {
33
33
  return this.api.executeNovel18(this.params);
34
34
  }
35
35
 
36
36
  r18Site(sites: R18Site | readonly R18Site[]) {
37
- this.set({ nocgenre: SearchBuilderBase.array2string(sites) });
37
+ this.set({ nocgenre: NovelSearchBuilderBase.array2string(sites) });
38
38
  return this;
39
39
  }
40
40
 
@@ -43,7 +43,7 @@ export default class SearchBuilderR18<
43
43
  * @return {SearchBuilder} this
44
44
  */
45
45
  xid(ids: number | readonly number[]) {
46
- this.set({ xid: SearchBuilderBase.array2string(ids) });
46
+ this.set({ xid: NovelSearchBuilderBase.array2string(ids) });
47
47
  return this;
48
48
  }
49
49
 
@@ -54,15 +54,15 @@ export default class SearchBuilderR18<
54
54
  fields<TFields extends R18Fields>(
55
55
  fields: TFields | readonly TFields[]
56
56
  ): SearchBuilderR18<SearchResultR18Fields<R18Fields>> {
57
- this.set({ of: SearchBuilderBase.array2string(fields) });
57
+ this.set({ of: NovelSearchBuilderBase.array2string(fields) });
58
58
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
59
  return this as any;
60
60
  }
61
61
 
62
62
  opt<TFields extends OptionalFields>(
63
63
  option: TFields | readonly TFields[]
64
- ): SearchBuilderR18<T, SerachResultOptionalFields<TFields>> {
65
- this.set({ opt: SearchBuilderBase.array2string(option) });
64
+ ): SearchBuilderR18<T, SearchResultOptionalFields<TFields>> {
65
+ this.set({ opt: NovelSearchBuilderBase.array2string(option) });
66
66
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
67
  return this as any;
68
68
  }
@@ -2,7 +2,7 @@ import NarouNovel from "./narou";
2
2
  import {
3
3
  NarouSearchResult,
4
4
  SearchResultFields,
5
- SerachResultOptionalFields,
5
+ SearchResultOptionalFields,
6
6
  } from "./narou-search-results";
7
7
  import NarouSearchResults from "./narou-search-results";
8
8
  import {
@@ -18,6 +18,7 @@ import {
18
18
  NovelTypeParam,
19
19
  GzipLevel,
20
20
  OptionalFields,
21
+ ParamsBaseWithOrder,
21
22
  } from "./params";
22
23
  import { Join } from "./util/type";
23
24
 
@@ -26,12 +27,18 @@ export type DefaultSearchResultFields = keyof Omit<
26
27
  "weekly_unique" | "noveltype" | "nocgenre" | "xid"
27
28
  >;
28
29
 
29
- export abstract class SearchBuilderBase<T extends SearchResultFieldNames> {
30
+ export abstract class SearchBuilderBase<
31
+ TParams extends ParamsBaseWithOrder<TOrder>,
32
+ TOrder extends string
33
+ > {
30
34
  /**
31
35
  * constructor
32
36
  * @private
33
37
  */
34
- constructor(protected params: SearchParams = {}, protected api: NarouNovel) {}
38
+ constructor(
39
+ protected params: TParams = {} as TParams,
40
+ protected api: NarouNovel
41
+ ) {}
35
42
 
36
43
  protected static distinct<T>(array: readonly T[]): T[] {
37
44
  return Array.from(new Set(array));
@@ -47,6 +54,77 @@ export abstract class SearchBuilderBase<T extends SearchResultFieldNames> {
47
54
  }
48
55
  }
49
56
 
57
+ /**
58
+ *
59
+ * @return {SearchBuilder} this
60
+ */
61
+ limit(num: number): this {
62
+ this.set({ lim: num } as TParams);
63
+ return this;
64
+ }
65
+
66
+ /**
67
+ *
68
+ * @return {SearchBuilder} this
69
+ */
70
+ start(num: number): this {
71
+ this.set({ st: num } as TParams);
72
+ return this;
73
+ }
74
+
75
+ /**
76
+ *
77
+ * @return {SearchBuilder} this
78
+ */
79
+ page(no: number, count = 20): this {
80
+ return this.limit(count).start(no * count);
81
+ }
82
+
83
+ /**
84
+ * 出力順序を指定する。指定しない場合は新着順となります。
85
+ * old 古い順
86
+ * @param {TOrder} order 出力順序
87
+ * @return {SearchBuilder} this
88
+ */
89
+ order(order: TOrder): this {
90
+ this.set({ order: order } as TParams);
91
+ return this;
92
+ }
93
+
94
+ /**
95
+ * gzip圧縮する。
96
+ *
97
+ * 転送量上限を減らすためにも推奨
98
+ * @param {GzipLevel} level gzip圧縮レベル(1~5)
99
+ * @return {SearchBuilder} this
100
+ */
101
+ gzip(level: GzipLevel): this {
102
+ this.set({ gzip: level } as TParams);
103
+ return this;
104
+ }
105
+
106
+ /**
107
+ * クエリパラメータをセットする
108
+ * @private
109
+ * @return {SearchBuilder} this
110
+ */
111
+ protected set(obj: TParams): this {
112
+ this.params = { ...this.params, ...obj };
113
+ return this;
114
+ }
115
+
116
+ /**
117
+ * クエリパラメータを削除する
118
+ */
119
+ protected unset(key: keyof TParams): this {
120
+ delete this.params[key];
121
+ return this;
122
+ }
123
+ }
124
+
125
+ export abstract class NovelSearchBuilderBase<
126
+ T extends SearchResultFieldNames
127
+ > extends SearchBuilderBase<SearchParams, Order> {
50
128
  /**
51
129
  * a
52
130
  * @return {SearchBuilder} this
@@ -180,7 +258,7 @@ export abstract class SearchBuilderBase<T extends SearchResultFieldNames> {
180
258
  * @return {SearchBuilder} this
181
259
  */
182
260
  length(length: number | readonly number[]): this {
183
- this.set({ length: SearchBuilderBase.array2string(length) });
261
+ this.set({ length: NovelSearchBuilderBase.array2string(length) });
184
262
  return this;
185
263
  }
186
264
 
@@ -207,7 +285,7 @@ export abstract class SearchBuilderBase<T extends SearchResultFieldNames> {
207
285
  * @return {SearchBuilder} this
208
286
  */
209
287
  sasie(num: number | readonly number[]): this {
210
- this.set({ sasie: SearchBuilderBase.array2string(num) });
288
+ this.set({ sasie: NovelSearchBuilderBase.array2string(num) });
211
289
  return this;
212
290
  }
213
291
 
@@ -216,7 +294,7 @@ export abstract class SearchBuilderBase<T extends SearchResultFieldNames> {
216
294
  * @return {SearchBuilder} this
217
295
  */
218
296
  time(num: number | readonly number[]): this {
219
- this.set({ time: SearchBuilderBase.array2string(num) });
297
+ this.set({ time: NovelSearchBuilderBase.array2string(num) });
220
298
  return this;
221
299
  }
222
300
 
@@ -225,7 +303,7 @@ export abstract class SearchBuilderBase<T extends SearchResultFieldNames> {
225
303
  * @return {SearchBuilder} this
226
304
  */
227
305
  ncode(ncodes: string | readonly string[]): this {
228
- this.set({ ncode: SearchBuilderBase.array2string(ncodes) });
306
+ this.set({ ncode: NovelSearchBuilderBase.array2string(ncodes) });
229
307
  return this;
230
308
  }
231
309
 
@@ -243,7 +321,7 @@ export abstract class SearchBuilderBase<T extends SearchResultFieldNames> {
243
321
  * @return {SearchBuilder} this
244
322
  */
245
323
  buntai(buntai: BuntaiParam | readonly BuntaiParam[]): this {
246
- this.set({ buntai: SearchBuilderBase.array2string(buntai) });
324
+ this.set({ buntai: NovelSearchBuilderBase.array2string(buntai) });
247
325
  return this;
248
326
  }
249
327
 
@@ -289,95 +367,11 @@ export abstract class SearchBuilderBase<T extends SearchResultFieldNames> {
289
367
  return this;
290
368
  }
291
369
 
292
- /**
293
- *
294
- * @return {SearchBuilder} this
295
- */
296
- limit(num: number): this {
297
- this.set({ lim: num });
298
- return this;
299
- }
300
-
301
- /**
302
- *
303
- * @return {SearchBuilder} this
304
- */
305
- start(num: number): this {
306
- this.set({ st: num });
307
- return this;
308
- }
309
-
310
- /**
311
- *
312
- * @return {SearchBuilder} this
313
- */
314
- page(no: number, count = 20): this {
315
- return this.limit(count).start(no * count);
316
- }
317
-
318
- /**
319
- * 出力順序を指定する。指定しない場合は新着順となります。
320
- *
321
- * @description
322
- * allunique 閲覧者の多い順(未実装)
323
- * favnovelcnt ブックマーク数の多い順
324
- * reviewcnt レビュー数の多い順
325
- * hyoka 総合評価の高い順
326
- * hyokaasc 総合評価の低い順
327
- * impressioncnt 感想の多い順
328
- * hyokacnt 評価者数の多い順
329
- * hyokacntasc 評価者数の少ない順
330
- * weekly 週間ユニークユーザの多い順 毎週火曜日早朝リセット
331
- * (前週の日曜日から土曜日分)
332
- * lengthdesc 小説本文の文字数が多い順
333
- * lengthasc 小説本文の文字数が少ない順
334
- * ncodedesc Nコードが新しい順
335
- * old 古い順
336
- * @param {Order} order 出力順序
337
- * @return {SearchBuilder} this
338
- */
339
- order(order: Order): this {
340
- this.set({ order: order });
341
- return this;
342
- }
343
-
344
- /**
345
- * gzip圧縮する。
346
- *
347
- * 転送量上限を減らすためにも推奨
348
- * @param {GzipLevel} level gzip圧縮レベル(1~5)
349
- * @return {SearchBuilder} this
350
- */
351
- gzip(level: GzipLevel): this {
352
- this.set({ gzip: level });
353
- return this;
354
- }
355
-
356
- /**
357
- * クエリパラメータをセットする
358
- * @private
359
- * @return {SearchBuilder} this
360
- */
361
- protected set(obj: SearchParams): this {
362
- this.params = { ...this.params, ...obj };
363
- return this;
364
- }
365
-
366
- /**
367
- * クエリパラメータを削除する
368
- * @private
369
- * @return {SearchBuilder} this
370
- */
371
- protected unset(key: keyof SearchParams): this {
372
- delete this.params[key];
373
- return this;
374
- }
375
-
376
370
  /**
377
371
  * なろう小説APIへの検索リクエストを実行する
378
372
  * @returns {Promise<NarouSearchResults>} 検索結果
379
373
  */
380
- execute(): Promise<NarouSearchResults<T>> {
374
+ execute(): Promise<NarouSearchResults<NarouSearchResult, T>> {
381
375
  return this.api.executeNovel(this.params);
382
376
  }
383
377
  }
@@ -389,13 +383,13 @@ export abstract class SearchBuilderBase<T extends SearchResultFieldNames> {
389
383
  export default class SearchBuilder<
390
384
  T extends keyof NarouSearchResult = DefaultSearchResultFields,
391
385
  TOpt extends keyof NarouSearchResult = never
392
- > extends SearchBuilderBase<T | TOpt> {
386
+ > extends NovelSearchBuilderBase<T | TOpt> {
393
387
  /**
394
388
  *
395
389
  * @return {SearchBuilder} this
396
390
  */
397
391
  bigGenre(genre: BigGenre | readonly BigGenre[]): this {
398
- this.set({ biggenre: SearchBuilderBase.array2string(genre) });
392
+ this.set({ biggenre: SearchBuilder.array2string(genre) });
399
393
  return this;
400
394
  }
401
395
 
@@ -404,7 +398,7 @@ export default class SearchBuilder<
404
398
  * @return {SearchBuilder} this
405
399
  */
406
400
  notBigGenre(genre: BigGenre | readonly BigGenre[]): this {
407
- this.set({ notbiggenre: SearchBuilderBase.array2string(genre) });
401
+ this.set({ notbiggenre: SearchBuilder.array2string(genre) });
408
402
  return this;
409
403
  }
410
404
 
@@ -413,7 +407,7 @@ export default class SearchBuilder<
413
407
  * @return {SearchBuilder} this
414
408
  */
415
409
  genre(genre: Genre | readonly Genre[]): this {
416
- this.set({ genre: SearchBuilderBase.array2string(genre) });
410
+ this.set({ genre: SearchBuilder.array2string(genre) });
417
411
  return this;
418
412
  }
419
413
 
@@ -422,7 +416,7 @@ export default class SearchBuilder<
422
416
  * @return {SearchBuilder} this
423
417
  */
424
418
  notGenre(genre: Genre | readonly Genre[]): this {
425
- this.set({ notgenre: SearchBuilderBase.array2string(genre) });
419
+ this.set({ notgenre: SearchBuilder.array2string(genre) });
426
420
  return this;
427
421
  }
428
422
 
@@ -431,7 +425,7 @@ export default class SearchBuilder<
431
425
  * @return {SearchBuilder} this
432
426
  */
433
427
  userId(ids: number | readonly number[]): this {
434
- this.set({ userid: SearchBuilderBase.array2string(ids) });
428
+ this.set({ userid: SearchBuilder.array2string(ids) });
435
429
  return this;
436
430
  }
437
431
 
@@ -455,15 +449,15 @@ export default class SearchBuilder<
455
449
  fields<TFields extends Fields>(
456
450
  fields: TFields | readonly TFields[]
457
451
  ): SearchBuilder<SearchResultFields<TFields>, TOpt> {
458
- this.set({ of: SearchBuilderBase.array2string(fields) });
452
+ this.set({ of: SearchBuilder.array2string(fields) });
459
453
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
460
454
  return this as any;
461
455
  }
462
456
 
463
457
  opt<TFields extends OptionalFields>(
464
458
  option: TFields | readonly TFields[]
465
- ): SearchBuilder<T, SerachResultOptionalFields<TFields>> {
466
- this.set({ opt: SearchBuilderBase.array2string(option) });
459
+ ): SearchBuilder<T, SearchResultOptionalFields<TFields>> {
460
+ this.set({ opt: SearchBuilder.array2string(option) });
467
461
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
468
462
  return this as any;
469
463
  }
@@ -0,0 +1,109 @@
1
+ import NarouSearchResults, {
2
+ UserSearchResult,
3
+ UserSearchResultFields,
4
+ } from "./narou-search-results";
5
+ import { UserFields, UserOrder, UserSearchParams } from "./params";
6
+ import { SearchBuilderBase } from "./search-builder";
7
+
8
+ /**
9
+ * なろうユーザ検索API
10
+ * @class UserSearch
11
+ */
12
+ export default class UserSearchBuilder<
13
+ TField extends keyof UserSearchResult = keyof UserSearchResult
14
+ > extends SearchBuilderBase<UserSearchParams, UserOrder> {
15
+ /**
16
+ * 単語を指定できます。
17
+ * 半角または全角スペースで区切るとAND抽出になります。
18
+ * 部分一致でHITします。検索の対象はユーザ名とユーザ名のフリガナです。
19
+ */
20
+ word(word: string) {
21
+ this.set({ word });
22
+ return this;
23
+ }
24
+
25
+ /**
26
+ * 含みたくない単語を指定できます。
27
+ * スペースで区切ることにより含ませない単語を増やせます。部分一致で除外されます。
28
+ * 除外の対象はユーザ名とユーザ名のフリガナです。
29
+ */
30
+ notWord(notword: string) {
31
+ this.set({ notword });
32
+ return this;
33
+ }
34
+
35
+ /**
36
+ * ユーザIDで抽出可能。
37
+ */
38
+ userId(userid: number) {
39
+ this.set({ userid });
40
+ return this;
41
+ }
42
+
43
+ /**
44
+ * 抽出するユーザのユーザ名のフリガナの頭文字を指定できます。
45
+ * 頭文字はユーザ名のフリガナをひらがなに変換し、最初の1文字が「ぁ」~「ん」の場合に対象となります。
46
+ * 「ぱ」や「ば」等の半濁音や濁音は清音として扱われます。
47
+ * 漢字や英数字が頭文字のユーザは対象外です。
48
+ */
49
+ name1st(name1st: string) {
50
+ this.set({ name1st });
51
+ return this;
52
+ }
53
+
54
+ /**
55
+ * 抽出するユーザの小説投稿数の下限を指定できます。
56
+ * 小説投稿件数が指定された数値以上のユーザを抽出します。
57
+ */
58
+ minNovel(minnovel: number) {
59
+ this.set({ minnovel });
60
+ return this;
61
+ }
62
+
63
+ /**
64
+ * 抽出するユーザの小説投稿数の上限を指定できます。
65
+ * 小説投稿件数が指定された数値以下のユーザを抽出します。
66
+ */
67
+ maxNovel(maxnovel: number) {
68
+ this.set({ maxnovel });
69
+ return this;
70
+ }
71
+
72
+ /**
73
+ * 抽出するユーザのレビュー投稿数の下限を指定できます。
74
+ * レビュー投稿件数が指定された数値以上のユーザを抽出します。
75
+ */
76
+ minReview(minreview: number) {
77
+ this.set({ minreview });
78
+ return this;
79
+ }
80
+
81
+ /**
82
+ * 抽出するユーザのレビュー投稿数の上限を指定できます。
83
+ * レビュー投稿件数が指定された数値以下のユーザを抽出します。
84
+ */
85
+ maxReview(maxreview: number) {
86
+ this.set({ maxreview });
87
+ return this;
88
+ }
89
+
90
+ /**
91
+ * 出力する項目を個別に指定できます。未指定時は全項目出力されます。転送量軽減のため、このパラメータの使用が推奨されます。
92
+ * @return {SearchBuilder} this
93
+ */
94
+ fields<TFields extends UserFields>(
95
+ fields: TFields | readonly TFields[]
96
+ ): UserSearchBuilder<UserSearchResultFields<TFields>> {
97
+ this.set({ of: UserSearchBuilder.array2string(fields) });
98
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
+ return this as any;
100
+ }
101
+
102
+ /**
103
+ * なろう小説APIへのリクエストを実行する
104
+ * @returns ランキング
105
+ */
106
+ execute(): Promise<NarouSearchResults<UserSearchResult, TField>> {
107
+ return this.api.executeUserSearch(this.params as UserSearchParams);
108
+ }
109
+ }
package/src/util/jsonp.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * MIT license
3
3
  */
4
- import nodeURL from "./url";
5
4
 
6
5
  // Callback index.
7
6
  let count = 0;
@@ -61,7 +60,7 @@ export function jsonp<T>(
61
60
 
62
61
  // Create script.
63
62
  const script = document.createElement("script");
64
- const urlObj = new nodeURL(url);
63
+ const urlObj = new URL(url);
65
64
  urlObj.searchParams.set(param, id);
66
65
  script.setAttribute("src", urlObj.toString());
67
66
  target.insertBefore(script, targetChild);