@scrabble-solver/word-lists 2.13.0 → 2.13.2

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.
@@ -1,14 +1,18 @@
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 types_1 = require("@scrabble-solver/types");
7
+ const latinize_1 = __importDefault(require("latinize"));
4
8
  const lib_1 = require("./lib");
5
- const FILE_URL = 'https://raw.githubusercontent.com/kamilmielnik/fise-2/master/fise-2.txt';
9
+ const FILE_URL = 'https://raw.githubusercontent.com/kamilmielnik/scrabble-dictionaries/master/spanish/fise-2.txt';
10
+ const N_PLACEHOLDER = '---n---';
6
11
  const getEsEsWordList = async () => {
7
12
  const words = await (0, lib_1.getTxtWordList)(FILE_URL, types_1.Locale.ES_ES);
8
- return words.map(normalizeWord);
9
- };
10
- const normalizeWord = (word) => {
11
- // normalization from https://stackoverflow.com/a/37511463
12
- return word.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
13
+ return words
14
+ .map((word) => word.replaceAll('ñ', N_PLACEHOLDER))
15
+ .map(latinize_1.default)
16
+ .map((word) => word.replaceAll(N_PLACEHOLDER, 'ñ'));
13
17
  };
14
18
  exports.default = getEsEsWordList;
@@ -5,10 +5,6 @@ const lib_1 = require("./lib");
5
5
  const FILE_URL = 'https://raw.githubusercontent.com/Thecoolsim/French-Scrabble-ODS8/main/French%20ODS%20dictionary.txt';
6
6
  const getFrFrWordList = async () => {
7
7
  const words = await (0, lib_1.getTxtWordList)(FILE_URL, types_1.Locale.FR_FR);
8
- return words.map(normalizeWord);
9
- };
10
- const normalizeWord = (word) => {
11
- // normalization from https://stackoverflow.com/a/37511463
12
- return word.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
8
+ return (0, lib_1.latinizeDiacritics)(words);
13
9
  };
14
10
  exports.default = getFrFrWordList;
@@ -1,23 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const fs_1 = __importDefault(require("fs"));
3
+ const types_1 = require("@scrabble-solver/types");
7
4
  const lib_1 = require("./lib");
8
- const FILE_URL = 'https://dexonline.ro/static/download/scrabble/loc-flexiuni-5.0.zip';
9
- const FILE_TO_EXTRACT_FROM_ZIP = 'loc-flexiuni-5.0.txt';
5
+ const FILE_URL = 'https://raw.githubusercontent.com/kamilmielnik/scrabble-dictionaries/master/romanian/loc-5.0.txt';
10
6
  const getRoRoWordList = async () => {
11
- const tempFilepath = (0, lib_1.getTempFilepath)();
12
- const zipTempFilename = await (0, lib_1.downloadFile)(FILE_URL);
13
- await (0, lib_1.unzip)(zipTempFilename, FILE_TO_EXTRACT_FROM_ZIP, tempFilepath);
14
- fs_1.default.unlinkSync(zipTempFilename);
15
- const file = fs_1.default.readFileSync(tempFilepath, 'utf-8');
16
- fs_1.default.unlinkSync(tempFilepath);
17
- const words = (0, lib_1.extractWords)(replaceDiacritics(file.toLocaleString()), 'ro-RO');
18
- return words;
19
- };
20
- const replaceDiacritics = (file) => {
21
- return file.replaceAll('ă', 'a').replaceAll('â', 'a').replaceAll('î', 'i').replaceAll('ș', 's').replaceAll('ț', 't');
7
+ const words = await (0, lib_1.getTxtWordList)(FILE_URL, types_1.Locale.RO_RO);
8
+ return (0, lib_1.latinizeDiacritics)(words);
22
9
  };
23
10
  exports.default = getRoRoWordList;
@@ -5,4 +5,6 @@ export { default as findFirstWordIndex } from './findFirstWordIndex';
5
5
  export { default as getHash } from './getHash';
6
6
  export { default as getTempFilepath } from './getTempFilepath';
7
7
  export { default as getTxtWordList } from './getTxtWordList';
8
+ export { default as latinizeDiacritics } from './latinizeDiacritics';
9
+ export { default as unique } from './unique';
8
10
  export { default as unzip } from './unzip';
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.unzip = exports.getTxtWordList = exports.getTempFilepath = exports.getHash = exports.findFirstWordIndex = exports.extractWords = exports.downloadHtml = exports.downloadFile = void 0;
6
+ exports.unzip = exports.unique = exports.latinizeDiacritics = exports.getTxtWordList = exports.getTempFilepath = exports.getHash = exports.findFirstWordIndex = exports.extractWords = exports.downloadHtml = exports.downloadFile = void 0;
7
7
  var downloadFile_1 = require("./downloadFile");
8
8
  Object.defineProperty(exports, "downloadFile", { enumerable: true, get: function () { return __importDefault(downloadFile_1).default; } });
9
9
  var downloadHtml_1 = require("./downloadHtml");
@@ -18,5 +18,9 @@ var getTempFilepath_1 = require("./getTempFilepath");
18
18
  Object.defineProperty(exports, "getTempFilepath", { enumerable: true, get: function () { return __importDefault(getTempFilepath_1).default; } });
19
19
  var getTxtWordList_1 = require("./getTxtWordList");
20
20
  Object.defineProperty(exports, "getTxtWordList", { enumerable: true, get: function () { return __importDefault(getTxtWordList_1).default; } });
21
+ var latinizeDiacritics_1 = require("./latinizeDiacritics");
22
+ Object.defineProperty(exports, "latinizeDiacritics", { enumerable: true, get: function () { return __importDefault(latinizeDiacritics_1).default; } });
23
+ var unique_1 = require("./unique");
24
+ Object.defineProperty(exports, "unique", { enumerable: true, get: function () { return __importDefault(unique_1).default; } });
21
25
  var unzip_1 = require("./unzip");
22
26
  Object.defineProperty(exports, "unzip", { enumerable: true, get: function () { return __importDefault(unzip_1).default; } });
@@ -0,0 +1,2 @@
1
+ declare const latinizeDiacritics: (words: string[]) => string[];
2
+ export default latinizeDiacritics;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const latinize_1 = __importDefault(require("latinize"));
7
+ const unique_1 = __importDefault(require("./unique"));
8
+ const latinizeDiacritics = (words) => {
9
+ return (0, unique_1.default)(words.map((word) => (0, latinize_1.default)(word)));
10
+ };
11
+ exports.default = latinizeDiacritics;
@@ -0,0 +1,2 @@
1
+ declare const unique: <T>(array: T[]) => T[];
2
+ export default unique;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const unique = (array) => Array.from(new Set(array));
4
+ exports.default = unique;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrabble-solver/word-lists",
3
- "version": "2.13.0",
3
+ "version": "2.13.2",
4
4
  "description": "Scrabble Solver 2 - Word lists",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -24,14 +24,16 @@
24
24
  "clean:force": "npm run clean && rimraf package-lock.json"
25
25
  },
26
26
  "dependencies": {
27
- "@scrabble-solver/types": "^2.13.0",
27
+ "@scrabble-solver/types": "^2.13.2",
28
28
  "cheerio": "^1.0.0-rc.12",
29
29
  "follow-redirects": "^1.15.2",
30
+ "latinize": "^1.0.0",
30
31
  "unzipper": "^0.10.11"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@types/follow-redirects": "^1.14.1",
35
+ "@types/latinize": "^0.2.17",
34
36
  "@types/unzipper": "^0.10.5"
35
37
  },
36
- "gitHead": "fb2e1c0ef099ea8983162ed9f0067d626ebdfaff"
38
+ "gitHead": "416ff4259dd617dd5a65212baf75aedfff2686af"
37
39
  }
@@ -1,17 +1,18 @@
1
1
  import { Locale } from '@scrabble-solver/types';
2
+ import latinize from 'latinize';
2
3
 
3
4
  import { getTxtWordList } from './lib';
4
5
 
5
- const FILE_URL = 'https://raw.githubusercontent.com/kamilmielnik/fise-2/master/fise-2.txt';
6
+ const FILE_URL = 'https://raw.githubusercontent.com/kamilmielnik/scrabble-dictionaries/master/spanish/fise-2.txt';
7
+ const N_PLACEHOLDER = '---n---';
6
8
 
7
9
  const getEsEsWordList = async (): Promise<string[]> => {
8
10
  const words = await getTxtWordList(FILE_URL, Locale.ES_ES);
9
- return words.map(normalizeWord);
10
- };
11
11
 
12
- const normalizeWord = (word: string): string => {
13
- // normalization from https://stackoverflow.com/a/37511463
14
- return word.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
12
+ return words
13
+ .map((word) => word.replaceAll('ñ', N_PLACEHOLDER))
14
+ .map(latinize)
15
+ .map((word) => word.replaceAll(N_PLACEHOLDER, 'ñ'));
15
16
  };
16
17
 
17
18
  export default getEsEsWordList;
@@ -1,17 +1,12 @@
1
1
  import { Locale } from '@scrabble-solver/types';
2
2
 
3
- import { getTxtWordList } from './lib';
3
+ import { getTxtWordList, latinizeDiacritics } from './lib';
4
4
 
5
5
  const FILE_URL = 'https://raw.githubusercontent.com/Thecoolsim/French-Scrabble-ODS8/main/French%20ODS%20dictionary.txt';
6
6
 
7
7
  const getFrFrWordList = async (): Promise<string[]> => {
8
8
  const words = await getTxtWordList(FILE_URL, Locale.FR_FR);
9
- return words.map(normalizeWord);
10
- };
11
-
12
- const normalizeWord = (word: string): string => {
13
- // normalization from https://stackoverflow.com/a/37511463
14
- return word.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
9
+ return latinizeDiacritics(words);
15
10
  };
16
11
 
17
12
  export default getFrFrWordList;
@@ -1,23 +1,12 @@
1
- import fs from 'fs';
1
+ import { Locale } from '@scrabble-solver/types';
2
2
 
3
- import { downloadFile, extractWords, getTempFilepath, unzip } from './lib';
3
+ import { getTxtWordList, latinizeDiacritics } from './lib';
4
4
 
5
- const FILE_URL = 'https://dexonline.ro/static/download/scrabble/loc-flexiuni-5.0.zip';
6
- const FILE_TO_EXTRACT_FROM_ZIP = 'loc-flexiuni-5.0.txt';
5
+ const FILE_URL = 'https://raw.githubusercontent.com/kamilmielnik/scrabble-dictionaries/master/romanian/loc-5.0.txt';
7
6
 
8
7
  const getRoRoWordList = async (): Promise<string[]> => {
9
- const tempFilepath = getTempFilepath();
10
- const zipTempFilename = await downloadFile(FILE_URL);
11
- await unzip(zipTempFilename, FILE_TO_EXTRACT_FROM_ZIP, tempFilepath);
12
- fs.unlinkSync(zipTempFilename);
13
- const file = fs.readFileSync(tempFilepath, 'utf-8');
14
- fs.unlinkSync(tempFilepath);
15
- const words = extractWords(replaceDiacritics(file.toLocaleString()), 'ro-RO');
16
- return words;
17
- };
18
-
19
- const replaceDiacritics = (file: string): string => {
20
- return file.replaceAll('ă', 'a').replaceAll('â', 'a').replaceAll('î', 'i').replaceAll('ș', 's').replaceAll('ț', 't');
8
+ const words = await getTxtWordList(FILE_URL, Locale.RO_RO);
9
+ return latinizeDiacritics(words);
21
10
  };
22
11
 
23
12
  export default getRoRoWordList;
package/src/lib/index.ts CHANGED
@@ -5,4 +5,6 @@ export { default as findFirstWordIndex } from './findFirstWordIndex';
5
5
  export { default as getHash } from './getHash';
6
6
  export { default as getTempFilepath } from './getTempFilepath';
7
7
  export { default as getTxtWordList } from './getTxtWordList';
8
+ export { default as latinizeDiacritics } from './latinizeDiacritics';
9
+ export { default as unique } from './unique';
8
10
  export { default as unzip } from './unzip';
@@ -0,0 +1,9 @@
1
+ import latinize from 'latinize';
2
+
3
+ import unique from './unique';
4
+
5
+ const latinizeDiacritics = (words: string[]): string[] => {
6
+ return unique(words.map((word) => latinize(word)));
7
+ };
8
+
9
+ export default latinizeDiacritics;
@@ -0,0 +1,3 @@
1
+ const unique = <T>(array: T[]): T[] => Array.from(new Set(array));
2
+
3
+ export default unique;