typing-game-cli 7.0.0 → 7.1.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.
package/dist/cli.js CHANGED
@@ -7,6 +7,7 @@ import compose from 'just-compose';
7
7
  import filter from 'just-filter-object';
8
8
  import App from './app.js';
9
9
  import { config } from './config.js';
10
+ import { getBestWpmResult, getGoal, wasGoalAchieved } from './helpers.js';
10
11
  const cli = meow(`
11
12
  Usage
12
13
  $ typing-game-cli
@@ -29,6 +30,8 @@ const cli = meow(`
29
30
  --all-history Show all history when displaying results (otherwise (default) display last 10 results respecting sorting parameter)
30
31
  --topic Use sentences from works written by specified author
31
32
  --top-n Display top n results in displaying results mode
33
+ --set-goal Set a goal (in wpm) that you wish to achieve
34
+ --goal-achieved Let you know whether a goal was achieved
32
35
 
33
36
  Short flags and aliases for options:
34
37
  --against-my-best: -b, --best, --my-best, --myself, --against-my-best-result
@@ -44,6 +47,8 @@ const cli = meow(`
44
47
  --top-n: --top
45
48
  --handicap --ha, --hndcp, --hdc, --han
46
49
  --handicap-count --hanco, --hanCo, --hndco, --haco
50
+ --set-goal --sgoal, --goal
51
+ --goal-achieved --goalach, --coolprogress, --progone, --goaldone, --aic
47
52
 
48
53
 
49
54
  Examples
@@ -63,6 +68,9 @@ const cli = meow(`
63
68
  $ typing-game-cli -r -s="-wpm" -a
64
69
  $ typing-game-cli --topic mark-twain
65
70
  $ typing-game-cli --topic ambrose-bierce
71
+ $ typing-game-cli --set-goal 60
72
+ $ typing-game-cli --goal 60
73
+ $ typing-game-cli --goal-achieved
66
74
  `, {
67
75
  importMeta: import.meta,
68
76
  flags: {
@@ -91,6 +99,14 @@ const cli = meow(`
91
99
  type: 'number',
92
100
  aliases: ['hanco', 'hanCo', 'hndco', 'haco']
93
101
  },
102
+ setGoal: {
103
+ type: 'string',
104
+ aliases: ['sgoal', 'goal']
105
+ },
106
+ goalAchieved: {
107
+ type: 'boolean',
108
+ aliases: ['goalach', 'coolprogress', 'progrone', 'progone', 'goaldone', 'aic']
109
+ },
94
110
  displayResults: {
95
111
  type: 'boolean',
96
112
  shortFlag: 'r',
@@ -141,6 +157,24 @@ if (cli.flags.clearResults) {
141
157
  config.clearAll();
142
158
  exitNow();
143
159
  }
160
+ if (cli.flags.setGoal) {
161
+ config.appendGoal(cli.flags.setGoal);
162
+ exitNow();
163
+ }
164
+ if (cli.flags.goalAchieved) {
165
+ const achiemenceResult = wasGoalAchieved();
166
+ if (achiemenceResult === null) {
167
+ console.log(`There are no goal yet. First set a goal by --set-goal [wpm] command`);
168
+ } else {
169
+ let messageToSay = achiemenceResult ? `Congrats, you have achieved your goal.` : `You goal is not achieved yet.`;
170
+ if (!achiemenceResult) {
171
+ const bestResult = getBestWpmResult();
172
+ messageToSay += ` Best result - ${bestResult.value.wpm}, goal - ${getGoal()}. Keep trying, don't give up!`;
173
+ }
174
+ console.log(messageToSay);
175
+ }
176
+ exitNow();
177
+ }
144
178
  const robotLevel = compose(flags => pick(flags, ['extraFast', 'fast', 'medium', 'low']), flags => filter(flags, (_, value) => value), flags => Object.keys(flags)[0] || 'medium')(cli.flags);
145
179
  const {
146
180
  handicap,
package/dist/config.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import os from 'node:os';
3
3
  import { join } from 'node:path';
4
+ import { formatISO } from 'date-fns';
4
5
  const defaultConfig = {};
5
6
  export default class Config {
6
7
  constructor() {
@@ -29,10 +30,27 @@ export default class Config {
29
30
  ...previous,
30
31
  ...entry
31
32
  }, null, 4);
32
- fs.writeFileSync(this._configFile, data, 'utf8');
33
+ this.persist(data);
34
+ }
35
+ appendGoal(wpm) {
36
+ const previous = this.get();
37
+ const currentGoals = previous.goals || [];
38
+ currentGoals.push({
39
+ wpm,
40
+ date: formatISO(new Date())
41
+ });
42
+ const data = JSON.stringify({
43
+ ...previous,
44
+ goals: currentGoals,
45
+ goal: wpm
46
+ }, null, 4);
47
+ this.persist(data);
33
48
  }
34
49
  clearAll() {
35
- fs.writeFileSync(this._configFile, '{}', 'utf8');
50
+ this.persist('{}');
51
+ }
52
+ persist(data) {
53
+ fs.writeFileSync(this._configFile, data, 'utf8');
36
54
  }
37
55
  }
38
56
  export const config = new Config();
package/dist/helpers.js CHANGED
@@ -225,6 +225,22 @@ const getResults = ({
225
225
  }
226
226
  return result;
227
227
  };
228
+ const getGoal = () => {
229
+ const config = new Config();
230
+ const data = config.get();
231
+ return data.goal;
232
+ };
233
+ const wasGoalAchieved = () => {
234
+ const goal = getGoal();
235
+ if (goal) {
236
+ const bestResult = getBestWpmResult();
237
+ if (bestResult === undefined) {
238
+ return false;
239
+ }
240
+ return goal <= bestResult.value.wpm;
241
+ }
242
+ return null;
243
+ };
228
244
  const getBestResult = () => {
229
245
  const config = new Config();
230
246
  const data = config.get();
@@ -291,4 +307,4 @@ const registerBestFrames = (config, frames) => {
291
307
  bestFrames: frames
292
308
  });
293
309
  };
294
- export { getDefaultSuite, getStatusVariant, getSentencesSkippingWords, getHaLeft, getHaCount, getWpmTextColor, getScoreTextColor, getMessage, getMessageOrPlaceholder, getBorderColor, getRobotBorderColor, getIntervalMs, isFinished, isWordTyped, isLastNumber as isLastNum, isAboutToFinish, calculateWPM, calculateCPS, calculateCPM, getCompetitionResult, getTypingWord, getRemainingPart, getResults, getBestResult, getBestResultCompactString, getBestFrames, getOpponentFrames, getResultByWordCount, getBestWpmResult, getSortedByString, getWordCount, getSuiteByTopic, registerResult, registerBestFrames };
310
+ export { getDefaultSuite, getStatusVariant, getSentencesSkippingWords, getHaLeft, getHaCount, getWpmTextColor, getScoreTextColor, getMessage, getMessageOrPlaceholder, getBorderColor, getRobotBorderColor, getIntervalMs, getGoal, isFinished, isWordTyped, isLastNumber as isLastNum, isAboutToFinish, calculateWPM, calculateCPS, calculateCPM, getCompetitionResult, getTypingWord, getRemainingPart, getResults, getBestResult, getBestResultCompactString, getBestFrames, getOpponentFrames, getResultByWordCount, getBestWpmResult, getSortedByString, getWordCount, getSuiteByTopic, registerResult, registerBestFrames, wasGoalAchieved };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typing-game-cli",
3
3
  "description": "Command line game to practice your typing speed by competing against typer-robot or against your best result",
4
- "version": "7.0.0",
4
+ "version": "7.1.0",
5
5
  "homepage": "https://github.com/akgondber/typing-game-cli",
6
6
  "repository": "akgondber/typing-game-cli",
7
7
  "author": "Rushan Alyautdinov <akgondber@gmail.com>",
@@ -114,6 +114,7 @@
114
114
  "typingpracrice",
115
115
  "bestresult",
116
116
  "terminalgame",
117
- "cligame"
117
+ "cligame",
118
+ "typingspeed"
118
119
  ]
119
120
  }
package/readme.md CHANGED
@@ -28,13 +28,15 @@ $ npm install --global typing-game-cli
28
28
  --medium Start a round with a robot having medium typing speed.
29
29
  --low Start a round with a robot having low typing speed.
30
30
  --handicap Start a round with handicap given by opponent to you by specified count of chars
31
- --handicap-count How many chars you wish to ask from opponent
31
+ --handicap-count How many chars you wish to ask from opponent
32
32
  --display-results Show cpm and wpm results
33
33
  --sort-by Sort results by specified value (-cpm, cpm, -wpm, wpm, -date, date), Starting "-" indicates descending order, default is "-date"
34
34
  --all-hostory Show all history when displaying results (otherwise (default) display last 10 results respecting sorting parameter)
35
35
  --compact-result Display top result in compact format
36
36
  --topic Use sentences from works written by specified author
37
37
  --top-n Display top n results when `--display-results` is being used
38
+ --set-goal Set a goal (in wpm) that you wish to achieve
39
+ --goal-achieved Let you know whether a goal was achieved
38
40
 
39
41
  Short flags and aliases for options:
40
42
  --against-my-best: -b, --best, --my-best, --myself, --against-my-best-result
@@ -49,6 +51,10 @@ $ npm install --global typing-game-cli
49
51
  --compact-result --cmpc
50
52
  --topic --author
51
53
  --top-n --top
54
+ --handicap --ha, --hndcp, --hdc, --han
55
+ --handicap-count --hanco, --hanCo, --hndco, --haco
56
+ --set-goal --sgoal, --goal
57
+ --goal-achieved --goalach, --coolprogress, --progone, --goaldone, --aic
52
58
 
53
59
 
54
60
  Examples