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

logic-oracle

v2.1.0

Published

Answers questions for Knights & Knaves logic games

Readme

logic-oracle

a.k.a The Oracle of Knights & Knaves

A module for deducing answers to yes-no questions on the Island of Knights & Knaves

Installation

npm i answer-deducer

Usage

First import the package:

import deducer from 'answer-deducer'
//OR
const deducer = require('answer-deducer')

Then ask a question:

const answer = deducer(identities, answerer, question)

Input | Syntax --- | --- | identities| object containing names and roles for all characters in your game, ex. {A: 'K', B: 'N'} answerer | string naming the character the question is directed to, ex. 'A' question (no connectives)| [array] of two elements: 1. a question/predicate string, ex. 'Same' and 2. an [array] of names or quantifiers.* question (with connectives)| object containing two or more question arrays as outlined above and the relevant connective, e.g. AND. See example below.

For example, the question 'Is either A or B a Knight but not both?' is represented by the following object:

const question = {
  1: {
    1: ['Knight', ['A']],
    2: ['Knight' ['B']],
    c: 'OR'
  },
  2: {
    1: {
      1: ['Knight', ['A']],
      2: ['Knight' ['B']],
      c: 'AND'
    },
    c: 'NOT'
  },
  c: 'AND'
}

*See Questions for the full list of predicates, connectives, and quantifiers.

The deducer function returns true or false in the voice of the character specified as answerer. So, if the specified character is a Knave and the statement is true the module will return false. See below for more on character identities.

Identities

You may name your characters any string you wish, though tradition would have it that your first character's name starts with 'A' and your second with 'B', etc. Character names are keys in your identities object with roles as values. Possible values for roles are the following:

Value | Name | Speaks --- | --- | --- 'K' | Knight | the truth, always 'N' | Knave | only lies 'D' | Dragon | the truth, except in the presence of a Knight 'M' | Monk | whatever they wish*

*Currently, this implemented by returning a random choice of true or false when a Monk is asked a question, but we hope to add craftier monks soon!