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

@ionutinit/custom-methods

v0.2.0

Published

A collection of methods I keep seeing myself using, so I decided to optimize them and put them in a package.

Downloads

1

Readme

Custom Methods

A collection of methods I keep seeing myself using, so I decided to optimize them and put them in a package.

Offers TypeScript support.

npm i @ionutinit/custom-methods

 

capitalize

Capitalizes the first letter of a string or each element in an array of strings.

capitalize(string | string[]) => string | string[]

Optional parameters (string only)

When provided a string, an optional style parameter can be invoked to capitalize each word or sentence respectively.

capitalize(string, { style: "word" | "sentence" });

Examples

capitalize("hello");
// "Hello"
capitalize(["good", "day"]);
// ["Good". "Day"]
capitalize("hello. how are you?", { style: "word" });
// "Hello. How Are You?"
capitalize("hello. how are you?", { style: "sentence" });
// "Hello. How are you?"

 

concord

Creates grammatical concord (agreement) between a string and an associated number.

If the first argument is a string, it parses it into a number

concord(number | string, string) => string

Optional parameters

concord(
    number | string,
    pluralForm?: string,
    round?: {-1 | 1 | true | false}
)
  • pluralForm: provides the plural form of the string; useful for irregular nouns, otherwise defaults to string + s

  • round: rounds the number into an integer according to criteria provided; defaults to false

    • true: rounds up or down, according to decimal value

    • -1: rounds down

    • 1: rounds up

Examples

concord(0, "item");
// "no items"
concord(1, "item");
// "1 item"
concord("2", "item");
// "2 items"
concord(1, "leaf", "leaves");
// "1 leaf"
concord(3, "leaf", "leaves");
// "3 leaves"
concord("5.25", "item", { round: 1 });
// "6 items"
concord("5.95", "leaf", "leaves", { round: 1 });
// "5 leaves"

 

enumerate

Returns a natural-language enumeration of an array of strings.

enumerate(string[]) => string

Optional parameters

enumerate(
    string[],
    limit?: number,
    tail?: number,
    options?: {unique: boolean}
)
  • limit: sets the length of the had of the output enumeration, followed by "..."

  • tail: sets the length of the tail of the output enumeration; works only in conjunction with limit; it is ignored if is larger or equal than the limit or the remainder of the array

  • unique: only a list of the unique elements of the array is enumerated; defaults to false

Examples

enumerate(["one", "two"]);
// "one and two"
enumerate(["one", "two", "three"]);
// "one, two and three"
enumerate(["one", "two", "three", "four"]);
// "one, two, three and four"
enumerate(["one", "two", "three", "four"], { limit: 2 });
// "one, two..."
enumerate(["one", "one", "two", "two", "three", "three", "four", "four"], {
  limit: 2,
  unique: true,
});
// "one, two..."
enumerate(["one", "one", "two", "two", "three", "three", "four", "four"], {
  limit: 1,
  tail: 1,
  unique: true,
});
// "one... four"
enumerate(["one", "two", "three", "four"], { limit: 2, tail: 4 });
// "one, two..."

 

pipe

A simple pipeline function

pipeline( ...args: function) => any

Example

const increment = (x) => x + 1;
const double = (x) => x * 2;
const toString = (x) => x.toString();

const piped = pipe(increment, double, toString);
piped(2);
// "6"

 

reduceText

Returns a text reduced to the full word or sentence nearest to the limit provided. The limit refers to the length of the string.

The default characters for the limit are . ! ? .

reduceText(string, number) => string

Optional parameters

reduceText(
  string,
  number,
  params?: string,
)

params: provide customs characters to be considered as the limit; each individual character is taken into consideration separately

Examples

reduceText("Hello. How are you? I'm fine!", 14);
// "Hello. How are you?"
// The limits taken into consideration are 5 (.), 18 (?), 28 (!). Closest to the limit provided is "?", so the string is cut at that point
reduceText("Hello. How are you? I'm fine!", 7);
// "Hello."
reduceText("Hello. How are you? I'm fine!", 1, "?");
// "Hello. How are you?"
reduceText("Hello. How are you? I'm fine!", 1, " ");
// "Hello." -> if a blank space is provided as param, it returns the words up the limit provided