npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yordle

v2.0.0

Published

[![npm version](https://img.shields.io/npm/v/yordle.svg)](https://www.npmjs.com/package/yordle) [![npm downloads](https://img.shields.io/npm/dm/yordle.svg)](https://www.npmjs.com/package/yordle) [![TypeScript](https://img.shields.io/badge/TypeScript-Ready

Downloads

196

Readme

Yordle

npm version npm downloads TypeScript License: MIT

A TypeScript library for creating Wordle-like word guessing games. Yordle provides a flexible and type-safe way to implement word guessing mechanics in your projects.

Features

  • 🎯 Full TypeScript support with comprehensive type definitions
  • 🎲 Built-in word list with option to use custom words
  • 🔄 Random word generation
  • ✅ Word verification
  • 📊 Detailed guess feedback system
  • 🎮 Game state management
  • 💾 Progress tracking

Installation

npm install yordle
# or
yarn add yordle

Quick Start

import yordle from 'yordle';

// Initialize the game
const game = yordle({
  word: 'hello',    // Target word
  wordSize: 5,      // Word length
  wordList: ['hello', 'world'], // Custom word list
  entries: []       // Previous game entries
});

// or

const game = yordle(); // Use the default values
const word = game.draw(true); // Generate a random word to guess

// Make a guess
const result = game.guess('world');
console.log(result);
// Output: [
//   { w: 'wrong' },
//   { o: 'exists' },
//   { r: 'wrong' },
//   { l: 'exact' },
//   { d: 'wrong' }
// ]

API Reference

yordle(props: YordleProps)

Main function to initialize the game controller.

Props

type YordleProps = {
  word?: string;          // Optional: Put a custom word or generate using draw(true) function
  wordSize?: number;      // Optional: Length of the word (Defaults to 5)
  wordList?: string[];    // Optional custom word list (Defaults to a 5-letter word list)
  entries?: ResultType[]; // Optional previous game entries
}

Returns

Object containing the following methods:

guess(input: string): ResultType

Makes a guess with the provided input word and returns the result.

  • Parameters:
    • input: The word guessed by the player
  • Returns: Array of objects containing letter matches:
    • 'exact': Letter is in correct position
    • 'exists': Letter exists in word but wrong position
    • 'wrong': Letter does not exist in word
const result = game.guess('spark');
// Example output:
// [
//   { s: 'wrong' },
//   { p: 'exists' },
//   { a: 'wrong' },
//   { r: 'exact' },
//   { k: 'wrong' }
// ]
draw(overwrite?: boolean): string

Returns a random word from the word list.

  • Parameters:
    • overwrite: If true, replaces the current target word (default: false)
  • Returns: A random word from the word list
const newWord = game.draw();        // Get random word
const newTarget = game.draw(true);  // Get and set new target word
verify(input: string): boolean

Verifies if a word exists in the word list.

  • Parameters:
    • input: Word to verify
  • Returns: Boolean indicating if the word is valid
const isValid = game.verify('hello'); // true

Types

type MatchType = 'exact' | 'exists' | 'wrong';

type ResultType = Array<{
  [letter: string]: MatchType
}>;

type LetterCountType = {
  [letter: string]: number
} | object;

Example Usage

Basic Game Implementation

import yordle from 'yordle';

// Initialize game
const game = yordle();
const word = game.draw(true);

// Process player guess
function handleGuess(playerInput: string) {
  if (!game.verify(playerInput)) {
    console.log('Invalid word!');
    return;
  }

  const result = game.guess(playerInput);
  
  // Check for win condition
  const isWin = result.every(letterResult => 
    Object.values(letterResult)[0] === 'exact'
  );

  if (isWin) {
    console.log('Congratulations!');
  }

  return result;
}

Custom Word List

const customGame = yordle({
  wordSize: 4,
  wordList: ['code', 'java', 'rust', 'ruby', 'perl'],
});
const word = customGame.draw(true);

License

MIT © Andrew Loloy

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request