narou 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/dist/chunk-3UZPHZZH.js +43 -0
  2. package/dist/chunk-46WN4HIZ.js +25 -0
  3. package/dist/chunk-55V5YY6H.js +71 -0
  4. package/dist/chunk-5OZA6DNS.js +14 -0
  5. package/dist/chunk-67BSHN66.js +82 -0
  6. package/dist/chunk-6SHYBHWX.js +0 -0
  7. package/dist/chunk-AIRK7Y7G.js +0 -0
  8. package/dist/chunk-C54MSVRN.js +3064 -0
  9. package/dist/chunk-EQL67JCA.js +38 -0
  10. package/dist/chunk-IKR7OZGM.js +49 -0
  11. package/dist/chunk-IVQKYEQQ.js +371 -0
  12. package/dist/chunk-JFVJBECE.js +36 -0
  13. package/dist/chunk-JS5XPNGB.js +93 -0
  14. package/dist/chunk-OVGZ6RWT.js +23 -0
  15. package/dist/chunk-U3H4E2XZ.js +396 -0
  16. package/dist/index.browser.cjs +1221 -0
  17. package/dist/index.browser.d.cts +40 -0
  18. package/dist/index.browser.d.ts +20 -16
  19. package/dist/index.browser.js +116 -72
  20. package/dist/index.cjs +4305 -0
  21. package/dist/index.common.cjs +1032 -0
  22. package/dist/index.common.d.cts +6 -0
  23. package/dist/index.common.d.ts +6 -15
  24. package/dist/index.common.js +73 -34
  25. package/dist/index.d.cts +47 -0
  26. package/dist/index.d.ts +21 -17
  27. package/dist/index.js +121 -80
  28. package/dist/narou-61329eea.d.ts +298 -0
  29. package/dist/narou-98ededc8.d.ts +298 -0
  30. package/dist/narou-fetch.cjs +3190 -0
  31. package/dist/narou-fetch.d.cts +16 -0
  32. package/dist/narou-fetch.d.ts +10 -7
  33. package/dist/narou-fetch.js +10 -46
  34. package/dist/narou-jsonp.cjs +158 -0
  35. package/dist/narou-jsonp.d.cts +13 -0
  36. package/dist/narou-jsonp.d.ts +8 -5
  37. package/dist/narou-jsonp.js +10 -24
  38. package/dist/narou-ranking-results.cjs +18 -0
  39. package/dist/narou-ranking-results.d.cts +4 -0
  40. package/dist/narou-ranking-results.d.ts +4 -10
  41. package/dist/narou-ranking-results.js +1 -3
  42. package/dist/narou-search-results-6727b1ce.d.ts +716 -0
  43. package/dist/narou-search-results-b7c10db0.d.ts +716 -0
  44. package/dist/narou-search-results.cjs +61 -0
  45. package/dist/narou-search-results.d.cts +2 -0
  46. package/dist/narou-search-results.d.ts +2 -131
  47. package/dist/narou-search-results.js +10 -62
  48. package/dist/narou.cjs +108 -0
  49. package/dist/narou.d.cts +4 -0
  50. package/dist/narou.d.ts +4 -26
  51. package/dist/narou.js +8 -30
  52. package/dist/params.cjs +436 -0
  53. package/dist/params.d.cts +2 -0
  54. package/dist/params.d.ts +2 -324
  55. package/dist/params.js +38 -246
  56. package/dist/ranking-history.cjs +38 -0
  57. package/dist/ranking-history.d.cts +17 -0
  58. package/dist/ranking-history.d.ts +8 -5
  59. package/dist/ranking-history.js +7 -14
  60. package/dist/ranking.cjs +659 -0
  61. package/dist/ranking.d.cts +47 -0
  62. package/dist/ranking.d.ts +8 -7
  63. package/dist/ranking.js +9 -87
  64. package/dist/search-builder-r18.cjs +473 -0
  65. package/dist/search-builder-r18.d.cts +32 -0
  66. package/dist/search-builder-r18.d.ts +9 -6
  67. package/dist/search-builder-r18.js +9 -45
  68. package/dist/search-builder.cjs +510 -0
  69. package/dist/search-builder.d.cts +4 -0
  70. package/dist/search-builder.d.ts +4 -220
  71. package/dist/search-builder.js +12 -381
  72. package/dist/user-search.cjs +300 -0
  73. package/{dist.esm/user-search.js → dist/user-search.d.cts} +18 -46
  74. package/dist/user-search.d.ts +8 -5
  75. package/dist/user-search.js +9 -94
  76. package/dist/util/jsonp.cjs +62 -0
  77. package/dist/util/jsonp.d.cts +13 -0
  78. package/dist/util/jsonp.d.ts +4 -8
  79. package/dist/util/jsonp.js +7 -46
  80. package/dist/util/type.cjs +18 -0
  81. package/dist/util/type.d.cts +4 -0
  82. package/dist/util/type.d.ts +4 -4
  83. package/dist/util/type.js +0 -3
  84. package/dist/util/unzipp.cjs +47 -0
  85. package/dist/util/unzipp.d.cts +3 -0
  86. package/dist/util/unzipp.d.ts +3 -4
  87. package/dist/util/unzipp.js +7 -12
  88. package/package.json +35 -33
  89. package/src/narou-fetch.ts +6 -16
  90. package/src/narou-jsonp.ts +0 -2
  91. package/src/narou-ranking-results.ts +10 -0
  92. package/src/narou-search-results.ts +118 -63
  93. package/src/narou.ts +42 -3
  94. package/src/params.ts +220 -61
  95. package/src/util/unzipp.ts +13 -3
  96. package/dist/index.browser.d.ts.map +0 -1
  97. package/dist/index.browser.js.map +0 -1
  98. package/dist/index.common.d.ts.map +0 -1
  99. package/dist/index.common.js.map +0 -1
  100. package/dist/index.d.ts.map +0 -1
  101. package/dist/index.js.map +0 -1
  102. package/dist/narou-fetch.d.ts.map +0 -1
  103. package/dist/narou-fetch.js.map +0 -1
  104. package/dist/narou-jsonp.d.ts.map +0 -1
  105. package/dist/narou-jsonp.js.map +0 -1
  106. package/dist/narou-ranking-results.d.ts.map +0 -1
  107. package/dist/narou-ranking-results.js.map +0 -1
  108. package/dist/narou-search-results.d.ts.map +0 -1
  109. package/dist/narou-search-results.js.map +0 -1
  110. package/dist/narou.d.ts.map +0 -1
  111. package/dist/narou.js.map +0 -1
  112. package/dist/params.d.ts.map +0 -1
  113. package/dist/params.js.map +0 -1
  114. package/dist/ranking-history.d.ts.map +0 -1
  115. package/dist/ranking-history.js.map +0 -1
  116. package/dist/ranking.d.ts.map +0 -1
  117. package/dist/ranking.js.map +0 -1
  118. package/dist/search-builder-r18.d.ts.map +0 -1
  119. package/dist/search-builder-r18.js.map +0 -1
  120. package/dist/search-builder.d.ts.map +0 -1
  121. package/dist/search-builder.js.map +0 -1
  122. package/dist/user-search.d.ts.map +0 -1
  123. package/dist/user-search.js.map +0 -1
  124. package/dist/util/jsonp.d.ts.map +0 -1
  125. package/dist/util/jsonp.js.map +0 -1
  126. package/dist/util/type.d.ts.map +0 -1
  127. package/dist/util/type.js.map +0 -1
  128. package/dist/util/unzipp.d.ts.map +0 -1
  129. package/dist/util/unzipp.js.map +0 -1
  130. package/dist.esm/index.browser.js +0 -86
  131. package/dist.esm/index.browser.js.map +0 -1
  132. package/dist.esm/index.common.js +0 -38
  133. package/dist.esm/index.common.js.map +0 -1
  134. package/dist.esm/index.js +0 -94
  135. package/dist.esm/index.js.map +0 -1
  136. package/dist.esm/narou-fetch.js +0 -49
  137. package/dist.esm/narou-fetch.js.map +0 -1
  138. package/dist.esm/narou-jsonp.js +0 -27
  139. package/dist.esm/narou-jsonp.js.map +0 -1
  140. package/dist.esm/narou-ranking-results.js +0 -3
  141. package/dist.esm/narou-ranking-results.js.map +0 -1
  142. package/dist.esm/narou-search-results.js +0 -63
  143. package/dist.esm/narou-search-results.js.map +0 -1
  144. package/dist.esm/narou.js +0 -33
  145. package/dist.esm/narou.js.map +0 -1
  146. package/dist.esm/params.js +0 -247
  147. package/dist.esm/params.js.map +0 -1
  148. package/dist.esm/ranking-history.js +0 -14
  149. package/dist.esm/ranking-history.js.map +0 -1
  150. package/dist.esm/ranking.js +0 -90
  151. package/dist.esm/ranking.js.map +0 -1
  152. package/dist.esm/search-builder-r18.js +0 -45
  153. package/dist.esm/search-builder-r18.js.map +0 -1
  154. package/dist.esm/search-builder.js +0 -381
  155. package/dist.esm/search-builder.js.map +0 -1
  156. package/dist.esm/user-search.js.map +0 -1
  157. package/dist.esm/util/jsonp.js +0 -46
  158. package/dist.esm/util/jsonp.js.map +0 -1
  159. package/dist.esm/util/type.js +0 -3
  160. package/dist.esm/util/type.js.map +0 -1
  161. package/dist.esm/util/unzipp.js +0 -12
  162. package/dist.esm/util/unzipp.js.map +0 -1
@@ -0,0 +1,16 @@
1
+ import { N as NarouNovel, a as NarouParams } from './narou-98ededc8.js';
2
+ import './narou-search-results-6727b1ce.js';
3
+ import './util/type.cjs';
4
+ import './ranking-history.cjs';
5
+
6
+ type Fetch = typeof fetch;
7
+ /**
8
+ * なろう小説APIへのリクエストを実行する
9
+ */
10
+ declare class NarouNovelFetch extends NarouNovel {
11
+ private fetch;
12
+ constructor(fetch?: Fetch);
13
+ protected execute<T>(params: NarouParams, endpoint: string): Promise<T>;
14
+ }
15
+
16
+ export { NarouNovelFetch as default };
@@ -1,13 +1,16 @@
1
- import nodeFetch from "node-fetch";
2
- import NarouNovel, { NarouParams } from "./narou";
1
+ import { N as NarouNovel, a as NarouParams } from './narou-61329eea.js';
2
+ import './narou-search-results-b7c10db0.js';
3
+ import './util/type.js';
4
+ import './ranking-history.js';
5
+
6
+ type Fetch = typeof fetch;
3
7
  /**
4
8
  * なろう小説APIへのリクエストを実行する
5
- * @class NarouNovel
6
- * @private
7
9
  */
8
- export default class NarouNovelFetch extends NarouNovel {
10
+ declare class NarouNovelFetch extends NarouNovel {
9
11
  private fetch;
10
- constructor(fetch?: typeof nodeFetch);
12
+ constructor(fetch?: Fetch);
11
13
  protected execute<T>(params: NarouParams, endpoint: string): Promise<T>;
12
14
  }
13
- //# sourceMappingURL=narou-fetch.d.ts.map
15
+
16
+ export { NarouNovelFetch as default };
@@ -1,46 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const node_fetch_1 = require("node-fetch");
4
- const unzipp_1 = require("./util/unzipp");
5
- const narou_1 = require("./narou");
6
- /**
7
- * なろう小説APIへのリクエストを実行する
8
- * @class NarouNovel
9
- * @private
10
- */
11
- class NarouNovelFetch extends narou_1.default {
12
- constructor(fetch = node_fetch_1.default) {
13
- super();
14
- this.fetch = fetch;
15
- }
16
- async execute(params, endpoint) {
17
- const query = { ...params, out: "json" };
18
- if (query.gzip === undefined) {
19
- query.gzip = 5;
20
- }
21
- const url = new URL(endpoint);
22
- Object.entries(query).forEach(([key, value]) => {
23
- if (value) {
24
- url.searchParams.append(key, value.toString());
25
- }
26
- });
27
- const res = await this.fetch(url);
28
- if (query.gzip === 0) {
29
- return await res.json();
30
- }
31
- const buffer = await res.buffer();
32
- try {
33
- return await (0, unzipp_1.unzipp)(buffer);
34
- }
35
- catch {
36
- try {
37
- throw JSON.stringify(buffer.toString());
38
- }
39
- catch {
40
- throw buffer.toString();
41
- }
42
- }
43
- }
44
- }
45
- exports.default = NarouNovelFetch;
46
- //# sourceMappingURL=narou-fetch.js.map
1
+ import {
2
+ NarouNovelFetch
3
+ } from "./chunk-C54MSVRN.js";
4
+ import "./chunk-OVGZ6RWT.js";
5
+ import "./chunk-55V5YY6H.js";
6
+ import "./chunk-JFVJBECE.js";
7
+ import "./chunk-IKR7OZGM.js";
8
+ export {
9
+ NarouNovelFetch as default
10
+ };
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/narou-jsonp.ts
21
+ var narou_jsonp_exports = {};
22
+ __export(narou_jsonp_exports, {
23
+ default: () => NarouNovelJsonp
24
+ });
25
+ module.exports = __toCommonJS(narou_jsonp_exports);
26
+
27
+ // src/narou-search-results.ts
28
+ var NarouSearchResults = class {
29
+ /**
30
+ * @constractor
31
+ * @private
32
+ */
33
+ constructor([header, ...result], params) {
34
+ const count2 = header.allcount;
35
+ const limit = params.lim ?? 20;
36
+ const start = params.st ?? 0;
37
+ this.allcount = count2;
38
+ this.limit = limit;
39
+ this.start = start;
40
+ this.page = start / limit;
41
+ this.length = result.length;
42
+ this.values = result;
43
+ }
44
+ };
45
+
46
+ // src/narou.ts
47
+ var NarouNovel = class {
48
+ /**
49
+ * APIへの検索リクエストを実行する
50
+ * @param params クエリパラメータ
51
+ * @param endpoint APIエンドポイント
52
+ * @returns 検索結果
53
+ */
54
+ async executeSearch(params, endpoint = "https://api.syosetu.com/novelapi/api/") {
55
+ return new NarouSearchResults(await this.execute(params, endpoint), params);
56
+ }
57
+ /**
58
+ * 小説APIへの検索リクエストを実行する
59
+ * @param params クエリパラメータ
60
+ * @returns 検索結果
61
+ * @see https://dev.syosetu.com/man/api/
62
+ */
63
+ async executeNovel(params) {
64
+ return await this.executeSearch(
65
+ params,
66
+ "https://api.syosetu.com/novelapi/api/"
67
+ );
68
+ }
69
+ /**
70
+ * R18小説APIへの検索リクエストを実行する
71
+ * @param params クエリパラメータ
72
+ * @returns 検索結果
73
+ * @see https://dev.syosetu.com/xman/api/
74
+ */
75
+ async executeNovel18(params) {
76
+ return await this.executeSearch(
77
+ params,
78
+ "https://api.syosetu.com/novel18api/api/"
79
+ );
80
+ }
81
+ /**
82
+ * ランキングAPIへのリクエストを実行する
83
+ * @param params クエリパラメータ
84
+ * @returns ランキング結果
85
+ * @see https://dev.syosetu.com/man/rankapi/
86
+ */
87
+ async executeRanking(params) {
88
+ return await this.execute(params, "https://api.syosetu.com/rank/rankget/");
89
+ }
90
+ /**
91
+ * 殿堂入りAPiへのリクエストを実行する
92
+ * @param params クエリパラメータ
93
+ * @returns ランキング履歴結果
94
+ * @see https://dev.syosetu.com/man/rankinapi/
95
+ */
96
+ async executeRankingHistory(params) {
97
+ return await this.execute(params, "https://api.syosetu.com/rank/rankin/");
98
+ }
99
+ /**
100
+ * ユーザー検索APIへのリクエストを実行する
101
+ * @param params クエリパラメータ
102
+ * @returns 検索結果
103
+ * @see https://dev.syosetu.com/man/userapi/
104
+ */
105
+ async executeUserSearch(params) {
106
+ return await this.execute(params, "https://api.syosetu.com/userapi/api/");
107
+ }
108
+ };
109
+
110
+ // src/util/jsonp.ts
111
+ var count = 0;
112
+ var noop = function() {
113
+ };
114
+ function jsonp(url, { prefix = "__jp", param = "callback", timeout = 15e3 } = {}) {
115
+ return new Promise(function(resolve, reject) {
116
+ const targetChild = document.getElementsByTagName("script").item(0);
117
+ const target = targetChild?.parentNode ?? document.head;
118
+ const id = `${prefix}${count++}`;
119
+ const cleanup = function() {
120
+ if (script && script.parentNode) {
121
+ script.parentNode.removeChild(script);
122
+ }
123
+ window[id] = noop;
124
+ if (timer) {
125
+ clearTimeout(timer);
126
+ }
127
+ };
128
+ const timer = timeout > 0 ? setTimeout(() => {
129
+ cleanup();
130
+ reject(new Error("Timeout"));
131
+ }, timeout) : void 0;
132
+ const callback = (data) => {
133
+ cleanup();
134
+ resolve(data);
135
+ };
136
+ window[id] = callback;
137
+ const script = document.createElement("script");
138
+ const urlObj = new URL(url);
139
+ urlObj.searchParams.set(param, id);
140
+ script.setAttribute("src", urlObj.toString());
141
+ target.insertBefore(script, targetChild);
142
+ });
143
+ }
144
+
145
+ // src/narou-jsonp.ts
146
+ var NarouNovelJsonp = class extends NarouNovel {
147
+ async execute(params, endpoint) {
148
+ const query = { ...params, out: "jsonp" };
149
+ query.gzip = 0;
150
+ const url = new URL(endpoint);
151
+ Object.entries(query).forEach(([key, value]) => {
152
+ if (value) {
153
+ url.searchParams.append(key, value.toString());
154
+ }
155
+ });
156
+ return await jsonp(url.toString());
157
+ }
158
+ };
@@ -0,0 +1,13 @@
1
+ import { N as NarouNovel, a as NarouParams } from './narou-98ededc8.js';
2
+ import './narou-search-results-6727b1ce.js';
3
+ import './util/type.cjs';
4
+ import './ranking-history.cjs';
5
+
6
+ /**
7
+ * なろう小説APIへのリクエストを実行する
8
+ */
9
+ declare class NarouNovelJsonp extends NarouNovel {
10
+ protected execute<T>(params: NarouParams, endpoint: string): Promise<T>;
11
+ }
12
+
13
+ export { NarouNovelJsonp as default };
@@ -1,10 +1,13 @@
1
- import NarouNovel, { NarouParams } from "./narou";
1
+ import { N as NarouNovel, a as NarouParams } from './narou-61329eea.js';
2
+ import './narou-search-results-b7c10db0.js';
3
+ import './util/type.js';
4
+ import './ranking-history.js';
5
+
2
6
  /**
3
7
  * なろう小説APIへのリクエストを実行する
4
- * @class NarouNovel
5
- * @private
6
8
  */
7
- export default class NarouNovelJsonp extends NarouNovel {
9
+ declare class NarouNovelJsonp extends NarouNovel {
8
10
  protected execute<T>(params: NarouParams, endpoint: string): Promise<T>;
9
11
  }
10
- //# sourceMappingURL=narou-jsonp.d.ts.map
12
+
13
+ export { NarouNovelJsonp as default };
@@ -1,24 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const narou_1 = require("./narou");
4
- const jsonp_1 = require("./util/jsonp");
5
- /**
6
- * なろう小説APIへのリクエストを実行する
7
- * @class NarouNovel
8
- * @private
9
- */
10
- class NarouNovelJsonp extends narou_1.default {
11
- async execute(params, endpoint) {
12
- const query = { ...params, out: "jsonp" };
13
- query.gzip = 0;
14
- const url = new URL(endpoint);
15
- Object.entries(query).forEach(([key, value]) => {
16
- if (value) {
17
- url.searchParams.append(key, value.toString());
18
- }
19
- });
20
- return await (0, jsonp_1.jsonp)(url.toString());
21
- }
22
- }
23
- exports.default = NarouNovelJsonp;
24
- //# sourceMappingURL=narou-jsonp.js.map
1
+ import {
2
+ NarouNovelJsonp
3
+ } from "./chunk-46WN4HIZ.js";
4
+ import "./chunk-EQL67JCA.js";
5
+ import "./chunk-55V5YY6H.js";
6
+ import "./chunk-JFVJBECE.js";
7
+ import "./chunk-IKR7OZGM.js";
8
+ export {
9
+ NarouNovelJsonp as default
10
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/narou-ranking-results.ts
17
+ var narou_ranking_results_exports = {};
18
+ module.exports = __toCommonJS(narou_ranking_results_exports);
@@ -0,0 +1,4 @@
1
+ import './narou-search-results-6727b1ce.js';
2
+ export { b as NarouRankingResult, R as RankingResult } from './narou-98ededc8.js';
3
+ import './util/type.cjs';
4
+ import './ranking-history.cjs';
@@ -1,10 +1,4 @@
1
- import { PickedNarouSearchResult } from "./narou-search-results";
2
- import { SearchResultFieldNames } from "./params";
3
- import { DefaultSearchResultFields } from "./search-builder";
4
- export interface NarouRankingResult {
5
- ncode: string;
6
- rank: number;
7
- pt: number;
8
- }
9
- export declare type RankingResult<T extends SearchResultFieldNames = DefaultSearchResultFields> = Partial<PickedNarouSearchResult<T>> & NarouRankingResult;
10
- //# sourceMappingURL=narou-ranking-results.d.ts.map
1
+ import './narou-search-results-b7c10db0.js';
2
+ export { b as NarouRankingResult, R as RankingResult } from './narou-61329eea.js';
3
+ import './util/type.js';
4
+ import './ranking-history.js';
@@ -1,3 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=narou-ranking-results.js.map
1
+ import "./chunk-AIRK7Y7G.js";