random-word-wikipedia 1.0.2 → 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 ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+
3
+ import meow from "meow";
4
+ import randomWordWikipedia from "./index.js";
5
+
6
+ const cli = meow(
7
+ `
8
+ Usage
9
+ $ random-word-wikipedia [lang=en]
10
+
11
+ Options
12
+ -n 10 or less [Default: 1]
13
+
14
+ Examples
15
+ $ random-word-wikipedia
16
+ YuruYuri
17
+
18
+ $ random-word-wikipedia ja -n 3
19
+ バダインジャラン砂漠
20
+ 内野 (印西市)
21
+ PAC-MAN 256
22
+
23
+ `,
24
+ {
25
+ importMeta: import.meta,
26
+ flags: {
27
+ n: {
28
+ type: "number"
29
+ }
30
+ }
31
+ }
32
+ );
33
+
34
+ randomWordWikipedia(cli.input[0], cli.flags.n || 1)
35
+ .then((res) => {
36
+ console.log(res.join("\n"));
37
+ })
38
+ .catch((err) => {
39
+ console.error("Error: err.message");
40
+ console.error("$ random-word-wikipedia --help");
41
+ });
package/index.js ADDED
@@ -0,0 +1,28 @@
1
+ import "isomorphic-fetch";
2
+ import promise from "es6-promise";
3
+ promise.polyfill();
4
+
5
+ const randomWordWikipedia = (lang, n = 1) => {
6
+ return new Promise(function (resolve, reject) {
7
+ lang = lang || "en";
8
+ if (typeof lang !== "string") {
9
+ throw new TypeError(`Expected a string, got ${typeof lang}`);
10
+ }
11
+
12
+ if (n <= 0 || n > 10) {
13
+ throw new TypeError(`Expected a -n (1 - 10), got ${n}`);
14
+ }
15
+
16
+ // rnlimit: API limit 10 or less
17
+ const url = `https://${lang}.wikipedia.org/w/api.php?format=json&action=query&list=random&rnnamespace=0&rnlimit=${n}`;
18
+
19
+ const res = fetch(url)
20
+ .then((res) => res.json())
21
+ .then((data) => {
22
+ const words = data.query.random;
23
+ resolve(words.slice(-n).map((v) => v.title));
24
+ });
25
+ });
26
+ };
27
+
28
+ export default randomWordWikipedia;
package/package.json CHANGED
@@ -1,44 +1,43 @@
1
1
  {
2
2
  "name": "random-word-wikipedia",
3
3
  "description": "Get random word from wikipedia random page",
4
- "version": "1.0.2",
4
+ "version": "1.1.0",
5
5
  "author": {
6
6
  "name": "elzup",
7
7
  "email": "guild0105@gmail.com",
8
- "url": "elzup.com"
8
+ "url": "https://anozon.me"
9
+ },
10
+ "type": "module",
11
+ "bin": {
12
+ "random-word-wikipedia": "./cli.js"
9
13
  },
10
- "bin": "lib/cli.js",
11
14
  "dependencies": {
12
- "es6-promise": "^4.2.2",
13
- "isomorphic-fetch": "^2.2.1",
14
- "meow": "^3.7.0"
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": "^0.20.0",
18
- "babel-cli": "^6.26.0",
19
- "babel-preset-es2015": "^6.24.1",
20
- "babel-preset-jsdoc-to-assert": "^4.0.0",
21
- "babel-preset-power-assert": "^1.0.0",
22
- "babel-register": "^6.26.0",
23
- "cross-env": "^5.1.3"
21
+ "ava": "3.15.0"
24
22
  },
25
23
  "engines": {
26
- "node": ">=6"
24
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
27
25
  },
28
26
  "files": [
29
- "bin/",
30
- "lib/",
31
- "src/"
27
+ "cli.js",
28
+ "index.js"
32
29
  ],
33
30
  "keywords": [
34
- "",
35
31
  "cli",
36
- "cli-app"
32
+ "cli-app",
33
+ "wikipedia",
34
+ "random",
35
+ "faker"
37
36
  ],
38
37
  "license": "MIT",
39
38
  "repository": "elzup/random-word-wikipedia",
40
39
  "scripts": {
41
- "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps && chmod +x lib/cli.js",
42
- "test": "npm run build && ava"
40
+ "test": "ava",
41
+ "cli": "node cli.js"
43
42
  }
44
43
  }
package/readme.md CHANGED
@@ -1,44 +1,44 @@
1
- # random-word-wikipedia [![Build Status](https://travis-ci.org/elzup/random-word-wikipedia.svg?branch=master)](https://travis-ci.org/elzup/random-word-wikipedia)
1
+ # random-word-wikipedia [![Node.js CI](https://github.com/elzup/random-word-wikipedia/actions/workflows/node.js.yml/badge.svg)](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('random-word-wikipedia');
14
+ const randomWordWikipedia = require("random-word-wikipedia");
17
15
 
18
- randomWordWikipedia('unicorns');
19
- //=> 'unicorns & rainbows'
20
- ```
16
+ randomWordWikipedia().then(console.log);
17
+ //=> [ 'Saxifraga spathularis' ]
21
18
 
19
+ randomWordWikipedia("ja", 2).then(console.log);
20
+ //=> [ 'ジョン・イサーク・ブリケ', '月は闇夜に隠るが如く' ]
21
+ ```
22
22
 
23
23
  ## API
24
24
 
25
- ### randomWordWikipedia(input, [options])
26
-
27
- #### input
25
+ ### randomWordWikipedia([lang, n])
28
26
 
29
- Type: `string`
27
+ #### options
30
28
 
31
- Lorem ipsum.
29
+ ##### lang
32
30
 
33
- #### options
31
+ Type: `string`<br>
32
+ Default: `en`
34
33
 
35
- ##### foo
34
+ wikipedia lang string.
36
35
 
37
- Type: `boolean`<br>
38
- Default: `false`
36
+ ##### n
39
37
 
40
- Lorem ipsum.
38
+ Type: `number` 1 - 10<br>
39
+ Default: 1
41
40
 
41
+ number of word.
42
42
 
43
43
  ## CLI
44
44
 
@@ -49,19 +49,22 @@ $ npm install --global random-word-wikipedia
49
49
  ```
50
50
  $ random-word-wikipedia --help
51
51
 
52
- Usage
53
- random-word-wikipedia [input]
52
+ Usage
53
+ $ random-word-wikipedia [lang]
54
54
 
55
- Options
56
- --foo Lorem ipsum [Default: false]
55
+ Options
56
+ -n 10 or less [Default: 1]
57
57
 
58
- Examples
59
- $ random-word-wikipedia
60
- unicorns & rainbows
61
- $ random-word-wikipedia ponies
62
- ponies & rainbows
63
- ```
58
+ Examples
59
+ $ random-word-wikipedia
60
+ YuruYuri
64
61
 
62
+ $ random-word-wikipedia ja -n 4
63
+ バダインジャラン砂漠
64
+ ゆるゆり
65
+ 内野 (印西市)
66
+ PAC-MAN 256
67
+ ```
65
68
 
66
69
  ## License
67
70
 
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/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/cli.js"],"names":["meow","require","cli","input","flags","n","then","console","log","res","join"],"mappings":";AACA;;AAEA;;;;;;AADA,IAAMA,OAAOC,QAAQ,MAAR,CAAb;;;AAGA,IAAMC,MAAMF,gUAAZ;;AAkBA,gBAAoBE,IAAIC,KAAJ,CAAU,CAAV,CAApB,EAAkCD,IAAIE,KAAJ,CAAUC,CAA5C,EAA+CC,IAA/C,CAAoD,eAAO;AAC1DC,SAAQC,GAAR,CAAYC,IAAIC,IAAJ,CAAS,IAAT,CAAZ;AACA,CAFD","file":"cli.js","sourcesContent":["\n\"use strict\";\nconst meow = require(\"meow\");\nimport randomWordWikipedia from \".\";\n\nconst 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バダインジャラン砂漠\n\t\t内野 (印西市)\n\t\tPAC-MAN 256\n\n`);\n\nrandomWordWikipedia(cli.input[0], cli.flags.n).then(res => {\n\tconsole.log(res.join(\"\\n\"));\n});\n"]}
package/lib/index.js DELETED
@@ -1,35 +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
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["require","polyfill","main","lang","n","TypeError","url","res","fetch","data","json","words","query","random","length","map","v","title"],"mappings":";;;;;;;;AAAA;;AACAA,QAAQ,aAAR,EAAuBC,QAAvB;;kBAEe,eAAeC,IAAf,CAAoBC,IAApB,EAA0BC,CAA1B,EAA6B;AAC3CD,QAAOA,QAAQ,IAAf;AACA,KAAI,OAAOA,IAAP,KAAgB,QAApB,EAA8B;AAC7B,QAAM,IAAIE,SAAJ,qCAA+CF,IAA/C,yCAA+CA,IAA/C,GAAN;AACA;;AAEDC,KAAIA,KAAK,CAAT;AACA,KAAIA,KAAK,CAAL,IAAUA,IAAI,EAAlB,EAAsB;AACrB,QAAM,IAAIC,SAAJ,kCAA6CD,CAA7C,CAAN;AACA;;AAED;AACA,KAAME,kBAAgBH,IAAhB,2FAAN;;AAEA,KAAMI,MAAM,MAAMC,MAAMF,GAAN,CAAlB;AACA,KAAMG,OAAO,MAAMF,IAAIG,IAAJ,EAAnB;AACA,KAAMC,QAAQF,KAAKG,KAAL,CAAWC,MAAzB;AACAF,OAAMG,MAAN,GAAeV,CAAf;AACA,QAAOO,MAAMI,GAAN,CAAU;AAAA,SAAKC,EAAEC,KAAP;AAAA,EAAV,CAAP;AACA,C","file":"index.js","sourcesContent":["import \"isomorphic-fetch\";\nrequire(\"es6-promise\").polyfill();\n\nexport default async function main(lang, n) {\n\tlang = lang || \"en\";\n\tif (typeof lang !== \"string\") {\n\t\tthrow new TypeError(`Expected a string, got ${typeof lang}`);\n\t}\n\n\tn = n || 1;\n\tif (n <= 0 || n > 10) {\n\t\tthrow new TypeError(`Expected a -n (1 - 10), got ${n}`);\n\t}\n\n\t// rnlimit: API limit 10 or less\n\tconst url = `http://${lang}.wikipedia.org/w/api.php?format=json&action=query&list=random&rnnamespace=0&rnlimit=10`;\n\n\tconst res = await fetch(url);\n\tconst data = await res.json();\n\tconst words = data.query.random;\n\twords.length = n;\n\treturn words.map(v => v.title);\n}\n"]}
package/src/cli.js DELETED
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- const meow = require("meow");
4
- import randomWordWikipedia from ".";
5
-
6
- const cli = meow(`
7
- Usage
8
- $ random-word-wikipedia [lang]
9
-
10
- Options
11
- -n 10 or less [Default: 1]
12
-
13
- Examples
14
- $ random-word-wikipedia
15
- YuruYuri
16
-
17
- $ random-word-wikipedia ja -n 3
18
- バダインジャラン砂漠
19
- 内野 (印西市)
20
- PAC-MAN 256
21
-
22
- `);
23
-
24
- randomWordWikipedia(cli.input[0], cli.flags.n).then(res => {
25
- console.log(res.join("\n"));
26
- });
package/src/index.js DELETED
@@ -1,23 +0,0 @@
1
- import "isomorphic-fetch";
2
- require("es6-promise").polyfill();
3
-
4
- export default async function main(lang, n) {
5
- lang = lang || "en";
6
- if (typeof lang !== "string") {
7
- throw new TypeError(`Expected a string, got ${typeof lang}`);
8
- }
9
-
10
- n = n || 1;
11
- if (n <= 0 || n > 10) {
12
- throw new TypeError(`Expected a -n (1 - 10), got ${n}`);
13
- }
14
-
15
- // rnlimit: API limit 10 or less
16
- const url = `http://${lang}.wikipedia.org/w/api.php?format=json&action=query&list=random&rnnamespace=0&rnlimit=10`;
17
-
18
- const res = await fetch(url);
19
- const data = await res.json();
20
- const words = data.query.random;
21
- words.length = n;
22
- return words.map(v => v.title);
23
- }