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

@gretzky/cratylus

v0.2.0

Published

language processing tools

Downloads

2

Readme

cratylus

Language processing tools. These can be used alongside i18n setups (like i18next) or on their own.

Cratylus is a dialog by Plato that debates the arbitrariness of language.

Usage

Install the package with the package manager of your choice.

// or yarn or pnpm
npm install @gretzky/cratylus

Levenshtein Distance

The Levenshtein distance is the minimum number of single-character edits required to change one word into another.

levenshtein(a: string, b: string, calcRatio: boolean): number

Returns the levenshtein distance calculation iteratively over 2 matrix rows.

levenshtein("crack", "whack") // 2
levenshtein("8675309", "1234567") // 6

Plurality

There are 2 enums and 2 functions for using plurals based off of the Arabic language set of 5 potential plural forms:

  • None = 0
  • One = 1
  • Two = 2,
  • Few = 3-5
  • Many = 5-99
  • Other = 100+

PluralForm and PluralGuard

Each enum is keyed by the 5 plural forms.

PluralForm returns the string name of the plural (e.g. none = none).

PluralGuard returns an arbitrary number that represents the plural (e.g. few = 3). This is more useful if you just need to determine the plural form and the actual number doesn't matter.

getPluralForm(count: number): PluralForm

Returns the string type of the plural based on the passed number.

getPluralForm(0) // "none"
getPluralForm(1) // "one"
getPluralForm(2) // "two"
getPluralForm(4) // "few"
getPluralForm(15) // "many"
getPluralForm(66) // "many"
getPluralForm(369) // "other"

Sentence

buildSentencePrimitive(stringArr: string[]): string

Returns a sentence built from an array of strings. Any punctuation in the array is adhered to, but if there's no end punctuation a period is added. Correct sentence casing is also added.

Consider an array to be 1 sentence.

const s1 = ["this", "is", "a", "sentence"]
const s2 = ["this is", "a sentence"]
const s3 = ["tHiS iS", "a SeNtEnCe"]
const s4 = ["this is", "a sentence", "!"]
const s5 = ["this", "is", "a sentence", "?"]

buildSentence(s1) // "This is a sentence."
buildSentence(s2) // "This is a sentence."
buildSentence(s3) // "This is a sentence."
buildSentence(s4) // "This is a sentence!"
buildSentence(s5) // "This is a sentence?"

String Formatting

TextCasing

Enum that represents 5 different ways of casing a string.

// capitalizes the first letter of a string, regardless of whether or not it has other words
TextCasing.capitalize // e.g. Foo bar
// uppercases a string
TextCasing.upper // e.g. FOO BAR
// lowercases a string
TextCasing.lower // e.g. foo bar
// title cases a string, capitalizing the first letter of each individual word in the string
TextCasing.title // e.g. Foo Bar
// sentence cases a string - very similar to capitalize but the regex is adjusted slightly
TextCasing.sentence // e.g. Foo bar

stringFormat(value: string, format: TextCasing): string

Returns a string formatted to a given text casing.

const str = "never gonna give you up"

stringFormat(str, TextCasing.capitalize) // "Never gonna give you up"
stringFormat(str, TextCasing.sentence) // "Never gonna give you up"
stringFormat(str, TextCasing.title) // "Never Gonna Give You Up"
stringFormat(str, TextCasing.lower) // "never gonna give you up"
stringFormat(str, TextCasing.upper) // "NEVER GONNA GIVE YOU UP"