random-word-wikipedia 2.0.0 β 2.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 +1 -1
- package/lib/cjs/index.js +17 -0
- package/lib/cjs/package.json +1 -0
- package/lib/esm/index.js +15 -0
- package/lib/types/index.d.ts +2 -0
- package/package.json +26 -4
- package/readme.md +10 -2
- package/index.js +0 -20
package/cli.js
CHANGED
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const randomWordWikipedia = async (lang = "en", n = 1) => {
|
|
4
|
+
if (typeof lang !== "string") {
|
|
5
|
+
throw new TypeError(`Expected a string, got ${typeof lang}`);
|
|
6
|
+
}
|
|
7
|
+
if (n <= 0 || n > 10) {
|
|
8
|
+
throw new TypeError(`Expected a -n (1 - 10), got ${n}`);
|
|
9
|
+
}
|
|
10
|
+
// rnlimit: API limit 10 or less
|
|
11
|
+
const url = `https://${lang}.wikipedia.org/w/api.php?format=json&action=query&list=random&rnnamespace=0&rnlimit=${n}`;
|
|
12
|
+
const res = await fetch(url);
|
|
13
|
+
const data = (await res.json());
|
|
14
|
+
const words = data.query.random;
|
|
15
|
+
return words.slice(-n).map((v) => v.title);
|
|
16
|
+
};
|
|
17
|
+
exports.default = randomWordWikipedia;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const randomWordWikipedia = async (lang = "en", n = 1) => {
|
|
2
|
+
if (typeof lang !== "string") {
|
|
3
|
+
throw new TypeError(`Expected a string, got ${typeof lang}`);
|
|
4
|
+
}
|
|
5
|
+
if (n <= 0 || n > 10) {
|
|
6
|
+
throw new TypeError(`Expected a -n (1 - 10), got ${n}`);
|
|
7
|
+
}
|
|
8
|
+
// rnlimit: API limit 10 or less
|
|
9
|
+
const url = `https://${lang}.wikipedia.org/w/api.php?format=json&action=query&list=random&rnnamespace=0&rnlimit=${n}`;
|
|
10
|
+
const res = await fetch(url);
|
|
11
|
+
const data = (await res.json());
|
|
12
|
+
const words = data.query.random;
|
|
13
|
+
return words.slice(-n).map((v) => v.title);
|
|
14
|
+
};
|
|
15
|
+
export default randomWordWikipedia;
|
package/package.json
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "random-word-wikipedia",
|
|
3
3
|
"description": "Get random word from wikipedia random page",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "elzup",
|
|
7
7
|
"email": "guild0105@gmail.com",
|
|
8
8
|
"url": "https://anozon.me"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
|
+
"main": "lib/cjs/index.js",
|
|
12
|
+
"module": "lib/esm/index.js",
|
|
13
|
+
"types": "lib/types/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./lib/types/index.d.ts",
|
|
17
|
+
"import": "./lib/esm/index.js",
|
|
18
|
+
"require": "./lib/cjs/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
11
21
|
"bin": {
|
|
12
22
|
"random-word-wikipedia": "./cli.js"
|
|
13
23
|
},
|
|
24
|
+
"sideEffects": false,
|
|
14
25
|
"engines": {
|
|
15
26
|
"node": ">=22"
|
|
16
27
|
},
|
|
17
28
|
"files": [
|
|
18
|
-
"
|
|
19
|
-
"
|
|
29
|
+
"lib/",
|
|
30
|
+
"cli.js"
|
|
20
31
|
],
|
|
21
32
|
"keywords": [
|
|
22
33
|
"cli",
|
|
@@ -28,8 +39,19 @@
|
|
|
28
39
|
"license": "MIT",
|
|
29
40
|
"repository": "elzup/random-word-wikipedia",
|
|
30
41
|
"scripts": {
|
|
42
|
+
"clean": "rimraf lib",
|
|
43
|
+
"build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:types",
|
|
44
|
+
"build:cjs": "tsc --module commonjs --outDir lib/cjs && echo '{\"type\":\"commonjs\"}' > lib/cjs/package.json",
|
|
45
|
+
"build:esm": "tsc --module esnext --outDir lib/esm",
|
|
46
|
+
"build:types": "tsc --declaration --emitDeclarationOnly --outDir lib/types",
|
|
47
|
+
"pretest": "npm run build",
|
|
31
48
|
"test": "node --test",
|
|
32
49
|
"cli": "node cli.js",
|
|
33
|
-
"prepublishOnly": "
|
|
50
|
+
"prepublishOnly": "npm test"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/node": "^24.0.0",
|
|
54
|
+
"rimraf": "^6.0.0",
|
|
55
|
+
"typescript": "^5.6.0"
|
|
34
56
|
}
|
|
35
57
|
}
|
package/readme.md
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
> Get a random word (article title) from Wikipedia's random page.
|
|
7
7
|
|
|
8
|
-
- πͺΆ **Zero dependencies** β uses the platform `fetch`, nothing else
|
|
9
|
-
- π¦ **ESM
|
|
8
|
+
- πͺΆ **Zero runtime dependencies** β uses the platform `fetch`, nothing else
|
|
9
|
+
- π¦ **ESM + CommonJS** with bundled **TypeScript types**, for Node.js `>= 22`
|
|
10
10
|
- π **Any language** β pass a Wikipedia language code (`en`, `ja`, β¦)
|
|
11
11
|
|
|
12
12
|
## Install
|
|
@@ -27,6 +27,14 @@ await randomWordWikipedia("ja", 2);
|
|
|
27
27
|
//=> ['γΈγ§γ³γ»γ€γ΅γΌγ―γ»γγͺγ±', 'ζγ―ιε€γ«ι γγε¦γ']
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
CommonJS (note the `.default`):
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
const randomWordWikipedia = require("random-word-wikipedia").default;
|
|
34
|
+
|
|
35
|
+
randomWordWikipedia().then(console.log);
|
|
36
|
+
```
|
|
37
|
+
|
|
30
38
|
## API
|
|
31
39
|
|
|
32
40
|
### `randomWordWikipedia(lang?, n?)`
|
package/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const randomWordWikipedia = async (lang = "en", n = 1) => {
|
|
2
|
-
if (typeof lang !== "string") {
|
|
3
|
-
throw new TypeError(`Expected a string, got ${typeof lang}`);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
if (n <= 0 || n > 10) {
|
|
7
|
-
throw new TypeError(`Expected a -n (1 - 10), got ${n}`);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// rnlimit: API limit 10 or less
|
|
11
|
-
const url = `https://${lang}.wikipedia.org/w/api.php?format=json&action=query&list=random&rnnamespace=0&rnlimit=${n}`;
|
|
12
|
-
|
|
13
|
-
const res = await fetch(url);
|
|
14
|
-
const data = await res.json();
|
|
15
|
-
const words = data.query.random;
|
|
16
|
-
|
|
17
|
-
return words.slice(-n).map((v) => v.title);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default randomWordWikipedia;
|