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-analyzer

v1.1.2

Published

A JavaScript package that provides a function to analyze a given string and returns various details about it, such as its length, character count, word count, presence of numbers, special characters, whitespace, and whether it's a palindrome. Additionally

Downloads

9

Readme

String Analyzer

This JavaScript function, analyzeString(), analyzes a given string and returns various details about it.

Installation

This function does not require any installation. You can simply include it in your JavaScript code.

Functionality

The analyzeString() function takes a string as input and returns an object containing the following details:

  • length: Length of the input string.
  • characterCount: Number of characters in the string.
  • wordCount: Number of words in the string.
  • containsNumbers: Boolean indicating whether the string contains any numeric digits.
  • containsSpecialCharacters: Boolean indicating whether the string contains any special characters.
  • containsWhitespace: Boolean indicating whether the string contains any whitespace characters.
  • isAllUpperCase: Boolean indicating whether the string is entirely uppercase.
  • isAllLowerCase: Boolean indicating whether the string is entirely lowercase.
  • isPalindrome: Boolean indicating whether the string is a palindrome (reads the same forwards and backwards).

Example

Input

const input = "A man, a plan, a canal, Panama!";
const stringDetails = analyzeString(input);

Expected Output

{
  "length": 30,
  "characterCount": 27,
  "wordCount": 6,
  "containsNumbers": false,
  "containsSpecialCharacters": true,
  "containsWhitespace": true,
  "isAllUpperCase": false,
  "isAllLowerCase": false,
  "isPalindrome": true
}

Additional Functionalities with update 1.1.1

In addition to the functionalities described above, the analyzeString() function now includes the following additional features:

  • characterFrequency: Returns an object containing the frequency of each character in the input string.

    Input

    const input = "hello";
    const characterFreq = analyzeString(input).characterFrequency;

    Expected Output

    {
      "h": 1,
      "e": 1,
      "l": 2,
      "o": 1
    }
  • vowelCount: Number of vowels in the string.

    Input

    const input = "hello world";
    const vowelCount = analyzeString(input).vowelCount;

    Expected Output

    3
  • consonantCount: Number of consonants in the string.

    Input

    const input = "hello world";
    const consonantCount = analyzeString(input).consonantCount;

    Expected Output

    7
  • isAnagram: Determines whether two input strings are anagrams of each other.

    Input

    const input1 = "listen";
    const input2 = "silent";
    const isAnagram = analyzeString(input1).isAnagram(input1, input2);

    Expected Output

    true
  • isAntigram: Determines whether two input strings are antigrams of each other.

    Input

    const input1 = "hello";
    const input2 = "world";
    const isAntigram = analyzeString(input1).isAntigram(input1, input2);

    Expected Output

    false
  • countSubstringOccurrences: Counts the number of occurrences of a substring in the input string.

    Input

    const input = "hello world hello";
    const substring = "hello";
    const count = analyzeString(input).countSubstringOccurrences(input, substring);

    Expected Output

    2
  • startsWith: Checks if the input string starts with a certain substring.

    Input

    const input = "hello world";
    const substring = "hello";
    const startsWith = analyzeString(input).startsWith(input, substring);

    Expected Output

    true
  • endsWith: Checks if the input string ends with a certain substring.

    Input

    const input = "hello world";
    const substring = "world";
    const endsWith = analyzeString(input).endsWith(input, substring);

    Expected Output

    true
  • longestWord: Returns the longest word in the input string.

    Input

    const input = "hello beautiful world";
    const longestWord = analyzeString(input).longestWord;

    Expected Output

    "beautiful"
  • reverseWords: Reverses the order of words in the input string.

    Input

    const input = "hello world";
    const reversedWords = analyzeString(input).reverseWords(input);

    Expected Output

    "world hello"

These additional functionalities enhance the capabilities of the analyzeString() function, providing users with a comprehensive tool for string analysis and manipulation.