New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

basic-utility-belt

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

basic-utility-belt

Basic Utility Belt is a versatile collection of essential utility functions designed to simplify a wide range of common programming tasks. Whether you need to manipulate dates, perform arithmetic operations, or process strings, this toolkit has you covere

  • 1.0.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

Basic Utility Belt

Basic Utility Belt is a versatile collection of essential utility functions designed to simplify a wide range of common programming tasks. Whether you need to manipulate dates, perform arithmetic operations, or process strings, this toolkit has you covered. Enhance your development workflow with these reliable and easy-to-use functions, all in one convenient package.

Navigation

  • Installation
  • Features
  • Docs
  • License

Installation

You can install Basic Utility Belt via npm:

npm install basic-utility-belt

Features

  • Arithmetic operations
  • Date and time manipulation
  • String processing
  • and more...

Docs

numbers

getRandomNumber(min, max)

Generate a random number within a specified range.

  • min: The minimum value.
  • max: The maximum value.
  • Returns: A random number between min and max (inclusive).
clamp(num, min, max)

Clamp a number within a specified range.

  • num: The number to clamp.
  • min: The minimum value.
  • max: The maximum value.
  • Returns: The clamped number.
round(num, decimalPlaces)

Round a number to a specified number of decimal places.

  • num: The number to round.
  • decimalPlaces: The number of decimal places.
  • Returns: The rounded number.
average(numbers)

Calculate the average of an array of numbers.

  • numbers: The array of numbers.
  • Returns: The average of the numbers.
sum(numbers)

Calculate the sum of an array of numbers.

  • numbers: The array of numbers.
  • Returns: The sum of the numbers.
factorial(num)

Calculate the factorial of a number.

  • num: The number to calculate the factorial of.
  • Returns: The factorial of the number.
fibonacci(numTerms)

Generate a Fibonacci sequence up to a specified number of terms.

  • numTerms: The number of terms in the Fibonacci sequence.
  • Returns: The Fibonacci sequence.
isPrime(num)

Check if a number is a prime number.

  • num: The number to check.
  • Returns: True if the number is prime, false otherwise.
gcd(...numbers)

Calculate the greatest common divisor of multiple numbers.

  • ...numbers: Numbers for which to calculate the greatest common divisor.
  • Returns: The greatest common divisor.
lcm(...numbers)

Calculate the least common multiple of multiple numbers.

  • ...numbers: Numbers for which to calculate the least common multiple.
  • Returns: The least common multiple.

dates

getCalendarDays(startDate, endDate)

Calculate the number of days between two dates, inclusive of both the start and end dates.

  • startDate: The start date.
  • endDate: The end date.
  • Returns: The number of days between the two dates.
getWorkingDays(startDate, endDate)

Calculate the number of working days (Monday to Friday) between two dates, inclusive of both the start and end dates.

  • startDate: The start date.
  • endDate: The end date.
  • Returns: The number of working days between the two dates.
addDays(date, days)

Add a specified number of days to a date.

  • date: The date to add days to.
  • days: The number of days to add.
  • Returns: The new date after adding days.
subtractDays(date, days)

Subtract a specified number of days from a date.

  • date: The date to subtract days from.
  • days: The number of days to subtract.
  • Returns: The new date after subtracting days.
getDayOfWeek(date)

Get the day of the week from a date.

  • date: The date to get the day of the week from.
  • Returns: The day of the week as a string.
isLeapYear(year)

Check if a year is a leap year.

  • year: The year to check.
  • Returns: true if the year is a leap year, false otherwise.

strings

capitalize(str)

Capitalize the first letter of a string.

  • str: The input string.
  • Returns: The string with the first letter capitalized.
camelCase(str)

Convert a string to camel case.

  • str: The input string.
  • Returns: The string in camel case.
reverseString(str)

Reverse a given string.

  • str: The input string.
  • Returns: The reversed string.
escapeHTML(str)

Escape HTML special characters in a string.

  • str: The input string.
  • Returns: The string with HTML special characters escaped.

arrays

shuffleArray(array)

Randomly shuffle the elements of an array.

  • array: The array to shuffle.
  • Returns: The shuffled array.
uniqueArray(array)

Remove duplicates from an array.

  • array: The array to remove duplicates from.
  • Returns: The array with duplicates removed.
flattenArray(array)

Flatten a nested array.

  • array: The nested array to flatten.
  • Returns: The flattened array.
chunkArray(array, size)

Split an array into chunks of a specified size.

  • array: The array to chunk.
  • size: The size of each chunk.
  • Returns: An array containing the chunked arrays.

regexs

validateEmail(email)

Validate an email address format.

  • email: The email address to validate.
  • Returns: true if the email address is valid, false otherwise.
validateURL(url)

Validate a URL format.

  • url: The URL to validate.
  • Returns: true if the URL is valid, false otherwise.
validateCreditCard(cardNumber)

Validate a credit card number format.

  • cardNumber: The credit card number to validate.
  • Returns: true if the credit card number is valid, false otherwise.
validateIPv4(ipv4Address)

Validate an IPv4 address format.

  • ipv4Address: The IPv4 address to validate.
  • Returns: true if the IPv4 address is valid, false otherwise.
validateIPv6(ipv6Address)

Validate an IPv6 address format.

  • ipv6Address: The IPv6 address to validate.
  • Returns: true if the IPv6 address is valid, false otherwise.
validateDate(dateString)

Validate a date string format.

  • dateString: The date string to validate.
  • Returns: true if the date string is valid, false otherwise. Note: This function supports many common date formats but may not cover all edge cases.

License

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

Keywords

FAQs

Package last updated on 26 May 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