@scrabble-solver/word-definitions 2.9.3 → 2.10.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.
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const types_1 = require("@scrabble-solver/types");
7
7
  const crawlEnglish_1 = __importDefault(require("./crawlEnglish"));
8
+ const crawlFarsi_1 = __importDefault(require("./crawlFarsi"));
8
9
  const crawlFrench_1 = __importDefault(require("./crawlFrench"));
9
10
  const crawlGerman_1 = __importDefault(require("./crawlGerman"));
10
11
  const crawlPolish_1 = __importDefault(require("./crawlPolish"));
@@ -14,6 +15,7 @@ const crawlPerLocale = {
14
15
  [types_1.Locale.EN_GB]: crawlEnglish_1.default,
15
16
  [types_1.Locale.EN_US]: crawlEnglish_1.default,
16
17
  [types_1.Locale.ES_ES]: crawlSpanish_1.default,
18
+ [types_1.Locale.FA_IR]: crawlFarsi_1.default,
17
19
  [types_1.Locale.FR_FR]: crawlFrench_1.default,
18
20
  [types_1.Locale.PL_PL]: crawlPolish_1.default,
19
21
  };
@@ -0,0 +1,2 @@
1
+ declare const crawlFarsi: (word: string) => Promise<string>;
2
+ export default crawlFarsi;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const lib_1 = require("../lib");
4
+ const crawlFarsi = (word) => {
5
+ return (0, lib_1.request)({
6
+ protocol: 'https',
7
+ hostname: 'www.vajehyab.com',
8
+ path: `/moein/${encodeURIComponent(word)}`,
9
+ });
10
+ };
11
+ exports.default = crawlFarsi;
@@ -15,7 +15,8 @@ const normalizeQuotes = (definition) => definition.replace(/\."/g, '".');
15
15
  const normalizeMarkers = (definition) => definition.replace(/^\(\d+\.\d+\)\s+/g, '');
16
16
  const normalizeTrailingSymbols = (definition) => definition.trim().replace(/:$/, '');
17
17
  const normalizeLeadingSymbols = (definition) => definition.trim().replace(/^:/, '');
18
- const normalizeNonWords = (definition) => (/\w/.test(definition) ? definition : '');
18
+ // https://stackoverflow.com/a/40732368
19
+ const normalizeNonWords = (definition) => (/[\w\u0621-\u064A]+/.test(definition) ? definition : '');
19
20
  const normalizeCommas = (definition) => {
20
21
  return definition
21
22
  .replace(/\s+,\s+/g, ', ')
@@ -1,5 +1,6 @@
1
1
  export { default as parse } from './parse';
2
2
  export { default as parseEnglish } from './parseEnglish';
3
+ export { default as parseFarsi } from './parseFarsi';
3
4
  export { default as parseFrench } from './parseFrench';
4
5
  export { default as parseGerman } from './parseGerman';
5
6
  export { default as parsePolish } from './parsePolish';
@@ -3,11 +3,13 @@ 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.parseSpanish = exports.parsePolish = exports.parseGerman = exports.parseFrench = exports.parseEnglish = exports.parse = void 0;
6
+ exports.parseSpanish = exports.parsePolish = exports.parseGerman = exports.parseFrench = exports.parseFarsi = exports.parseEnglish = exports.parse = void 0;
7
7
  var parse_1 = require("./parse");
8
8
  Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return __importDefault(parse_1).default; } });
9
9
  var parseEnglish_1 = require("./parseEnglish");
10
10
  Object.defineProperty(exports, "parseEnglish", { enumerable: true, get: function () { return __importDefault(parseEnglish_1).default; } });
11
+ var parseFarsi_1 = require("./parseFarsi");
12
+ Object.defineProperty(exports, "parseFarsi", { enumerable: true, get: function () { return __importDefault(parseFarsi_1).default; } });
11
13
  var parseFrench_1 = require("./parseFrench");
12
14
  Object.defineProperty(exports, "parseFrench", { enumerable: true, get: function () { return __importDefault(parseFrench_1).default; } });
13
15
  var parseGerman_1 = require("./parseGerman");
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const types_1 = require("@scrabble-solver/types");
7
7
  const lib_1 = require("../lib");
8
8
  const parseEnglish_1 = __importDefault(require("./parseEnglish"));
9
+ const parseFarsi_1 = __importDefault(require("./parseFarsi"));
9
10
  const parseFrench_1 = __importDefault(require("./parseFrench"));
10
11
  const parseGerman_1 = __importDefault(require("./parseGerman"));
11
12
  const parsePolish_1 = __importDefault(require("./parsePolish"));
@@ -15,6 +16,7 @@ const parsePerLocale = {
15
16
  [types_1.Locale.EN_GB]: parseEnglish_1.default,
16
17
  [types_1.Locale.EN_US]: parseEnglish_1.default,
17
18
  [types_1.Locale.ES_ES]: parseSpanish_1.default,
19
+ [types_1.Locale.FA_IR]: parseFarsi_1.default,
18
20
  [types_1.Locale.FR_FR]: parseFrench_1.default,
19
21
  [types_1.Locale.PL_PL]: parsePolish_1.default,
20
22
  };
@@ -0,0 +1,3 @@
1
+ import { ParseResult } from '../types';
2
+ declare const parseFarsi: (html: string) => ParseResult;
3
+ export default parseFarsi;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cheerio_1 = require("cheerio");
4
+ const DOES_NOT_EXIST_MESSAGE = '404 Page Not Found';
5
+ const parseFarsi = (html) => {
6
+ const $ = (0, cheerio_1.load)(html);
7
+ const $definitions = $('[itemprop=articleBody]');
8
+ return {
9
+ definitions: Array.from($definitions).map((definition) => $(definition).text()),
10
+ exists: $('#container h1').text() !== DOES_NOT_EXIST_MESSAGE,
11
+ };
12
+ };
13
+ exports.default = parseFarsi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrabble-solver/word-definitions",
3
- "version": "2.9.3",
3
+ "version": "2.10.0",
4
4
  "description": "Scrabble Solver 2 - Word definitions",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "clean": "rimraf build/ node_modules/ package-lock.json"
24
24
  },
25
25
  "dependencies": {
26
- "@scrabble-solver/types": "^2.9.3",
26
+ "@scrabble-solver/types": "^2.10.0",
27
27
  "cheerio": "^1.0.0-rc.12",
28
28
  "follow-redirects": "^1.15.2",
29
29
  "striptags": "^3.2.0"
@@ -31,5 +31,5 @@
31
31
  "devDependencies": {
32
32
  "@types/follow-redirects": "^1.14.1"
33
33
  },
34
- "gitHead": "ef8d030cbb76256a377f747f7ebe4b85b7eba61e"
34
+ "gitHead": "7fd0f6bf536fca88c18ce02e320da71b0c6d6f61"
35
35
  }
@@ -1,6 +1,7 @@
1
1
  import { Locale } from '@scrabble-solver/types';
2
2
 
3
3
  import crawlEnglish from './crawlEnglish';
4
+ import crawlFarsi from './crawlFarsi';
4
5
  import crawlFrench from './crawlFrench';
5
6
  import crawlGerman from './crawlGerman';
6
7
  import crawlPolish from './crawlPolish';
@@ -11,6 +12,7 @@ const crawlPerLocale: Record<Locale, (word: string) => Promise<string>> = {
11
12
  [Locale.EN_GB]: crawlEnglish,
12
13
  [Locale.EN_US]: crawlEnglish,
13
14
  [Locale.ES_ES]: crawlSpanish,
15
+ [Locale.FA_IR]: crawlFarsi,
14
16
  [Locale.FR_FR]: crawlFrench,
15
17
  [Locale.PL_PL]: crawlPolish,
16
18
  };
@@ -0,0 +1,11 @@
1
+ import { request } from '../lib';
2
+
3
+ const crawlFarsi = (word: string): Promise<string> => {
4
+ return request({
5
+ protocol: 'https',
6
+ hostname: 'www.vajehyab.com',
7
+ path: `/moein/${encodeURIComponent(word)}`,
8
+ });
9
+ };
10
+
11
+ export default crawlFarsi;
@@ -21,7 +21,8 @@ const normalizeTrailingSymbols: Normalize = (definition) => definition.trim().re
21
21
 
22
22
  const normalizeLeadingSymbols: Normalize = (definition) => definition.trim().replace(/^:/, '');
23
23
 
24
- const normalizeNonWords: Normalize = (definition) => (/\w/.test(definition) ? definition : '');
24
+ // https://stackoverflow.com/a/40732368
25
+ const normalizeNonWords: Normalize = (definition) => (/[\w\u0621-\u064A]+/.test(definition) ? definition : '');
25
26
 
26
27
  const normalizeCommas: Normalize = (definition) => {
27
28
  return definition
@@ -1,5 +1,6 @@
1
1
  export { default as parse } from './parse';
2
2
  export { default as parseEnglish } from './parseEnglish';
3
+ export { default as parseFarsi } from './parseFarsi';
3
4
  export { default as parseFrench } from './parseFrench';
4
5
  export { default as parseGerman } from './parseGerman';
5
6
  export { default as parsePolish } from './parsePolish';
@@ -4,6 +4,7 @@ import { normalizeDefinition, unique } from '../lib';
4
4
  import { ParseResult } from '../types';
5
5
 
6
6
  import parseEnglish from './parseEnglish';
7
+ import parseFarsi from './parseFarsi';
7
8
  import parseFrench from './parseFrench';
8
9
  import parseGerman from './parseGerman';
9
10
  import parsePolish from './parsePolish';
@@ -14,6 +15,7 @@ const parsePerLocale: Record<Locale, (html: string) => ParseResult> = {
14
15
  [Locale.EN_GB]: parseEnglish,
15
16
  [Locale.EN_US]: parseEnglish,
16
17
  [Locale.ES_ES]: parseSpanish,
18
+ [Locale.FA_IR]: parseFarsi,
17
19
  [Locale.FR_FR]: parseFrench,
18
20
  [Locale.PL_PL]: parsePolish,
19
21
  };
@@ -0,0 +1,17 @@
1
+ import { load } from 'cheerio';
2
+
3
+ import { ParseResult } from '../types';
4
+
5
+ const DOES_NOT_EXIST_MESSAGE = '404 Page Not Found';
6
+
7
+ const parseFarsi = (html: string): ParseResult => {
8
+ const $ = load(html);
9
+ const $definitions = $('[itemprop=articleBody]');
10
+
11
+ return {
12
+ definitions: Array.from($definitions).map((definition) => $(definition).text()),
13
+ exists: $('#container h1').text() !== DOES_NOT_EXIST_MESSAGE,
14
+ };
15
+ };
16
+
17
+ export default parseFarsi;