@scrabble-solver/word-lists 2.8.3 → 2.8.5
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/build/getPlPlWordList.js +2 -3
- package/build/lib/downloadFile.d.ts +1 -2
- package/build/lib/downloadFile.js +24 -6
- package/build/lib/getTxtWordList.js +2 -4
- package/package.json +3 -3
- package/src/getPlPlWordList.ts +2 -3
- package/src/lib/downloadFile.ts +25 -7
- package/src/lib/getTxtWordList.ts +2 -4
package/build/getPlPlWordList.js
CHANGED
|
@@ -11,15 +11,14 @@ const lib_1 = require("./lib");
|
|
|
11
11
|
const PAGE_URL = 'https://sjp.pl/sl/growy/';
|
|
12
12
|
const FILE_TO_EXTRACT_FROM_ZIP = 'slowa.txt';
|
|
13
13
|
const getPlPlWordList = async () => {
|
|
14
|
-
const zipTempFilename = (0, lib_1.getTempFilename)();
|
|
15
14
|
const tempFilename = (0, lib_1.getTempFilename)();
|
|
16
15
|
const zipUrl = await fetchZipUrl(PAGE_URL);
|
|
17
|
-
await (0, lib_1.downloadFile)(zipUrl
|
|
16
|
+
const zipTempFilename = await (0, lib_1.downloadFile)(zipUrl);
|
|
18
17
|
await unzip(zipTempFilename, tempFilename);
|
|
19
18
|
memfs_1.fs.unlinkSync(zipTempFilename);
|
|
20
19
|
const file = memfs_1.fs.readFileSync(tempFilename, 'utf-8');
|
|
21
20
|
memfs_1.fs.unlinkSync(tempFilename);
|
|
22
|
-
const words = (0, lib_1.extractWords)(file.
|
|
21
|
+
const words = (0, lib_1.extractWords)(file.toLocaleString());
|
|
23
22
|
return words;
|
|
24
23
|
};
|
|
25
24
|
const fetchZipUrl = async (url) => {
|
|
@@ -1,19 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const follow_redirects_1 = require("follow-redirects");
|
|
4
|
-
const
|
|
7
|
+
const memfs_1 = require("memfs");
|
|
8
|
+
const getTempFilename_1 = __importDefault(require("./getTempFilename"));
|
|
9
|
+
const downloadFile = (url) => {
|
|
5
10
|
return new Promise((resolve, reject) => {
|
|
11
|
+
const tempFilename = (0, getTempFilename_1.default)();
|
|
6
12
|
const protocol = url.startsWith('https') ? follow_redirects_1.https : follow_redirects_1.http;
|
|
13
|
+
const writeStream = memfs_1.fs.createWriteStream(tempFilename);
|
|
7
14
|
const request = protocol.get(url, (response) => {
|
|
8
15
|
if (typeof response.statusCode === 'undefined' || response.statusCode >= 400) {
|
|
9
|
-
reject();
|
|
16
|
+
reject(new Error(`Cannot download file: ${url}`));
|
|
10
17
|
return;
|
|
11
18
|
}
|
|
12
|
-
response.
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
response.on('error', (error) => {
|
|
20
|
+
writeStream.close();
|
|
21
|
+
reject(error);
|
|
22
|
+
});
|
|
23
|
+
response.on('end', () => {
|
|
24
|
+
writeStream.on('finish', () => {
|
|
25
|
+
writeStream.close();
|
|
26
|
+
resolve(tempFilename);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
response.pipe(writeStream);
|
|
30
|
+
});
|
|
31
|
+
request.on('error', (error) => {
|
|
32
|
+
writeStream.close();
|
|
33
|
+
reject(error);
|
|
15
34
|
});
|
|
16
|
-
request.on('error', reject);
|
|
17
35
|
});
|
|
18
36
|
};
|
|
19
37
|
exports.default = downloadFile;
|
|
@@ -6,12 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const memfs_1 = require("memfs");
|
|
7
7
|
const downloadFile_1 = __importDefault(require("./downloadFile"));
|
|
8
8
|
const extractWords_1 = __importDefault(require("./extractWords"));
|
|
9
|
-
const getTempFilename_1 = __importDefault(require("./getTempFilename"));
|
|
10
9
|
const getTxtWordList = async (url) => {
|
|
11
|
-
const tempFilename = (0,
|
|
12
|
-
await (0, downloadFile_1.default)(url, memfs_1.fs.createWriteStream(tempFilename));
|
|
10
|
+
const tempFilename = await (0, downloadFile_1.default)(url);
|
|
13
11
|
const file = memfs_1.fs.readFileSync(tempFilename, 'utf-8');
|
|
14
|
-
const words = (0, extractWords_1.default)(file.
|
|
12
|
+
const words = (0, extractWords_1.default)(file.toLocaleString());
|
|
15
13
|
memfs_1.fs.unlinkSync(tempFilename);
|
|
16
14
|
return words;
|
|
17
15
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scrabble-solver/word-lists",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.5",
|
|
4
4
|
"description": "Scrabble Solver 2 - Word lists",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"clean:force": "npm run clean && rimraf package-lock.json"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@scrabble-solver/types": "^2.8.
|
|
27
|
+
"@scrabble-solver/types": "^2.8.5",
|
|
28
28
|
"cheerio": "^1.0.0-rc.12",
|
|
29
29
|
"follow-redirects": "^1.15.2",
|
|
30
30
|
"memfs": "^3.4.7",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"@types/follow-redirects": "^1.14.1",
|
|
35
35
|
"@types/unzipper": "^0.10.5"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "79ba3664458e7dc8d805599a3cf3cd1faba86309"
|
|
38
38
|
}
|
package/src/getPlPlWordList.ts
CHANGED
|
@@ -9,15 +9,14 @@ const PAGE_URL = 'https://sjp.pl/sl/growy/';
|
|
|
9
9
|
const FILE_TO_EXTRACT_FROM_ZIP = 'slowa.txt';
|
|
10
10
|
|
|
11
11
|
const getPlPlWordList = async (): Promise<string[]> => {
|
|
12
|
-
const zipTempFilename = getTempFilename();
|
|
13
12
|
const tempFilename = getTempFilename();
|
|
14
13
|
const zipUrl = await fetchZipUrl(PAGE_URL);
|
|
15
|
-
await downloadFile(zipUrl
|
|
14
|
+
const zipTempFilename = await downloadFile(zipUrl);
|
|
16
15
|
await unzip(zipTempFilename, tempFilename);
|
|
17
16
|
fs.unlinkSync(zipTempFilename);
|
|
18
17
|
const file = fs.readFileSync(tempFilename, 'utf-8');
|
|
19
18
|
fs.unlinkSync(tempFilename);
|
|
20
|
-
const words = extractWords(file.
|
|
19
|
+
const words = extractWords(file.toLocaleString());
|
|
21
20
|
return words;
|
|
22
21
|
};
|
|
23
22
|
|
package/src/lib/downloadFile.ts
CHANGED
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
import { http, https } from 'follow-redirects';
|
|
2
|
-
import {
|
|
2
|
+
import { fs } from 'memfs';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import getTempFilename from './getTempFilename';
|
|
5
|
+
|
|
6
|
+
const downloadFile = (url: string): Promise<string> => {
|
|
5
7
|
return new Promise((resolve, reject) => {
|
|
8
|
+
const tempFilename = getTempFilename();
|
|
6
9
|
const protocol = url.startsWith('https') ? https : http;
|
|
10
|
+
const writeStream = fs.createWriteStream(tempFilename);
|
|
7
11
|
const request = protocol.get(url, (response) => {
|
|
8
12
|
if (typeof response.statusCode === 'undefined' || response.statusCode >= 400) {
|
|
9
|
-
reject();
|
|
13
|
+
reject(new Error(`Cannot download file: ${url}`));
|
|
10
14
|
return;
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
response.
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
response.on('error', (error) => {
|
|
18
|
+
writeStream.close();
|
|
19
|
+
reject(error);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
response.on('end', () => {
|
|
23
|
+
writeStream.on('finish', () => {
|
|
24
|
+
writeStream.close();
|
|
25
|
+
resolve(tempFilename);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
response.pipe(writeStream);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
request.on('error', (error) => {
|
|
33
|
+
writeStream.close();
|
|
34
|
+
reject(error);
|
|
16
35
|
});
|
|
17
|
-
request.on('error', reject);
|
|
18
36
|
});
|
|
19
37
|
};
|
|
20
38
|
|
|
@@ -2,13 +2,11 @@ import { fs } from 'memfs';
|
|
|
2
2
|
|
|
3
3
|
import downloadFile from './downloadFile';
|
|
4
4
|
import extractWords from './extractWords';
|
|
5
|
-
import getTempFilename from './getTempFilename';
|
|
6
5
|
|
|
7
6
|
const getTxtWordList = async (url: string): Promise<string[]> => {
|
|
8
|
-
const tempFilename =
|
|
9
|
-
await downloadFile(url, fs.createWriteStream(tempFilename));
|
|
7
|
+
const tempFilename = await downloadFile(url);
|
|
10
8
|
const file = fs.readFileSync(tempFilename, 'utf-8');
|
|
11
|
-
const words = extractWords(file.
|
|
9
|
+
const words = extractWords(file.toLocaleString());
|
|
12
10
|
fs.unlinkSync(tempFilename);
|
|
13
11
|
return words;
|
|
14
12
|
};
|