@k03mad/dice 11.8.0 → 12.0.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.
@@ -12,7 +12,7 @@ jobs:
12
12
  lint:
13
13
  runs-on: ubuntu-latest
14
14
  steps:
15
- - uses: actions/checkout@v6
15
+ - uses: actions/checkout@v7
16
16
  - uses: actions/setup-node@v6
17
17
  with:
18
18
  node-version-file: '.nvmrc'
@@ -13,7 +13,7 @@ jobs:
13
13
  publish:
14
14
  runs-on: ubuntu-latest
15
15
  steps:
16
- - uses: actions/checkout@v6
16
+ - uses: actions/checkout@v7
17
17
  with:
18
18
  fetch-depth: 0
19
19
 
package/app/run.ts ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'node:fs/promises';
4
+ import path from 'node:path';
5
+ import {emitKeypressEvents} from 'node:readline';
6
+
7
+ import image from 'terminal-image';
8
+
9
+ import config from './utils/config.ts';
10
+ import {getRandomArrElem} from './utils/helpers.ts';
11
+
12
+ const imgFolderAbs = path.join(import.meta.dirname, config.dice.picturesFolder);
13
+
14
+ const imgFiles: string[] = await fs.readdir(imgFolderAbs);
15
+ const imgFilesAbs = imgFiles.map(img => path.join(imgFolderAbs, img));
16
+
17
+ emitKeypressEvents(process.stdin);
18
+ process.stdin.setRawMode(true);
19
+
20
+ let diceCurrentCount: number = config.dice.defaultCount;
21
+ console.log(config.messages.welcome);
22
+
23
+ process.stdin.on('keypress', async (char: string, key: {ctrl: boolean; name: string}) => {
24
+ if (
25
+ (key.ctrl === true && key.name === config.exit.ctrlKeyModifier) ||
26
+ char === config.exit.extraKey
27
+ ) {
28
+ process.exit();
29
+ } else {
30
+ console.log(config.dice.separator);
31
+ }
32
+
33
+ diceCurrentCount = Number(char) || diceCurrentCount;
34
+
35
+ const output = await Promise.all(
36
+ Array.from({length: diceCurrentCount}, () => {
37
+ const diceImg = getRandomArrElem(imgFilesAbs);
38
+ return image.file(diceImg, {height: config.dice.height});
39
+ }),
40
+ );
41
+
42
+ console.log(output.join('\n'));
43
+ });
@@ -0,0 +1,29 @@
1
+ import chalk from 'chalk';
2
+
3
+ const {green, dim, bold} = chalk;
4
+
5
+ const EXIT_EXTRA_KEY = 'q';
6
+
7
+ export default {
8
+ dice: {
9
+ defaultCount: 1,
10
+ picturesFolder: 'png',
11
+ height: '30%',
12
+ separator: dim('>\n'),
13
+ },
14
+
15
+ exit: {
16
+ ctrlKeyModifier: 'c',
17
+ extraKey: EXIT_EXTRA_KEY,
18
+ },
19
+
20
+ messages: {
21
+ welcome: green(
22
+ [
23
+ '— type any digit to generate that number of dice',
24
+ '— press any key to reroll dice',
25
+ `— press ${bold('CTRL+C')} or type '${bold(EXIT_EXTRA_KEY)}' to exit`,
26
+ ].join('\n'),
27
+ ),
28
+ },
29
+ } as const;
@@ -0,0 +1,9 @@
1
+ export const getRandomArrElem = <T>(arr: T[]): T => {
2
+ const elem = arr[Math.floor(Math.random() * arr.length)];
3
+
4
+ if (elem === undefined) {
5
+ throw new Error('Array is empty');
6
+ }
7
+
8
+ return elem;
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k03mad/dice",
3
- "version": "11.8.0",
3
+ "version": "12.0.0",
4
4
  "description": "Dice",
5
5
  "license": "MIT",
6
6
  "maintainers": [
@@ -11,11 +11,11 @@
11
11
  "url": "git+https://github.com/k03mad/dice.git"
12
12
  },
13
13
  "bin": {
14
- "dice": "app/run.js"
14
+ "dice": "app/run.ts"
15
15
  },
16
16
  "type": "module",
17
17
  "scripts": {
18
- "lint": "oxlint && oxfmt -c node_modules/@k03mad/oxlint-config/.oxfmtrc.json --check",
18
+ "lint": "oxlint && oxfmt -c node_modules/@k03mad/oxlint-config/.oxfmtrc.json --check && tsc --noEmit",
19
19
  "prepare": "husky || true"
20
20
  },
21
21
  "dependencies": {
@@ -24,9 +24,12 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "@k03mad/oxlint-config": "0.10.1",
27
+ "@tsconfig/strictest": "2.0.8",
28
+ "@types/node": "26.1.0",
27
29
  "husky": "9.1.7",
28
30
  "oxfmt": "0.57.0",
29
- "oxlint": "1.72.0"
31
+ "oxlint": "1.72.0",
32
+ "typescript": "6.0.3"
30
33
  },
31
34
  "engines": {
32
35
  "node": ">=24"
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@tsconfig/strictest/tsconfig.json",
3
+ "compilerOptions": {
4
+ "types": ["node"],
5
+ "noEmit": true,
6
+ "allowImportingTsExtensions": true,
7
+ "erasableSyntaxOnly": true
8
+ }
9
+ }
package/app/run.js DELETED
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from 'node:fs/promises';
4
- import path from 'node:path';
5
- import {emitKeypressEvents} from 'node:readline';
6
-
7
- import image from 'terminal-image';
8
-
9
- import config from './utils/config.js';
10
- import {getRandomArrElem} from './utils/helpers.js';
11
-
12
- const imgFolderAbs = path.join(import.meta.dirname, config.dice.picturesFolder);
13
-
14
- const imgFiles = await fs.readdir(imgFolderAbs);
15
- const imgFilesAbs = imgFiles.map(img => path.join(imgFolderAbs, img));
16
-
17
- emitKeypressEvents(process.stdin);
18
- process.stdin.setRawMode(true);
19
-
20
- let diceCurrentCount = config.dice.defaultCount;
21
- console.log(config.messages.welcome);
22
-
23
- process.stdin.on('keypress', async (char, key) => {
24
- if (
25
- (key.ctrl === true && key.name === config.exit.ctrlKeyModifier) ||
26
- char === config.exit.extraKey
27
- ) {
28
- process.exit();
29
- } else {
30
- console.log(config.dice.separator);
31
- }
32
-
33
- diceCurrentCount = Number(char) || diceCurrentCount;
34
-
35
- const output = await Promise.all(
36
- Array.from({length: diceCurrentCount}, () => {
37
- const diceImg = getRandomArrElem(imgFilesAbs);
38
- return image.file(diceImg, {height: config.dice.height});
39
- }),
40
- );
41
-
42
- console.log(output.join('\n'));
43
- });
@@ -1,29 +0,0 @@
1
- import chalk from 'chalk';
2
-
3
- const {green, dim, bold} = chalk;
4
-
5
- const EXIT_EXTRA_KEY = 'q';
6
-
7
- export default {
8
- dice: {
9
- defaultCount: 1,
10
- picturesFolder: 'png',
11
- height: '30%',
12
- separator: dim('>\n'),
13
- },
14
-
15
- exit: {
16
- ctrlKeyModifier: 'c',
17
- extraKey: EXIT_EXTRA_KEY,
18
- },
19
-
20
- messages: {
21
- welcome: green(
22
- [
23
- '— type any digit to generate that number of dice',
24
- '— press any key to reroll dice',
25
- `— press ${bold('CTRL+C')} or type '${bold(EXIT_EXTRA_KEY)}' to exit`,
26
- ].join('\n'),
27
- ),
28
- },
29
- };
@@ -1,2 +0,0 @@
1
- /** @param {Array} arr */
2
- export const getRandomArrElem = arr => arr[Math.floor(Math.random() * arr.length)];