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

perl-for-nodejs

v1.0.0

Published

Array and String Manipulation Kit

Downloads

54

Readme

Perl for Node.js: Array and String Manipulation Kit

Description

A powerful toolkit for robust array and string manipulation in Node.js, inspired by the text-processing capabilities of Perl.

Installation

npm install perl-for-nodejs

Usage

Array Manipulation

const ArrayManipulator = require('perl-for-nodejs');

const arrManip = new ArrayManipulator();
arrManip.addElement(10);
arrManip.addElement(5);
arrManip.displayArray();  // Outputs: Current array: [10, 5]
arrManip.sortArray();
arrManip.displayArray();  // Outputs: Current array: [5, 10]
arrManip.reverseArray();
arrManip.displayArray();  // Outputs: Current array: [10, 5]
arrManip.insertElementAt(20, 1);
arrManip.displayArray();  // Outputs: Current array: [10, 20, 5]
arrManip.mergeArray([7, 8, 9]);
arrManip.displayArray();  // Outputs: Current array: [10, 20, 5, 7, 8, 9]
console.log("Max element:", arrManip.findMax());  // Outputs: Max element: 20
console.log("Min element:", arrManip.findMin());  // Outputs: Min element: 5
arrManip.removeDuplicates();
arrManip.displayArray();  // Outputs: Current array: [10, 20, 5, 7, 8, 9]

// Array manipulation methods
arrManip.mapArray(x => x * 2);  // Outputs: Mapped array: [20, 40, 10, 14, 16, 18]
const sum = arrManip.reduceArray((acc, val) => acc + val, 0);  // Outputs: Reduced array result: 118
arrManip.filterArray(x => x > 15);  // Outputs: Filtered array: [20, 40, 16, 18]

String Manipulation

const StringManipulator = require('perl-for-nodejs/stringManipulator');

const strManip = new StringManipulator();
console.log(strManip.toUpperCase("hello"));  // Outputs: HELLO
console.log(strManip.reverseString("world"));  // Outputs: dlrow
console.log(strManip.isPalindrome("racecar"));  // Outputs: true
console.log(strManip.trimWhitespace("  hello world  "));  // Outputs: hello world
console.log(strManip.replaceSubstring("hello world", "world", "there"));  // Outputs: hello there
console.log(strManip.countOccurrences("hello world", "l"));  // Outputs: 3
console.log(strManip.containsSubstring("hello world", "world"));  // Outputs: true
console.log(strManip.splitString("hello world", " "));  // Outputs: [ 'hello', 'world' ]
console.log(strManip.toCamelCase("hello_world-example"));  // Outputs: helloWorldExample
console.log(strManip.toSnakeCase("helloWorldExample"));    // Outputs: hello_world_example
console.log(strManip.findLongestWord("Find the longest word in this sentence"));  // Outputs: sentence
console.log(strManip.findShortestWord("Find the shortest word"));  // Outputs: the
console.log(strManip.countVowelsAndConsonants("Hello World!"));  // Outputs: { vowels: 3, consonants: 7 }
console.log(strManip.removeNonAlphanumeric("Hello, World!"));  // Outputs: Hello World
console.log(strManip.shuffleCharacters("abcdef"));  // Outputs: Randomly shuffled characters of "abcdef"
console.log(strManip.countWords("Hello world! This is an example."));  // Outputs: 5

Methods

ArrayManipulator Methods

  • addElement(element): Adds an element to the array.
  • removeElement(element): Removes an element from the array.
  • getElement(index): Gets an element by its index.
  • displayArray(): Displays the current array.
  • sortArray(): Sorts the array in ascending order.
  • reverseArray(): Reverses the order of the array.
  • insertElementAt(element, index): Inserts an element at a specified index.
  • mergeArray(newArray): Merges another array into the current array.
  • findMax(): Finds the maximum element in the array.
  • findMin(): Finds the minimum element in the array.
  • removeDuplicates(): Removes duplicate elements from the array.
  • mapArray(callback): Applies a callback function to each element and returns the modified array.
  • reduceArray(callback, initialValue): Reduces the array to a single value using a callback function and an initial value.
  • filterArray(callback): Filters the array based on a callback function.

StringManipulator Methods

  • toUpperCase(str): Converts a string to uppercase.
  • toLowerCase(str): Converts a string to lowercase.
  • capitalizeFirstLetter(str): Capitalizes the first letter of a string.
  • reverseString(str): Reverses a string.
  • isPalindrome(str): Checks if a string is a palindrome.
  • trimWhitespace(str): Trims leading and trailing whitespace from a string.
  • replaceSubstring(str, searchValue, newValue): Replaces all occurrences of a substring with a new value.
  • countOccurrences(str, substring): Counts the number of occurrences of a substring in a string.
  • containsSubstring(str, substring): Checks if a string contains a specific substring.
  • splitString(str, delimiter): Splits a string into an array based on a delimiter.
  • toCamelCase(str): Converts a string to camelCase.
  • toSnakeCase(str): Converts a string to snake_case.
  • findLongestWord(str): Finds and returns the longest word in a string.
  • findShortestWord(str): Finds and returns the shortest word in a string.
  • countVowelsAndConsonants(str): Counts the number of vowels and consonants in a string.
  • removeNonAlphanumeric(str): Removes non-alphanumeric characters from a string.
  • shuffleCharacters(str): Shuffles the characters of a string.
  • countWords(str): Counts the number of words in a string.