narou 0.6.2 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/index.browser.d.ts.map +1 -1
  2. package/dist/index.browser.js +5 -1
  3. package/dist/index.browser.js.map +1 -1
  4. package/dist/index.common.d.ts +7 -5
  5. package/dist/index.common.d.ts.map +1 -1
  6. package/dist/index.common.js +11 -3
  7. package/dist/index.common.js.map +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +5 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/narou-ranking-results.d.ts +4 -3
  12. package/dist/narou-ranking-results.d.ts.map +1 -1
  13. package/dist/narou-search-results.d.ts +49 -19
  14. package/dist/narou-search-results.d.ts.map +1 -1
  15. package/dist/narou-search-results.js +16 -2
  16. package/dist/narou-search-results.js.map +1 -1
  17. package/dist/narou.d.ts +4 -4
  18. package/dist/narou.d.ts.map +1 -1
  19. package/dist/narou.js.map +1 -1
  20. package/dist/params.d.ts +225 -173
  21. package/dist/params.d.ts.map +1 -1
  22. package/dist/params.js +206 -150
  23. package/dist/params.js.map +1 -1
  24. package/dist/ranking-history.d.ts +2 -2
  25. package/dist/ranking-history.d.ts.map +1 -1
  26. package/dist/ranking.d.ts +10 -12
  27. package/dist/ranking.d.ts.map +1 -1
  28. package/dist/ranking.js +7 -19
  29. package/dist/ranking.js.map +1 -1
  30. package/dist/search-builder-r18.d.ts +13 -6
  31. package/dist/search-builder-r18.d.ts.map +1 -1
  32. package/dist/search-builder-r18.js +18 -18
  33. package/dist/search-builder-r18.js.map +1 -1
  34. package/dist/search-builder.d.ts +54 -48
  35. package/dist/search-builder.d.ts.map +1 -1
  36. package/dist/search-builder.js +166 -138
  37. package/dist/search-builder.js.map +1 -1
  38. package/dist/util/jsonp.d.ts.map +1 -1
  39. package/dist/util/jsonp.js +2 -1
  40. package/dist/util/jsonp.js.map +1 -1
  41. package/dist/util/type.d.ts +4 -0
  42. package/dist/util/type.d.ts.map +1 -0
  43. package/dist/util/type.js +3 -0
  44. package/dist/util/type.js.map +1 -0
  45. package/dist/util/url.d.ts +1 -1
  46. package/dist.es2015/index.browser.js.map +1 -1
  47. package/dist.es2015/index.common.js +4 -3
  48. package/dist.es2015/index.common.js.map +1 -1
  49. package/dist.es2015/index.js.map +1 -1
  50. package/dist.es2015/narou-search-results.js +14 -1
  51. package/dist.es2015/narou-search-results.js.map +1 -1
  52. package/dist.es2015/narou.js.map +1 -1
  53. package/dist.es2015/params.js +204 -149
  54. package/dist.es2015/params.js.map +1 -1
  55. package/dist.es2015/ranking.js +3 -14
  56. package/dist.es2015/ranking.js.map +1 -1
  57. package/dist.es2015/search-builder-r18.js +19 -19
  58. package/dist.es2015/search-builder-r18.js.map +1 -1
  59. package/dist.es2015/search-builder.js +105 -99
  60. package/dist.es2015/search-builder.js.map +1 -1
  61. package/dist.es2015/util/jsonp.js +1 -0
  62. package/dist.es2015/util/jsonp.js.map +1 -1
  63. package/dist.es2015/util/type.js +2 -0
  64. package/dist.es2015/util/type.js.map +1 -0
  65. package/dist.esm/index.browser.js.map +1 -1
  66. package/dist.esm/index.common.js +4 -3
  67. package/dist.esm/index.common.js.map +1 -1
  68. package/dist.esm/index.js.map +1 -1
  69. package/dist.esm/narou-search-results.js +14 -1
  70. package/dist.esm/narou-search-results.js.map +1 -1
  71. package/dist.esm/narou.js.map +1 -1
  72. package/dist.esm/params.js +205 -149
  73. package/dist.esm/params.js.map +1 -1
  74. package/dist.esm/ranking.js +4 -15
  75. package/dist.esm/ranking.js.map +1 -1
  76. package/dist.esm/search-builder-r18.js +19 -19
  77. package/dist.esm/search-builder-r18.js.map +1 -1
  78. package/dist.esm/search-builder.js +165 -138
  79. package/dist.esm/search-builder.js.map +1 -1
  80. package/dist.esm/util/jsonp.js +2 -1
  81. package/dist.esm/util/jsonp.js.map +1 -1
  82. package/dist.esm/util/type.js +2 -0
  83. package/dist.esm/util/type.js.map +1 -0
  84. package/package.json +23 -46
  85. package/src/index.browser.ts +2 -2
  86. package/src/index.common.ts +20 -4
  87. package/src/index.ts +2 -2
  88. package/src/narou-ranking-results.ts +6 -2
  89. package/src/narou-search-results.ts +70 -20
  90. package/src/narou.ts +13 -6
  91. package/src/params.ts +279 -177
  92. package/src/ranking-history.ts +2 -2
  93. package/src/ranking.ts +47 -23
  94. package/src/search-builder-r18.ts +45 -20
  95. package/src/search-builder.ts +154 -128
  96. package/src/util/jsonp.ts +3 -0
  97. package/src/util/type.ts +3 -0
  98. package/package-lock.json +0 -3328
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "narou",
3
- "version": "0.6.2",
3
+ "version": "0.7.2",
4
4
  "description": "Narou API Wrapper",
5
5
  "main": "dist/index.js",
6
6
  "browser": "dist/index.browser.js",
@@ -21,29 +21,26 @@
21
21
  "url": "https://github.com/deflis/node-narou.git"
22
22
  },
23
23
  "dependencies": {
24
- "date-fns": "^2.16.1",
25
- "node-fetch": "^2.6.1"
24
+ "date-fns": "^2.16.1"
26
25
  },
27
26
  "devDependencies": {
28
- "@types/chai": "^4.1.2",
29
- "@types/mocha": "^5.2.7",
27
+ "@types/jest": "^28.1.5",
30
28
  "@types/node": "^13.5.0",
31
29
  "@types/node-fetch": "^2.5.7",
32
- "chai": "^4.1.2",
33
- "mocha": "^9.1.3",
34
- "mocha-typescript": "^1.1.12",
30
+ "@typescript-eslint/eslint-plugin": "^5.30.6",
31
+ "@typescript-eslint/parser": "^5.30.6",
32
+ "eslint": "^8.19.0",
33
+ "eslint-config-prettier": "^8.5.0",
34
+ "eslint-plugin-prettier": "^4.2.1",
35
+ "jest": "^28.1.3",
36
+ "node-fetch": "^2.6.1",
35
37
  "npm-run-all": "^4.1.4",
36
- "nyc": "^15.0.0",
37
- "prettier": "^2.4.1",
38
- "rimraf": "^3.0.0",
39
- "touch": "^3.1.0",
40
- "ts-node": "^10.3.0",
41
- "tslint": "^6.0.0",
42
- "tslint-config-prettier": "^1.16.0",
43
- "tslint-plugin-prettier": "^2.0.1",
44
- "typedoc": "^0.22.5",
45
- "typescript": "^4.4.4",
46
- "node-fetch": "^2.6.1"
38
+ "prettier": "^2.7.1",
39
+ "ts-jest": "^28.0.6",
40
+ "typescript": "^4.7.4"
41
+ },
42
+ "optionalDependencies": {
43
+ "node-fetch": "^2.6.7"
47
44
  },
48
45
  "scripts": {
49
46
  "build": "npm-run-all check clean build:tsc",
@@ -52,35 +49,15 @@
52
49
  "build:tsc:esm": "tsc -p ./tsconfig.esm.json",
53
50
  "build:tsc:es2017": "tsc -p ./tsconfig.es2017.json",
54
51
  "check": "npm-run-all --parallel check:lint check:build test",
55
- "check:lint": "tslint --project .",
52
+ "check:lint": "eslint src/** test/**",
56
53
  "check:build": "tsc --noEmit",
57
54
  "prepare": "npm-run-all format build",
58
- "format": "npm-run-all format:prettier format:tslint",
59
- "format:prettier": "prettier --write src/**/*.ts",
60
- "format:tslint": "tslint --project . --fix",
61
- "test": "mocha --recursive --require ts-node/register \"test/**/*.ts\"",
62
- "cover": "nyc mocha --recursive --require ts-node/register \"test/**/*.ts\"",
63
- "clean": "rimraf dist dist.*",
55
+ "format": "eslint --fix src/** test/**",
56
+ "test": "jest",
57
+ "clean": "npx rimraf dist dist.*",
64
58
  "docs": "npm-run-all docs:clean docs:typedoc docs:nojekyll",
65
- "docs:clean": "rimraf docs",
66
- "docs:typedoc": "typedoc --out ./docs src/index.ts",
67
- "docs:nojekyll": "nodetouch ./docs/.nojekyll"
68
- },
69
- "nyc": {
70
- "include": [
71
- "src/**/*.js"
72
- ],
73
- "extension": [
74
- ".ts"
75
- ],
76
- "require": [
77
- "ts-node/register"
78
- ],
79
- "reporter": [
80
- "json",
81
- "html",
82
- "text"
83
- ],
84
- "sourceMap": true
59
+ "docs:clean": "npx rimraf docs",
60
+ "docs:typedoc": "npx typedoc --out ./docs src/index.ts",
61
+ "docs:nojekyll": "npx touch ./docs/.nojekyll"
85
62
  }
86
63
  }
@@ -16,7 +16,7 @@ const narouNovelJsonp = new NarouNovelJsonp();
16
16
  * @returns {SearchBuilder}
17
17
  */
18
18
  export function search(
19
- word: string = "",
19
+ word = "",
20
20
  api: NarouNovel = narouNovelJsonp
21
21
  ): SearchBuilder {
22
22
  const builder = new SearchBuilder({}, api);
@@ -30,7 +30,7 @@ export function search(
30
30
  * @returns {SearchBuilder}
31
31
  */
32
32
  export function searchR18(
33
- word: string = "",
33
+ word = "",
34
34
  api: NarouNovel = narouNovelJsonp
35
35
  ): SearchBuilderR18 {
36
36
  const builder = new SearchBuilderR18({}, api);
@@ -1,10 +1,13 @@
1
1
  import NarouNovel from "./narou";
2
- import { RankingHistoryResult } from "./ranking-history";
2
+ import NarouSearchResults from "./narou-search-results";
3
3
 
4
- export { NarouNovel, RankingHistoryResult };
5
- export { RankingType } from "./ranking";
4
+ export { NarouNovel, NarouSearchResults };
5
+
6
+ export { RankingHistoryResult } from "./ranking-history";
6
7
  export {
8
+ RankingType,
7
9
  Fields,
10
+ SearchResultFieldNames,
8
11
  Order,
9
12
  BigGenre,
10
13
  BigGenreNotation,
@@ -12,6 +15,19 @@ export {
12
15
  GenreNotation,
13
16
  R18Site,
14
17
  R18SiteNotation,
18
+ BuntaiParam,
19
+ NovelTypeParam,
20
+ BooleanNumber,
15
21
  } from "./params";
16
- export { NarouSearchResult } from "./narou-search-results";
22
+ export {
23
+ NarouSearchResult,
24
+ PickedNarouSearchResult,
25
+ SearchResultFields,
26
+ SearchResultR18Fields,
27
+ PcOrK,
28
+ NovelType,
29
+ End,
30
+ } from "./narou-search-results";
17
31
  export { NarouRankingResult, RankingResult } from "./narou-ranking-results";
32
+ export { DefaultSearchResultFields } from "./search-builder";
33
+ export { DefaultR18SearchResultFields } from "./search-builder-r18";
package/src/index.ts CHANGED
@@ -17,7 +17,7 @@ const narouNovelFetch = new NarouNovelFetch();
17
17
  * @returns {SearchBuilder}
18
18
  */
19
19
  export function search(
20
- word: string = "",
20
+ word = "",
21
21
  api: NarouNovel = narouNovelFetch
22
22
  ): SearchBuilder {
23
23
  const builder = new SearchBuilder({}, api);
@@ -31,7 +31,7 @@ export function search(
31
31
  * @returns {SearchBuilder}
32
32
  */
33
33
  export function searchR18(
34
- word: string = "",
34
+ word = "",
35
35
  api: NarouNovel = narouNovelFetch
36
36
  ): SearchBuilderR18 {
37
37
  const builder = new SearchBuilderR18({}, api);
@@ -1,4 +1,6 @@
1
- import { NarouSearchResult } from "./narou-search-results";
1
+ import { PickedNarouSearchResult } from "./narou-search-results";
2
+ import { SearchResultFieldNames } from "./params";
3
+ import { DefaultSearchResultFields } from "./search-builder";
2
4
 
3
5
  export interface NarouRankingResult {
4
6
  ncode: string;
@@ -6,4 +8,6 @@ export interface NarouRankingResult {
6
8
  pt: number;
7
9
  }
8
10
 
9
- export interface RankingResult extends NarouSearchResult, NarouRankingResult {}
11
+ export type RankingResult<
12
+ T extends SearchResultFieldNames = DefaultSearchResultFields
13
+ > = Partial<PickedNarouSearchResult<T>> & NarouRankingResult;
@@ -1,24 +1,35 @@
1
+ import {
2
+ BooleanNumber as BooleanNumber,
3
+ Genre,
4
+ R18Site,
5
+ SearchParams,
6
+ Fields,
7
+ BigGenre,
8
+ R18Fields,
9
+ OptionalFields,
10
+ } from "./params";
11
+
1
12
  /**
2
13
  * なろう小説API検索結果
3
14
  * @class NarouSearchResults
4
15
  */
5
-
6
- import { booleanNumber, Genre, R18Site, SearchParams } from "./params";
7
-
8
- export default class NarouSearchResults {
16
+ export default class NarouSearchResults<T extends keyof NarouSearchResult> {
9
17
  allcount: number;
10
18
  limit: number;
11
19
  start: number;
12
20
  page: number;
13
21
  length: number;
14
- values: NarouSearchResult[];
22
+ values: PickedNarouSearchResult<T>[];
15
23
 
16
24
  /**
17
25
  * @constractor
18
26
  * @private
19
27
  */
20
28
  constructor(
21
- [header, ...result]: [{ allcount: number }, ...NarouSearchResult[]],
29
+ [header, ...result]: [
30
+ { allcount: number },
31
+ ...PickedNarouSearchResult<T>[]
32
+ ],
22
33
  params: SearchParams
23
34
  ) {
24
35
  const count = header.allcount;
@@ -52,7 +63,7 @@ export default class NarouSearchResults {
52
63
  this.length = result.length;
53
64
  /**
54
65
  * 検索結果
55
- * @type {NarouSearchResult[]}
66
+ * @type {PickedNarouSearchResult<T>[]}
56
67
  */
57
68
  this.values = result;
58
69
  }
@@ -70,7 +81,7 @@ export default class NarouSearchResults {
70
81
  * @property {string} general_firstup 初回掲載日 YYYY-MM-DD HH:MM:SSの形式
71
82
  * @property {string} general_lastup 最終掲載日 YYYY-MM-DD HH:MM:SSの形式
72
83
  * @property {number} noveltype 連載の場合は1、短編の場合は2
73
- * @property {number} end 連載の場合は1、短編の場合は2
84
+ * @property {number} end 短編小説と完結済小説は0となっています。連載中は1です。
74
85
  * @property {number} general_all_no 全掲載話数です。短編の場合は1です。
75
86
  * @property {number} length 全掲載話数です。短編の場合は1です。
76
87
  * @property {number} time 読了時間(分単位)です。読了時間は小説文字数÷500を切り上げした数値です。
@@ -94,24 +105,25 @@ export interface NarouSearchResult {
94
105
  writer: string;
95
106
  story: string;
96
107
  nocgenre: R18Site;
108
+ biggenre: BigGenre;
97
109
  genre: Genre;
98
110
  keyword: string;
99
111
  general_firstup: string;
100
112
  general_lastup: string;
101
113
  novel_type: number;
102
- noveltype: number;
103
- end: booleanNumber;
114
+ noveltype: NovelType;
115
+ end: End;
104
116
  general_all_no: number;
105
117
  length: number;
106
118
  time: number;
107
- isstop: booleanNumber;
108
- isr15: booleanNumber;
109
- isbl: booleanNumber;
110
- isgl: booleanNumber;
111
- iszankoku: booleanNumber;
112
- istensei: booleanNumber;
113
- istenni: booleanNumber;
114
- pc_or_k: number;
119
+ isstop: BooleanNumber;
120
+ isr15: BooleanNumber;
121
+ isbl: BooleanNumber;
122
+ isgl: BooleanNumber;
123
+ iszankoku: BooleanNumber;
124
+ istensei: BooleanNumber;
125
+ istenni: BooleanNumber;
126
+ pc_or_k: PcOrK;
115
127
  global_point: number;
116
128
  daily_point: number;
117
129
  weekly_point: number;
@@ -125,7 +137,45 @@ export interface NarouSearchResult {
125
137
  all_hyoka_cnt: number;
126
138
  sasie_cnt: number;
127
139
  kaiwaritu: number;
128
- novelupdated_at: number;
129
- update_at: number;
140
+ novelupdated_at: string;
141
+ updated_at: string;
130
142
  weekly_unique: number;
131
143
  }
144
+
145
+ export const PcOrK = {
146
+ Ketai: 1,
147
+ Pc: 2,
148
+ PcAndKetai: 3,
149
+ } as const;
150
+ export type PcOrK = typeof PcOrK[keyof typeof PcOrK];
151
+
152
+ export const NovelType = {
153
+ Rensai: 1,
154
+ Tanpen: 2,
155
+ } as const;
156
+ export type NovelType = typeof NovelType[keyof typeof NovelType];
157
+
158
+ export const End = {
159
+ KanketsuOrTanpen: 0,
160
+ Rensai: 1,
161
+ } as const;
162
+ export type End = typeof End[keyof typeof End];
163
+
164
+ export type SearchResultFields<T extends Fields> = {
165
+ [K in keyof typeof Fields]: typeof Fields[K] extends T ? K : never;
166
+ }[keyof typeof Fields];
167
+
168
+ export type SerachResultOptionalFields<T extends OptionalFields> = {
169
+ [K in keyof typeof OptionalFields]: typeof OptionalFields[K] extends T
170
+ ? K
171
+ : never;
172
+ }[keyof typeof OptionalFields];
173
+
174
+ export type SearchResultR18Fields<T extends R18Fields> = {
175
+ [K in keyof typeof R18Fields]: typeof R18Fields[K] extends T ? K : never;
176
+ }[keyof typeof R18Fields];
177
+
178
+ export type PickedNarouSearchResult<T extends keyof NarouSearchResult> = Pick<
179
+ NarouSearchResult,
180
+ T
181
+ >;
package/src/narou.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NarouRankingResult } from "./narou-ranking-results";
2
- import NarouSearchResults from "./narou-search-results";
2
+ import NarouSearchResults, { NarouSearchResult } from "./narou-search-results";
3
3
  import { RankingHistoryParams, RankingParams, SearchParams } from "./params";
4
4
  import { RankingHistoryRawResult } from "./ranking-history";
5
5
 
@@ -22,21 +22,28 @@ export default abstract class NarouNovel {
22
22
  endpoint: string
23
23
  ): Promise<T>;
24
24
 
25
- async executeSearch(
25
+ async executeSearch<T extends keyof NarouSearchResult>(
26
26
  params: NarouParams,
27
27
  endpoint = "http://api.syosetu.com/novelapi/api/"
28
- ): Promise<NarouSearchResults> {
29
- return new NarouSearchResults(await this.execute(params, endpoint), params);
28
+ ): Promise<NarouSearchResults<T>> {
29
+ return new NarouSearchResults<T>(
30
+ await this.execute(params, endpoint),
31
+ params
32
+ );
30
33
  }
31
34
 
32
- async executeNovel(params: SearchParams): Promise<NarouSearchResults> {
35
+ async executeNovel<T extends keyof NarouSearchResult>(
36
+ params: SearchParams
37
+ ): Promise<NarouSearchResults<T>> {
33
38
  return await this.executeSearch(
34
39
  params,
35
40
  "http://api.syosetu.com/novelapi/api/"
36
41
  );
37
42
  }
38
43
 
39
- async executeNovel18(params: SearchParams): Promise<NarouSearchResults> {
44
+ async executeNovel18<T extends keyof NarouSearchResult>(
45
+ params: SearchParams
46
+ ): Promise<NarouSearchResults<T>> {
40
47
  return await this.executeSearch(
41
48
  params,
42
49
  "http://api.syosetu.com/novel18api/api/"