random-word-wikipedia 1.0.5 → 1.1.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.
- package/cli.js +19 -9
- package/index.js +11 -10
- package/package.json +14 -10
- package/readme.md +3 -7
- package/lib/cli.js +0 -19
- package/lib/index.js +0 -37
package/cli.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
const meow = require("meow");
|
|
4
|
-
const randomWordWikipedia = require(".");
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
import meow from "meow";
|
|
4
|
+
import randomWordWikipedia from "./index.js";
|
|
5
|
+
|
|
6
|
+
const cli = meow(
|
|
7
|
+
`
|
|
7
8
|
Usage
|
|
8
|
-
$ random-word-wikipedia [lang]
|
|
9
|
+
$ random-word-wikipedia [lang=en]
|
|
9
10
|
|
|
10
11
|
Options
|
|
11
12
|
-n 10 or less [Default: 1]
|
|
@@ -19,13 +20,22 @@ const cli = meow(`
|
|
|
19
20
|
内野 (印西市)
|
|
20
21
|
PAC-MAN 256
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
`,
|
|
24
|
+
{
|
|
25
|
+
importMeta: import.meta,
|
|
26
|
+
flags: {
|
|
27
|
+
n: {
|
|
28
|
+
type: "number"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
);
|
|
23
33
|
|
|
24
|
-
randomWordWikipedia(cli.input[0], cli.flags.n)
|
|
25
|
-
.then(res => {
|
|
34
|
+
randomWordWikipedia(cli.input[0], cli.flags.n || 1)
|
|
35
|
+
.then((res) => {
|
|
26
36
|
console.log(res.join("\n"));
|
|
27
37
|
})
|
|
28
|
-
.catch(err => {
|
|
38
|
+
.catch((err) => {
|
|
29
39
|
console.error("Error: err.message");
|
|
30
40
|
console.error("$ random-word-wikipedia --help");
|
|
31
41
|
});
|
package/index.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import "isomorphic-fetch";
|
|
2
|
+
import promise from "es6-promise";
|
|
3
|
+
promise.polyfill();
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
return new Promise(function(resolve, reject) {
|
|
5
|
+
const randomWordWikipedia = (lang, n = 1) => {
|
|
6
|
+
return new Promise(function (resolve, reject) {
|
|
6
7
|
lang = lang || "en";
|
|
7
8
|
if (typeof lang !== "string") {
|
|
8
9
|
throw new TypeError(`Expected a string, got ${typeof lang}`);
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
n = n || 1;
|
|
12
12
|
if (n <= 0 || n > 10) {
|
|
13
13
|
throw new TypeError(`Expected a -n (1 - 10), got ${n}`);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
// rnlimit: API limit 10 or less
|
|
17
|
-
const url = `
|
|
17
|
+
const url = `https://${lang}.wikipedia.org/w/api.php?format=json&action=query&list=random&rnnamespace=0&rnlimit=${n}`;
|
|
18
18
|
|
|
19
19
|
const res = fetch(url)
|
|
20
|
-
.then(res => res.json())
|
|
21
|
-
.then(data => {
|
|
20
|
+
.then((res) => res.json())
|
|
21
|
+
.then((data) => {
|
|
22
22
|
const words = data.query.random;
|
|
23
|
-
words.
|
|
24
|
-
resolve(words.map(v => v.title));
|
|
23
|
+
resolve(words.slice(-n).map((v) => v.title));
|
|
25
24
|
});
|
|
26
25
|
});
|
|
27
26
|
};
|
|
27
|
+
|
|
28
|
+
export default randomWordWikipedia;
|
package/package.json
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "random-word-wikipedia",
|
|
3
3
|
"description": "Get random word from wikipedia random page",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "elzup",
|
|
7
7
|
"email": "guild0105@gmail.com",
|
|
8
|
-
"url": "
|
|
8
|
+
"url": "https://anozon.me"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"bin": {
|
|
12
|
+
"random-word-wikipedia": "./cli.js"
|
|
9
13
|
},
|
|
10
|
-
"bin": "cli.js",
|
|
11
14
|
"dependencies": {
|
|
12
|
-
"es6-promise": "
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
+
"es6-promise": "4.2.8",
|
|
16
|
+
"fetch-mock": "9.11.0",
|
|
17
|
+
"isomorphic-fetch": "3.0.0",
|
|
18
|
+
"meow": "10.1.2"
|
|
15
19
|
},
|
|
16
20
|
"devDependencies": {
|
|
17
|
-
"ava": "
|
|
21
|
+
"ava": "3.15.0"
|
|
18
22
|
},
|
|
19
23
|
"engines": {
|
|
20
|
-
"node": ">=
|
|
24
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
21
25
|
},
|
|
22
26
|
"files": [
|
|
23
27
|
"cli.js",
|
|
24
28
|
"index.js"
|
|
25
29
|
],
|
|
26
30
|
"keywords": [
|
|
27
|
-
"",
|
|
28
31
|
"cli",
|
|
29
32
|
"cli-app",
|
|
30
33
|
"wikipedia",
|
|
@@ -34,6 +37,7 @@
|
|
|
34
37
|
"license": "MIT",
|
|
35
38
|
"repository": "elzup/random-word-wikipedia",
|
|
36
39
|
"scripts": {
|
|
37
|
-
"test": "ava"
|
|
40
|
+
"test": "ava",
|
|
41
|
+
"cli": "node cli.js"
|
|
38
42
|
}
|
|
39
43
|
}
|
package/readme.md
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
# random-word-wikipedia [](https://github.com/elzup/random-word-wikipedia/actions/workflows/node.js.yml)
|
|
2
2
|
|
|
3
3
|
> Get random word from wikipedia random page
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
## Install
|
|
7
6
|
|
|
8
7
|
```
|
|
9
8
|
$ npm install random-word-wikipedia
|
|
10
9
|
```
|
|
11
10
|
|
|
12
|
-
|
|
13
11
|
## Usage
|
|
14
12
|
|
|
15
13
|
```js
|
|
16
|
-
const randomWordWikipedia = require(
|
|
14
|
+
const randomWordWikipedia = require("random-word-wikipedia");
|
|
17
15
|
|
|
18
16
|
randomWordWikipedia().then(console.log);
|
|
19
17
|
//=> [ 'Saxifraga spathularis' ]
|
|
20
18
|
|
|
21
|
-
randomWordWikipedia(
|
|
19
|
+
randomWordWikipedia("ja", 2).then(console.log);
|
|
22
20
|
//=> [ 'ジョン・イサーク・ブリケ', '月は闇夜に隠るが如く' ]
|
|
23
21
|
```
|
|
24
22
|
|
|
25
|
-
|
|
26
23
|
## API
|
|
27
24
|
|
|
28
25
|
### randomWordWikipedia([lang, n])
|
|
@@ -69,7 +66,6 @@ $ random-word-wikipedia --help
|
|
|
69
66
|
PAC-MAN 256
|
|
70
67
|
```
|
|
71
68
|
|
|
72
|
-
|
|
73
69
|
## License
|
|
74
70
|
|
|
75
71
|
MIT © [elzup](https://elzup.com)
|
package/lib/cli.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
"use strict";
|
|
4
|
-
|
|
5
|
-
var _ = require(".");
|
|
6
|
-
|
|
7
|
-
var _2 = _interopRequireDefault(_);
|
|
8
|
-
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
|
|
11
|
-
var meow = require("meow");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var cli = meow("\n\tUsage\n\t $ random-word-wikipedia [lang]\n\n\tOptions\n\t -n 10 or less [Default: 1]\n\n\tExamples\n\t $ random-word-wikipedia\n\t\tYuruYuri\n\n\t $ random-word-wikipedia ja -n 3\n\t\t\u30D0\u30C0\u30A4\u30F3\u30B8\u30E3\u30E9\u30F3\u7802\u6F20\n\t\t\u5185\u91CE (\u5370\u897F\u5E02)\n\t\tPAC-MAN 256\n\n");
|
|
15
|
-
|
|
16
|
-
(0, _2.default)(cli.input[0], cli.flags.n).then(function (res) {
|
|
17
|
-
console.log(res.join("\n"));
|
|
18
|
-
});
|
|
19
|
-
//# sourceMappingURL=cli.js.map
|
package/lib/index.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
|
8
|
-
|
|
9
|
-
require("isomorphic-fetch");
|
|
10
|
-
|
|
11
|
-
require("es6-promise").polyfill();
|
|
12
|
-
|
|
13
|
-
exports.default = async function main(lang, n) {
|
|
14
|
-
lang = lang || "en";
|
|
15
|
-
if (typeof lang !== "string") {
|
|
16
|
-
throw new TypeError("Expected a string, got " + (typeof lang === "undefined" ? "undefined" : _typeof(lang)));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
n = n || 1;
|
|
20
|
-
if (n <= 0 || n > 10) {
|
|
21
|
-
throw new TypeError("Expected a -n (1 - 10), got " + n);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// rnlimit: API limit 10 or less
|
|
25
|
-
var url = "http://" + lang + ".wikipedia.org/w/api.php?format=json&action=query&list=random&rnnamespace=0&rnlimit=10";
|
|
26
|
-
|
|
27
|
-
var res = await fetch(url);
|
|
28
|
-
var data = await res.json();
|
|
29
|
-
var words = data.query.random;
|
|
30
|
-
words.length = n;
|
|
31
|
-
return words.map(function (v) {
|
|
32
|
-
return v.title;
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
module.exports = exports["default"];
|
|
37
|
-
//# sourceMappingURL=index.js.map
|