0.0.6 • Published 4 months ago

create-word-puzzle v0.0.6

Weekly downloads
-
License
-
Repository
-
Last release
4 months ago

Create Word Puzzle

Generate customizable word search puzzles of any size with this versatile npm package. Because, let's face it, what developer doesn't dream of creating puzzles instead of solving coding challenges? Or, let me do better— who doesn't need puzzles in their lives?

Table of Contents

  1. Installation
  2. Usage
  3. Options
  4. Contributing
  5. License

Installation

You can install the library using npm:

npm i create-word-puzzle

Usage

  1. Import the package into your project:
import createWordPuzzle from 'create-word-puzzle';

in Node.js:

const createWordPuzzle = require('create-word-puzzle');
  1. Generate a word puzzle by providing a list of words and defining the grid width and height as an object. This function accepts an options object as an argument and returns an object as a result:
const words = ['apple', 'banana', 'cherry'];
const puzzle = createWordPuzzle({ wordlist: words, width: 8, height: 8 });

You can access the output grid array from the grid property of puzzle object.

Example grid array output:

[
  ['X', 'B', 'A', 'N', 'A', 'N', 'A', 'A'],
  ['Q', 'W', 'J', 'H', 'M', 'Q', 'X', 'P'],
  ['L', 'W', 'O', 'C', 'S', 'Y', 'W', 'P'],
  ['D', 'Q', 'A', 'H', 'N', 'B', 'U', 'L'],
  ['P', 'U', 'A', 'E', 'U', 'G', 'Y', 'E'],
  ['Y', 'R', 'J', 'R', 'Y', 'I', 'C', 'J'],
  ['L', 'F', 'S', 'R', 'V', 'D', 'Y', 'U'],
  ['L', 'L', 'K', 'Y', 'V', 'Q', 'R', 'N'],
];
  1. You can customize the puzzle generation by providing additional options:
const puzzle = createWordPuzzle({
  wordlist: words,
  width: 8,
  height: 8,
  minWordLength: 4,
  listSize: 8,
  margin: 0,
  shareLetters: true,
  allowReverseWords: true,
  reverseWordRatio: 0.33,
});

Options

Here are all the options you can provide to customize the puzzle:

NameTypeDefaultDescription
wordlistarray[]List of words to include in the word search puzzle.
widthnumber11Width of the word search puzzle grid.
heightnumber11Height of the word search puzzle grid.
minWordLengthnumber3Minimum length of words to be included in the puzzle.
listSizenumberundefinedNumber of words to be included in the puzzle.
marginnumber0Margin between the maximum word length and the maximum grid dimension in the puzzle grid.
shareLettersbooleantrueWhether words in the puzzle can share letters.
allowReverseWordsbooleantrueWhether to allow words to appear in reverse order.
reverseWordRationumber0.33Ratio of words that can appear in reverse order in grid.

Contributing

Contributions are welcome! If you have ideas for new features, improvements, or bug fixes, please submit a pull request or open an issue.

License

This project is licensed under the MIT License - see the LICENSE file for details.

0.0.5

4 months ago

0.0.4

4 months ago

0.0.6

4 months ago

0.0.3

4 months ago

0.0.2

4 months ago

0.0.1

4 months ago