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

sycamore.js

v0.2.0

Published

A decision tree based chat library.

Readme

sycamore.js

🌲 A decision tree based chat library

Usage

import Sycamore from 'sycamore.js'

// import the data
import data from './data.json'

// or

// create the data array
const data = [
	{
		id: 'intro',
		type: 'message',
		text: 'Hey!',
		next: 'compliment'
	},
	{
		id: 'fact',
		type: 'message',
		text: 'I am not a robot, I am a real human.',
		next: 'color'
	},
	{
		id: 'compliment',
		type: 'message',
		text: 'You look great today!',
		next: 'animal',
	},
	{
		id: 'animal',
		type: 'question',
		question: 'Which animal do you like more?',
		answers: [
			{
				text: 'Cat',
				next: 'age',
				callback: catCallback
			},
			{
				text: 'Dog',
				next: 'age'
			}
		]
	},
	{
		id: 'age',
		type: 'question',
		question: 'How old are you?',
		answers: [
			{
				text: 'Under 15',
				next: 'color'
			},
			{
				text: '15 - 30',
				next: 'color'
			},
			{
				text: '31 - 45',
				next: 'color'
			},
			{
				text: '46 - 60',
				next: 'color'
			},
			{
				text: 'Over 60',
				next: 'color'
			}
		]
	},
	{
		id: 'color',
		type: 'question',
		question: 'Which colour is your favourite?',
		answers: [
			{
				text: 'red'
			},
			{
				text: 'blue'
			},
			{
				text: 'green'
			},
			{
				text: 'yellow'
			},
			{
				text: 'purple'
			},
			{
				text: 'orange'
			}
		]
	}
]

const someFunction = () => {
	// this is the callback function for the answer 'Cat'
}

// create instance of sycamore with data
const sycamore = new Sycamore(data)

// initiate and start with the first question in the data
sycamore.init()

// or

// initiate and start with a specific question by it's ID
sycamore.init('age')

Events

// when Sycamore is emulating writing and sending the question
sycamore.on('typing', (wait) => {
	// passed the wait time in milliseconds
	
	// start a 'typing' animation for example
})

// sycamore emits a message to the user
sycamore.on('message', (obj) => {

})

// sycamore emits a question and will wait for the answer() method to be called in response
sycamore.on('question', (obj) => {
	// stop the 'typing' animation
	// do something with obj.question to display the question
	// iterate over and display each obj.answers.text
})

// when there is a delay between questions/messages this will fire
sycamore.on('delay', (delay) => {

})

// sycamore emits the 'answered' event when the answer() method is called
sycamore.on('answered', (qa) => {
	//qa obj contains the question and answer
})

// after each question is answered, sycamore will emit an updated event with the current collected data
sycamore.on('update', (data) => {

})

// once the tree reaches an end, the finished event will be emitted with the final collected data
sycamore.on('finished', (data) => {
	// can display or store the data array here
})

Methods

// send back the answer to the previous asked question
sycamore.answer(answer)

Options

| Option | Type | Default | Description | | --- | --- | --- | --- | | speed | int | 5 | A value between 1 - 10. 5 is an average typing speed. If number is below 1 or above 10 then it will be ignored and default will be used. | delay | int | 0 | A millisecond value greater or equal to 0, which specifies the delay time after the answer() method is called before the next question is asked | delayMinMax | array | | An array of 2 numbers only to determine the range of randomised delay after each answer() (ex. [1500, 3000]) | firstQuestion | string | | Supply a question ID string to determine that is the first question

const options = {
	speed: 5, // Determine the speed of the typing, from 1 - 10
	delay: 1000, // Delay after question is answered before next is asked, millisecond >= 0
	delayMinMax: [1500, 3000], // Array containing only 2 numbers, first index must be lower than second
	firstQuestion: 'age' // The first question can be set in the options or passed as the first parameter to the init method
}

const sycamore = new Sycamore(data, options)