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

sudoku-formats

v1.0.3

Published

Convert between different sudoku formats (lisudoku, fpuzzles)

Downloads

293

Readme

sudoku-formats

Convert between different sudoku formats (lisudoku, fpuzzles etc).

See it in action on the lisudoku solver page through the import button.

Decoding and encoding puzzles

import { decodeSudoku, encodeSudoku, FORMATS, SudokuDataFormat } from 'sudoku-formats'

// Parse grid string
decodeSudoku('1000003002000004').then(({ constraints }) => {
  console.log(constraints)
})

// Parse lisudoku puzzle
const LISUDOKU_URL = 'https://lisudoku.xyz/solver?import=1000003002000004'
const { format, dataString, constraints, error } = await decodeSudoku(LISUDOKU_URL)
console.log(constraints) // { gridSize: 4, regions: [...], ... }
console.log(dataString) // '1000003002000004'
console.log(format) // 'lisudoku'
console.log(error) // undefined

console.log(encodeSudoku({ constraints: constraints, format: SudokuDataFormat.Lisudoku }))
// { dataString: '1000003002000004', url: 'https://lisudoku.xyz/solver?import=1000003002000004' }

// Parse f-puzzles puzzle
const FPUZZLES_URL = 'https://f-puzzles.com/?load=N4IgzglgXgpiBcBOANCA5gJwgEwQbT1ADcBDAGwFc54BGVNCImAOwQBcMqBfZYHv3vyGCRfALrJCwgTOlyJU0XKVKFsles1c1yrRu2S9R+Yd1nVp/Vdk7r58WK5A'
const { format, dataString, constraints, error } = await decodeSudoku(FPUZZLES_URL)
console.log(constraints) // { size: 9, grid: [...], ... }
console.log(dataString) // 'N4IgzglgXgpiBcBOAN...'
console.log(format) // 'fpuzzles'
console.log(error) // undefined

// Handling errors
const { error } = await decodeSudoku('123');
console.log(error) // 'Error while parsing inline data'

// Get all formats
console.log(FORMATS) // [{ format: 'lisudoku', urlPatterns: ... }, ...]

Converting between formats

import { decodeSudoku, transformSudoku, SudokuDataFormat } from 'sudoku-formats'

const LISUDOKU_URL = 'https://lisudoku.xyz/solver?import=1000003002000004'
const { format, constraints } = await decodeSudoku(LISUDOKU_URL)

// lisudoku -> fpuzzles
const result = transformSudoku({
  constraints,
  fromFormat: format,
  toFormat: SudokuDataFormat.Fpuzzles,
})
console.log(result.constraints) // { size: 4, ... }
console.log(result.url) // 'https://f-puzzles.com/?load=...'
console.log(result.error) // undefined

Supported formats

Format | URL patterns | Example -------- | ----------------------- | ------- lisudoku | https://lisudoku.xyz/e?import=:data https://lisudoku.xyz/solver?import=:data https://lisudoku.xyz/p/:id | example1 example2 fpuzzles | https://f-puzzles.com/?load=:data | example1

Contribute

Do you want another format supported? Open an issue or a pull request.

Consider joining the discord server.