3.3.2 • Published 3 years ago

@techmmunity/easy-check v3.3.2

Weekly downloads
8
License
Apache-2.0
Repository
github
Last release
3 years ago

Techmmunity Easy Check

CodeFactor DeepScan grade Coverage Status tests npm Downloads

All projects that involve programming work with data at some level, and the most worrying thing about that data is its reliability.

If any data on your system is outside the expected and accepted standard, this can generate unforeseen bugs, which will give you a lot of headaches.

With that in mind, we created Techmmunity Easy Check, a simple library that seeks to solve all your problems with validation.

Our main goals with this lib:

  • ZERO dependencies (there's no blind spot, you can see exactly how it's being validated)
  • Extremely intuitive
  • Highly reliable
  • Highly predictable (each method returns true or false, there's no third option)

Guilded Badge

Install

With Yarn:

yarn add @techmmunity/easy-check

With NPM:

npm i @techmmunity/easy-check

Upgrading

2.x > 3.x

The easier way to upgrade to version 3.x, is changing the import method, like this:

// 2.x:
import { check } from "@techmmunity/easy-check";

// 3.x:
import * as check from "@techmmunity/easy-check";

Usage

import { isEmail } from "@techmmunity/easy-check";

if (isEmail("example@email.com")) {
	// ...
}

How to contribute?

All the details about contributing to the project are described here.

Methods - Table Format

Strings

MethodHow To Use
isCPFisCPF("55357314047")
isMaskedCPFisMaskedCPF("553.573.140-47")
isEmailisEmail("example@email.com")
isEmojiisEmoji("😂")
hasEmojishasEmojis("Yes, there is emojis here 😂")
isHerokuApiKeyisHerokuApiKey("625628d3-8a45-466e-a55e-ead5c6886887")
hasHtmlTagshasHtmlTags("Foo <b>Bar</b>")
isIpv4isIpv4("192.168.1.1")
isIpv4WithMaskisIpv4WithMask("192.168.1.1/24")
isStrongPasswordisStrongPassword("$t0ngP@ssw0rD")
isBrazillianPhoneisBrazillianPhone("2199999999")
isUrlisUrl("https://google.com")
hasUrlhasUrl("foo bar https://google.com foo bar")
isSimpleUsernameisSimpleUsername("foo-bar")
isUUIDv4isUUIDv4("24bd85a1-4eb7-4f63-829e-75c08ac2b6c0")

Colors

MethodHow To Use
isDarkHexColorisDarkHexColor("#000000")
isHexColorisHexColor("#000")
isLightHexColorisLightHexColor("#ffffff")

Numbers

MethodHow To Use
isDivisibleByTenisDivisibleByTen(10)
isEvenisEven(2)
isNumericisNUmeric("123")
isOddisOdd(1)

Dates

MethodHow To Use
isDateDMYisDateDMY("31-01-2020")
isDateDMYSisDateDMYS("31/01/2020")
isDateMDYisDateMDY("01-31-2020")
isDateMDYSisDateMDYS("01/31/2020")
isDateYMDisDateYMD("2020-01-31")
isDateYMDSisDateYMDS("2020/01/31")
isLeapisLeap("2020")

Methods - Detailed Description

Strings

isCpf

Check if the string is a CPF (brazzilian federal tax id).

import { isCpf } from "@techmmunity/easy-check";

if (isCpf("55357314047")) {
	// ...
}

isMaskedCpf

Check if the string is a masked CPF (brazzilian federal tax id).

import { isMaskedCpf } from "@techmmunity/easy-check";

if (isMaskedCpf("553.573.140-47")) {
	// ...
}

isEmail

Check if the string is a valid email.

import { isEmail } from "@techmmunity/easy-check";

if (isEmail("example@email.com")) {
	// ...
}

isEmoji

Check if the string is an emoji.

import { isEmoji } from "@techmmunity/easy-check";

if (isEmoji("😂")) {
	// ...
}

hasEmoji

Check if the string has at least one emoji.

import { hasEmoji } from "@techmmunity/easy-check";

if (hasEmoji("Yes, there is emojis here 😂")) {
	// ...
}

isHerokuApiKey

Check if the string is in the heroku api key format.

Alert: This doens't validates if the api key is valid! Only if it's on the correct format.

import { isHerokuApiKey } from "@techmmunity/easy-check";

if (isHerokuApiKey("625628d3-8a45-466e-a55e-ead5c6886887")) {
	// ...
}

hasHtmlTags

Check if the string contains html tags like.

Alert: This doens't validates if the html tags are valid! Only if there is something that look likes a html tag.

import { hasHtmlTags } from "@techmmunity/easy-check";

if (hasHtmlTags("Foo <b>Bar</b>")) {
	// ...
}

isIpv4

Check if the string is a valid ipv4.

import { isIpv4 } from "@techmmunity/easy-check";

if (isIpv4("192.168.1.1")) {
	// ...
}

isIpv4WithMask

Check if the string is a valid ipv4 with mask.

import { isIpv4WithMask } from "@techmmunity/easy-check";

if (isIpv4WithMask("192.168.1.1/24")) {
	// ...
}

isStrongPassword

Check if the string is a strong password.

  • At least 6 characters
  • At most 100 characters
  • At least one Uppercase
  • At least one Lowercase
  • At least one Number
  • At least one of @#$!%\*?&
import { isStrongPassword } from "@techmmunity/easy-check";

if (isStrongPassword("$t0ngP@ssw0rD")) {
	// ...
}

isBrazillianPhone

Check if the string is a valid brazzilian phone.

Alert: It doesn't validates if the phone existis or if it's really valid, just if it's in the correct format, includind validation by DDD.

import { isBrazillianPhone } from "@techmmunity/easy-check";

if (isBrazillianPhone("19999904610")) {
	// ...
}

isUrl

Check if the string is a valid url.

import { isUrl } from "@techmmunity/easy-check";

if (isUrl("https://google.com")) {
	// ...
}

hasUrl

Check if the string has a valid url.

import { hasUrl } from "@techmmunity/easy-check";

if (hasUrl("foo bar https://google.com foo bar")) {
	// ...
}

isSimpleUsername

Check if the string is a valid username.

  • 3 to 16 characters
  • Lower And Upper case allowed
  • Allows only aplhanumeric and - and _
import { isSimpleUsername } from "@techmmunity/easy-check";

if (isSimpleUsername("foo-bar")) {
	// ...
}

isUUIDv4

Check if the string is a valid uuid v4.

import { isUUIDv4 } from "@techmmunity/easy-check";

if (isUUIDv4("24bd85a1-4eb7-4f63-829e-75c08ac2b6c0")) {
	// ...
}

Colors

isDarkHexColor

Check if the string is a dark color in hex format.

import { isDarkHexColor } from "@techmmunity/easy-check";

if (isDarkHexColor("#000") || isDarkHexColor("#000000")) {
	// ...
}

isHexColor

Check if the string is a color in hex format.

import { isHexColor } from "@techmmunity/easy-check";

if (isHexColor("#000") || isHexColor("#000000")) {
	// ...
}

isLightHexColor

Check if the string is a light color in hex format.

import { isLightHexColor } from "@techmmunity/easy-check";

if (isLightHexColor("#fff") || isLightHexColor("#ffffff")) {
	// ...
}

Numbers

isDivisibleByTen

Check if a number is divisible by 10.

import { isDivisibleByTen } from "@techmmunity/easy-check";

if (isDivisibleByTen(10)) {
	// ...
}

isEven

Check if a number is even (divisible by 2).

import { isEven } from "@techmmunity/easy-check";

if (isEven(2)) {
	// ...
}

isNumeric

Check if a istring is made only by numbers

import { isNumeric } from "@techmmunity/easy-check";

if (isNumeric("123")) {
	// ...
}

isOdd

Check if a number is odd (NOT divisible by 2).

import { isOdd } from "@techmmunity/easy-check";

if (isOdd(3)) {
	// ...
}

Dates

isDateDMY

Check if the string is a date in the DD-MM-YYYY format.

Bonus: This validates if it's a valid date too!

import { isDateDMY } from "@techmmunity/easy-check";

if (isDateDMY("31-01-2020")) {
	// ...
}

isDateDMYS

Check if the string is a date in the DD/MM/YYYY format.

Bonus: This validates if it's a valid date too!

import { isDateDMYS } from "@techmmunity/easy-check";

if (isDateDMYS("31/01/2020")) {
	// ...
}

isDateMDY

Check if the string is a date in the MM-DD-YYYY format.

Bonus: This validates if it's a valid date too!

import { isDateMDY } from "@techmmunity/easy-check";

if (isDateMDY("01-31-2020")) {
	// ...
}

isDateMDYS

Check if the string is a date in the MM/DD/YYYY format.

Bonus: This validates if it's a valid date too!

import { isDateMDYS } from "@techmmunity/easy-check";

if (isDateMDYS("01/31/2020")) {
	// ...
}

isDateYMD

Check if the string is a date in the YYYY-MM-DD format.

Bonus: This validates if it's a valid date too!

import { isDateYMD } from "@techmmunity/easy-check";

if (isDateYMD("2020-01-31")) {
	// ...
}

isDateYMDS

Check if the string is a date in the YYYY/MM/DD format.

Bonus: This validates if it's a valid date too!

import { isDateYMDS } from "@techmmunity/easy-check";

if (isDateYMDS("2020/01/31")) {
	// ...
}

isLeap

Check if the string or the number is leap year (year with February 29).

Bonus: This validates if it's a valid year too!

import { isLeap } from "@techmmunity/easy-check";

if (isLeap("2020") || isLeap(2020)) {
	// ...
}
3.3.2

3 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.2.1

3 years ago

3.1.2

3 years ago

3.2.0

3 years ago

3.1.1

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.4.1

3 years ago

2.4.0

3 years ago

2.3.0

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago