scrabble-cheater 3.6.4 → 3.6.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/dist/cjs/cli.js CHANGED
@@ -1,13 +1,4 @@
1
1
  #!/usr/bin/env node
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  import { program as commander } from 'commander';
12
3
  import { createRequire } from 'module';
13
4
  const require = createRequire(import.meta.url);
@@ -32,10 +23,15 @@ if (commanderOptions.maximum && !parseInt(commanderOptions.maximum, 10)) {
32
23
  console.error(' Error: invalid maximum number specified.');
33
24
  commander.help();
34
25
  }
35
- const options = Object.assign(Object.assign(Object.assign(Object.assign({}, (commanderOptions.letters && { letters: commanderOptions.letters })), (commanderOptions.maximum && { maximum: commanderOptions.maximum })), (commanderOptions.quiet && { quiet: commanderOptions.quiet })), (commanderOptions.single && { single: commanderOptions.single }));
36
- void (() => __awaiter(void 0, void 0, void 0, function* () {
26
+ const options = {
27
+ ...(commanderOptions.letters && { letters: commanderOptions.letters }),
28
+ ...(commanderOptions.maximum && { maximum: commanderOptions.maximum }),
29
+ ...(commanderOptions.quiet && { quiet: commanderOptions.quiet }),
30
+ ...(commanderOptions.single && { single: commanderOptions.single }),
31
+ };
32
+ void (async () => {
37
33
  try {
38
- const matches = yield new ScrabbleCheater(commanderOptions.wordlist, options).start();
34
+ const matches = await new ScrabbleCheater(commanderOptions.wordlist, options).start();
39
35
  if (matches.length && !commanderOptions.single) {
40
36
  console.info(matches.join('\n'));
41
37
  }
@@ -45,4 +41,4 @@ void (() => __awaiter(void 0, void 0, void 0, function* () {
45
41
  console.error(error);
46
42
  process.exit(1);
47
43
  }
48
- }))();
44
+ })();
package/dist/cjs/index.js CHANGED
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import clipboard from 'clipboardy';
11
2
  import fs from 'fs';
12
3
  import readline from 'readline';
@@ -22,32 +13,30 @@ export class ScrabbleCheater {
22
13
  constructor(wordListPath, options) {
23
14
  this.dictionary = [];
24
15
  this.wordListPath = wordListPath;
25
- this.options = Object.assign(Object.assign({}, defaultOptions), options);
16
+ this.options = { ...defaultOptions, ...options };
26
17
  }
27
18
  setLetters(letters) {
28
19
  this.options.letters = letters;
29
20
  return this;
30
21
  }
31
- start() {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const length = yield this.loadWords();
34
- if (!length) {
35
- throw new Error('No words loaded. Wordlist file corrupt?');
36
- }
37
- this.log(`${length} word${length > 1 ? 's' : ''} loaded.`);
38
- const letters = this.options.letters ? this.formatLetters(this.options.letters) : yield this.readLineAsync();
39
- let matches = this.findMatches(letters);
40
- this.log(`ScrabbleCheater: ${matches.length} matches found`, true);
41
- if (this.options.maximum) {
42
- this.log(`, ${this.options.singleMode ? 'sending' : 'displaying'} the first ${this.options.maximum}`, true);
43
- matches = matches.slice(0, this.options.maximum);
44
- }
45
- this.log('.\n\n', true);
46
- if (this.options.singleMode) {
47
- this.singleOutput(matches);
48
- }
49
- return matches;
50
- });
22
+ async start() {
23
+ const length = await this.loadWords();
24
+ if (!length) {
25
+ throw new Error('No words loaded. Wordlist file corrupt?');
26
+ }
27
+ this.log(`${length} word${length > 1 ? 's' : ''} loaded.`);
28
+ const letters = this.options.letters ? this.formatLetters(this.options.letters) : await this.readLineAsync();
29
+ let matches = this.findMatches(letters);
30
+ this.log(`ScrabbleCheater: ${matches.length} matches found`, true);
31
+ if (this.options.maximum) {
32
+ this.log(`, ${this.options.singleMode ? 'sending' : 'displaying'} the first ${this.options.maximum}`, true);
33
+ matches = matches.slice(0, this.options.maximum);
34
+ }
35
+ this.log('.\n\n', true);
36
+ if (this.options.singleMode) {
37
+ this.singleOutput(matches);
38
+ }
39
+ return matches;
51
40
  }
52
41
  findMatches(letters) {
53
42
  const regex = new RegExp(`^[${letters}]+$`);
@@ -57,13 +46,11 @@ export class ScrabbleCheater {
57
46
  const regex = new RegExp('[^A-Za-z]');
58
47
  return letters.replace(regex, '').toLowerCase();
59
48
  }
60
- loadWords() {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- const regex = new RegExp('^[A-Za-z]+$');
63
- const wordList = yield readFileAsync(this.wordListPath, 'utf-8');
64
- this.dictionary = wordList.split('\n').filter(value => regex.test(value));
65
- return this.dictionary.length;
66
- });
49
+ async loadWords() {
50
+ const regex = new RegExp('^[A-Za-z]+$');
51
+ const wordList = await readFileAsync(this.wordListPath, 'utf-8');
52
+ this.dictionary = wordList.split('\n').filter(value => regex.test(value));
53
+ return this.dictionary.length;
67
54
  }
68
55
  log(message, raw = false) {
69
56
  if (!this.options.quietMode) {
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { assert, expect, describe, test } from 'vitest';
11
2
  import path from 'path';
12
3
  import { fileURLToPath } from 'url';
@@ -16,21 +7,21 @@ const __dirname = path.dirname(__filename);
16
7
  const wordList = path.resolve(__dirname, '../fixtures/wordlist.txt');
17
8
  const emptyList = path.resolve(__dirname, '../fixtures/empty.txt');
18
9
  describe('ScrabbleCheater', () => {
19
- test('finds all words', () => __awaiter(void 0, void 0, void 0, function* () {
10
+ test('finds all words', async () => {
20
11
  const sc = new ScrabbleCheater(wordList, { letters: 'her', quietMode: true });
21
- const matches = yield sc.start();
12
+ const matches = await sc.start();
22
13
  expect(matches.includes('here')).toBe(true);
23
14
  expect(matches.includes('her')).toBe(true);
24
15
  expect(matches.includes('he')).toBe(true);
25
- }));
26
- test(`Doesn't accept an empty file`, () => __awaiter(void 0, void 0, void 0, function* () {
16
+ });
17
+ test(`Doesn't accept an empty file`, async () => {
27
18
  const sc = new ScrabbleCheater(emptyList);
28
19
  try {
29
- yield sc.start();
20
+ await sc.start();
30
21
  assert.fail();
31
22
  }
32
23
  catch (error) {
33
24
  // nothing to do
34
25
  }
35
- }));
26
+ });
36
27
  });
package/dist/esm/cli.js CHANGED
@@ -23,7 +23,12 @@ if (commanderOptions.maximum && !parseInt(commanderOptions.maximum, 10)) {
23
23
  console.error(' Error: invalid maximum number specified.');
24
24
  commander.help();
25
25
  }
26
- const options = Object.assign(Object.assign(Object.assign(Object.assign({}, (commanderOptions.letters && { letters: commanderOptions.letters })), (commanderOptions.maximum && { maximum: commanderOptions.maximum })), (commanderOptions.quiet && { quiet: commanderOptions.quiet })), (commanderOptions.single && { single: commanderOptions.single }));
26
+ const options = {
27
+ ...(commanderOptions.letters && { letters: commanderOptions.letters }),
28
+ ...(commanderOptions.maximum && { maximum: commanderOptions.maximum }),
29
+ ...(commanderOptions.quiet && { quiet: commanderOptions.quiet }),
30
+ ...(commanderOptions.single && { single: commanderOptions.single }),
31
+ };
27
32
  void (async () => {
28
33
  try {
29
34
  const matches = await new ScrabbleCheater(commanderOptions.wordlist, options).start();
package/dist/esm/index.js CHANGED
@@ -13,7 +13,7 @@ export class ScrabbleCheater {
13
13
  constructor(wordListPath, options) {
14
14
  this.dictionary = [];
15
15
  this.wordListPath = wordListPath;
16
- this.options = Object.assign(Object.assign({}, defaultOptions), options);
16
+ this.options = { ...defaultOptions, ...options };
17
17
  }
18
18
  setLetters(letters) {
19
19
  this.options.letters = letters;
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "description": "A simple Scrabble cheating tool.",
9
9
  "devDependencies": {
10
10
  "rimraf": "5.0.7",
11
- "typescript": "5.4.5",
11
+ "typescript": "5.5.2",
12
12
  "vitest": "1.6.0"
13
13
  },
14
14
  "engines": {
@@ -45,6 +45,6 @@
45
45
  "test": "vitest run"
46
46
  },
47
47
  "type": "module",
48
- "version": "3.6.4",
49
- "gitHead": "28c184f53a87d8eb082cc27c923ef7b352bbe875"
48
+ "version": "3.6.5",
49
+ "gitHead": "f7a6a79286e4eb85392b5f2d33942ab166142109"
50
50
  }