@scrabble-solver/word-definitions 2.15.8 → 2.15.10

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2024 Kamil Mielnik <kamil@kamilmielnik.com>
1
+ Copyright (c) 2025 Kamil Mielnik <kamil@kamilmielnik.com>
2
2
 
3
3
  Attribution-NonCommercial-NoDerivatives 4.0 International
4
4
 
@@ -15,7 +15,7 @@ const crawl = (word) => {
15
15
  exports.crawl = crawl;
16
16
  const parse = (json) => {
17
17
  const response = JSON.parse(json);
18
- if (response.error) {
18
+ if (!Array.isArray(response) || ('error' in response && response.error)) {
19
19
  return {
20
20
  definitions: [],
21
21
  exists: false,
@@ -1,3 +1,3 @@
1
- export * from './normalizeDefinition';
2
- export * from './request';
3
- export * from './unique';
1
+ export { normalizeDefinition } from './normalizeDefinition';
2
+ export { request } from './request';
3
+ export { unique } from './unique';
@@ -1,19 +1,9 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./normalizeDefinition"), exports);
18
- __exportStar(require("./request"), exports);
19
- __exportStar(require("./unique"), exports);
3
+ exports.unique = exports.request = exports.normalizeDefinition = void 0;
4
+ var normalizeDefinition_1 = require("./normalizeDefinition");
5
+ Object.defineProperty(exports, "normalizeDefinition", { enumerable: true, get: function () { return normalizeDefinition_1.normalizeDefinition; } });
6
+ var request_1 = require("./request");
7
+ Object.defineProperty(exports, "request", { enumerable: true, get: function () { return request_1.request; } });
8
+ var unique_1 = require("./unique");
9
+ Object.defineProperty(exports, "unique", { enumerable: true, get: function () { return unique_1.unique; } });
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.request = void 0;
4
+ const types_1 = require("@scrabble-solver/types");
4
5
  const follow_redirects_1 = require("follow-redirects");
5
6
  const request = ({ protocol, ...options }) => {
6
7
  const agent = protocol === 'https' ? follow_redirects_1.https : follow_redirects_1.http;
@@ -17,7 +18,7 @@ const request = ({ protocol, ...options }) => {
17
18
  resolve(data);
18
19
  }
19
20
  catch (error) {
20
- reject(error);
21
+ reject((0, types_1.isError)(error) ? error : new Error(String(error)));
21
22
  }
22
23
  });
23
24
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrabble-solver/word-definitions",
3
- "version": "2.15.8",
3
+ "version": "2.15.10",
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/"
24
24
  },
25
25
  "dependencies": {
26
- "@scrabble-solver/types": "^2.15.8",
26
+ "@scrabble-solver/types": "^2.15.10",
27
27
  "cheerio": "^1.0.0",
28
28
  "follow-redirects": "^1.15.9",
29
29
  "striptags": "^3.2.0"
@@ -32,5 +32,5 @@
32
32
  "@types/follow-redirects": "^1.14.4",
33
33
  "domhandler": "^5.0.3"
34
34
  },
35
- "gitHead": "da3ecd2d83f48bcc6aa7d43a6dc937d103e1312d"
35
+ "gitHead": "dab5a817c1bde1a3ebf8e8907215adf12af5cb27"
36
36
  }
@@ -13,9 +13,9 @@ export const crawl = (word: string): Promise<string> => {
13
13
  };
14
14
 
15
15
  export const parse = (json: string): ParsingResult => {
16
- const response = JSON.parse(json);
16
+ const response = JSON.parse(json) as [{ anlamlarListe: [{ anlam: string }] }] | { error?: unknown };
17
17
 
18
- if (response.error) {
18
+ if (!Array.isArray(response) || ('error' in response && response.error)) {
19
19
  return {
20
20
  definitions: [],
21
21
  exists: false,
@@ -23,7 +23,7 @@ export const parse = (json: string): ParsingResult => {
23
23
  }
24
24
 
25
25
  const [wordInfo] = response;
26
- const definitions = wordInfo.anlamlarListe.map((entry: { anlam: string }) => entry.anlam.replace('►', '').trim());
26
+ const definitions = wordInfo.anlamlarListe.map((entry) => entry.anlam.replace('►', '').trim());
27
27
 
28
28
  return {
29
29
  definitions,
package/src/lib/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './normalizeDefinition';
2
- export * from './request';
3
- export * from './unique';
1
+ export { normalizeDefinition } from './normalizeDefinition';
2
+ export { request } from './request';
3
+ export { unique } from './unique';
@@ -1,3 +1,4 @@
1
+ import { isError } from '@scrabble-solver/types';
1
2
  import { http, https } from 'follow-redirects';
2
3
  import { RequestOptions } from 'http';
3
4
 
@@ -20,7 +21,7 @@ export const request = ({ protocol, ...options }: Options): Promise<string> => {
20
21
  try {
21
22
  resolve(data);
22
23
  } catch (error) {
23
- reject(error);
24
+ reject(isError(error) ? error : new Error(String(error)));
24
25
  }
25
26
  });
26
27
  })
package/src/parse.test.ts CHANGED
@@ -4,7 +4,7 @@ import path from 'path';
4
4
 
5
5
  import { parse } from './parse';
6
6
 
7
- export const readTestFile = (filepath: string): string => {
7
+ const readTestFile = (filepath: string): string => {
8
8
  const absoluteFilepath = path.resolve(__dirname, '__tests__', filepath);
9
9
  return fs.readFileSync(absoluteFilepath, 'utf-8');
10
10
  };