check-javascript-typescript-validations

Overview
The check-javascript-typescript-validations package offers essential utility functions for validating common data types and performing array operations in JavaScript and TypeScript environments. It simplifies the validation process by providing functions to check email validity, phone number formatting, password strength, and date validity. Additionally, it includes functions to determine the language of a text, check variable emptiness, and verify numeric data types. For array manipulation, the package offers functions to remove duplicates, sort arrays, and both remove duplicates and sort arrays simultaneously. These utilities enhance code quality and reliability by ensuring that data meets specified criteria, contributing to more robust applications and smoother user experiences.
Support on
JavaScript, TypeScript, React JS, React Native , Node JS, Next JS, Nest JS, etc.
Installation
Install the package using npm:
npm install check-javascript-typescript-validations
Install the package using yarn:
yarn add check-javascript-typescript-validations
ValidationFunctions.ts
isValidEmail
This function validates whether an email address is in the correct format.
isValidPhoneNumber
This function validates the format of a phone number, with an optional parameter to specify the required length.
isStrongPassword
This function checks the strength of a password, ensuring it meets specific criteria for complexity.
detectLanguage
This function detects the language of a given text, such as English or Arabic.
isValidDate
This function validates the format and correctness of a date.
variableIsEmpty
This function checks whether a variable is empty or undefined.
checkIsNumber
This function checks if a value is a number.
validateUsername
This function validates a username, ensuring it contains only alphanumeric characters and underscores, and its length is within the specified minimum and maximum range (default: 3–16).
validateURL
This function checks if a given string is a valid URL.
validateCreditCard
This function validates a credit card number using the Luhn algorithm.
validateIndianPAN
This function checks if a given string is a valid Indian PAN (Permanent Account Number) format.
ArrayOperations.ts
removeDuplicatesFromArray
This function removes duplicate elements from an array while preserving the original order.
sortArray
This function sorts the elements of an array in ascending or descending order.
removeAndSortArray
This function removes duplicates from an array and then sorts it, providing a streamlined approach to data manipulation.
differenceOfTwoDates
This function will give you a difference between 2 dates.
Overview
import {
isValidEmail,
deepCloneArray,
variableIsEmpty,
checkIsNumber,
isValidPhoneNumber,
isStrongPassword,
isValidDate,
removeDuplicatesFromArray,
sortArray,
removeDuplicatesAndSortArray,
compareTwoStrings,
differenceOfTwoDates,
detectLanguage,
validateUsername,
validateURL,
validateCreditCard,
validateIndianPAN,
} from "./check-javascript-typescript-validations";
const email = "test@example.com";
console.log(isValidEmail(email));
const text = "مرحبا كيف حالك؟";
console.log(detectLanguage(text));
const originalArray = [{ id: 1 }, { id: 2 }];
console.log(deepCloneArray(originalArray));
const emptyString = "";
console.log(variableIsEmpty(emptyString));
const value = 123;
console.log(checkIsNumber(value));
const phoneNumber = "+1234567890";
console.log(isValidPhoneNumber(phoneNumber));
const password = "Str0ng@Pass";
console.log(isStrongPassword(password));
const date = "2021-10-10";
console.log(isValidDate(date));
const array = [1, 2, 2, 3, 4, 4, 5];
console.log(removeDuplicatesFromArray(array));
const unsortedArray = [5, 3, 8, 1, 2];
console.log(sortArray(unsortedArray));
const arrayWithDuplicates = [5, 3, 8, 1, 2, 3, 5];
console.log(removeDuplicatesAndSortArray(arrayWithDuplicates));
const str1 = "hello";
const str2 = "hello";
console.log(compareTwoStrings(str1, str2));
const startDate = "2024-05-10";
const endDate = "2024-05-20";
console.log(differenceOfTwoDates(startDate, endDate));
const username = "user_name123";
console.log(validateUsername(username));
const url = "https://www.example.com";
console.log(validateURL(url));
const creditCardNumber = "4111111111111111";
console.log(validateCreditCard(creditCardNumber));
const pan = "ABCDE1234F";
console.log(validateIndianPAN(pan));
console.log(checkDataEmptyOrNot([]));
console.log(checkDataEmptyOrNot({}));
console.log(checkDataEmptyOrNot({ a: 1 }));
console.log(checkDataEmptyOrNot(2));
console.log(checkDataEmptyOrNot("abc"));
Keywords
JavaScript, TypeScript, validation, email validation, phone number validation, password strength, date validation, language detection, array operations, remove duplicates, sort array, data validation, utility functions, data types, check empty, number check, compare strings, date difference, npm package, frontend, backend, Node.js, React, Next.js, NestJS