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

check-javascript-typescript-validations

v1.0.11

Published

To check all the validations related to javascript and typescript.

Downloads

19

Readme

check-javascript-typescript-validations

npm version license

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.

isValidDate
This function validates the format and correctness of a date.

isTextArabic
This function determines whether a text string is in Arabic.

isTextEnglish
This function determines whether a text string is in English.

variableIsEmpty
This function checks whether a variable is empty or undefined.

checkIsNumber
This function checks if a value is a number.

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,
    isTextArabic,
    isTextEnglish,
    checkIsNumber,
    isValidPhoneNumber,
    isStrongPassword,
    isValidDate,
    removeDuplicatesFromArray,
    sortArray,
    removeDuplicatesAndSortArray,
    compareTwoStrings,
    differenceOfTwoDates
} from './check-javascript-typescript-validations';

// Example usage of isValidEmail
const email = "[email protected]";
console.log(isValidEmail(email)); // true

// Example usage of deepCloneArray
const originalArray = [{ id: 1 }, { id: 2 }]; 
console.log(deepCloneArray(originalArray)); // [{ id: 1 }, { id: 2 }]

// Example usage of variableIsEmpty
const emptyString = "";
console.log(variableIsEmpty(emptyString)); // true

// Example usage of isTextArabic
const arabicText = "مرحبا";
console.log(isTextArabic(arabicText)); // true

// Example usage of isTextEnglish
const englishText = "Hello";
console.log(isTextEnglish(englishText)); // true

// Example usage of checkIsNumber
const value = 123;
console.log(checkIsNumber(value)); // true

// Example usage of isValidPhoneNumber
const phoneNumber = "+1234567890";
console.log(isValidPhoneNumber(phoneNumber)); // true

// Example usage of isStrongPassword
const password = "Str0ng@Pass";
console.log(isStrongPassword(password)); // true

// Example usage of isValidDate
const date = "2021-10-10";
console.log(isValidDate(date)); // true

// Example usage of removeDuplicatesFromArray
const array = [1, 2, 2, 3, 4, 4, 5];
console.log(removeDuplicatesFromArray(array)); // [1, 2, 3, 4, 5]

// Example usage of sortArray
const unsortedArray = [5, 3, 8, 1, 2]; 
console.log(sortArray(unsortedArray)); // [1, 2, 3, 5, 8]

// Example usage of removeDuplicatesAndSortArray
const arrayWithDuplicates = [5, 3, 8, 1, 2, 3, 5]; 
console.log(removeDuplicatesAndSortArray(arrayWithDuplicates)); // [1, 2, 3, 5, 8]

// Example usage of compareTwoStrings
const str1 = "hello";
const str2 = "hello";
console.log(compareTwoStrings(str1, str2)); // true

// Example of  differenceOfTwoDates
const startDate = "2024-05-10"; // Start date format will be  *** YYYY-MM-DD ***
const endDate = "2024-05-20"; // End date format will be  *** YYYY-MM-DD ***
console.log(differenceOfTwoDates(startDate, endDate)); // {  days: 10 ,hours: 0, minutes: 0, seconds: 0 }

console.log(checkDataEmptyOrNot([])) // true <-  Empty
console.log(checkDataEmptyOrNot({})) // true <-  Empty
console.log(checkDataEmptyOrNot({a:1})) // false <- not Empty
console.log(checkDataEmptyOrNot(2)) // false <- not Empty
console.log(checkDataEmptyOrNot("abc")) // false <- not Empty