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

string-transformation

v2.1.0

Published

Makes working with strings easy and also provide uuid.

Downloads

2

Readme

String Transformation

A JavaScript module for performing various string transformation tasks. To install this module run command

npm i string-transformation

Current Features Badge Badge

Import Module

const stringUtil = require('string-transformation');
stringUtil.stringLength(str);

OR

const { stringLength } = require('string-transformation');

Functions

stringLength(str)

Calculates the length of the given string.

Input:

stringLength('Hello, World!');

Output:

13

convertToUpperCase(str)

Convert string to UpperCase.

Input:

convertToUpperCase('hello');

Output:

HELLO

convertToLowerCase(str)

Convert string to LowerCase.

Input:

convertToLowerCase('WORLD');

Output:

world

capitalizeFirstLetter(str)

Capitalize first character of string.

Input:

capitalizeFirstLetter('hello world!');

Output:

Hello world!

convertToTitleCase(str)

Capitalize first character of every word in the string.

Input:

convertToTitleCase('this is a test sentence');

Output:

This Is A Test Sentence

getSubstring(str, start, end)

Get a substring from the string.

Input:

getSubstring('abcdef', 1, 4);

Output:

bcd

trimWhitespace(str)

Trim white space from both end of the string.

Input:

trimWhitespace('   Hello, World!   ');

Output:

Hello, World!

trimLeft(str)

Trim leading white space from string.

Input:

trimLeft('   Leading whitespace');

Output:

Leading whitespace

trimRight(str)

Trim trailing white space from string.

Input:

trimRight('Trailing whitespace   ');

Output:

Trailing whitespace

replaceCharacter(str, oldChar, newChar)

Replace a character in the string.

Input:

replaceCharacter('banana', 'a', 'o');

Output:

bonono

removeCharacter(str, charToRemove)

Remove a character from the string.

Input:

removeCharacter('banana', 'a');

Output:

bnn

splitString(str, delimiter)

Split string and gives an array.

Input:

splitString('apple,orange,banana', ',');

Output:

[ 'apple', 'orange', 'banana' ]

joinStrings(array, delimiter)

Joins an array of string and provides a string.

Input:

joinStrings(['apple', 'orange', 'banana'], ', ');

Output:

apple, orange, banana

firstOccurrence(str, substring)

Get the first occorrence of a substring in a string.

Input:

firstOccurrence('programming', 'g');

Output:

3

findAllOccurrences(str, substring)

Get all the occorrence of a substring in a string as a array.

Input:

findAllOccurrences('banana', 'a');

Output:

[1, 3, 5]

replaceSubstring(str, oldSubstring, newSubstring)

Replace a substring from the string with a new string.

Input:

replaceSubstring('hello world', 'world', 'there');

Output:

hello there

replaceWhitespaceWith(str, newCharacter)

Remove white space from string and replace it with new character.

Input:

replaceWhitespaceWith('Hello    World!', '-');

Output:

Hello----World!

padLeft(str, padChar, totalLength)

Make the string longer by adding padding character to the left of the string if the string is shorter than the total required length of the string.

Input:

padLeft('42', '0', 5);

Output:

00042

padRight(str, padChar, totalLength)

Make the string longer by adding padding character to the right of the string if the string is shorter than the total required length of the string.

Input:

padRight('42', '0', 5);

Output:

42000

reverseString(str)

Reverse the string.

Input:

reverseString('world');

Output:

dlrow

isPalindrome(str)

Check if the provided string is a palindrome.

Input:

isPalindrome('racecar');

Output:

true

isNumeric(str)

Check if the provided string contains only numeric values (numbers).

Input:

isNumeric('42.5');

Output:

true

encodeBase64(str)

Encode the provided string to base64.

Input:

encodeBase64('Hello, World!');

Output:

SGVsbG8sIFdvcmxkIQ==

decodeBase64(str)

Decode base64 code to string.

Input:

decodeBase64('SGVsbG8sIFdvcmxkIQ==');

Output:

Hello, World!

matchRegex(str, regex)

Returns an array of all occurrences of a given regular expression pattern in a string.

Input:

matchRegex('abc123def456', /\d+/g);

Output:

["123", "456"]

replaceRegex(str, regex, replacement)

Replaces occurrences of a given regular expression pattern with a specified replacement in a string.

Input:

replaceRegex('abc123def456', /\d+/g, 'X');

Output:

abcXdefX

encodeURIComponent(str)

Encodes a string for safe use in a URL.

Input:

encodeURIComponent('Hello, World!');

Output:

Hello%2C%20World!

decodeURIComponent(str)

Decodes a URL-encoded string back to its original form.

Input:

decodeURIComponent('Hello%2C%20World%21');

Output:

Hello, World!

getPathFromURL(url)

Extracts the path portion from a given URL.

Input:

getPathFromURL('https://example.com/path/file.html');

Output:

/path/file.html

compareStrings(str1, str2)

Compares two strings lexicographically and returns a comparison result.

Input:

compareStrings('apple', 'banana');

Output:

-1

equalsIgnoreCase(str1, str2)

Checks if two strings are equal, ignoring their case.

Input:

equalsIgnoreCase('hello', 'Hello');

Output:

true

formatString(format, ...values)

Formats a string using placeholders and corresponding values.

Input:

formatString('Hello, {0}!', 'World');

Output:

Hello, World!

Input:

formatString('Hello {0}, Hello {1}!', 'there', 'World');

Output:

Hello there, Hello World!

getUnicodeCodePointAt(str, index)

Retrieves the Unicode code point at a specific position in a string.

Input:

getUnicodeCodePointAt('A', 0);

Output:

65

convertToUnicode(str)

Converts a string to a sequence of Unicode code points.

Input:

convertToUnicode('Hello');

Output:

U+48 U+65 U+6c U+6c U+6f

truncateText(str, maxLength, ellipsis)

Truncates a string to a specified length with an optional ellipsis.

Input:

truncateText('Lorem ipsum dolor sit amet', 15);

Output:

Lorem ipsum dol...

normalizeWhitespace(str)

Replaces consecutive whitespace characters with a single space.

Input:

normalizeWhitespace('  Hello    World!   ');

Output:

 Hello World! 

collapseWhitespace(str)

Removes all whitespace characters from a string.

Input:

collapseWhitespace('Hello   World!');

Output:

HelloWorld! 

getCharacterType(char)

Determines the type of a character (uppercase, lowercase, digit, etc.).

Input:

getCharacterType('A');

Output:

uppercase 

getCharacterCode(char)

Retrieves the Unicode code point of a character.

Input:

getCharacterCode('A');

Output:

65 

padWithContent(str, padContent, totalLength)

Pads a string with a specified content to achieve a desired length.

Input:

padWithContent('Hello', '*', 10);

Output:

**Hello***

convertToCamelCase(str)

Converts a string to camel case format.

Input:

convertToCamelCase('hello-world');

Output:

helloWorld

convertToSnakeCase(str)

Converts a string to snake case format.

Input:

convertToSnakeCase('helloWorld');

Output:

hello_world

wrapText(text, maxWidth)

Wraps a long text string into multiple lines with a specified maximum width.

Input:

wrapText('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 20);

Output:

Lorem ipsum dolor sit
amet, consectetur
adipiscing elit.

uuid()

Provide uuid for (Universally Unique IDentifier).

Input:

uuid();

Output:

28d921a6-fc82-2dcf79-8244-c7112d52af

uuidNumber()

Provide uuid which only consist of numbers.

Input:

uuidNumber();

Output:

500879049-52937-13546-19988-1519210004

uuidDateTime()

Provide uuid based on Date and Time.

Input:

uuidDateTime();

Output:

1ee41006916c750-faba78b560-1ee4-9234-0123456789ab