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

stringlib.js

v1.0.5

Published

Utility functions for manipulating strings in various formats

Downloads

2

Readme

Stringlib.js

npm version

npm downloads

NPM Package

Description:

This repository contains a collection of utility functions for manipulating strings in various formats. These functions are designed to make it easier to work with strings by performing actions such as capitalization, removing spaces, and transforming strings into different naming conventions.

Installation:

npm install stringlib.js

Usage:

const { 
  capitalize,
  allCaps,
  capitalizeWords,
  capitalizeHeadlines,
  removeExtraSpaces,
  kebobCase,
  snakeCase,
  camelCase,
  shift,
  makeHashTag,
  isEmpty 
  } = require('stringlib.js');

Functions

capitalize(str)

This function takes a string as input and returns the same string with the first character capitalized while keeping the rest of the characters unchanged.

Example:

console.log(capitalize('hello world')); // Returns: "Hello world"

allCaps(str)

This function converts all characters in the input string to uppercase.

Example:

console.log(allCaps('hello world')); // Returns: "HELLO WORLD"

capitalizeWords(str)

The capitalizeWords function capitalizes the first character of each word in the input string. Words are separated by spaces.

Example:

console.log(capitalizeWords('hello world')); // Returns: "Hello World"

capitalizeHeadlines(str)

The capitalizeHeadlines function capitalizes all of the words except the words: the, in, a, an, and, but, for, at, by, from unless one of these words is the first word of the string.

Example:

console.log(capitalizeHeadlines('the best dog a boy could have')); // Returns: "The Best Dog a Boy Could Have"

removeExtraSpaces(str)

removeExtraSpaces removes any leading, trailing, or extra spaces within the input string, ensuring that there is only one space between words.

Example:

console.log(removeExtraSpaces('   hello   world   ')); // Returns: "hello world"

kebabCase(str)

The kebabCase function converts the input string into kebab-case format. It removes extra spaces, replaces spaces with hyphens, and converts all characters to lowercase.

Example:

console.log(kebabCase('Hello   World')); // Returns: "hello-world"

snakeCase(str)

snakeCase transforms the input string into snake_case format. It removes extra spaces, replaces spaces with underscores, and converts all characters to lowercase.

Example:

console.log(snakeCase('Hello   World')); // Returns: "hello_world"

camelCase(str)

The camelCase function converts the input string into camelCase format. It removes extra spaces, lowercase the first character of the first word, and capitalizes the first character of each subsequent word, with no spaces between words.

Example:

console.log(camelCase('Hello   World')); // Returns: "helloWorld"

shift(str, number)

This function takes two arguments: a string (str) and a number (number). It shifts the specified number of characters from the beginning of the string to the end, resulting in a modified string.

Example:

console.log(shift('hello world', 2)); // Returns: "llo worldhe"

makeHashTag(str)

makeHashTag converts the given string into a hash tag format. It takes the input string, converts it to lowercase, splits it into an array of words, and sorts the array by word length. If there are more than three words, only the top three longest words are selected. The function then adds a '#' symbol to each word and returns an array of hash tags.

Example:

console.log(makeHashTag('Convert this string to hash tag')); // Returns: [ '#convert', '#string', '#tag' ]

isEmpty(str)

The isEmpty function returns true if the given string is empty or contains only whitespace. It trims the input string to remove leading and trailing spaces, and then checks if the resulting string is empty. Additionally, it iterates through the trimmed string and checks if each character is a newline, carriage return, or tab character. If none of these conditions are met, the function returns false.

Example:

console.log(isEmpty('     ')); // Returns: true
console.log(isEmpty('   hello   ')); // Returns: false