@scrabble-solver/word-definitions 2.5.0 → 2.7.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.
@@ -1,4 +1,6 @@
1
1
  export { default as parse } from './parse';
2
2
  export { default as parseEnglish } from './parseEnglish';
3
3
  export { default as parseFrench } from './parseFrench';
4
+ export { default as parseGerman } from './parseGerman';
4
5
  export { default as parsePolish } from './parsePolish';
6
+ export { default as parseSpanish } from './parseSpanish';
@@ -15,6 +15,8 @@ const tests = [
15
15
  { locale: Locale.EN_US, word: 'pawnee' },
16
16
  { locale: Locale.EN_US, word: 'pean' },
17
17
  { locale: Locale.EN_US, word: 'wiz' },
18
+ { locale: Locale.ES_ES, word: 'corma' },
19
+ { locale: Locale.ES_ES, word: 'portero' },
18
20
  ];
19
21
 
20
22
  describe('parse', () => {
@@ -5,11 +5,15 @@ import { ParseResult } from '../types';
5
5
 
6
6
  import parseEnglish from './parseEnglish';
7
7
  import parseFrench from './parseFrench';
8
+ import parseGerman from './parseGerman';
8
9
  import parsePolish from './parsePolish';
10
+ import parseSpanish from './parseSpanish';
9
11
 
10
12
  const parsePerLocale: Record<Locale, (html: string) => ParseResult> = {
13
+ [Locale.DE_DE]: parseGerman,
11
14
  [Locale.EN_GB]: parseEnglish,
12
15
  [Locale.EN_US]: parseEnglish,
16
+ [Locale.ES_ES]: parseSpanish,
13
17
  [Locale.FR_FR]: parseFrench,
14
18
  [Locale.PL_PL]: parsePolish,
15
19
  };
@@ -0,0 +1,21 @@
1
+ import cheerio from 'cheerio';
2
+
3
+ import { ParseResult } from '../types';
4
+
5
+ const parseGerman = (html: string): ParseResult => {
6
+ const $ = cheerio.load(html);
7
+ const $meaningOverview = $('.bedeutungsuebersicht');
8
+ let $definitions;
9
+ if ($meaningOverview.length > 0) {
10
+ $definitions = $('.bedeutungsuebersicht > ol > li > a');
11
+ } else {
12
+ $definitions = $('.dwdswb-lesart .dwdswb-definition');
13
+ }
14
+
15
+ return {
16
+ definitions: Array.from($definitions).map((definition) => $(definition).text().replace('/\n/', '')),
17
+ isAllowed: $definitions.length > 0,
18
+ };
19
+ };
20
+
21
+ export default parseGerman;
@@ -0,0 +1,35 @@
1
+ import cheerio from 'cheerio';
2
+
3
+ import { ParseResult } from '../types';
4
+
5
+ const parseSpanish = (html: string): ParseResult => {
6
+ const $ = cheerio.load(html);
7
+ $('.verdBold14 + .gris11 + .gris13').remove();
8
+ $('br + .gris13').remove();
9
+ $('.grisItalic13 + .gris13').remove();
10
+ $('font[class^="verd"]').remove();
11
+ $('font.gris11').remove();
12
+ $('font[class^="grisBold"]').remove();
13
+ $('font[class^="grisItalic"]').remove();
14
+
15
+ Array.from($('.gris13')).forEach((element) => {
16
+ const children = $(element).find('.gris13');
17
+
18
+ if (children && children.length > 0) {
19
+ children.remove();
20
+ }
21
+ });
22
+
23
+ const definitions = Array.from($('.dcom-search-result .gris13'));
24
+
25
+ return {
26
+ definitions: definitions
27
+ .map((definition) => $(definition).text().trim())
28
+ .filter(Boolean)
29
+ .map((definition) => definition.replace(/\s+\.$/g, ''))
30
+ .map((definition) => (definition.endsWith('.') ? definition : `${definition}.`)),
31
+ isAllowed: definitions.length > 0,
32
+ };
33
+ };
34
+
35
+ export default parseSpanish;