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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pollway

v1.1.4

Published

Survey flow logic translator

Readme

Pollway NPM Package

A TypeScript library for handling survey flow logic and navigation.

Installation

npm install pollway

Core Functions

getNextQuestion(surveyData, currentQuestionId, response)

Determines the next question in a survey based on the current question and user response.

  • Parameters:
    • surveyData: Object containing survey questions and branches
    • currentQuestionId: String ID of the current question
    • response: User's response (string or string[])
  • Returns: String ID of the next question or null if no next question exists

getPreviousQuestion(surveyData, currentQuestionId, previousResponse)

Navigates to the previous question in the survey flow based on the current question and the previous response.

  • Parameters:
    • surveyData: Object containing survey questions and branches
    • currentQuestionId: String ID of the current question
    • previousResponse: Previous user's response (string or string[])
  • Returns: String ID of the previous question or null if:
    • No incoming branches exist
    • No matching conditional branch is found
    • No default branch exists

The function works by:

  1. Finding all branches that point to the current question
  2. For speech-type questions, returns the first incoming question
  3. For other questions, evaluates branch conditions against the previous response
  4. Falls back to an unconditional branch if no conditional branches match

encodeSurvey(surveyData)

Encodes survey data for transmission or storage.

decodeSurvey(encodedData)

Decodes previously encoded survey data.

Types

Question Types

type QuestionType = 'multipleChoice' | 'multipleSelect' | 'textInput' | 'speech'

Question Categories

type QuestionCategory = 'generic' | 'speech' | 'call to action' | 'voting' | 'volunteering' | 'personal info'

Core Interfaces

Question

Represents a survey question:

interface Question {
  id: string
  category: QuestionCategory
  type: QuestionType
  label: QuestionLabel
  text: string
  icon: string
  options: string[]
  position: Position
  color: string
  isStartingPoint?: boolean
  isEditingInput?: boolean
  isEndingQuestion?: boolean
  validation?: {
    pattern?: string
    format?: string
    errorMessage?: string
  }
  customProperties?: {
    wasCustomized?: boolean
    [key: string]: any
  }
}

Branch

Defines the connection between questions:

interface Branch {
  id: string
  fromId: string
  toId: string
  conditions: BranchCondition[]
  selectedOption?: string
}

Session

Represents a survey session:

interface Session {
  id: string
  timestamp: number
  name?: string
  questions: Question[]
  branches: Branch[]
}

Branch Conditions

RegexCondition

interface RegexCondition {
  type: 'regex'
  pattern: string
}

OptionCondition

interface OptionCondition {
  type: 'option'
  value: string
}

SurveyData

interface SurveyData {
  questions: Question[]
  branches: Branch[]
}

Usage Example

import {
  getNextQuestion,
  getPreviousQuestion,
  encodeSurvey,
  decodeSurvey
  type SurveyData,
} from 'pollway';

type Direction = 'forward' | 'backward'

// Create survey data
const surveyData: SurveyData = {
  questions: [...],
  branches: [...]
};

// Navigate forward based on response
const nextQuestionId = getNextQuestion(surveyData, 'question1', 'Yes');

// Navigate backward based on previous response
const previousQuestionId = getPreviousQuestion(surveyData, 'question2', 'Yes');

// Encode survey for storage
const encoded = encodeSurvey(surveyData);

// Decode survey data
const decoded = decodeSurvey(encoded);

// Example of handling navigation in both directions
function navigateSurvey(
  surveyData,
  currentQuestionId,
  response,
  direction: 'forward' | 'backward'
): string | null {
  if (direction === 'forward') {
    return getNextQuestion(surveyData, currentQuestionId, response);
  } else {
    return getPreviousQuestion(surveyData, currentQuestionId, response);
  }
}