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

@caelus-utils/strfmt

v0.1.0

Published

A lightweight utility library providing a comprehensive set of string formatting and manipulation functions for JavaScript/TypeScript projects.

Readme

String formatting @caelus-utils/strfmt

A lightweight utility library providing a comprehensive set of string formatting and manipulation functions for JavaScript/TypeScript projects. This package simplifies common string operations such as case conversion, splitting, replacing, padding, and more. It aims to be a one-stop solution for your string manipulation needs, making your code cleaner and more efficient.

Installation

  • using npm
npm install @caelus-utils/strfmt
  • using yarn
yarn add @caelus-utils/strfmt
  • using pnpm
pnpm add @caelus-utils/strfmt

Functions

isEmptyStr(str, config)

Checks if a given string is empty.

  • str: The string to check.
  • config: An optional configuration object.
    • ignoreWhitespace: Determines whether whitespace characters should be ignored during processing. Defaults to true.

Returns true if the string is considered empty, false otherwise.

Usage Example

import {isEmptyStr} from "@caelus-utils/strfmt";

isEmptyStr(''); // true
isEmptyStr('  '); // true
isEmptyStr('  ', {ignoreWhitespace: false}); // false
isEmptyStr(' hello '); // false

splitStr(sentence, onlyLetterNumber)

Splits a given sentence into an array of words based on various delimiters and patterns.

  • sentence: The input string to be split into words.
  • onlyLetterNumber: If true, filters the resulting array to include only words containing alphanumeric characters (letters and numbers only). Defaults to false.

Returns an array of words (string) obtained by splitting the input sentence.

Usage Example

import {splitStr} from "@caelus-utils/strfmt";

splitStr('hello world'); // ['hello', 'world']

strReplace(string, payload)

Replaces occurrences of a search string or multiple search strings in the given input string with the specified replacement value(s).

  • string: The input string to perform replacements on.
  • payload: The replacement payload(s). It can be a single payload object or an array of payload objects. Each payload includes the search string to be replaced and the replace value.
    • search: A string or regular expression (string | RegExp) to specify the search pattern.
    • replace: A string or a function to replace parts of a string.

Returns the resulting string after all replacements have been applied.

Usage Example

import {strReplace} from "@caelus-utils/strfmt";

strReplace('hello world', {search: 'world', replace: 'everyone'}); // 'hello everyone'
strReplace('hello world', [{search: 'hello', replace: 'hi'}, {search: 'world', replace: 'everyone!'}]); // 'hi everyone!'

capitalize(str)

Capitalizes the first letter of a given string.

  • str: The input string to be capitalized.

Returns the modified string with the first letter capitalized.

Usage Example

import {capitalize} from "@caelus-utils/strfmt";

capitalize('hello world'); // Hello world

uncapitalize(str)

Converts the first character of a string to lowercase and returns the modified string.

  • str: The input string to process.

Returns the input string with the first character converted to lowercase.

Usage Example

import {uncapitalize} from "@caelus-utils/strfmt";

uncapitalize('Hello World'); // hello World

titleCase(str)

Converts a given string into title case format, where the first letter of each word is capitalized.

  • str: The input string to be transformed into title case.

Returns the transformed string in title case.

Usage Example

import {titleCase} from "@caelus-utils/strfmt";

titleCase('hello world'); // Hello World

camelCase(str)

Converts a given string to camelCase format.

  • str: The input string to be transformed into camelCase.

Returns the camelCase formatted string.

Usage Example

import {camelCase} from "@caelus-utils/strfmt";

camelCase('hello world'); // helloWorld

constantCase(str)

Converts a given string to constant case, where all letters are uppercase and words are separated by underscores.

  • str: The input string to be converted.

Returns the string converted to constant case.

Usage Example

import {constantCase} from "@caelus-utils/strfmt";

constantCase('hello world'); // HELLO_WORLD

snakeCase(str)

Converts a given string into snake_case format.

  • str: The input string to be converted.

Returns the transformed string in snake_case format.

Usage Example

import {snakeCase} from "@caelus-utils/strfmt";

snakeCase('hello world'); // hello_world

kebabCase(str)

Converts a given string to kebab-case by transforming it to lowercase and separating words with dashes.

  • str: The input string to be transformed into kebab-case.

Returns the transformed string in kebab-case format.

Usage Example

import {kebabCase} from "@caelus-utils/strfmt";

kebabCase('hello world'); // hello-world

pascalCase(str)

Converts a given string to PascalCase.

  • str: The input string to be transformed into PascalCase.

Returns the string converted to PascalCase.

Usage Example

import {pascalCase} from "@caelus-utils/strfmt";

pascalCase('hello world'); // HelloWorld

strRmSpace(str)

Removes all whitespace characters from the given string.

  • str: The input string from which spaces will be removed.

Returns the resulting string with all spaces removed.

Usage Example

import {strRmSpace} from "@caelus-utils/strfmt";

strRmSpace(' hello world '); // helloworld

padStr(str, config)

Pads the given string or number with a specified prefix to a desired length.

  • str: The string or number to be padded.
  • config: The configuration object for padding.
    • size: The desired length of the final padded string. Defaults to 2.
    • position: The position where the padding should be added, either 'start' or 'end'. Defaults to start.
    • prefix: The string to be used as the padding character(s). Defaults to an empty string.

Note: if no prefix was provided nothing occur to the str value

Returns the padded string based on the configuration provided.

Usage Example

import {padStr} from "@caelus-utils/strfmt";

padStr('1', {size: 3, prefix: '0'}); // '001'
padStr(1, {size: 3, prefix: 0}); // '001'

charCode(input, hexCase)

Converts the characters in the input string to their hexadecimal Unicode representation.

  • input: The input string to be converted to hexadecimal representation.
  • hexCase: If true, the output hexadecimal values will be in uppercase; otherwise, they will be in lowercase. Defaults to false.

Returns the string containing the hexadecimal representation of the input characters.

Usage Example

import {charCode} from "@caelus-utils/strfmt";

charCode('A'); // '41'

strConcat(payload, sharedDivider)

Concatenates an iterable of strings, numbers, or booleans with a specified divider.

  • payload: Can be a single StrConcatPayload object or an array of them. Contains values and divider

    • values: An iterable of strings, numbers or booleans to be concatenated.
    • divider: An optional string used to divide between the concatenated values. Defaults to an empty string.
  • sharedDivider: An optional string used as a divider between concatenated values for all payloads in case payload is an array.

Returns the concatenated string with the specified divider between elements or an array of strings when the input is an array of payloads.

Usage Example

import {strConcat} from "@caelus-utils/strfmt";

strConcat({values: ['hello', 'world'], divider: '-'}); // 'hello-world'
// Each value has it's own divider
strConcat([{values: ['hello', 'world'], divider: '-'}, {values: ['hi', 'everyone!'], divider: '-'}]); // ['hello-world', 'hi-everyone!']
// All the values will share the same divider
strConcat([{values: ['hello', 'world']}, {values: ['hi', 'everyone!']}], '-'); // ['hello-world', 'hi-everyone!']

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

License

MIT License