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

utilitylibrary-js

v1.0.2

Published

An npm package to use array methods,date formating,string manipulation,looping over arrays

Downloads

4

Readme

Welcome to Utility Library for JavaScript!

This npm package provides a versatile utility library for JavaScript developers, encompassing essential functionalities for array manipulation, conditional loops, date formatting, and string manipulation.

Utility Library for JavaScript

This npm package provides a versatile utility library for JavaScript developers, encompassing essential functionalities for array manipulation, conditional loops, date formatting, and string manipulation.

Installation

You can install the package via npm: npm install utilitylibrary-js

Import

Import in your project: import utilitylibrary from "utilitylibrary-js";

Usage

Array Methods:

Example Array : const myArray = [1, 2, 3, 4, 5, 3, 2];

  1. isEmpty(arr): Checks if an array is empty. Example: console.log("Is the array empty?", utilityLibrary.array.isEmpty(myArray)); //Is the array empty? false

  2. contains(arr, element): Checks if an array contains a specific element. Example console.log("Does the array contain3?",utilityLibrary.array.contains(myArray, 3)); //Does the array contain 3? true

  3. removeDuplicates(arr): Removes duplicates from an array. Example: console.log("Unique elements in the array:",utilityLibrary.array.removeDuplicates(myArray)); //Unique elements in the array:[1,2,3,4,5]

  4. flatten(arr): Flattens a nested array. Example: console.log("Flattened array:",utilityLibrary.array.flatten([[1, 2],[3, 4],[5, 6],])); //Flattened array: [ 1, 2, 3, 4, 5, 6 ]

  5. shuffle(arr): Shuffles the elements of an array. Example: console.log("Shuffled array:", utilityLibrary.array.shuffle(myArray)); //Shuffled array: [ 2, 3, 4, 5,3, 2, 1]

  6. sum(arr): Calculates the sum of all elements in an array. Example: console.log("Sum of array elements:", utilityLibrary.array.sum(myArray)); //Sum of array elements: 20

  7. average(arr): Calculates the average of all elements in an array. Example: console.log("Average of array elements:",utilityLibrary.array.average(myArray)); //Average of array elements: 2.857142857142857

  8. max(arr): Finds the maximum element in an array. Example: console.log("Maximum element in the array:", utilityLibrary.array.max(myArray)); Example: //Maximum element in the array: 5

  9. min(arr): Finds the minimum element in an array. Example: console.log("Minimum element in the array:", utilityLibrary.array.min(myArray)); //Minimum element in the array: 1

  10. filter() method: takes a callback function as an argument and returns a new array. Example: const evenNumbers = utilityLibrary.loop.filter(myArray, num => num % 2 === 0); console.log("Even numbers:", evenNumbers); //[2,4,2]

  11. map() method: iterates over an array and applies a callback function to each element& returns a new array containing the transformed elements. Example: const squaredNumbers = utilityLibrary.array.map(myArray,(number) => number * number); console.log(squaredNumbers); //[ 1, 4, 9, 16, 25, 9, 4]

  12. forEach() method: takes a callback function as an argument and applies it to each element of the array. Example: utilityLibrary.array.forEach(myArray, (number) => console.log(number * number)); //1 4 9 16 25 9 4

Conditional Loops

forEach() loop: const myArray = [1, 2, 3, 4, 5, 3, 2]; utilityLibrary.loop.forEach(myArray, (num) => console.log("Number:", num)); //Number: 1 Number: 2 Number: 3 Number: 4 Number: 5 Number: 3 Number: 2

Date Formatting

  1. formatDate(date, format): Formats a date object according to the specified format. Example: const currentDate = new Date();//Sun Mar 03 2024 11:43:49 GMT+0530 (India Standard Time) console.log("Formatted date:", utilityLibrary.formatDate(currentDate)); //Formatted date: March 3, 2024 at 11:43:03

String Manipulation

Example String: const myString = "hello world";

  1. capitalize(str): Capitalizes the first letter of a string. Example: console.log("Capitalized string:", utilityLibrary.string.capitalize(myString)); //Capitalized string: Hello world
  2. reverse(str): Reverses a string. Example: console.log("Reversed string:", utilityLibrary.string.reverse(myString)); //Reversed string: dlrow olleh
  3. truncate(str, length): Truncates a string to a specified length. Example: console.log("Truncated string:", utilityLibrary.string.truncate(myString, 5)); //Truncated string: hello...
  4. countOccurrences(str, substring): Counts the occurrences of a substring within a string. Example: console.log("Word count:", utilityLibrary.string.countWords(myString)); //Word count: 2
  5. removeWhitespace(str): Removes whitespace from the beginning and end of a string. Example: console.log("whiteSpace Removed:",utilityLibrary.string.removeWhitespace(myString)); //whiteSpace Removed: helloworld
  6. replace() method searches a string for a value or a regular expression& returns new string but not changes original string. Example: const replacedString = utilityLibrary.string.replace(myString,"world", "javascript"); console.log("Replaced string:", replacedString); //Replaced string: hello javascript

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests on the GitHub repository(https://github.com/mrshri/utilitylibrary-js).

License

This project is licensed under the Apache-2.0 License - see the LICENSE file for details.