1.0.7 • Published 26 days ago

utility-validate v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
26 days ago

utility-validate

A collection of validators, sanitizers, and utilities.

npm version Bundlephobia Downloads MIT License jsDocs.io

Contents

Installation

Install via NPM:

npm install utility-validate

Or via Yarn:

yarn add utility-validate

Usage

First, import the utility-validate function:

import utilityValidate from 'utility-validate';

You can now utilize the library's methods:

const {isEmail, removeWhitespace, sanitizeAlphaNumericSpace} = utilityValidate();
const email = isEmail('blckclov3r@gmail.com')
console.log(email) // true

If you prefer not to install the package and want to include the entry point directly in your project, you can use the following script tags:

<script type="module">
    import {isEmail} from 'https://unpkg.com/utility-validate@1.0.7/dist/index.mjs';

    const email = isEmail('blckclov3r@gmail.com')
    console.log(email) // true
</script>

Utility

Function NameDescription
generateRandomStringGenerates a random string.
removeWhitespaceRemoves whitespace from a string.
sanitizeAlphaNumericSpaceSanitizes a string, keeping alphanumeric characters and spaces.
sanitizeAlphaNumericLowerSanitizes a string, keeping only lowercase alphanumeric characters.
sanitizeAlphaNumericUpperSanitizes a string, keeping only uppercase alphanumeric characters.
sanitizeNumericValueSanitizes a string, keeping only numeric characters.
sanitizeIntegerValueSanitizes a string, keeping only integer values.
sanitizeAlphaLowerSanitizes a string, keeping only lowercase alphabetic characters.
sanitizeAlphaUpperSanitizes a string, keeping only uppercase alphabetic characters.
escapeHTMLEscapes HTML special characters in a string.
removeNonPrintableASCIIRemoves non-printable ASCII characters from a string.
removeControlCharactersRemoves control characters from a string.
trimWhitespaceTrims whitespace from the beginning and end of a string.
removeDuplicateCharsRemoves duplicate characters from a string.
removeExtraWhitespaceRemoves extra whitespace from a string.
decodeHTMLEntitiesDecodes HTML entities in a string.
countCharacterCounts occurrences of a character in a string.
collapseSpacesCollapses consecutive spaces in a string to a single space.
removeNonNumericRemoves non-numeric characters from a string.
extractNumbersExtracts numeric values from a string.
reverseStringReverses a string.
capitalizeStrCapitalizes the first letter of each word in a string.
truncateStrTruncates a string to a specified length.
slugifyConverts a string to a URL-friendly slug.
countWordsCounts the number of words in a string.
replaceStrReplaces occurrences of a substring in a string.
toKebabCaseConverts a string to kebab case.
toSnakeCaseConverts a string to snake case.
toCamelCaseConverts a string to camel case.
startsWithChecks if a string starts with a specified substring.
endsWithChecks if a string ends with a specified substring.
containsChecks if a string contains a specified substring.
splitStringSplits a string into an array of substrings.
encodeToBase64Encodes a string to Base64.
decodeFromBase64Decodes a Base64 string.
getCurrentLogDateGets the current date formatted for logging.
getCurrentYYYYMMDDGets the current date in YYYYMMDD format.
getCurrentYYYYMMDDStrGets the current date as a string in YYYYMMDD format.
getCurrentYYYYMMDDHHmmssSSSGets the current date and time in YYYYMMDDHHmmssSSS format.
getUnixTimestampGets the current Unix timestamp.
toSafeNumberConverts a value to a safe number.
randomIntInRangeGenerates a random integer within a specified range.
shuffleArrayShuffles the elements of an array.
sanitizeEmailSanitizes an email address.
sanitizeUrlSanitizes a URL.
sanitizePhoneNumberSanitizes a phone number.
sanitizeAlphaNumericSpecialSanitizes a string, keeping alphanumeric characters and special characters.
sanitizeAlphaNumericAccentsSanitizes a string, keeping alphanumeric characters and accents.
sanitizeHtmlTagsSanitizes HTML tags from a string.
sanitizeFileNameSanitizes a filename.
sanitizeJsonSanitizes JSON data.
sanitizeBase64Sanitizes a Base64 string.
sanitizeHexadecimalSanitizes a hexadecimal string.
sanitizeIPv4Sanitizes an IPv4 address.
sanitizeIPv6Sanitizes an IPv6 address.
sanitizeSSNSanitizes a Social Security Number (SSN).
sanitizeWithAllowedCharactersSanitizes a string, keeping only specified allowed characters.
toPascalCaseConverts a string to Pascal case.
toConstantCaseConverts a string to constant case.
toTrainCaseConverts a string to train case.
toMacroCaseConverts a string to macro case.
stringifyJsonConverts JSON data to a string.
mapValuesJsonMaps values of a JSON object.
mapKeysJsonMaps keys of a JSON object.
omitJsonOmits specified keys from a JSON object.
removeFalsyValuesRemoves falsy values from an array.
groupObjectsByKeyGroups objects in an array by a specified key.
findMaxValueFinds the maximum value in an array.
findMinValueFinds the minimum value in an array.
calculateMedianCalculates the median of an array of numbers.
calculateStandardDeviationCalculates the standard deviation of an array of numbers.
deepCloneCreates a deep clone of an object.
distinctValuesFinds distinct values in an array.
calculateFactorialCalculates the factorial of a number.
calculatePowerCalculates the power of a number.
roundToDecimalPlacesRounds a number to a specified number of decimal places.
generateRangeGenerates a range of numbers.
calculateSquareRootCalculates the square root of a number.
calculateAbsoluteValueCalculates the absolute value of a number.
calculateLCMCalculates the least common multiple of two numbers.
toBinaryConverts a number to binary.
fromBinaryConverts binary to a number.
toMorseCodeConverts a string to Morse code.
fromMorseCodeConverts Morse code to a string.
trimStartTrims whitespace from the beginning of a string.
trimEndTrims whitespace from the end of a string.
padStartPads the start of a string with specified characters.
padEndPads the end of a string with specified characters.
substringExtracts a substring from a string.
indexOfReturns the index of the first occurrence of a substring in a string.
lastIndexOfReturns the index of the last occurrence of a substring in a string.
extractURLsExtracts URLs from a string.
extractEmailsExtracts email addresses from a string.
extractHashtagsExtracts hashtags from a string.
extractMentionsExtracts mentions from a string.
removeHTMLTagsRemoves HTML tags from a string.
removeSpecificHTMLTagsRemoves specific HTML tags from a string.
replaceHTMLEntitiesReplaces HTML entities in a string.
encloseStringWithEncloses a string with specified characters.
trimMultiLineStringTrims whitespace from the beginning and end of each line in a multiline string.
padWithAlternatingCharsPads a string with alternating characters.
replaceIfSurroundedByWhitespaceReplaces a substring if it's surrounded by whitespace.
toFixedLengthWithRepeatTruncates or pads a string to a fixed length, repeating characters if necessary.
formatJsonFormats JSON data for readability.
toFixedLengthWithEllipsisTruncates or pads a string to a fixed length, adding an ellipsis if necessary.
toFixedLengthWithFillerTruncates or pads a string to a fixed length, filling with a specified filler character.
toTitleCaseExceptConverts a string to title case, excluding specified words.
generateFibonacciSequenceGenerates a Fibonacci sequence up to a specified length.
factorialCalculates the factorial of a number.
calculateCircleAreaCalculates the area of a circle.
degreesToRadiansConverts degrees to radians.
radiansToDegreesConverts radians to degrees.
secondsToHHMMSSConverts seconds to HH:MM:SS format.
bytesToHumanReadableConverts bytes to a human-readable format.
getCurrentTimestampInSecondsGets the current timestamp in seconds.
millisecondsToSecondsConverts milliseconds to seconds.
secondsToMillisecondsConverts seconds to milliseconds.
formatDateFormats a date according to specified format.
getCurrentTimeGets the current time in HH:MM:SS format.
introSortSorts an array using intro sort algorithm.
mergeSortSorts an array using merge sort algorithm.
quickSortSorts an array using quick sort algorithm.
timSortSorts an array using Timsort algorithm.

Validate

Function NameDescription
isPositiveChecks if a number is positive.
isNegativeChecks if a number is negative.
isZeroChecks if a number is zero.
isEmptyJsonChecks if a JSON object is empty.
isIPv4Checks if a string is an IPv4 address.
isIPv6Checks if a string is an IPv6 address.
isLeapYearChecks if a year is a leap year.
isPrimeChecks if a number is a prime number.
isEvenChecks if a number is even.
isInRangeChecks if a number is within a specified range.
isOddChecks if a number is odd.
isDecimalChecks if a number is a decimal.
isDivisibleChecks if a number is divisible by another.
isMACAddressChecks if a string is a MAC address.
isIntegerChecks if a number is an integer.
isFloatChecks if a number is a float.
isObjectChecks if a value is an object.
isTruthyChecks if a value is truthy.
isFalsyChecks if a value is falsy.
isErrorChecks if a value is an error.
isRegExpChecks if a value is a regular expression.
isPromiseChecks if a value is a promise.
isNumberChecks if a value is a number.
isBooleanChecks if a value is a boolean.
isFunctionChecks if a value is a function.
isSymbolChecks if a value is a symbol.
isUndefinedChecks if a value is undefined.
isNullChecks if a value is null.
isBlobChecks if a value is a Blob object.
isFileChecks if a value is a File object.
isBigIntChecks if a value is a BigInt.
isCreditCardChecks if a string is a credit card number.
isURLChecks if a string is a URL.
isDateChecks if a value is a Date object.
isEmptyChecks if a value is empty.
isEqualArrayChecks if two arrays are equal.
isEqualObjectChecks if two objects are equal.
isAsciiChecks if a string contains only ASCII characters.
isDivisibleByChecks if a number is divisible by a specified value.
isHexadecimalChecks if a string is a hexadecimal number.
isHexColorChecks if a string is a hexadecimal color code.
isHSLChecks if a string is an HSL color code.
isIMEIChecks if a string is an IMEI number.
isISBNChecks if a string is an ISBN number.
isJSONChecks if a string is a valid JSON.
isJWTChecks if a string is a JSON Web Token (JWT).
isEmailChecks if a string is an email address.
isPalindromeChecks if a string is a palindrome.
isSSNChecks if a string is a Social Security Number (SSN).
isVINChecks if a string is a Vehicle Identification Number (VIN).
isLatitudeChecks if a string is a latitude coordinate.
isLongitudeChecks if a string is a longitude coordinate.
isWhitespaceChecks if a string contains only whitespace characters.
isIPAddressChecks if a string is an IP address.
isOnlyAlphaChecks if a string contains only alphabetic characters.
isOnlyNumericChecks if a string contains only numeric characters.
isOnlyAlphanumericChecks if a string contains only alphanumeric characters.
isSafeNumberStringChecks if a string represents a safe number.
isEmptyOrWhitespaceChecks if a string is empty or contains only whitespace characters.
isObjectEmptyChecks if an object is empty.
isMimeTypeChecks if a string is a valid MIME type.
isSlugChecks if a string is a URL slug.
isStrongPasswordChecks if a string is a strong password.
isAlphaChecks if a string contains only alphabetic characters.
isAlphaNumericChecks if a string contains only alphanumeric characters.
hasSpecialCharactersChecks if a string contains special characters.
hasUppercaseChecks if a string contains uppercase characters.
hasLowercaseChecks if a string contains lowercase characters.
hasNumericChecks if a string contains numeric characters.
hasWhitespaceChecks if a string contains whitespace characters.
isStringChecks if a value is a string.

Contribution

Contributions are welcome! If you'd like to contribute to utility-validate, please follow these guidelines:

  • Fork the repository on GitHub.
  • Clone your forked repository (git clone https://github.com/blckclov3r/utility-validate).
  • Create a new branch for your changes (git checkout -b your-branch-name).
  • Make your changes.
  • Commit your changes (git commit -am 'Description of your changes').
  • Push your changes to your branch (git push origin your-branch-name).
  • Create a Pull Request on GitHub.

License

MIT © blckclov3r