sudoku-pro 1.0.11 → 1.0.13

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 +154 -27
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,53 +1,180 @@
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
+ ## 🔗 Live Demo (Frontend)
12
+
13
+ You can try the full frontend demo here:
14
+
15
+ 👉 **https://sudoku-pro.duckdns.org/**
16
+
17
+ This demo uses:
18
+ - `sudoku-pro` as an npm dependency
19
+ - Vite for bundling
20
+ - Docker + Nginx
21
+ - HTTPS via Let’s Encrypt
22
+
23
+ ---
24
+
25
+ ## Install
8
26
 
9
27
  ```bash
10
- npm i sudoku-pro
28
+ npm install sudoku-pro
11
29
  ```
12
30
 
13
- ## Usage
31
+ ---
32
+
33
+ ## Difficulty Levels
14
34
 
15
- ```npm
16
- npm run easy
17
- npm run medium
18
- npm run hard
19
- npm run very
35
+ | Code | Level |
36
+ |------|------------|
37
+ | `e` | Easy |
38
+ | `m` | Medium |
39
+ | `h` | Hard |
40
+ | `v` | Very Hard |
41
+
42
+ ---
43
+
44
+ ## CLI (Terminal) Usage
45
+
46
+ ### Run via npx
47
+
48
+ ```bash
49
+ npx sudoku-pro e
50
+ npx sudoku-pro m
51
+ npx sudoku-pro h
52
+ npx sudoku-pro v
20
53
  ```
21
54
 
22
- ## Example: How to use the functions in your applications
55
+ ### CLI Controls
56
+
57
+ When the puzzle prints:
58
+
59
+ - **h** → apply a hint (fills one correct empty cell)
60
+ - **c** → print the complete solution and exit
23
61
 
24
- ```javascript
25
- // Import the module
62
+ ---
63
+
64
+ ## Node.js Usage (CommonJS)
65
+
66
+ ```js
26
67
  const {
27
68
  generateSudoku,
28
69
  printSudoku,
29
70
  solveSudoku,
30
71
  getHint,
31
- waitForHint,
72
+ waitForHint
32
73
  } = require("sudoku-pro");
33
74
 
34
- // Get the difficulty level
35
- const args = process.argv.slice(2);
75
+ const { sudoku, solvedSudoku } = generateSudoku("m");
76
+ printSudoku(sudoku);
77
+ waitForHint(sudoku, solvedSudoku);
78
+ ```
36
79
 
37
- const difficulty = args[0]; // Get the difficulty level from command line arguments
80
+ ---
38
81
 
39
- // Generate a Sudoku puzzle
40
- const { sudoku, solvedSudoku } = generateSudoku(difficulty);
82
+ ## Solve an Existing Puzzle
41
83
 
42
- // Print the puzzle
43
- printSudoku(sudoku);
84
+ ```js
85
+ const { solveSudoku } = require("sudoku-pro");
44
86
 
45
- // Function to wait for user input for hint or complete solution
46
- waitForHint(sudoku, solvedSudoku);
87
+ const grid = [
88
+ [0,0,0,0,4,0,0,0,1],
89
+ [0,0,0,7,0,0,4,6,2],
90
+ [1,4,6,0,0,3,0,7,0],
91
+ [0,2,0,3,0,4,0,0,7],
92
+ [0,9,0,0,0,8,6,1,0],
93
+ [0,6,0,0,5,0,3,0,0],
94
+ [0,0,0,8,0,7,2,4,3],
95
+ [0,8,7,0,0,0,0,5,0],
96
+ [4,1,2,0,3,6,0,0,0]
97
+ ];
98
+
99
+ solveSudoku(grid);
100
+ console.log(grid);
101
+ ```
102
+
103
+ ---
104
+
105
+ ## Frontend Usage (Browser)
106
+
107
+ ### Important
108
+
109
+ You **cannot** import npm packages directly in plain HTML (`file://`).
110
+
111
+ You **must** use a bundler such as:
112
+ - Vite (recommended)
113
+ - Webpack
114
+ - Parcel
47
115
 
48
- // This script will continue running until the user chooses to exit
116
+ ---
49
117
 
50
- process.exit();
118
+ ## Frontend Quick Start (Vite)
119
+
120
+ ```bash
121
+ npm create vite@latest sudoku-demo -- --template vanilla
122
+ cd sudoku-demo
123
+ npm install
124
+ npm install sudoku-pro
125
+ npm run dev
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Frontend Example
131
+
132
+ ```js
133
+ import { generateSudoku, getHint } from "sudoku-pro";
134
+
135
+ const { sudoku, solvedSudoku } = generateSudoku("m");
136
+ const hint = getHint(sudoku, solvedSudoku);
137
+ console.log(hint);
51
138
  ```
52
139
 
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.
140
+ ---
141
+
142
+ ## API Reference
143
+
144
+ ### generateSudoku(difficulty)
145
+
146
+ Returns:
147
+
148
+ ```js
149
+ { sudoku, solvedSudoku }
150
+ ```
151
+
152
+ `sudoku` uses `0` for empty cells.
153
+
154
+ ---
155
+
156
+ ### solveSudoku(grid)
157
+
158
+ Solves the puzzle **in place**.
159
+
160
+ ---
161
+
162
+ ### getHint(sudoku, solvedSudoku, opts?)
163
+
164
+ Returns:
165
+
166
+ ```js
167
+ { row, col, value }
168
+ ```
169
+
170
+ ---
171
+
172
+ ### waitForHint(sudoku, solvedSudoku)
173
+
174
+ Terminal-only interactive mode.
175
+
176
+ ---
177
+
178
+ ## License
179
+
180
+ 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.13",
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",