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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@art-suite/art-core-strings

v0.1.4

Published

The Standard Library for JavaScript that aught to be.

Readme

@art-suite/art-core-strings

A powerful and extensive utility library for string manipulation, parsing, generation, and regular expressions.

Features

  • Robust string manipulation: padding, replacing, joining, shortening, escaping.
  • Random string generation, including cryptographically secure options.
  • URL parsing, manipulation, and generation utilities.
  • Comprehensive set of pre-defined regular expressions for common patterns (URLs, emails, colors, etc.).
  • JSON stringification utilities.
  • Pluralization and singularization of English words.
  • TypeScript definitions for complete type safety.

Installation

npm install @art-suite/art-core-strings

API Overview

String Manipulation & Utilities

  • compactFlattenJoin(array: any[], joiner?: string): string: Flattens and compacts an array, then joins its elements into a string.
  • replaceLast(source: string, find: string, replace: string): string: Replaces the last occurrence of a substring.
  • getPadding(length: number, character?: string): string: Generates a padding string of a specified length.
  • pad(str: string, length: number, character?: string, alignLeft?: boolean): string: Pads a string to a certain length.
  • escapeJavascriptString(str: string): string: Escapes a string for safe use within JavaScript single or double quotes.
  • allIndexes(source: string, find: string): number[]: Finds all indexes of a substring.
  • eachMatch(str: string, regex: RegExp, callback: (match: RegExpExecArray) => void): void: Iterates over all matches of a regex in a string.
  • humanFriendlyShorten(str: string, maxLength?: number, separator?: string): string: Shortens a string in a human-friendly way, typically by adding an ellipsis.
  • stripTrailingWhitespace(str: string): string: Removes trailing whitespace from a string.

Random String Generation

  • base62Characters: string: A string containing all base62 characters (0-9a-zA-Z).
  • randomString(length: number, characters?: string): string: Generates a random string of a specified length from a given set of characters.
  • cryptoRandomString(length: number, characters?: string): string: Generates a cryptographically random string.
  • randomBase62Character(): string: Returns a single random base62 character.

JSON Utilities

  • jsStringify(value: any, indent?: number | string, includeFunctions?: boolean, includeUndefined?: boolean): string: Extended JSON.stringify with options for functions and undefined.
  • consistentJsonStringify(obj: any): string: Stringifies an object with keys sorted for consistent output.

URL Utilities

  • sameOrigin(url1: string, url2: string): boolean: Checks if two URLs have the same origin.
  • parseQuery(queryString: string): Record<string, string | string[]>: Parses a URL query string into an object.
  • generateQuery(params: Record<string, any>): string: Generates a URL query string from an object.
  • urlJoin(...parts: string[]): string: Joins URL parts intelligently.
  • urlResolve(...parts: string[]): string: Resolves URL parts similar to path.resolve but for URLs.
  • appendQuery(url: string, query: string | Record<string, any>): string: Appends a query string or params to a URL.
  • parseUrl(url: string): object: Parses a URL into its components (protocol, host, path, query, etc.).
  • findUrlOrigin(url: string): string | undefined: Extracts the origin (protocol + host + port) from a URL.
  • normalizeUrl(url: string): string: Normalizes a URL string (e.g., sorts query params, decodes, etc.).

Pluralization

  • plural(word: string, count?: number): string: Returns the plural form of a word. Can provide count for conditional pluralization.
  • singular(word: string): string: Returns the singular form of a word.
  • isSingular(word: string): boolean: Checks if a word is singular.
  • isPlural(word: string): boolean: Checks if a word is plural.
  • addPluralizeRule(singular: string | RegExp, plural: string | ((match: string, count: number) => string)): void: Adds a custom pluralization/singularization rule.
  • pluralize(word: string, count?: number, inclusive?: boolean): string: More comprehensive pluralization function (alias or more featureful version of plural).

Regular Expressions

This library provides a wide array of pre-defined RegExp objects for common matching tasks. Below are some key categories (refer to index.d.ts for the full list and exact names if aliased, e.g. someRegexp vs someRegex).

  • General: escapeRegExp, numberRegExp, wordsRegExp, exactlyOneWordRegExp, isoDateRegExp.
  • URL Structure: urlProtocolRegExp, domainRegExp, urlPathRegExp, urlQueryRegExp, urlQueryParamsRegExp, findLegalUrlCharacterRegExp, findUrlPortRegExp, findUrlFragmentRegExp.
  • URL Finding: findUrlRegExp, urlRegExp, findUrlWithOptionalProtocolRegExp, urlWithOptionalProtocolRegExp, findAllUrlsRegExp, findAllUrlsWithOptionalProtocolRegExp, findSourceReferenceUrlRegExp.
  • Email: emailRegExp, findEmailRegExp, findEmailLocalRegExp.
  • Color: hex16ColorRegExp, hex256ColorRegExp, hex16GreyColorRegExp, hex256GreyColorRegExp, rgbColorRegExp, rgbaColorRegExp, findColorRegExp, colorRegExp.

(Note: Many RegExp exports have aliases like ...Regexp or ...Regex. The primary documented form is usually ...RegExp.)

Examples

String Manipulation

import {
  pad,
  compactFlattenJoin,
  humanFriendlyShorten,
} from "@art-suite/art-core-strings";

console.log(pad("test", 10, "_", false)); // "______test"
console.log(
  compactFlattenJoin(["hello", null, ["world", undefined, "!"]], " ")
); // "hello world !"
console.log(
  humanFriendlyShorten("This is a very long string that needs shortening", 20)
); // "This is a very long..."

URL Utilities

import {
  parseUrl,
  generateQuery,
  appendQuery,
} from "@art-suite/art-core-strings";

const myUrl = "http://example.com/path?foo=bar#hash";
const parsed = parseUrl(myUrl);
console.log(parsed.host); // "example.com"

const params = { a: 1, b: "test" };
console.log(generateQuery(params)); // "a=1&b=test"
console.log(appendQuery("http://example.com", params)); // "http://example.com?a=1&b=test"

Regular Expressions

import { emailRegExp, urlRegExp } from "@art-suite/art-core-strings";

console.log(emailRegExp.test("[email protected]")); // true
console.log(urlRegExp.test("http://example.com")); // true

Pluralization

import { plural, singular } from "@art-suite/art-core-strings";

console.log(plural("cat")); // "cats"
console.log(plural("box")); // "boxes"
console.log(singular("apples")); // "apple"
console.log(plural("mouse", 2)); // "mice"

License

MIT