sudoku-pro 1.0.11 → 1.0.12

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.
Files changed (2) hide show
  1. package/README.md +140 -27
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,53 +1,166 @@
1
- # sudoku-pro: Sudoku Generator and Sudoku Solver
1
+ # sudoku-pro Sudoku Generator, Solver & CLI (Node + Frontend)
2
2
 
3
- sudoku-pro is a JavaScript package that provides functionalities to generate, solve, and print Sudoku puzzles of varying difficulty levels using the backtracking algorithm. It offers an easy-to-use interface to create and solve Sudoku puzzles for both recreational and educational purposes.
3
+ `sudoku-pro` is a lightweight JavaScript library (plus optional CLI) to **generate**, **solve**, and **play** Sudoku puzzles with built-in difficulty levels.
4
4
 
5
- ## Installation
5
+ Works in **Node.js** (CommonJS)
6
+ ✅ Works in **Frontend apps** (ES Modules via bundlers like Vite/Webpack)
7
+ ✅ Includes a **CLI** for terminal play (hint + complete solution)
6
8
 
7
- You can install the package via npm:
9
+ ---
10
+
11
+ ## Install
8
12
 
9
13
  ```bash
10
- npm i sudoku-pro
14
+ npm install sudoku-pro
11
15
  ```
12
16
 
13
- ## Usage
17
+ ---
18
+
19
+ ## Difficulty Levels
20
+
21
+ | Code | Level |
22
+ |------|------------|
23
+ | `e` | Easy |
24
+ | `m` | Medium |
25
+ | `h` | Hard |
26
+ | `v` | Very Hard |
27
+
28
+ ---
14
29
 
15
- ```npm
16
- npm run easy
17
- npm run medium
18
- npm run hard
19
- npm run very
30
+ ## CLI (Terminal) Usage
31
+
32
+ ### Run via npx
33
+
34
+ ```bash
35
+ npx sudoku-pro e
36
+ npx sudoku-pro m
37
+ npx sudoku-pro h
38
+ npx sudoku-pro v
20
39
  ```
21
40
 
22
- ## Example: How to use the functions in your applications
41
+ ### CLI Controls
23
42
 
24
- ```javascript
25
- // Import the module
43
+ When the puzzle prints:
44
+
45
+ - **h** → apply a hint (fills one correct empty cell)
46
+ - **c** → print the complete solution and exit
47
+
48
+ ---
49
+
50
+ ## Node.js Usage (CommonJS)
51
+
52
+ ```js
26
53
  const {
27
54
  generateSudoku,
28
55
  printSudoku,
29
56
  solveSudoku,
30
57
  getHint,
31
- waitForHint,
58
+ waitForHint
32
59
  } = require("sudoku-pro");
33
60
 
34
- // Get the difficulty level
35
- const args = process.argv.slice(2);
61
+ const { sudoku, solvedSudoku } = generateSudoku("m");
62
+ printSudoku(sudoku);
63
+ waitForHint(sudoku, solvedSudoku);
64
+ ```
36
65
 
37
- const difficulty = args[0]; // Get the difficulty level from command line arguments
66
+ ---
38
67
 
39
- // Generate a Sudoku puzzle
40
- const { sudoku, solvedSudoku } = generateSudoku(difficulty);
68
+ ## Solve an Existing Puzzle
41
69
 
42
- // Print the puzzle
43
- printSudoku(sudoku);
70
+ ```js
71
+ const { solveSudoku } = require("sudoku-pro");
44
72
 
45
- // Function to wait for user input for hint or complete solution
46
- waitForHint(sudoku, solvedSudoku);
73
+ const grid = [
74
+ [0,0,0,0,4,0,0,0,1],
75
+ [0,0,0,7,0,0,4,6,2],
76
+ [1,4,6,0,0,3,0,7,0],
77
+ [0,2,0,3,0,4,0,0,7],
78
+ [0,9,0,0,0,8,6,1,0],
79
+ [0,6,0,0,5,0,3,0,0],
80
+ [0,0,0,8,0,7,2,4,3],
81
+ [0,8,7,0,0,0,0,5,0],
82
+ [4,1,2,0,3,6,0,0,0]
83
+ ];
84
+
85
+ solveSudoku(grid);
86
+ console.log(grid);
87
+ ```
88
+
89
+ ---
90
+
91
+ ## Frontend Usage (Browser)
92
+
93
+ ### Important
94
+
95
+ You **cannot** import npm packages directly in plain HTML (`file://`).
96
+
97
+ You **must** use a bundler such as:
98
+ - Vite (recommended)
99
+ - Webpack
100
+ - Parcel
101
+
102
+ ---
103
+
104
+ ## Frontend Quick Start (Vite)
47
105
 
48
- // This script will continue running until the user chooses to exit
106
+ ```bash
107
+ npm create vite@latest sudoku-demo -- --template vanilla
108
+ cd sudoku-demo
109
+ npm install
110
+ npm install sudoku-pro
111
+ npm run dev
112
+ ```
113
+
114
+ ---
115
+
116
+ ## Frontend Example
49
117
 
50
- process.exit();
118
+ ```js
119
+ import { generateSudoku, getHint } from "sudoku-pro";
120
+
121
+ const { sudoku, solvedSudoku } = generateSudoku("m");
122
+ const hint = getHint(sudoku, solvedSudoku);
123
+ console.log(hint);
51
124
  ```
52
125
 
53
- Now, in addition to generating and solving Sudoku puzzles, users can also request hints or print the complete solution while the script is running.
126
+ ---
127
+
128
+ ## API Reference
129
+
130
+ ### generateSudoku(difficulty)
131
+
132
+ Returns:
133
+
134
+ ```js
135
+ { sudoku, solvedSudoku }
136
+ ```
137
+
138
+ `sudoku` uses `0` for empty cells.
139
+
140
+ ---
141
+
142
+ ### solveSudoku(grid)
143
+
144
+ Solves the puzzle **in place**.
145
+
146
+ ---
147
+
148
+ ### getHint(sudoku, solvedSudoku, opts?)
149
+
150
+ Returns:
151
+
152
+ ```js
153
+ { row, col, value }
154
+ ```
155
+
156
+ ---
157
+
158
+ ### waitForHint(sudoku, solvedSudoku)
159
+
160
+ Terminal-only interactive mode.
161
+
162
+ ---
163
+
164
+ ## License
165
+
166
+ MIT © Ashish Vashisht
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sudoku-pro",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Sudoku generator, solver, and CLI tool. Works in terminal and frontend apps with a clean library-first design.",
5
5
  "license": "MIT",
6
6
  "author": "Ashish Vashisht",