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

titojs

v1.0.1

Published

text-in-text-out is a library to process input text and return a text answer acoording to the rules it was configured with.

Downloads

2

Readme

TITO - Text In Text Out

Tito is a simple library that exports a configurable object capable of process input text data and produce text response if input data matches some of the configured rules.

Installation:

npm install titojs --save

Usage:

There is a whole example on examples folder.

Import the library:

const tito = require('titojs')

Define some rules and use initialize method to store those rules in tito object:

const rules = [
  {
    in: /(^|\W)not today(\W|$)/,
    out: [
        { weight: 20, text: 'You will die this time, sorry' },
        { weight: 80, text: "That's what we say to the god of death" }
    ]
  },
  {
    in: [
      /(^|\W)not tomorrow(\W|$)/,
      /(^|\W)not yesterday(\W|$)/
    ],
    out: "I bet you didn't see Game of Thrones..."
  }
]

tito.initialize(rules)

Process some input data. Tito should return configured outputs on matching input text:

// These ones should log "I bet you didn't see Game of Thrones"
let err, response
[err, response] = tito.process('What do we say to the god of death? Not tomorrow.')
console.log(response);
[err, response] = tito.process('What do we say to the god of death? Not yesterday.')
console.log(response);

/* This one should return 20% "You will die this time, sorry" and 80% "That's what we say to the god of death" */
[err, response] = tito.process('The answer is "not today"')
console.log(response)

Methods:

initialize()

This is used to set the rules. Rules is an array of objects. Each object is a rule. Each rule object must contain in and out properties.

in property can be a regular expression or an array of regular expressions.

out object is more complex. It can be string, object, array of strings, array of objects, or a mix. If it's an object, it must contain weight and text properties, where first one is integer type and second one is string type.

weight represents the probability of that option to be selected as result when input text matches that in rule.

process()

This is the main feature of tito. It is used to compare input text with rules array. If input text matches one of the rules, tito returns related output text.

This method can return an array [error, response] or an object { error, response }

In both cases error will be null if input param is valid, and a string with error text otherwise. Response will contain the output string choice if there is a matching rule.

getRules()

This method returns an array with configured rules.

getOptions()

This method returns an object with options data.

setOptions()

This method requires an object with valid options and will set those options to the provided values.

Contributions:

The package.json is configured to only allow commits that passes standard style rules, and defined tests. If you want to contribute to this package, clone this repo, run npm install, then start by writing your test. There is an example on tests folder.

Run npm run dev, so on saving changes all test will run.

If code passes standard rules and tests, feel free to send a pull request :)