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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@polarfoxdev/straenge-riddle-generator

v1.1.0

Published

Riddle generation library with Web Worker support for Angular and other web apps

Readme

@polarfoxdev/straenge-riddle-generator

A TypeScript library for generating word riddles for the Stränge/Strängar puzzle game, with Web Worker support for non-blocking UI in Angular and other web applications.

Note: This library is specifically designed to generate riddles compatible with the Stränge/Strängar game format. It is not intended for general-purpose riddle generation.

Installation

npm install @polarfoxdev/straenge-riddle-generator

Usage

Option 1: Using Web Worker (Recommended for UI apps)

The Web Worker approach prevents the riddle generation from blocking your main thread, keeping your UI responsive.

Angular Setup

  1. Create a worker file in your Angular project (e.g., src/app/riddle.worker.ts):
/// <reference lib="webworker" />

// Re-export the worker implementation
import "@polarfoxdev/straenge-riddle-generator/worker";
  1. Update angular.json to include web worker support (Angular CLI usually handles this automatically).

  2. Use the service in your component or service:

import { Component, OnDestroy } from '@angular/core';
import { 
  RiddleGeneratorService, 
  RiddleResult 
} from '@polarfoxdev/straenge-riddle-generator';

@Component({
  selector: 'app-riddle',
  template: `
    <button (click)="generateRiddle()" [disabled]="generating">
      {{ generating ? 'Generating...' : 'Generate Riddle' }}
    </button>
    <div *ngIf="progress">Attempt: {{ progress }}</div>
  `
})
export class RiddleComponent implements OnDestroy {
  private riddleService: RiddleGeneratorService;
  generating = false;
  progress = 0;

  constructor() {
    // Create the worker using Angular's worker syntax
    const worker = new Worker(new URL('./riddle.worker', import.meta.url));
    this.riddleService = new RiddleGeneratorService(worker);
  }

  async generateRiddle(): Promise<void> {
    this.generating = true;
    this.progress = 0;

    try {
      const riddle = await this.riddleService.generate(
        'LOESUNG',  // Super solution (6+ characters)
        ['WORT', 'HAUS', 'BAUM', 'TIER', 'WALD', 'BERG'],  // Word pool
        {
          timeoutMs: 30000,
          maxAttempts: 500,
          onProgress: (attempt) => {
            this.progress = attempt;
          }
        }
      );

      console.log('Generated riddle:', riddle);
      // Use riddle.nodes, riddle.words, riddle.edges to render
    } catch (error) {
      console.error('Failed to generate riddle:', error);
    } finally {
      this.generating = false;
    }
  }

  ngOnDestroy(): void {
    this.riddleService.terminate();
  }
}

Option 2: Direct Usage (Simple, but blocks main thread)

For server-side usage or when blocking is acceptable:

import { tryGenerateRiddle, Riddle } from '@polarfoxdev/straenge-riddle-generator';

const riddle: Riddle | null = tryGenerateRiddle(
  'LOESUNG',
  ['WORT', 'HAUS', 'BAUM', 'TIER', 'WALD', 'BERG']
);

if (riddle) {
  console.log('Success!');
  // Access riddle.nodes, riddle.words, riddle.edges
}

API Reference

RiddleGeneratorService

class RiddleGeneratorService {
  constructor(worker: Worker);
  
  generate(
    superSolution: string,
    wordPool: string[],
    options?: GenerateOptions
  ): Promise<RiddleResult>;
  
  terminate(): void;
}

GenerateOptions

interface GenerateOptions {
  timeoutMs?: number;      // Default: 30000 (30 seconds)
  maxAttempts?: number;    // Default: 1000
  onProgress?: (attempt: number) => void;
  locale?: string;         // Default: 'en' (see Language Support below)
}

Language Support

The library uses Unicode grapheme segmentation to properly handle characters in different languages. By default, English ('en') locale is used, but you can configure it for other languages:

With Web Worker

Pass the locale in the options when generating:

const riddle = await riddleService.generate(
  'LÖSUNG',
  ['WÖRTER', 'BÄUME', 'GRÜN'],
  {
    locale: 'de'  // German locale for proper umlaut handling
  }
);

Direct Usage (without Web Worker)

Use the configure function before generating:

import { configure, tryGenerateRiddle } from '@polarfoxdev/straenge-riddle-generator';

// Set the locale before generating
configure({ locale: 'de' });

const riddle = tryGenerateRiddle('LÖSUNG', ['WÖRTER', 'BÄUME']);

Supported Locales

Any valid BCP 47 language tag is supported. Common examples:

| Locale | Language | |--------|----------| | 'en' | English (default) | | 'de' | German | | 'fr' | French | | 'es' | Spanish | | 'th' | Thai | | 'ko' | Korean | | 'ja' | Japanese | | 'ar' | Arabic |

RiddleResult

interface RiddleResult {
  nodes: NodeResult[];   // 6x8 grid of nodes
  words: WordResult[];   // All words in the riddle
  edges: EdgeResult[];   // Connections between letters
}

interface NodeResult {
  row: number;
  col: number;
  letter: string | null;
  wordIndex: number;        // Index into words array
  isSuperSolution: boolean;
}

interface WordResult {
  word: string;
  isSuperSolution: boolean;
  color: string;
  used: boolean;
}

interface EdgeResult {
  node1: { row: number; col: number };
  node2: { row: number; col: number };
  wordIndex: number;
}

Constants

const RIDDLE_WIDTH = 6;   // Grid width
const RIDDLE_HEIGHT = 8;  // Grid height

Requirements

  • Super solution must be at least 6 characters long
  • Word pool should contain enough words to fill the remaining grid space
  • Words are automatically converted to uppercase and special characters are normalized

Building from Source

cd ts
npm install
npm run build

License

MIT