@mitchell-sung/functions

1.0.3 • Public • Published

@mitchell-sung/functions

The @mitchell-sung/functions library provides developers with an all-encompassing suite of functions.

Installation

npm install @mitchell-sung/functions

Basic Usage

import { validateUsername } from '@mitchell-sung/functions';

const func_name = () => {
	const inputUsername = 'mitchell@streamdata.com';

	const res = validateUsername(inputUsername);

	console.log('hasError :>> ', res.hasError); // true or false
	console.log('errorMessage :>> ', res.errorMessage); // "Error messages..."
};
var { VALID_MSG } = require('@mitchell-sung/functions');

function func_name() {
	console.log(VALID_MSG.SELECTOR_REQUIRED);
	// Result : "At least one option must be selected."
}

API Documentation

Validations

validateFirstName()
Description This function checks if a given input conforms to the accepted standards for a first name, ensuring it contains only alphabetical characters and no special symbols or numbers.
Param string
Return { hasError: boolean, errorMessage: string }
Throws TypeError
validateLastName()
Description This function checks if a given input conforms to the accepted standards for a last name, ensuring it contains only alphabetical characters and no special symbols or numbers.
Param string
Return { hasError: boolean, errorMessage: string }
Throws TypeError
validateUsername()
Description This function checks if a given input adheres to the prescribed criteria for usernames, such as length, allowed characters, and the absence of prohibited symbols.
Param string
Return { hasError: boolean, errorMessage: string }
Throws TypeError
validateEmail()
Description This function checks if a given input is a valid email address by verifying its format and structure.
Param string
Return { hasError: boolean, errorMessage: string }
Throws TypeError
validatePhone()
Description This function checks if a given input matches the standard format for phone numbers, ensuring it contains the correct number of digits and accepted symbols, if any.
Param string
Return { hasError: boolean, errorMessage: string }
Throws TypeError
validatePassword()
Description This function checks if a given input meets the specified criteria for strong passwords, such as minimum length, inclusion of uppercase and lowercase letters, numbers, and special symbols.
Param string
Return { hasError: boolean, errorMessage: string }
Throws TypeError
handleValidation()
Description This function returns an object that contains hasError and errorMessage.
Param1 boolean
Param2 string
Return { hasError: boolean, errorMessage: string }
Throws TypeError
isAlphabetOnly()
Description Check if the input value contains only alphabetic characters.
Param string
Return boolean
Throws TypeError
isNumberOnly()
Description Check if the input value contains only numberic characters.
Param string
Return boolean
Throws TypeError
trimAndGetStringLength()
Description This function trims any leading and trailing white space from a string and then returns its length.
Param string
Return { trimmedValue: string, valueLen: number }
Throws TypeError

CheckTypes

checkBoolType()
Description This function verifies if the provided input is not of boolean type, throw TypeError
Param * any
Return void
Throws TypeError
checkStringType()
Description This function verifies if the provided input is not of string type, throw TypeError
Param * any
Return void
Throws TypeError

Contants

VALID_MSG
Name Description
FIRSTNAME_LENGTH First name must be minimum number characters and maximum number characters.
LASTNAME_LENGTH Last name must be minimum number characters and maximum number characters.
CONSECUTIVE_SPACES Multiple consecutive spaces are not allowed.
NAME_INVALID_SYMBOL Invalid characters detected. Only alphabets and the symbols ",", "-", and "\'" are allowed.
EMAIL_LENGTH Email must be minimum number characters and maximum number characters.
EMAIL_FORMAT Invalid email format. (ex, text@gmail.com)
USERNAME_LENGTH Username must be minimum number characters and maximum number characters.
USERNAME_SYMBOL Only allow dot, dash, underbar, and at sign.
USERNAME_SPACE No space is allowed.
PASSWORD_LENGTH Password must be minimum number characters and maximum number characters.
PASSWORD_UPPERCASE Password must be minimum 1 uppercase letter.
PASSWORD_LOWERCASE Password must be minimum 1 lowercase letter.
PASSWORD_NUMBER Password must be minimum 1 number.
PASSWORD_SYMBOL Password must be minimum 1 symbol.
PASSWORD_MISMATCH Password and confirmation password fields do not match.
PASSWORD_ORDER Please enter the password before confirmation password field.
REQUIRED This information is required.
PHONE_NUMBER_LENGTH Please enter a number-digit number without the country code.
PHONE_NUMBER_ONLY_DIGITS Phone numbers should only contain digits, not letters.
PHONE_COUNTRY_CODE_ONLY_LETTERS Phone country code should only contain letters, not digits.
PHONE_DIAL_CODE_ONLY_DIGITS Phone country dial code should only contain digits, not letters.
PHONE_EXTENSION_ONLY_DIGITS Phone extension numbers should only contain digits, not letters.
SELECTOR_REQUIRED At least one option must be selected.

Readme

Keywords

none

Package Sidebar

Install

npm i @mitchell-sung/functions

Weekly Downloads

0

Version

1.0.3

License

ISC

Unpacked Size

43.2 kB

Total Files

25

Last publish

Collaborators

  • mitchell-sung