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

text-validator

v0.0.3

Published

Javascript utility for validating English text inputs

Readme

text-validator can be used for validating text inputs in English to make it more difficult for users to skip through forms by simply keyboard mashing. It performs a variety of simple tests, including sentence length, number of repeats (e.g., "blah blah blah blah"), and comparing words against a database of known words. It compensates for many simple spelling errors as well, using a simple insertion/deletion/mutation model of spelling.

API:

  • validate(sentence): Returns a SentenceTest object. The isValid property indicates whether the sentence is valid. The default parameters are very generous. See examples below for more details.

  • getValidationParams(): Get the current set of validation parameters.

  • setValidationParams(params): Set the validation parameters. The validation parameters object has the following properties by default:

{
    gibberishThreshold: 0.5, // max fraction of the sentence that can be unknown words
    maxRepeatPercentage: 0.5, // max fraction of a sentence that can be a single repeated word (e.g. "blah blah blah blah"
    minSentenceLength: 3 // minimum length of a valid sentence in words
}
  • serve(port): Serves a rest API on the specified port. To use the server, POST to the /validate endpoint with the text to be validated in the POST body, and content type text/plain. It will return a SentenceTest object.

Examples:


> var tv = require('text-validator');
> tv.validate('i am th ver model of a mdorne major genreal')
SentenceTest {
  matches: 
   [ WordMatch { score: 0, match: 'i', word: 'i' },
     WordMatch { score: 0, match: 'am', word: 'am' },
     WordMatch { score: 1, match: 'ah', word: 'th' },
     WordMatch { score: 1, match: 'eer', word: 'ver' },
     WordMatch { score: 0, match: 'model', word: 'model' },
     WordMatch { score: 0, match: 'of', word: 'of' },
     WordMatch { score: 0, match: 'a', word: 'a' },
     WordMatch { score: -1, match: undefined, word: 'mdorne' },
     WordMatch { score: 0, match: 'major', word: 'major' },
     WordMatch { score: 1, match: 'general', word: 'genreal' } ],
  validateParams: 
   { gibberishThreshold: 0.5,
     maxRepeatPercentage: 0.5,
     minSentenceLength: 3 },
  sentence: 'i am th ver model of a mdorne major genreal',
  words: 
   [ 'i',
     'am',
     'th',
     'ver',
     'model',
     'of',
     'a',
     'mdorne',
     'major',
     'genreal' ],
  wordMatch: 
   [ WordMatch { score: 0, match: 'i', word: 'i' },
     WordMatch { score: 0, match: 'am', word: 'am' },
     WordMatch { score: 1, match: 'ah', word: 'th' },
     WordMatch { score: 1, match: 'eer', word: 'ver' },
     WordMatch { score: 0, match: 'model', word: 'model' },
     WordMatch { score: 0, match: 'of', word: 'of' },
     WordMatch { score: 0, match: 'a', word: 'a' },
     WordMatch { score: -1, match: undefined, word: 'mdorne' },
     WordMatch { score: 0, match: 'major', word: 'major' },
     WordMatch { score: 1, match: 'general', word: 'genreal' } ],
  isValid: true }

> tv.validate('asdf nas hjasdfkln fasdf')
SentenceTest {
  matches: 
   [ WordMatch { score: -1, match: undefined, word: 'asdf' },
     WordMatch { score: 1, match: 'as', word: 'nas' },
     WordMatch { score: -1, match: undefined, word: 'hjasdfkln' },
     WordMatch { score: -1, match: undefined, word: 'fasdf' } ],
  validateParams: 
   { gibberishThreshold: 0.5,
     maxRepeatPercentage: 0.5,
     minSentenceLength: 3 },
  sentence: 'asdf nas hjasdfkln fasdf',
  words: [ 'asdf', 'nas', 'hjasdfkln', 'fasdf' ],
  wordMatch: 
   [ WordMatch { score: -1, match: undefined, word: 'asdf' },
     WordMatch { score: 1, match: 'as', word: 'nas' },
     WordMatch { score: -1, match: undefined, word: 'hjasdfkln' },
     WordMatch { score: -1, match: undefined, word: 'fasdf' } ],
  isValid: false }

  > tv.validate('twas brillig and the slithy toves did gyre and gimble in the wabe')
SentenceTest {
  matches: 
   [ WordMatch { score: 1, match: 'was', word: 'twas' },
     WordMatch { score: -1, match: undefined, word: 'brillig' },
     WordMatch { score: 0, match: 'and', word: 'and' },
     WordMatch { score: 0, match: 'the', word: 'the' },
     WordMatch { score: 1, match: 'smithy', word: 'slithy' },
     WordMatch { score: 1, match: 'toes', word: 'toves' },
     WordMatch { score: 0, match: 'did', word: 'did' },
     WordMatch { score: 1, match: 'lyre', word: 'gyre' },
     WordMatch { score: 0, match: 'and', word: 'and' },
     WordMatch { score: 1, match: 'nimble', word: 'gimble' },
     WordMatch { score: 0, match: 'in', word: 'in' },
     WordMatch { score: 0, match: 'the', word: 'the' },
     WordMatch { score: 1, match: 'abe', word: 'wabe' } ],
  validateParams: 
   { gibberishThreshold: 0.5,
     maxRepeatPercentage: 0.5,
     minSentenceLength: 3 },
  sentence: 'twas brillig and the slithy toves did gyre and gimble in the wabe',
  words: 
   [ 'twas',
     'brillig',
     'and',
     'the',
     'slithy',
     'toves',
     'did',
     'gyre',
     'and',
     'gimble',
     'in',
     'the',
     'wabe' ],
  wordMatch: 
   [ WordMatch { score: 1, match: 'was', word: 'twas' },
     WordMatch { score: -1, match: undefined, word: 'brillig' },
     WordMatch { score: 0, match: 'and', word: 'and' },
     WordMatch { score: 0, match: 'the', word: 'the' },
     WordMatch { score: 1, match: 'smithy', word: 'slithy' },
     WordMatch { score: 1, match: 'toes', word: 'toves' },
     WordMatch { score: 0, match: 'did', word: 'did' },
     WordMatch { score: 1, match: 'lyre', word: 'gyre' },
     WordMatch { score: 0, match: 'and', word: 'and' },
     WordMatch { score: 1, match: 'nimble', word: 'gimble' },
     WordMatch { score: 0, match: 'in', word: 'in' },
     WordMatch { score: 0, match: 'the', word: 'the' },
     WordMatch { score: 1, match: 'abe', word: 'wabe' } ],
  isValid: true }

> tv.validate('O frabjous day! Callooh! Callay!')
SentenceTest {
  matches: 
   [ WordMatch { score: -1, match: undefined, word: 'o' },
     WordMatch { score: -1, match: undefined, word: 'frabjous' },
     WordMatch { score: 0, match: 'day', word: 'day' },
     WordMatch { score: -1, match: undefined, word: 'callooh' },
     WordMatch { score: 1, match: 'allay', word: 'callay' } ],
  validateParams: 
   { gibberishThreshold: 0.5,
     maxRepeatPercentage: 0.5,
     minSentenceLength: 3 },
  sentence: 'o frabjous day callooh callay ',
  words: [ 'o', 'frabjous', 'day', 'callooh', 'callay' ],
  wordMatch: 
   [ WordMatch { score: -1, match: undefined, word: 'o' },
     WordMatch { score: -1, match: undefined, word: 'frabjous' },
     WordMatch { score: 0, match: 'day', word: 'day' },
     WordMatch { score: -1, match: undefined, word: 'callooh' },
     WordMatch { score: 1, match: 'allay', word: 'callay' } ],
  isValid: false }