Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

string-analyzer

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-analyzer

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

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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.

FAQs

Package last updated on 27 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc