New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 - npm Package Compare versions

Comparing version 1.0.1 to 1.1.1

67

index.js

@@ -11,3 +11,13 @@ function analyzeString(inputString) {

isAllLowerCase: inputString.toLowerCase() === inputString,
isPalindrome: isPalindrome(inputString)
isPalindrome: isPalindrome(inputString),
characterFrequency: countCharacterFrequency(inputString),
vowelCount: countVowels(inputString),
consonantCount: countConsonants(inputString),
isAnagram: isAnagram,
isAntigram: isAntigram,
countSubstringOccurrences: countSubstringOccurrences,
startsWith: startsWith,
endsWith: endsWith,
longestWord: findLongestWord(inputString),
reverseWords: reverseWords(inputString)
};

@@ -32,3 +42,56 @@

function countCharacterFrequency(inputString) {
const characterCounts = {};
for (const char of inputString) {
characterCounts[char] = (characterCounts[char] || 0) + 1;
}
return characterCounts;
}
module.exports = analyzeString;
function countVowels(inputString) {
const vowels = /[aeiou]/gi;
return (inputString.match(vowels) || []).length;
}
function countConsonants(inputString) {
const consonants = /[bcdfghjklmnpqrstvwxyz]/gi;
return (inputString.match(consonants) || []).length;
}
function isAnagram(inputString1, inputString2) {
const cleanedString1 = inputString1.toLowerCase().replace(/[^a-z]/g, '');
const cleanedString2 = inputString2.toLowerCase().replace(/[^a-z]/g, '');
return cleanedString1.split('').sort().join('') === cleanedString2.split('').sort().join('');
}
function isAntigram(inputString1, inputString2) {
const cleanedString1 = inputString1.toLowerCase().replace(/[^a-z]/g, '');
const cleanedString2 = inputString2.toLowerCase().replace(/[^a-z]/g, '');
return cleanedString1.split('').every(char => !cleanedString2.includes(char));
}
function countSubstringOccurrences(inputString, substring) {
const regex = new RegExp(substring, 'gi');
const matches = inputString.match(regex);
return matches ? matches.length : 0;
}
function startsWith(inputString, substring) {
return inputString.startsWith(substring);
}
function endsWith(inputString, substring) {
return inputString.endsWith(substring);
}
function findLongestWord(inputString) {
const words = inputString.split(/\s+/).filter(word => word.trim() !== '');
if (words.length === 0) return null;
return words.reduce((longest, current) => current.length > longest.length ? current : longest, "");
}
function reverseWords(inputString) {
return inputString.split(/\s+/).map(word => word.split('').reverse().join('')).join(' ');
}
module.exports = analyzeString;

6

package.json
{
"name": "string-analyzer",
"version": "1.0.1",
"description": "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.",
"version": "1.1.1",
"description": "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, it includes functionalities for character frequency analysis, counting vowels and consonants, checking for anagrams and antigrams, assessing readability, and performing string transformations like reversing and capitalizing.",
"main": "index.js",

@@ -12,5 +12,5 @@ "scripts": {

"type": "git",
"url": "https://github.com/LaXnZ/intro-to-node-js.git"
"url": "https://github.com/LaXnZ/string-analyzer.git"
},
"license": "ISC"
}

@@ -23,17 +23,14 @@ # String Analyzer

## **Example**
## Example
### **Input**
### Input
```jsx
javascript
```javascript
const input = "A man, a plan, a canal, Panama!";
const stringDetails = analyzeString(input);
```
### **Expected Output**
### Expected Output
```json
json
{

@@ -48,4 +45,170 @@ "length": 30,

"isAllLowerCase": false,
"isPalindrome": true}
"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
```javascript
const input = "hello";
const characterFreq = analyzeString(input).characterFrequency;
```
### Expected Output
```json
{
"h": 1,
"e": 1,
"l": 2,
"o": 1
}
```
- **vowelCount**: Number of vowels in the string.
### Input
```javascript
const input = "hello world";
const vowelCount = analyzeString(input).vowelCount;
```
### Expected Output
```json
3
```
- **consonantCount**: Number of consonants in the string.
### Input
```javascript
const input = "hello world";
const consonantCount = analyzeString(input).consonantCount;
```
### Expected Output
```json
7
```
- **isAnagram**: Determines whether two input strings are anagrams of each other.
### Input
```javascript
const input1 = "listen";
const input2 = "silent";
const isAnagram = analyzeString(input1).isAnagram(input1, input2);
```
### Expected Output
```json
true
```
- **isAntigram**: Determines whether two input strings are antigrams of each other.
### Input
```javascript
const input1 = "hello";
const input2 = "world";
const isAntigram = analyzeString(input1).isAntigram(input1, input2);
```
### Expected Output
```json
false
```
- **countSubstringOccurrences**: Counts the number of occurrences of a substring in the input string.
### Input
```javascript
const input = "hello world hello";
const substring = "hello";
const count = analyzeString(input).countSubstringOccurrences(input, substring);
```
### Expected Output
```json
2
```
- **startsWith**: Checks if the input string starts with a certain substring.
### Input
```javascript
const input = "hello world";
const substring = "hello";
const startsWith = analyzeString(input).startsWith(input, substring);
```
### Expected Output
```json
true
```
- **endsWith**: Checks if the input string ends with a certain substring.
### Input
```javascript
const input = "hello world";
const substring = "world";
const endsWith = analyzeString(input).endsWith(input, substring);
```
### Expected Output
```json
true
```
- **longestWord**: Returns the longest word in the input string.
### Input
```javascript
const input = "hello beautiful world";
const longestWord = analyzeString(input).longestWord;
```
### Expected Output
```json
"beautiful"
```
- **reverseWords**: Reverses the order of words in the input string.
### Input
```javascript
const input = "hello world";
const reversedWords = analyzeString(input).reverseWords(input);
```
### Expected Output
```json
"world hello"
```
These additional functionalities enhance the capabilities of the `analyzeString()` function, providing users with a comprehensive tool for string analysis and manipulation.
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