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 🙏

© 2024 – Pkg Stats / Ryan Hefner

chomsky-phrase

v1.0.1

Published

Generates memorable phrases using the Wordnik API. Phrases have sentence structure similar to Noam Chomsky's famous 'Colorless green ideas sleep furiously' and are not guaranteed to make sense

Downloads

14

Readme

Chomsky-Phrase

Generates memorable phrases using the Wordnik API getRandomWords method. Phrases have sentence structure similar to Noam Chomsky's famous 'Colorless green ideas sleep furiously' and are not guaranteed to make sense.

Can be installed globally as a CLI tool or locally as a project dependency. Has no third-party dependencies.

Brief Implementation Details

For each word in a phrase, chomsky-phrase sends a request to the Wordnik API getRandomWords method. A random word from the response is then selected. This implementation was chosen to let users obtain proper word tenses since the Wordnik API useCanonicalForm option seems to be broken.

Local

Installation

npm install chomsky-phrase

Default Usage

var chomsky = require('chomsky-phrase');
var phraseFactory = chomsky.PhraseFactory.createDefault();

phraseFactory.create((phrase) => {
  console.log(phrase);
});

Custom Phrases

You can build a custom phrase factory to output a phrase of any number of words and with any structure.

WordnikConfig

Each WordFactory takes a WordnikConfig that defines the API options for getting a random word. At this time, the following url options are configurable:

  • wordType
  • minCorpusCount
  • minLength
  • maxLength

Example:

var chomsky = require('chomsky-phrase');

// Get Adjectives between 1 and 25 characters long with minCorpusCount = 10000
var adjectiveConfig = new chomsky.WordnikConfig('adjective', 10000, 1, 25);

See the Wordnik API getRandomWords documentation for more information

WordFactory

A WordFactory creates words. Each WordFactory takes a WordnikConfig and optional filters to be used on the getRandomWords API response. Filter functions are used with the Array.prototype.filter function. Below is an example filter function that keeps only words that end with 'ing'

function onlyIng(word) {
  return word.endsWith('ing');
}

Filters used in the default PhraseFactory can be found here

Example:

var chomsky = require('chomsky-phrase');
var http = require('http');

var adjectiveConfig = new chomsky.WordnikConfig('adjective');
var adjectiveFactory = new chomsky.WordFactory(http, adjectiveConfig, [
  chomsky.resultFilters.filterWithEndings([ 'y', 'ing' ]),
  chomsky.resultFilters.filterContractions
]);

console.log(adjectiveFactory.create());

>>> 'fiery'

PhraseFactory

Inject a WordFactory array that will be used to create the phrase. Each WordFactory is used in order to form the phrase.

IE - The final phrase will be

[
  WordFactoryArray[0].create(),
  WordFactoryArray[1].create(),
  ...
  WordFactoryArray[n].create()
]

See PhraseFactory.createDefault() to see how the default factory is created.

Global

Installing chomsky-phrase globally will allow you to create phrases with the default PhraseFactory from the CLI. It is not configurable at this time.

Installation

npm install chomsky-phrase -g

Usage

chomsky-phrase

>>> [ 3, 'sultry', 'clogs', 'persist', 'soundly' ]