super-simple-validation
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

Installation

$ npm install --save super-simple-validation

or if you prefer yarn

$ yarn add super-simple-validation

Usage

import { isEmail } from "super-simple-validation";

console.log(isEmail("some-email@example.com")); // true

API

is-email

Validates if the given string is an email address.

const valid = isEmail("user@example.com");

console.log(valid); // true

is-url

Validates if the given string is a URL.

const valid = isUrl("https://example.com");

console.log(valid); // true

is-phone

Validates if the given string is a phone number.

const valid = isPhone("+8612345678901");

console.log(valid); // true

is-hex-color

Validates if the given string is a hex color.

const valid = isHexColor("#ffffff");

console.log(valid); // true

is-css-color

Validates if the given string is a CSS color.

const valid =
  isCssColor("rgb(255, 255, 255)") &&
  isCssColor("rgba(255, 255, 255, 1)") &&
  isCssColor("hsl(0, 0%, 100%)") &&
  isCssColor("hsla(0, 0%, 100%, 1)") &&
  isCssColor("hwb(0, 0%, 0%)") &&
  isCssColor("blue") &&
  isCssColor("transparent");

console.log(valid); // true

is-discord-id

Validates if the given string is a Discord ID.

const valid = isDiscordId("973608903801708634");

console.log(valid); // true

is-date-time

Validates if the given string is a date time.

const valid = isDateTime("2021-10-01T00:00:00.000Z");

console.log(valid); // true

is-cc-number

Validates if the given string is a credit card number.

Strings with spaces and dashes are also supported.

Use true in second parameter to validate the the number with the Luhn algorithm. (More info: https://en.wikipedia.org/wiki/Luhn_algorithm)

const valid = isCcNumber("4539 1488 0343 6467");

console.log(valid); // true

// Optionally use true in the second parameter to validate the Luhn algorithm
const validWithLuhn = isCcNumber("4539 1488 0343 6467", true);

console.log(validWithLuhn); // true

is-cc-exp

Validates if the given string is a credit card expiration date.

const valid = isCcExp("10/25");

console.log(valid); // true

is-cc-cvv

Validates if the given string is a credit card CVV.

const valid = isCcCvv("123");

console.log(valid); // true

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.81latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.81
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i super-simple-validation

Weekly Downloads

1

Version

1.0.8

License

MIT

Unpacked Size

31.5 kB

Total Files

29

Last publish

Collaborators

  • lightyagami200