@k03mad/dice 3.0.0 → 3.2.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/app/run.js CHANGED
@@ -7,38 +7,28 @@ import {emitKeypressEvents} from 'node:readline';
7
7
  import {log} from '@k03mad/simple-log';
8
8
  import image from 'terminal-image';
9
9
 
10
- import {
11
- DICE_DEFAULT_COUNT,
12
- DICE_HEIGHT,
13
- DICE_PICTURES_FOLDER,
14
- EXIT_CTRL_MODIFIER,
15
- EXIT_EXTRA_KEY,
16
- texts,
17
- } from './utils/config.js';
10
+ import config from './utils/config.js';
18
11
  import {getRandomArrElem} from './utils/helpers.js';
19
12
 
20
- const imgFolderAbs = path.join(import.meta.dirname, DICE_PICTURES_FOLDER);
13
+ const imgFolderAbs = path.join(import.meta.dirname, config.dice.picturesFolder);
21
14
 
22
15
  const imgFiles = await fs.readdir(imgFolderAbs);
23
16
  const imgFilesAbs = imgFiles.map(img => path.join(imgFolderAbs, img));
24
17
 
25
18
  emitKeypressEvents(process.stdin);
19
+ process.stdin.setRawMode(true);
26
20
 
27
- if (process.stdin.isTTY) {
28
- process.stdin.setRawMode(true);
29
- }
30
-
31
- let diceCurrentCount = DICE_DEFAULT_COUNT;
32
- log(texts.message);
21
+ let diceCurrentCount = config.dice.defaultCount;
22
+ log(config.messages.welcome);
33
23
 
34
24
  process.stdin.on('keypress', async (char, key) => {
35
25
  if (
36
- (key.ctrl === true && key.name === EXIT_CTRL_MODIFIER)
37
- || char === EXIT_EXTRA_KEY
26
+ (key.ctrl === true && key.name === config.exit.ctrlKeyModifier)
27
+ || char === config.exit.extraKey
38
28
  ) {
39
29
  process.exit();
40
30
  } else {
41
- log(texts.delimiter);
31
+ log(config.dice.separator);
42
32
  }
43
33
 
44
34
  diceCurrentCount = Number(char) || diceCurrentCount;
@@ -46,7 +36,7 @@ process.stdin.on('keypress', async (char, key) => {
46
36
  const output = await Promise.all(
47
37
  Array.from({length: diceCurrentCount}, () => {
48
38
  const diceImg = getRandomArrElem(imgFilesAbs);
49
- return image.file(diceImg, {height: DICE_HEIGHT});
39
+ return image.file(diceImg, {height: config.dice.height});
50
40
  }),
51
41
  );
52
42
 
@@ -2,18 +2,26 @@ import chalk from 'chalk';
2
2
 
3
3
  const {green, dim, bold} = chalk;
4
4
 
5
- export const DICE_DEFAULT_COUNT = 1;
6
- export const DICE_PICTURES_FOLDER = 'png';
7
- export const DICE_HEIGHT = '30%';
5
+ const EXIT_EXTRA_KEY = 'q';
8
6
 
9
- export const EXIT_CTRL_MODIFIER = 'c';
10
- export const EXIT_EXTRA_KEY = 'q';
7
+ export default {
8
+ dice: {
9
+ defaultCount: 1,
10
+ picturesFolder: 'png',
11
+ height: '30%',
12
+ separator: dim('>\n'),
13
+ },
11
14
 
12
- export const texts = {
13
- message: green([
14
- '— enter any digit to generate this count of dices',
15
- '— press any key to repeat previous count generating',
16
- bold(`— press "CTRL+C" or enter "${EXIT_EXTRA_KEY}" to exit`),
17
- ].join('\n')),
18
- delimiter: dim('——————————————\n'),
15
+ exit: {
16
+ ctrlKeyModifier: 'c',
17
+ extraKey: EXIT_EXTRA_KEY,
18
+ },
19
+
20
+ messages: {
21
+ welcome: green([
22
+ '— enter any digit to generate that number of dice',
23
+ '— press any key to repeat the previous count generation',
24
+ `— press ${bold('CTRL+C')} or enter '${bold(EXIT_EXTRA_KEY)}' to exit`,
25
+ ].join('\n')),
26
+ },
19
27
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k03mad/dice",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "Dice",
5
5
  "maintainers": [
6
6
  "Kirill Molchanov <k03.mad@gmail.com"