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

@alduino/humanizer

v1.1.0

Published

Javascript port of Humanizer.NET

Readme

This is a port of Humanizer for Javascript. Humanizer meets all your Javascript needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities. It is licensed under the MIT (an OSI approved license).

This library is currently in very early development, so most features of Humanizer aren't supported yet. The features currently documented in this readme are the ones that are supported.

Install

You can install Humanizer from NPM:

npm i @alduino/humanizer
yarn add @alduino/humanizer
pnpm i @alduino/humanizer

Alternatives

  • humanizer.node
    • Pros: More faithful port of Humanizer.NET, currently supports more features, recently updated
    • Cons: Pollutes prototypes

Features

Humanise string

import {humanize} from "@alduino/humanizer/string";
// or
const {humanize} = require("@alduino/humanizer/string");

You can call the humanize() function to turn an otherwise computerised string into a more readable human-friendly one.

humanize("PascalCaseInputStringIsTurnedIntoSentence") => "Pascal case input string is turned into sentence"
humanize("Underscored_input_string_is_turned_into_sentence") => "Underscored input string is turned into sentence"
humanize("Underscored_input_String_is_turned_INTO_sentence") => "Underscored input String is turned INTO sentence"

Dehumanise string

import {dehumanize} from "@alduino/humanizer/string";
// or
const {dehumanize} = require("@alduino/humanizer/string");

Much like you can humanise a computer friendly into human friendly string, you can dehumanise a human friendly string into a computer friendly one:

dehumanize("Pascal case input string is turned into sentence") => "PascalCaseInputStringIsTurnedIntoSentence"

Transform string

import {transform, toLowerCase} from "@alduino/humanizer/string";
// or
const {transform, toLowerCase} = require("@alduino/humanizer/string");

The transform function applies some kind of transformation to the input string. There are a few default implementations:

transform("Sentence casing", toLowerCase) => "sentence casing"
transform("Sentence casing", toSentenceCase) => "Sentence casing"
transform("Sentence casing", toTitleCase) => "Sentence Casing"
transform("Sentence casing", toUpperCase) => "SENTENCE CASING"

You can create your own transformers by implementing the IStringTransformer interface, which you can import from the same place.

Truncate string

import {truncate} from "@alduino/humanizer/string";
// or
const {truncate} = require("@alduino/humanizer/string");

You can truncate a string using the truncate method:

truncate("Long text to truncate", 10) => "Long text…"

By default, the character is used to truncate strings. The advantage of using the character over ... is that the former is only a single character long, and thus allows more text to be shown before truncation. If you want, you can override this with your own truncation string:

truncate("Long text to truncate", 10, "---") => "Long te---"

The default truncation strategy, fixedLength, is used to truncate the input stringto a specific length, including the truncation string length. There are two more default truncator strategies available: one for a fixed number of (alpha-numerical) characters, and one for a fixed number of words. To use a specific truncator when truncating, pass it after the truncation string (you can use null as the truncation string value to use its default):

import {fixedLength, fixedNumberOfCharacters, fixedNumberOfWords} from "@alduino/humanizer/string";

truncate("Long text to truncate", 10, null, fixedLength) => "Long text…"
truncate("Long text to truncate", 6, null, fixedNumberOfCharacters) => "Long t…"
truncate("Long text to truncate", 2, null, fixedNumberOfWords) => "Long text…"

You can create your own truncator by implementing the ITruncator interfacea from the same import.

There is also an option to choose whether to truncate the string from the beginning (TruncateFrom.Start) or the end (TruncateFrom.End). Default is the end as shown in the examples above, however you can truncate from the beginning by passing TruncateFrom.Start as the last parameter.

Inflector functions

Pluralize

import {pluralize} from "@alduino/humanizer/string";
// or
const {pluralize} = require("@alduino/humanizer/string");

Pluralize pluralises the provided input while taking irregular and uncountable words into consideration:

pluralize("Man") => "Men"
pluralize("string") => "strings"

Normally, you would call pluralize on a singular word, but if you are unsure you can specify the last parameter as false:

pluralize("Men", false) => "Men"
pluralize("Man", false) => "Men"
pluralize("string", false) => "strings"

Singularize

See pluralize, but reversed.

Adding words

Sometimes, you may need to add a rule from the singularisation/pluralisation vocabulary (the examples below are already in the default vocabulary):

import {defaultVocabulary} from "@alduino/humanizer/string";

// Adds a word that can't easily be matched using regex
// By default, will be matched as an ending option, so could be `person` or `salesperson`
defaultVocabulary.addIrregular("person", "people");
// To only match whole words, add a parameter `false`:
defaultVocabulary.addIrregular("person", "people", false);

// Adds an uncountable word
defaultVocabulary.addUncountable("fish");

// Adds a rule to the vocabulary that doesn't follow trivial rules
defaultVocabulary.addPlural("bus", "busses");
defaultVocabulary.addPlural("(vert|ind)ices$", "$1ex")